[WORKAROUND] Send an attachment to notification without article body

Moderator: crythias

Locked
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

[WORKAROUND] Send an attachment to notification without article body

Post by Giulio Soleni »

Hi,
I would like to send a notification to an external e-mail address upon the creation of a new ticket on a specific queue, and I would like to add to this notification any possible attachment that the customer may have included to the new ticket.
For this reason I defined a Notification event that is triggered on the "ArticleCreate" event for this specific queue (filtered in the "Ticket Filter" section) and with the Article Filter set as:
Article Type: webrequest
Article sender type: customer
Include attachments to notification: yes

All works as expected, but for a little thing: along with any "real" attachment, also the whole ticket body is sent out as an attachment itself to the notification, wrapped into an html text file.

Question: Is there a way to strip this part and send out the notification only with the real (if any) attachment?

Looking at the code I see that in /Kernel/System/Ticket/Event/NotificationEvent.pm there is this part:

Code: Select all

            # add attachments to notification
            if ( $Notification{Data}->{ArticleAttachmentInclude}->[0] ) {
                my %Index = $TicketObject->ArticleAttachmentIndex(
                    ArticleID                  => $Param{Data}->{ArticleID},
                    UserID                     => $Param{UserID},
                    StripPlainBodyAsAttachment => 3,
                );
                if (%Index) {
                    FILE_ID:
                    for my $FileID ( sort keys %Index ) {
                        my %Attachment = $TicketObject->ArticleAttachment(
                            ArticleID => $Param{Data}->{ArticleID},
                            FileID    => $FileID,
                            UserID    => $Param{UserID},
                        );
                        next FILE_ID if !%Attachment;
                        push @Attachments, \%Attachment;
                    }
                }
            }
        }
I tried different values for StripPlainBodyAsAttachment => 3, but the behaviour is always the same, and probably that attribute is set for some other reason that I do not know...

Do you know is there anything that I could do to actually strip this "fake" attachment from the notification?

Thank you in advance,
Giulio
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: [WORKAROUND] Send an attachment to notification without article body

Post by Giulio Soleni »

After checking all the documented values of StripPlainBodyAsAttachment without any result, I came to a workaround to my problem:

editing of /opt/otrs/Kernel/System/Ticket/Event/NotificationEvent.pm this way:

Code: Select all

            if ( $Notification{Data}->{ArticleAttachmentInclude}->[0] ) {
                my %Index = $TicketObject->ArticleAttachmentIndex(
                    ArticleID                  => $Param{Data}->{ArticleID},
                    UserID                     => $Param{UserID},
                    StripPlainBodyAsAttachment => 3,  # >>>> IT SEEMS TO BE USELESS... ALSO CHANGING ITS VALUES TO 1 OR 2
                );
                if (%Index) {
                    FILE_ID:
                    for my $FileID ( sort keys %Index ) {
                        my %Attachment = $TicketObject->ArticleAttachment(
                            ArticleID => $Param{Data}->{ArticleID},
                            FileID    => $FileID,
                            UserID    => $Param{UserID},
                        );
                        
                        next FILE_ID if (($FileID == 1 ) && ($Attachment{Disposition} eq 'inline')); # >>>> SET TO STRIP THE FIRST INLINE ATTACHMENT WHICH IS THE ARTICLE BODY ITSELF
                        
                        next FILE_ID if !%Attachment;
                        push @Attachments, \%Attachment;
                    }
                }
            }
However this is a workaround ... I am going to open a bug for StripPlainBodyAsAttachment because either it is not working or it is not correctly explained within the manuals.
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: [WORKAROUND] Send an attachment to notification without article body

Post by crythias »

It seems that you're looking at StripPlainBodyAsAttachment to affect "other" attachments, which the documentation doesn't suggest.

An HTML message arrives as a multi-part mail with the "Plain Text" version as an attachment. This really has nothing to do with attached files to the email.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: [WORKAROUND] Send an attachment to notification without article body

Post by Giulio Soleni »

crythias wrote:It seems that you're looking at StripPlainBodyAsAttachment to affect "other" attachments
Hi crythias,
no ... I would like StripPlainBodyAsAttachment to actually strip plain body leaving any other attachment intact.
Since the first inline attachment in the article is always the body (regardless the value of StripPlainBodyAsAttachment), my workaround does exactly what I need: it strips the plain body from the attachments list and leave any other attachment at its place.
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
Locked