File: email-file-attachments.t

package info (click to toggle)
request-tracker4 4.4.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,888 kB
  • sloc: javascript: 130,444; perl: 65,442; sh: 1,350; makefile: 480; python: 37; php: 30
file content (77 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use strict;
use warnings;

use RT::Test tests => undef,
    config => 'Set( $TreatAttachedEmailAsFiles, 1);'
;

use File::Spec ();
use Email::Abstract;

# We're not testing acls here.
my $everyone = RT::Group->new(RT->SystemUser);
$everyone->LoadSystemInternalGroup('Everyone');
$everyone->PrincipalObj->GrantRight( Right =>'SuperUser' );

# some utils
sub first_txn    { return $_[0]->Transactions->First }
sub count_attachs { return first_txn($_[0])->Attachments->Count }

sub mail_in_ticket {
    my ($filename) = @_;
    my $path = RT::Test::get_relocatable_file($filename,
        (File::Spec->updir(), 'data', 'emails'));
    my $content = RT::Test->file_content($path);

    RT::Test->clean_caught_mails;
    my ($status, $id) = RT::Test->send_via_mailgate( $content );
    ok( !$status, "Fed $filename into mailgate");

    my $ticket = RT::Ticket->new(RT->SystemUser);
    $ticket->Load($id);
    ok( $ticket->Id, "Successfully created ticket ".$ticket->Id);

    my @mail = map {Email::Abstract->new($_)->cast('MIME::Entity')}
        RT::Test->fetch_caught_mails;
    return ($ticket, @mail);
}

diag "Process email with an email file attached";
{
    my ($ticket) = mail_in_ticket('email-file-attachment.eml');
    like( first_txn($ticket)->Content , qr/This is a test with an email file attachment/, "Parsed the email body");
    is( count_attachs($ticket), 3,
        "Has three attachments, presumably multipart/mixed, text-plain, message");

    my $attachments = $ticket->Transactions->First->Attachments;

    my $attachment = $attachments->Next;
    is( $attachment->Subject, 'This is a test', 'Subject is correct' );

    $attachment = $attachments->Next;
    is( $attachment->ContentType, 'text/plain', 'Got the first part of the main email' );

    $attachment = $attachments->Next;
    is( $attachment->Filename, 'test-email.eml', 'Got a filename for the attached email file' );
}

diag "Process email with a multipart email file attached";
{
    my ($ticket) = mail_in_ticket('email-file-attachment-2.eml');
    like( first_txn($ticket)->Content , qr/This is a test with a multipart email file attachment/, "Parsed the email body");
    is( count_attachs($ticket), 3,
        "Has three attachments, presumably multipart/mixed, text-plain, message");

    my $attachments = $ticket->Transactions->First->Attachments;

    my $attachment = $attachments->Next;
    is( $attachment->Subject, 'This is another test', 'Subject is correct' );

    $attachment = $attachments->Next;
    is( $attachment->ContentType, 'text/plain', 'Got the first part of the main email' );

    $attachment = $attachments->Next;
    is( $attachment->Filename, 'test-email-2.eml', 'Got a filename for the attached email file' );
}

done_testing();