..a dose of zero-day know-hows ..

5/01/2009

Fix: SugarCRM 5.1.2x Inbound Email -> Plain Text attachments getting Discarded

In SugarCRM 5.1.2c and up, you will notice that the Inbound Email functionality fails to pickup plain text attachments, this affects files with csv, txt extenstions and other files with plain text mime type. You should be able reproduce this issue by sending an email to an address that is monitored by SugarCRM, once cron invokes cron.php, the emails will be fetched but the plain text attachments are nowhere in the email.

It took me awhile fixing our company instance only to figure out the culprit was only one line which was added upon my upgrade (from 5.1.2a or 5.1.2b or from 5.1.2b to 5.1.2c I cannot exactly pinpoint)

The fix was simple, simply change line 3385 (approx) of /modules/InboundEmails/InboundEmail.php from

if(strtolower($part->disposition) == 'attachment' || 
((strtolower($part->disposition) == 'inline'))
&& $part->type != 0) {
to
if(strtolower($part->disposition) == 'attachment' || 
((strtolower($part->disposition) == 'inline'))) {
You will notice that with the unchanged code, there is no way for attachments whose $part->type is '0' (plain text) to get parsed and be attached in the email object.

I hope this spares someone form hair pulling I had to go through

No comments: