-
Notifications
You must be signed in to change notification settings - Fork 939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When composing, first lines of body could get interpreted as headers if there is an attachment #811
Comments
Me and @xjeline5 have looked into this issue as part of our school project and we can confirm that this bug is still unfixed (under both Ruby 1.9.3 and 2.1.2).
The problem is combination of creating multipart email and the way of setting the attachment and the body. Once the email is multipart, the simple assignment to body is treated as creating new part of email. This calls Mail::Part.new(value) in message's body_lazy function and then the value is checked for headers, which are in format "foo: bar". When creating new Part, :body parameter can be supplied instead and this leads to correct setting of the body (the same way convert_to_multipart does it). But because of the project structure design (there is a Message class, but also a Part class, that extends Message as well), there is not an easy way of recognizing that body_lazy function is called on an actual body of the whole email and it cannot be fixed there.
This way of setting the attachment does not call the function convert_to_multipart, unlike when calling add_file, but the message is considered multipart internally. convert_to_multipart takes the old body and saves it as a new part correctly. If the text body is set before setting the attachment your way, it is overwritten. The workaround to avoid this problem is to first set the body, then use add_file to insert attachment or call convert_to_multipart and then set the attachment the way mentioned in your example:
or:
Another way of achieving this that does not depend on the order of setting the body and attachment:
If anyone has a hint how to solve the root cause, let us know and we can arrange the fix. |
…rt instead of adding a raw MIME part Fixes super-confusing API usage where you add an attachment, then set the body text, and end up parsing the body text as if it were a raw MIME part. Closes mikel#1114. Fixes mikel#811. Thanks to @Venousek for diagnosis!
Fixed by #1114 😊 |
Hello. I would like to a report a bug in version 2.6.1 of the mail gem.
To reproduce this bug, I ran the following code under ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]:
The output I get from this is:
Note how there is no blank line before the "a:", so it is actually a header. I would have expected there to be a blank line before the "a:" line, so that it would be part of the body of that MIME part.
I believe this is a bug because I would expect that a string passed into the
#body=
method would be treated as part of the body, not as a combined thing that contains headers and body.This bad behavior goes away if I comment out the line that adds the attachments, or if I delete the colon or newline from the body.
The text was updated successfully, but these errors were encountered: