[rt-users] Staffan Larsen's Attachements in correspondence
Ashley Gould
agould at aslab.com
Fri Nov 9 19:49:41 EST 2001
I'm trying to use Staffan Larsen's package
RT::Action::NotifyWithAttachment Which enables sending attachements from
within RT. I just don't have the grasp of using perl objects well
enough to see how this plugs in. I've inclused the pm and some comments
about it below.
What I don't get is Where in RT would the call to
NotifyWithAttachment::Prepare take place. Which module
calls Prepare or imports NotifyWithAttachment? Or what?
Basically, how do I make this work?
This is in 2.0.8
ashley
Subject: Re: [rt-users] Attachements in correspondence
> looking at RT::Action::Notify, I see it ISA RT::Action::SendMessage.
> SendMessage has a bunch of methods and it looks as if the Commit()
method
> actually pulls the parts together and creates the message. Am I on
the right
> track to override RT::Action::Notify::Commit() to put together the
> appropriate MIME headers and attach the content from some parts of the
> $self object? Not being a Mason hack, I'm not sure from where I'd
> pull the CGI upload contents here.
>
You're right that Notify ISA SendMessage. You actually want to override
Prepare. (If Prepare succeeds, the scrips system calls Commit).
So, create NotifyWithAttachments.
set a sub Prepare that
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.)
is that enough to get going?
------
Thanks for getting me going, Jesse. Attached is an implementation of
your
ideas. My knowledge of RT in particular and Perl in general is not what
it should be so please take a look for any obvious errors. I have run
this sucessfully with RT 2.0.7.
Regards,
/Staffan Larsen
# Includes transaction attachments in email sent out.
# Author: Staffan Larsen (staffan_larsen at appeal_se (replace all _))
# Idea: Jesse Vincent (jesse at bestpractical.com)
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;
my $cnt = $attachments->Count;
$RT::Logger->debug("$self: Adding $cnt 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,
Disposisiton => "attachment",
Filename => $fname);
}
return 1;
}
# }}}
More information about the rt-users
mailing list