[Rt-commit] rt branch, 4.0/rfc822-attachment, updated. rt-4.0.0-219-gf889cbb
Thomas Sibley
trs at bestpractical.com
Thu May 12 18:44:58 EDT 2011
The branch, 4.0/rfc822-attachment has been updated
via f889cbb350deda1e20af8be720cc5ebe5a60bfbc (commit)
via 0f916e34bbede7dcddd5e2b3e341a99faac65bf4 (commit)
via 6a65e7e6a04dcc0f635be9ad8d060a20a764d536 (commit)
via d34fd4b7a7183e48eb61f142480348d4162f5b72 (commit)
via ce28b2a95e18362d27c1a1f0336b2fc9c1e0d970 (commit)
via 11c0d5d840e331e9fb1d3dd48c3d535a83e7666e (commit)
from 6742ab2bb746ef812f354a9a1eabc0e94861f8f5 (commit)
Summary of changes:
lib/RT/Attachment.pm | 17 +++++++++++++-
lib/RT/Interface/Email.pm | 11 +++-----
lib/RT/Transaction.pm | 46 ++++++++++--------------------------
t/web/ticket_forward.t | 56 +++++++++++++++++++++++++++++++-------------
4 files changed, 72 insertions(+), 58 deletions(-)
- Log -----------------------------------------------------------------
commit 11c0d5d840e331e9fb1d3dd48c3d535a83e7666e
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:18:03 2011 -0400
Rework both ContentAsMIME methods to reconstruct the original message
RT::Attachment->ContentAsMIME now takes a Children parameter indicating
whether it should recursively add all children or not to the MIME
entity.
RT::Transaction->ContentAsMIME is simplified to iterate over all of the
top level transaction's attachments in original order and add each as a
part.
t/web/ticket_forward.t is passing for now, but
t/mail/rfc822-attachment.t still fails.
diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 7fc9aba..1196850 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -419,14 +419,21 @@ sub Quote {
return (\$body, $max);
}
-=head2 ContentAsMIME
+=head2 ContentAsMIME [Children => 1]
Returns MIME entity built from this attachment.
+If the optional parameter C<Children> is set to a true value, the children are
+recursively added to the entity.
+
=cut
sub ContentAsMIME {
my $self = shift;
+ my %opts = (
+ Children => 0,
+ @_
+ );
my $entity = MIME::Entity->new();
foreach my $header ($self->SplitHeaders) {
@@ -444,6 +451,14 @@ sub ContentAsMIME {
MIME::Body::Scalar->new( $self->OriginalContent )
);
+ if ($opts{'Children'}) {
+ my $children = $self->Children;
+ while (my $child = $children->Next) {
+ $entity->make_multipart unless $entity->is_multipart;
+ $entity->add_part( $child->ContentAsMIME(%opts) );
+ }
+ }
+
return $entity;
}
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 2baccc2..2f14487 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -549,44 +549,21 @@ sub _Attach {
sub ContentAsMIME {
my $self = shift;
- my $main_content = $self->ContentObj;
- return unless $main_content;
-
- my $entity = $main_content->ContentAsMIME;
-
- if ( $main_content->Parent ) {
- # main content is not top most entity, we shouldn't loose
- # From/To/Cc headers that are on a top part
- my $attachments = RT::Attachments->new( $self->CurrentUser );
- $attachments->Columns(qw(id Parent TransactionId Headers));
- $attachments->Limit( FIELD => 'TransactionId', VALUE => $self->id );
- $attachments->Limit( FIELD => 'Parent', VALUE => 0 );
- $attachments->Limit( FIELD => 'Parent', OPERATOR => 'IS', VALUE => 'NULL', QUOTEVALUE => 0 );
- $attachments->OrderBy( FIELD => 'id', ORDER => 'ASC' );
- my $tmp = $attachments->First;
- if ( $tmp && $tmp->id ne $main_content->id ) {
- $entity->make_multipart;
- $entity->head->add( split /:/, $_, 2 ) foreach $tmp->SplitHeaders;
- $entity->make_singlepart;
- }
- }
+ return unless $self->CurrentUserCanSee;
+
+ my $entity = MIME::Entity->build(
+ Type => 'multipart/mixed',
+ Description => 'transaction ' . $self->Id,
+ );
my $attachments = RT::Attachments->new( $self->CurrentUser );
+ $attachments->OrderBy( FIELD => 'id', ORDER => 'ASC' );
$attachments->Limit( FIELD => 'TransactionId', VALUE => $self->id );
- $attachments->Limit(
- FIELD => 'id',
- OPERATOR => '!=',
- VALUE => $main_content->id,
- );
- $attachments->Limit(
- FIELD => 'ContentType',
- OPERATOR => 'NOT STARTSWITH',
- VALUE => 'multipart/',
- );
- $attachments->LimitNotEmpty;
+ $attachments->Limit( FIELD => 'Parent', VALUE => 0 );
+
while ( my $a = $attachments->Next ) {
$entity->make_multipart unless $entity->is_multipart;
- $entity->add_part( $a->ContentAsMIME );
+ $entity->add_part( $a->ContentAsMIME(Children => 1) );
}
return $entity;
}
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index bd13f40..5192d00 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -175,7 +175,7 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
my $ticket = RT::Test->create_ticket(
Queue => 1,
- Subject => 'test foward, attachments but no "content"',
+ Subject => 'test forward, attachments but no "content"',
MIMEObj => $mime,
);
@@ -186,6 +186,7 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
$m->content_like( qr/image\/png/, 'uploaded image file content type' );
RT::Test->clean_caught_mails;
+ # Forward txn
$m->follow_link_ok( { text => 'Forward', n => 2 }, 'follow 2nd Forward' );
$m->submit_form(
form_name => 'ForwardMessage',
@@ -196,15 +197,34 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
);
$m->content_contains( 'Send email successfully', 'sent mail msg' );
$m->content_like( qr/Forwarded Transaction #\d+ to rt-test\@example\.com/, 'txn msg' );
- my ($mail) = RT::Test->fetch_caught_mails;
- like( $mail, qr/Subject: test foward, attachments but no "content"/, 'Subject field' );
- like( $mail, qr/To: rt-test\@example.com/, 'To field' );
- like( $mail, qr/This is a forward of transaction/, 'content' );
- like( $mail, qr/awesome\.patch/, 'att file name' );
- like( $mail, qr/this is an attachment/, 'att content' );
- like( $mail, qr/text\/x-diff/, 'att content type' );
- like( $mail, qr/bpslogo\.png/, 'att image file name' );
- like( $mail, qr/image\/png/, 'att image content type' );
+
+ # Forward ticket
+ $m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
+ $m->submit_form(
+ form_name => 'ForwardMessage',
+ fields => {
+ To => 'rt-test at example.com',
+ },
+ button => 'ForwardAndReturn'
+ );
+ $m->content_contains( 'Send email successfully', 'sent mail msg' );
+ $m->content_like( qr/Forwarded Ticket to rt-test\@example\.com/, 'txn msg' );
+
+ my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
+ my $tag = qr/Fwd: \[example\.com #\d+\]/;
+ like( $forward_txn, qr/Subject: $tag attachments for everyone/, 'Subject field is from txn' );
+ like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
+ like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
+ like( $forward_ticket, qr/This is a forward of ticket/, 'forward description' );
+
+ for my $mail ($forward_txn, $forward_ticket) {
+ like( $mail, qr/To: rt-test\@example.com/, 'To field' );
+ like( $mail, qr/awesome\.patch/, 'att file name' );
+ like( $mail, qr/this is an attachment/, 'att content' );
+ like( $mail, qr/text\/x-diff/, 'att content type' );
+ like( $mail, qr/bpslogo\.png/, 'att image file name' );
+ like( $mail, qr/image\/png/, 'att image content type' );
+ }
}
undef $m;
commit ce28b2a95e18362d27c1a1f0336b2fc9c1e0d970
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:35:44 2011 -0400
Explain why we check ACLs here
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 2f14487..177d8d9 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -549,6 +549,9 @@ sub _Attach {
sub ContentAsMIME {
my $self = shift;
+ # RT::Attachments doesn't limit ACLs as strictly as RT::Transaction does
+ # since it has less information available without looking to it's parent
+ # transaction. Check ACLs here before we go any further.
return unless $self->CurrentUserCanSee;
my $entity = MIME::Entity->build(
commit d34fd4b7a7183e48eb61f142480348d4162f5b72
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:38:05 2011 -0400
Transactions are messages, so use an appropriate content type
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 177d8d9..c9d816d 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -555,7 +555,7 @@ sub ContentAsMIME {
return unless $self->CurrentUserCanSee;
my $entity = MIME::Entity->build(
- Type => 'multipart/mixed',
+ Type => 'message/rfc822',
Description => 'transaction ' . $self->Id,
);
commit 6a65e7e6a04dcc0f635be9ad8d060a20a764d536
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:42:53 2011 -0400
Rather than bury the forward one level deeper, just add it as a top level part
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 3561805..ab42e2e 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -739,12 +739,8 @@ sub SendForward {
$mail->head->set( $_ => EncodeToMIME( String => $args{$_} ) )
foreach grep defined $args{$_}, qw(To Cc Bcc);
- $mail->attach(
- Type => 'message/rfc822',
- Disposition => 'attachment',
- Description => 'forwarded message',
- Data => $entity->as_string,
- );
+ $mail->make_multipart unless $mail->is_multipart;
+ $mail->add_part( $entity );
my $from;
my $subject = '';
commit 0f916e34bbede7dcddd5e2b3e341a99faac65bf4
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:43:48 2011 -0400
Add a description to the MIME entity representing the forwarded ticket
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index ab42e2e..5842306 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -651,7 +651,8 @@ sub ForwardTicket {
) for qw(Create Correspond);
my $entity = MIME::Entity->build(
- Type => 'multipart/mixed',
+ Type => 'multipart/mixed',
+ Description => 'forwarded ticket',
);
$entity->add_part( $_ ) foreach
map $_->ContentAsMIME,
commit f889cbb350deda1e20af8be720cc5ebe5a60bfbc
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu May 12 18:44:35 2011 -0400
Setup our test attachments with a disposition of attachment rather than inline
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index 5192d00..4fd3e91 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -161,16 +161,18 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
);
$mime->attach(
- Path => $att_file,
- Type => 'text/x-diff',
- Filename => 'awesome.patch',
+ Path => $att_file,
+ Type => 'text/x-diff',
+ Filename => 'awesome.patch',
+ Disposition => 'attachment',
);
$mime->attach(
- Path => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'),
- Type => 'image/png',
- Filename => 'bpslogo.png',
- Encoding => 'base64',
+ Path => RT::Test::get_relocatable_file('bpslogo.png', '..', 'data'),
+ Type => 'image/png',
+ Filename => 'bpslogo.png',
+ Encoding => 'base64',
+ Disposition => 'attachment',
);
my $ticket = RT::Test->create_ticket(
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list