Problems creating multipart messages
- Dominant language
- Ruby
- Stars
- 3.7k
- Forks
- 934
- PR merge metrics
- No merged PRs in 30d
Description
I am dealing with mail that has been parsed a little already and I want to do further parsing to handle multipart messages. I found one way to do this that works and two more natural ways that don't. By "working", I mean that parts, html_part, and text_part work as I expect.
1) This works: Mail.new("Content-Type: multipart/alternative; ...\r\n\r\nBODY")
2) This doesn't work: Mail.new(:headers => { :content_type => "..." }, :body => "...")
3) Neither does this:
Mail.new do
header "..."
body "..."
end
I looked into the code and I think the reason is because initialize_with_string is the only place that sets @separate_parts, which is used in process_body_raw. #3 doesn't work because it calls initialize_with_hash. #2 doesn't work because initialize runs the block after initialize_with_string.
It seems that you could eliminate @separate_parts and use multipart? instead. I didn't take a stab at this because this is my first day looking at the code, so maybe I'm missing something. Other than this bug, Mail looks well-suited to my needs. Thanks!
Contributor guide
Research direction
Start with the issue's construction paths: initialize_with_string, initialize_with_hash, the initializer block, and process_body_raw; inspect how @separate_parts is set and how multipart? is used. Reproduce the three Mail.new forms and compare parts, html_part, and text_part, then ensure the hash and block forms handle multipart messages consistently with the string form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100