rt 4.0.23
[freeside.git] / rt / t / api / emailparser.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 11;
6
7 ok(require RT::EmailParser);
8
9 RT->Config->Set( RTAddressRegexp => undef );
10 is(RT::EmailParser::IsRTAddress("",""),undef, "Empty emails from users don't match queues without email addresses" );
11
12 RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
13
14 is(RT::EmailParser::IsRTAddress("","rt\@example.com"),1, "Regexp matched rt address" );
15 is(RT::EmailParser::IsRTAddress("","frt\@example.com"),undef, "Regexp didn't match non-rt address" );
16
17 my @before = ("rt\@example.com", "frt\@example.com");
18 my @after = ("frt\@example.com");
19 ok(eq_array(RT::EmailParser->CullRTAddresses(@before),@after), "CullRTAddresses only culls RT addresses");
20
21 {
22     require RT::Interface::Email;
23     my ( $addr, $name ) =
24       RT::Interface::Email::ParseAddressFromHeader('foo@example.com');
25     is( $addr, 'foo@example.com', 'addr for foo@example.com' );
26     is( $name, undef,             'no name for foo@example.com' );
27
28     ( $addr, $name ) =
29       RT::Interface::Email::ParseAddressFromHeader('Foo <foo@example.com>');
30     is( $addr, 'foo@example.com', 'addr for Foo <foo@example.com>' );
31     is( $name, 'Foo',             'name for Foo <foo@example.com>' );
32
33     ( $addr, $name ) =
34       RT::Interface::Email::ParseAddressFromHeader('foo@example.com (Comment)');
35     is( $addr, 'foo@example.com', 'addr for foo@example.com (Comment)' );
36     is( $name, undef,             'no name for foo@example.com (Comment)' );
37 }
38