On Wed, Feb 5, 2014 at 12:32 PM, Hugo Escobar <[email protected]> wrote:
> > On Wed, Feb 5, 2014 at 10:23 AM, Kevin Falcone > <[email protected]>wrote: > >> On Tue, Feb 04, 2014 at 04:02:05PM -0500, Hugo Escobar wrote: >> > $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, >> checks_failure => \$checks_failure, >> > results => \@results, CallbackName => 'Initial' ); >> > >> > which exists at the beginning of the <%INIT> section >> > My implementation of this callback creates a MIME::Entity and adds >> the file to it, then it >> > 'writes' the whole message to $session{'Attachments'} >> > >> > I've been trying to do the right changes for this to work under >> 4.2.2 but no luck so far >> >> You've not shown your code, so I'm guessing, but if you look at how >> 4.2 stores attachments in the session, it uses a token to finally fix >> the bug of creating two tickets simultaneously and accidentally >> attaching the wrong attachments to the wrong ticket. >> >> $session{Attachments}{$ARGS{Token}} >> >> Relevant code is in ProcessAttachments and you can also see it used in >> CreateTicket. >> > > This is what I do: > > my $Message = MIME::Entity->build( > Type => 'multipart/mixed', > "Message-Id" => RT::Interface::Email::GenMessageId, > ); > > my ( $filehandle, @ar_content, $buffer ); > open( $filehandle, "<", \$content ); > while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) { > push @ar_content, $buffer; > } > close $filehandle; > > $Message->attach( > Filename => $doc_path, > Type => 'application/pdf', > Data => \@ar_content, > ); > > # Attachment parts really shouldn't get a Message-ID > $Message->head->delete('Message-ID'); > $Message->make_singlepart; > RT::I18N::SetMIMEEntityToUTF8($Message); # convert text parts > into utf-8 > > $session{'Attachments'} = { > %{$session{'Attachments'} || {}}, > $key . '.pdf' => $Message > }; > > (...) > > I changed the blue lines by the following: > > session{'Attachments'}{Digest::MD5::md5_hex(rand(1024))}{$key . '.pdf'} = > $Message; > > The reason I create a token here is that at this point > ('/Ticket/Display.html') there seems to be no 'Attachment' in $session > > The problem persists, post added without attachment > > Solved. Adding the following lines solves the problem: $ARGSRef->{'Token'} = Digest::MD5::md5_hex(rand(1024)); $session{'Attachments'}{$ARGSRef->{'Token'}}{$key . '.pdf'} = $Message; $ARGSRef->{'UpdateType'} = 'response'; $ARGSRef->{'UpdateAttach'} = '1'; $ARGSRef->{UpdateContent} = 'any text'; Thank you for your help, it pointed me in the right direction -- Hugo Escobar [image: AFS_logo.png] Follow us on Facebook and Linked-In [image: facebook-24x24.png]<http://www.facebook.com/pages/Miami-FL/ASSOCIATION-FINANCIAL/64952991864> [image: linkedin-24x24.png] <http://www.linkedin.com/companies/1006276>
<<AFS_logo.png>>
<<linkedin-24x24.png>>
<<facebook-24x24.png>>
