[rt-users] Attachements in correspondence

Staffan Larsen larsen at appeal.se
Mon Oct 15 09:46:20 EDT 2001


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

Jesse Vincent wrote:
> 
> > Obviously, at least one other person on this list seems to think it
> > would send the attachment with the response.
> 
> *nod*  We've actually had this one a few times before, too.  This addition
> would be useful for more than just web updates, but also to send out attachments
> that come in as part of MIME encoded mail messages.
> 
> I want this behaviour as well, It's just not high on my list. But I'd definitely
> be happy to help you out making it go.
> 
> > 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?
> 
> > _______________________________________________
> > rt-users mailing list
> > rt-users at lists.fsck.com
> > http://lists.fsck.com/mailman/listinfo/rt-users
> >
> 
> --
> http://www.bestpractical.com/products/rt  -- Trouble Ticketing. Free.
> 
> _______________________________________________
> rt-users mailing list
> rt-users at lists.fsck.com
> http://lists.fsck.com/mailman/listinfo/rt-users

--
Appeal Virtual Machines - Makers of JRockit
http://www.jrockit.com/
-------------- 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)

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;
}

# }}}


1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: insert_action.pl
Type: application/x-perl
Size: 1804 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20011015/34bb36c9/attachment.bin>


More information about the rt-users mailing list