Skip to content

Commit 98e080d

Browse files
committed
handle emails with attachments before main body
1 parent f1a259e commit 98e080d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

email.d

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ class MimePart {
747747

748748
MimeAttachment att;
749749
att.type = type;
750-
if(att.type == "application/octet-stream" && filename.length == 0 && name.length > 0 ) {
750+
if(filename.length == 0 && name.length > 0 ) {
751751
att.filename = name;
752752
} else {
753753
att.filename = filename;
@@ -1218,11 +1218,17 @@ class IncomingEmailMessage : EmailMessage {
12181218
break;
12191219
case "multipart/mixed":
12201220
if(part.stuff.length) {
1221-
auto msg = part.stuff[0];
1222-
foreach(thing; part.stuff[1 .. $]) {
1223-
attachments ~= thing.toMimeAttachment();
1221+
MimePart msg;
1222+
foreach(idx, thing; part.stuff) {
1223+
if(msg is null && thing.disposition != "attachment" && (thing.type.length == 0 || thing.type.indexOf("multipart/") != -1 || thing.type.indexOf("text/") != -1)) {
1224+
// the message should be the first suitable item for conversion
1225+
msg = thing;
1226+
} else {
1227+
attachments ~= thing.toMimeAttachment();
1228+
}
12241229
}
1225-
part = msg;
1230+
if(msg)
1231+
part = msg;
12261232
goto deeperInTheMimeTree;
12271233
}
12281234

@@ -1653,7 +1659,7 @@ unittest {
16531659

16541660
assert(result.subject.equal(mail.subject));
16551661
assert(mail.to.canFind(result.to));
1656-
assert(result.from == mail.from.toString);
1662+
assert(result.from == mail.from.toProtocolString);
16571663

16581664
// This roundtrip works modulo trailing newline on the parsed message and LF vs CRLF
16591665
assert(result.textMessageBody.replace("\n", "\r\n").stripRight().equal(mail.textBody_));

0 commit comments

Comments
 (0)