If an email is sent with a single media-type part (eg. an image), rather than as a multipart email with an image attachement, then the single part fails to be imported.

What happens is MailhandlerPhpImapRetrieve::get_parts has the default part_number as FALSE, so when there is a single part, it pulls the entire message text including headers, and in my case attempts to base64 decode that (the content of the mail is base64 encoded, and this is recognised correctly from headers). the decoded data comes out as empty (the headers in the stream cause the data to be invalid base64 data), and I get a zero-byte file created. I haven't tested what happens to single-part text emails, but i suspect that it works better than base64 encoded data (you might get extra headers included in the final data or something, but text would probably survive).

I'm attaching an example mail to this issue to reproduce the issue. Headers will need customization in order to use it in testing. I have a patch for this and will attach shortly.

See http://www.ietf.org/rfc/rfc1730.txt section 6.4.5, which mentions single part emails as valid. The only part number in that case is "1".

Comments

alan evans’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB
danepowell’s picture

Thanks for the patch. Will test when I can. Marked #1396976: Image attachments not working when body is empty as dupe.

Status: Needs review » Needs work

The last submitted patch, mailhandler-single-part.patch, failed testing.

danepowell’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Here is #1 rolled against HEAD, so it has a better chance of passing testing.

danepowell’s picture

Title: Mailhandler ignores single-part media emails » Single-part media emails ignored
Status: Needs review » Fixed
alan evans’s picture

Brilliant, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danepowell’s picture

Status: Closed (fixed) » Active

Turns out that this is probably not the right way to solve this problem- it caused the following regression: #1597384: File attachments have zero bytes Thus, I have reverted the fixes in #5.

The problem seems to be that for multipart messages with only two parts (a text body and HTML body), the parts are indexed as "1" and "2". However, with the change in #5, get_parts adds a prefix and tries to access them as "1.1" "1.2", which fails and throws a 'No Data!!' error.

danepowell’s picture

Also, oddly, even with the fix in #5 reverted, the single-part simpletest is still passing. So it would seem that that test is broken.

danepowell’s picture

Status: Active » Postponed (maintainer needs more info)

Okay, I've figured out part of the problem- in #5, I actually committed something different than what's in patch #4, which has quite a different effect.

So, can you please confirm that this is still a problem with the latest dev release? If so, then I just need to apply #4 as-is (as long as it doesn't cause a regression, e.g. #1597384: File attachments have zero bytes).

danepowell’s picture

Okay- I've just committed some major changes to how messages are retrieved. I would appreciate if you would try the 7.x-2.x-dev version that rolls tonight and let me know if this is still a problem. Otherwise, I will assume this is fixed. Thanks.

alan evans’s picture

Just checked this on the latest 7.x-2.x from git and it seems to be working well using both the example single-part mail here as well as a standard email with an attached photo. Thanks!

danepowell’s picture

Status: Postponed (maintainer needs more info) » Fixed

Glad to hear it.

foxtrotcharlie’s picture

I was also having the same issue but with version 6.x-2.5. The email attachment (an image) was not being shown in the content type (mapped to a cck image field) after importing and I was getting the "No Data!!" message in watchdog.

Upgrading to the latest dev (currently 6.x-2.5+19-dev) fixed the issue for me, thanks :-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.