benprew/pony — pull request #13 by dslh (2014-09-08 13:23:59+00:00)
Title: Nested multipart boundaries for emails with attachments and body and html body

We've been having a problem where the emails that pony is delivering for us aren't displaying correctly in a number of different email clients. Variously the emails arrive with a body but no attachment, an attachment but no body, or the body as an attachment alongside the real attachment. We've tracked this down to incorrect usage of MIME multipart boundaries to separate attachments and content-type alternatives.

Briefly: "mixed/multipart" boundaries should be used to separate attachments from the body. "mixed/alternative" boundaries should be used to separate alternative versions of the same resource (i.e. the body). Therefore when you have the trifecta you need a mixed/alternative boundary nested inside a mixed/multipart boundary.

To be honest this would probably be better fixed in the underlying mail library; even though it's possible to do things correctly the documentation implies that the correct boundaries will be generated automatically. However we needed this fixed in a hurry and we found pony's code was considerably easier to work with :)

We've also made a change to normalize filenames that have consecutive whitespace characters, which was causing a null-pointer exception.