[rt-users] Attachments sent from RT are 'inline'
Lynoure Rajamäki
lynoure at otaverkko.fi
Fri Jan 3 02:08:10 EST 2003
On Thu, 2003-01-02 at 16:09, Douglas E. Warner wrote:
>
> Yes, I'm using the one from the contrib area. Would you mind attaching it to
> the list so everyone can benefit?
Ok, though my version is by no means perfect either (I took the shortcut
and set Content-Type to fit our needs, and it's not right for all other
character sets). Also, I am very new to perl...
--
Lynoure Rajamäki
lynoure at otaverkko.fi
lynoure at tuug.fi
-------------- next part --------------
# Includes transaction attachments in email sent out.
# Author: Staffan Larsen (staffan_larsen at appeal_se (replace all _))
# Idea: Jesse Vincent (jesse at bestpractical.com)
# some changes by Lynoure Rajamaki (lynoure at tuug.fi)
package RT::Action::NotifyWithAttachment;
require RT::Action::SendEmail;
require RT::Action::Notify;
@ISA = qw(RT::Action::Notify);
# {{{ sub Prepare
=head2 Prepare
From email from Jesse:
calls SUPER::Prepare.
if that returns true, iterate through
$self->TransactionObj->Attachments and add them to
$self->TemplateObj->MIMEObj.
(TransactionObj is an RT::Transaction object which already has
all of this transaction.s attachments already attached.
MIMEObj is a MIME::Entity.)
=cut
sub Prepare {
my $self = shift;
$self->SUPER::Prepare() || return 0;
my $attachments = $self->TransactionObj->Attachments;
$attachments->GotoFirstItem;
#If you want to track what's going on, use the line below.
# $RT::Logger->debug($self->TemplateObj->MIMEObj->stringify);
#Entity is made multipart so that we can get rid of the body
#and make sure that it will behave nicely with the attachments
$self->TemplateObj->MIMEObj->make_multipart;
#We'll delete all of the parts to get rid of the body
@keep = ();
$self->TemplateObj->MIMEObj->parts(\@keep);
#Adding the ex-body manually
my $textpart = $self->TransactionObj->Content;
$RT::Logger->debug("$self: Attaching transaction content.\n");
#Your encoding might vary.
$self->TemplateObj->MIMEObj->attach(Data => $textpart,
Type => "text/plain",
Encoding => "8bit",
Disposition => "inline");
my $cnt = $attachments->Count;
my $toaddcnt = $cnt-2;
if ($toaddcnt < 0) {
$toaddcnt = 0};
$RT::Logger->debug("$self: Adding $toaddcnt atts.\n");
# skip the first one, it is already attached
# Why do I have to skip two?
$attachments->GotoItem(2);
while (my $message=$attachments->Next) {
next unless ($message->Content);
my $fname = $message->Filename;
$fname =~ s/.*(\\|\/)//g;
$RT::Logger->debug("$self: Adding attachment $fname.\n");
$self->TemplateObj->MIMEObj->attach(Data => $message->Content,
Type => $message->ContentType,
Encoding => 'base64',
Description => $fname,
Disposition => 'attachment',
Filename => $fname);
}
return 1;
}
# }}}
1;
More information about the rt-users
mailing list