benprew / pony

The express way to send mail from Ruby.
1.14k stars 51 forks source link

Nested multipart boundaries for emails with attachments and body and html body #13

Closed dslh closed 10 years ago

dslh commented 10 years ago

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.

benprew commented 10 years ago

@dslh, this is great! Thanks for working on this.