[Rt-commit] rt branch, 4.0/preserve-content-disposition, created. rt-4.0.4-184-g8cbcb67
Thomas Sibley
trs at bestpractical.com
Fri Jan 13 13:04:20 EST 2012
The branch, 4.0/preserve-content-disposition has been created
at 8cbcb67b311914174b70d57b7e428cd7f4cf471c (commit)
- Log -----------------------------------------------------------------
commit 8cbcb67b311914174b70d57b7e428cd7f4cf471c
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Jan 13 11:40:59 2012 -0500
Preserve the dispositions of attachments when redistributing mail
Use the original Content-Disposition if there is one, otherwise let
MIME::Entity default to inline.
MIME::Entity->build (used by ->attach) defaults to an inline disposition
if none is specified. This had the affect of mutating all incoming
parts with an attachment disposition into inline content when RT
redistributed it to watchers.
diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index ad1136f..e2aa00b 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -408,11 +408,16 @@ sub AddAttachment {
my $attach = shift;
my $MIMEObj = shift || $self->TemplateObj->MIMEObj;
+ # ->attach expects just the disposition type; extract it if we have the header
+ my $disp = ($attach->GetHeader('Content-Disposition') || '')
+ =~ /^\s*(inline|attachment)/i ? $1 : undef;
+
$MIMEObj->attach(
- Type => $attach->ContentType,
- Charset => $attach->OriginalEncoding,
- Data => $attach->OriginalContent,
- Filename => $self->MIMEEncodeString( $attach->Filename ),
+ Type => $attach->ContentType,
+ Charset => $attach->OriginalEncoding,
+ Data => $attach->OriginalContent,
+ Disposition => $disp, # a false value defaults to inline in MIME::Entity
+ Filename => $self->MIMEEncodeString( $attach->Filename ),
'RT-Attachment:' => $self->TicketObj->Id . "/"
. $self->TransactionObj->Id . "/"
. $attach->id,
diff --git a/t/mail/disposition-outgoing.t b/t/mail/disposition-outgoing.t
new file mode 100644
index 0000000..06295a0
--- /dev/null
+++ b/t/mail/disposition-outgoing.t
@@ -0,0 +1,69 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue->id, 'loaded queue';
+
+my ($ok, $msg) = $queue->AddWatcher(
+ Type => 'AdminCc',
+ Email => 'test at example.com',
+);
+ok $ok, $msg;
+
+my $mail = <<'.';
+From: root at localhost
+Subject: I like inline dispositions and I cannot lie
+Content-type: multipart/related; boundary="foo"
+
+--foo
+Content-type: text/plain; charset="UTF-8"
+
+ho hum just some text
+
+--foo
+Content-type: text/x-patch; name="filename.patch"
+Content-disposition: inline; filename="filename.patch"
+
+a fake patch
+
+--foo
+.
+
+# inline
+{
+ my $rt = send_and_receive($mail);
+ like $rt, qr/Content-Disposition:\s*inline.+?filename\.patch/is, 'found inline disposition';
+}
+
+# attachment
+{
+ $mail =~ s/(?<=Content-disposition: )inline/attachment/i;
+
+ my $rt = send_and_receive($mail);
+ like $rt, qr/Content-Disposition:\s*attachment.+?filename\.patch/is, 'found attachment disposition';
+}
+
+# no disposition
+{
+ $mail =~ s/^Content-disposition: .+?\n(?=\n)//ism;
+
+ my $rt = send_and_receive($mail);
+ like $rt, qr/Content-Disposition:\s*inline.+?filename\.patch/is, 'found default (inline) disposition';
+}
+
+sub send_and_receive {
+ my $mail = shift;
+ my ($stat, $id) = RT::Test->send_via_mailgate($mail);
+ is( $stat >> 8, 0, "The mail gateway exited normally" );
+ ok( $id, "created ticket" );
+
+ my @mails = RT::Test->fetch_caught_mails;
+ is @mails, 2, "got 2 outgoing emails";
+
+ # first is autoreply
+ pop @mails;
+}
+
+done_testing;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list