On 05/02/2017 11:13 AM, Timo Sirainen wrote:
On 2 May 2017, at 11.21, Giovanni Salvatore Fois giovannisalvatore.fois@eng.it wrote:
Hi all, at work we use Roundcube acting as a mail client for the Dovecot Imap server.
In Roundube the messages are parsed through the Imap BODYSTRUCTURE command If a message contains forwarded messages and attachments and some of the messages contains a quote (") in the subject, then the resulting BODYSTRUCTURE appears to be malformed.
After some digging through the code of Dovecot, it seems to me that the problem is related to the function: imap_append_string_for_humans defined at the line 120 of the file src/lib-imap/imap-quote.c (dovecot sources v. 2.2.29)
Said function is supposed to return a quoted version of the input string while removing unwanted characters from the input data.
But, if I call it with a string containing quotes as argument (eg: I am a lazy " programmer) in the resulting output the quotes aren't escaped and the output string is not quoted.
It's then written as a literal, so it actually looks correct to me.
I have done some further analysis of my real world cases and the problem arises when the subject line contains also a closed parenthesis, as in:
I'm a really ) bad "message"
In that case, part of the bodystructure is rendered as:
("Mon, 27 Mar 2017 11:18:04 +0000" I'm a really ) bad "message" (("First Address" NIL "username" "domain.com"))(( "Second Address" NIL "othername" "otherdomain.com")) ... and so on ...
That lonely parenthesis confuses the parser and so the resulting structure is slightly messed up.
I'm pretty positive that I can overcome the issue working on the client side.
Thank you for your time and please keep going with the good job.
Best regards, Giovanni S. Fois