Custom callback for ticket update not working after update 4.0.2 -> 4.2.2

I developed a callback that allowed staff users to quickly respond certain
requests from customers
just by pressing a button on ticket-display instead of having to go to
/Ticket/Update.html, writing, attaching the file, etc

This worked perfectly on 4.0.2. In 4.2.2, the response is being created but
the file(s) is(are) not being attached.

The callback I used for this customization is called in the following line:

$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

Any help will be greatly appreciated

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

$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.

-kevin

$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

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

$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