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