[SOLVED] Stripping text from an incoming email body

Moderator: crythias

Locked
carisu
Znuny newbie
Posts: 5
Joined: 12 Jun 2012, 12:30
Znuny Version: 3.1.x
Real Name: Chris Davis
Company: Clifford Thames

[SOLVED] Stripping text from an incoming email body

Post by carisu »

Hi,

We are upgrading our existing system to OTRS, and currently our customers connect to an external system which sends the customer email through. This has a large amount of information stored in the email body which we populate in the ticket's dynamic fields in the postmaster filter.
In order to tidy up the email for the agents, we want to strip off all data populated as dynamic fields from the body, just leaving the problem description. This also ensures that we can guarantee that filters will only be run against initial ticket emails, since these values will no longer be present in any replies/forwards.

I have written a post-filter module which takes the body of the new article, strips out all but the part of the body I want, and calls ArticleUpdate to perform the update (Key=>'Body', Value=>$StrippedBody). When I run a SQL query, such as

Code: Select all

SELECT ticket.tn, article.a_subject, article.a_body FROM ticket JOIN article ON ticket.id = article.ticket_id
I can clearly see the body has been updated. However, when I go to look at the ticket, the email still displays the original email body.

Does anyone know why details displayed in the ticket view are not matching those in the database, and what else I need to do to get the body stripped correctly?
Last edited by carisu on 12 Jun 2012, 15:22, edited 1 time in total.
dev: OTRS 3.1.0.rc1 on WIndows 7, mySQL
live: OTRS 3.1.3 on Ubuntu, SQL Server 2008
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Stripping text from an incoming email body

Post by jojo »

is it a multipart message containing also HTML?

also you should use APT functions instead of SQL
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
carisu
Znuny newbie
Posts: 5
Joined: 12 Jun 2012, 12:30
Znuny Version: 3.1.x
Real Name: Chris Davis
Company: Clifford Thames

Re: Stripping text from an incoming email body

Post by carisu »

Yes, the email is a multipart email containing both plain text and HTML.
I am using the API Kernel::System::Ticket::Article::ArticleUpdate call to perform the update. The SQL was just to check the update had worked correctly in the database.
dev: OTRS 3.1.0.rc1 on WIndows 7, mySQL
live: OTRS 3.1.3 on Ubuntu, SQL Server 2008
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Stripping text from an incoming email body

Post by jojo »

The Article is just containing the plaintext part as the HTML part is safed as attachment. So the best way would be to delete it.
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
carisu
Znuny newbie
Posts: 5
Joined: 12 Jun 2012, 12:30
Znuny Version: 3.1.x
Real Name: Chris Davis
Company: Clifford Thames

Re: Stripping text from an incoming email body

Post by carisu »

Excellent. That seems to fix the problem. I now need to work out how to make sure I keep non-body attachments, as ArticleDeleteAttachment is described as deleting all attachments, but this certainly gets me on the right line.

Thanks
dev: OTRS 3.1.0.rc1 on WIndows 7, mySQL
live: OTRS 3.1.3 on Ubuntu, SQL Server 2008
Locked