5 use RT::Test tests => 23;
7 plan skip_all => 'GnuPG required.'
8 unless eval 'use GnuPG::Interface; 1';
9 plan skip_all => 'gpg executable is required.'
10 unless RT::Test->find_executable('gpg');
12 use Digest::MD5 qw(md5_hex);
14 use File::Temp qw(tempdir);
15 my $homedir = tempdir( CLEANUP => 1 );
17 # catch any outgoing emails
18 RT::Test->set_mail_catcher;
20 RT->Config->Set( 'GnuPG',
22 OutgoingMessagesFormat => 'RFC' );
24 RT->Config->Set( 'GnuPGOptions',
26 'passphrase' => 'rt-test',
27 'no-permission-warning' => undef);
29 RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' );
31 RT::Test->import_gnupg_key('rt-recipient@example.com');
32 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
34 my ($baseurl, $m) = RT::Test->started_ok;
36 ok( $m->login, 'we did log in' );
38 # configure key for General queue
40 $m->get( $baseurl.'/Admin/Queues/');
41 $m->follow_link_ok( {text => 'General'} );
44 fields => { CorrespondAddress => 'rt-recipient@example.com' },
46 $m->content_like(qr/rt-recipient\@example.com.* - never/, 'has key info.');
49 ok(my $user = RT::User->new($RT::SystemUser));
50 ok($user->Load('root'), "Loaded user 'root'");
51 $user->SetEmailAddress('recipient@example.com');
54 Principal => 'Everyone',
55 Right => ['CreateTicket'],
59 my $id = send_via_mailgate('quoted_inline_signature.txt');
61 my $tick = RT::Ticket->new( $RT::SystemUser );
63 ok ($tick->id, "loaded ticket #$id");
65 my $txn = $tick->Transactions->First;
66 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
68 is( $msg->GetHeader('X-RT-Privacy'),
70 "no privacy is set as this ticket is not encrypted"
73 my @mail = RT::Test->fetch_caught_mails;
74 is(scalar @mail, 1, "autoreply only");
78 my $id = send_via_mailgate('binary-asc-attach-marked-plain-text.txt');
80 my $tick = RT::Ticket->new( $RT::SystemUser );
82 ok ($tick->id, "loaded ticket #$id");
84 my $txn = $tick->Transactions->First;
85 my ($msg, @attachs) = @{$txn->Attachments->ItemsArrayRef};
87 is (scalar @attachs, 3, 'text, attachment and original');
88 my $bin = $attachs[1];
90 (split /;/, $bin->GetHeader('Content-Type'))[0],
91 'application/octet-stream',
94 is(md5_hex($bin->Content), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "correct png");
98 my $id = send_via_mailgate('inline-binary-attachment-with-wrap.txt');
100 my $tick = RT::Ticket->new( $RT::SystemUser );
102 ok ($tick->id, "loaded ticket #$id");
104 my $txn = $tick->Transactions->First;
105 my ($msg, @attachs) = @{$txn->Attachments->ItemsArrayRef};
107 is (scalar @attachs, 3, 'text, attachment and original');
108 my $bin = $attachs[1];
110 (split /;/, $bin->GetHeader('Content-Type'))[0],
111 'application/octet-stream',
114 is(md5_hex($bin->Content), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "correct png");
117 sub send_via_mailgate {
119 my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
120 qw(data gnupg emails special));
121 my $file = File::Spec->catfile( $emaildatadir, $fname );
122 my $mail = RT::Test->file_content($file);
124 my ($status, $id) = RT::Test->send_via_mailgate($mail);
125 is ($status >> 8, 0, "the mail gateway exited normally");
126 ok ($id, "got id of a newly created ticket - $id");