[Rt-devel] Re: [PATCH] forwarding attachments on web UI for RT3.4.2, 3.4.3

Jesse Vincent jesse at bestpractical.com
Tue Aug 16 13:19:59 EDT 2005




On Mon, Aug 15, 2005 at 01:23:09AM +0200, akos.torok at docca.hu wrote:
> Sorry... change this file, and the patch-package suits 3.4.3 already.
> 
> Ákos
> 
> akos.torok at docca.hu wrote:
> 
> >Hi All,
> >
> >I'm very new in this area, so be patiens if I make mistakes, please.

You seem to have done very well so far. Your patch is well doccumented 
and seems to do what it's trying to very nicely.  The one thing I'd
_love_ to see is a test script that shows that it works. 

Basically, it would create a couple tickets with attachments, then drive
the webui to "Forward" them, checking that the mail that goes out looks
right.

> >
> >I made a patch for forwarding attechment, I hope someone'll find it 
> >useful. I'm not a perl master, and this is just my second day of 
> >seeing the RT's code, so probably there is more elegant way to 
> >complete this job. The next one will be better.

For only two days in, you're doing really, really well :)

Best,
Jesse

> >Regards,
> >
> >Ákos
> >
> >
> >Readme.txt
> >
> >This is a patch package for www.bestpractical.com's RT.
> >By: Akos Torok (akos dot torok at docca dot hu)
> >Date: 2005.08.14.
> >
> >Mission:
> >========
> >Making possible forwarding attachments directly from a ticket
> >on the Web UI, without saving+browsing+attaching that attachments.
> >
> >
> >Applying these patch files:
> >===========================
> >This is my first time doing anything on RT. This is my first time of
> >making patch files. I hope they are O.K. Just use them on the standard 
> >way.
> >
> >
> >Usage:
> >======
> >Attach:
> >You can find all the ticket attachments at the bottom of the
> >"Update ticket" page. Check the boxes + save changes for attach.
> >
> >Remove:
> >Same as the normal attachments: check the boxes and click "Add More
> >Files" or "Save changes" button.
> >
> >
> 

> --- ./Web.pm	2005-07-12 18:22:01.000000000 +0200
> +++ ./Web.pm	2005-08-15 00:46:29.000000000 +0200
> @@ -446,6 +446,7 @@
>      #Make the update content have no 'weird' newlines in it
>      if (   $args{ARGSRef}->{'UpdateTimeWorked'}
>          || $args{ARGSRef}->{'UpdateContent'}
> +        || $args{ARGSRef}->{'UpdateForwardAttachments'}
>          || $args{ARGSRef}->{'UpdateAttachments'} )
>      {
>  
> @@ -495,6 +496,12 @@
>            foreach values %{ $args{ARGSRef}->{'UpdateAttachments'} };
>      }
>  
> +    if ( $args{ARGSRef}->{'UpdateForwardAttachments'} ) {
> +        $Message->make_multipart;
> +        $Message->add_part($_)
> +          foreach values %{ $args{ARGSRef}->{'UpdateForwardAttachments'} };
> +    }
> +
>      ## TODO: Implement public comments
>      if ( $args{ARGSRef}->{'UpdateType'} =~ /^(private|public)$/ ) {
>          my ( $Transaction, $Description, $Object ) = $args{TicketObj}->Comment(
> @@ -548,6 +555,7 @@
>          Cc                  => undef,
>          Body                => undef,
>          AttachmentFieldName => undef,
> +        ForwardAttachment   => undef,
>  #        map Encode::encode_utf8($_), @_,
>          @_,
>      );
> @@ -614,6 +622,48 @@
>  
>      }
>  
> +
> +
> +    # FORWARDING
> +    
> +    # If there is anything to forward...
> +    if ($args{'ForwardAttachment'}) {
> +    # Load the original attachment
> +     my $AttachmentObj = new RT::Attachment($session{'CurrentUser'});
> +     my $trans;
> +     my $attach;
> +     if ($args{'ForwardAttachment'} =~ '^(\d+)/(\d+)') { $trans = $1; $attach = $2; }
> +     $AttachmentObj->Load($attach) || Abort(loc("Attachment '[_1]' could not be loaded", $attach));
> +     unless ($AttachmentObj->id) { Abort(loc("Attachment '[_1]' could not be loaded", $attach)); }
> +     unless ($AttachmentObj->TransactionId() == $trans ) { Abort(loc("Attachment '[_1]' could not be loaded", $attach)); }
> +     
> +    #Save the original attachment into a temporary file on a new name: Sent-$original_name
> +    use File::Temp qw(tempfile tempdir);
> +    my ( $fh, $temp_file );
> +    for ( 1 .. 10 ) {
> +        # on NFS and NTFS, it is possible that tempfile() conflicts
> +        # with other processes, causing a race condition. we try to
> +        # accommodate this by pausing and retrying.
> +        last if ($fh, $temp_file) = eval { tempfile( UNLINK => 1) };
> +        sleep 1;
> +    }
> +    binmode $fh;    #thank you, windows
> +    print $fh $AttachmentObj->Content;
> +    my $filename= "Sent-".$AttachmentObj->Filename;
> +
> +    #Create the MIME attachment
> +    $Message->attach(
> +        Path     => $temp_file,
> +        Filename => $filename,
> +        Type     => $AttachmentObj->ContentType
> +    );
> +    close($fh);
> +    }
> +
> +    # END OF FORWARDING
> +    
> +    
> +
>      $Message->make_singlepart();
>      RT::I18N::SetMIMEEntityToUTF8($Message); # convert text parts into utf-8
>  

> _______________________________________________
> Rt-devel mailing list
> Rt-devel at lists.bestpractical.com
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel


-- 


More information about the Rt-devel mailing list