Skip to content

Commit 75c1889

Browse files
committed
Fix an issue with feedback emails with text and html body, and an attachment.
Email::Stuffer incorrectly adds an attachment together with the text and html body parts all at the same level with content type multipart/mixed. Structurally this is as follows: [ (content type multipart/mixed) text body, html body, attachment ] As a result, when an email has a text body, an html body, and an attachment, both the text and html are shown in most email clients. The text and html body should be parts of a separate part that has content type 'multipart/alternative'. So the email has two parts, and the first part has two parts in that which are the text and html body. The second part is the attachment. The following shows how it should be structurally: [ (content type multipart/mixed) [ (content type multipart/alternative) text body, html body ], attachment ] To fix this, before adding an attachment the text and html body are moved into a separate part with content type multipart/alternative.
1 parent f18833f commit 75c1889

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/WeBWorK/ContentGenerator/Feedback.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ sub initialize ($c) {
203203
return;
204204
}
205205

206+
# Email::Stuffer incorrectly adds the attachment together with the text and html body parts at the same
207+
# level. As a result, when an email has a text body, an html body, and an attachment, both the text and
208+
# html are shown in most email clients. The text and html body should be parts of a separate part that has
209+
# content type 'multipart/alternative'. So the email has two parts, and the first part has two parts which
210+
# are the text and html body. The second part is the attachment. So before attaching the file move the text
211+
# and html body into their own part.
212+
$email->{parts} = [
213+
Email::MIME->create(
214+
attributes => { content_type => 'multipart/alternative' },
215+
parts => $email->{parts}
216+
)
217+
];
218+
206219
# Attach the file.
207220
$email->attach($contents, filename => $filename);
208221
}

0 commit comments

Comments
 (0)