From 100331a6b73b97337ae59f40694162eed9201572 Mon Sep 17 00:00:00 2001 From: Damien Caliste Date: Mon, 10 Sep 2018 09:03:17 +0200 Subject: Add recursion when looking for attachments Some attachments are stored like that on disk for instance: $ ll 1454950441.21419.3MYc5-parts total 204 -rw-r--r-- 1 nemo 197093 Feb 8 17:54 2.1 -rw-r--r-- 1 nemo 936 Feb 8 17:54 1.2 -rw-r--r-- 1 nemo 936 Feb 8 17:54 1.1 The file 2.1 being a PDF. This kind of attachments are not listed, coming from the fact that in src/libraries/qmfclient/qmailmessage.cpp:1199, the inMultipartMixed() method is not recursive. It is listing only the first level of attachments (i.e. parts that are named [0-9]+ on disk). Making the attachment finder recursive have the drawback that some calendar invitations are now visible as attachment. This patch is taking care of this too. Structure of a failing email: Content-Type: multipart/mixed; boundary=--boundary_1233_7a77cb73-30a7-446e-ac29-52a7fda0bb71 MIME-Version: 1.0 ----boundary_1233_7a77cb73-30a7-446e-ac29-52a7fda0bb71 Content-Type: multipart/alternative; boundary=--boundary_1232_a7997778-4b33-4b26-a978-c17ad93d215e ----boundary_1232_a7997778-4b33-4b26-a978-c17ad93d215e Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 ----boundary_1232_a7997778-4b33-4b26-a978-c17ad93d215e Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 ----boundary_1232_a7997778-4b33-4b26-a978-c17ad93d215e-- ----boundary_1233_7a77cb73-30a7-446e-ac29-52a7fda0bb71 Content-Type: multipart/mixed; boundary=--boundary_1234_3ec882e1-3b08-47d3-965b-1380c61b8e8e ----boundary_1234_3ec882e1-3b08-47d3-965b-1380c61b8e8e Content-Type: application/octet-stream; name="air china c.a. - itinerary receipt.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment ----boundary_1234_3ec882e1-3b08-47d3-965b-1380c61b8e8e-- ----boundary_1233_7a77cb73-30a7-446e-ac29-52a7fda0bb71-- Change-Id: I00e6d0b1755fbfb6ecbd347b812c0db983d221f6 Reviewed-by: Michael Nosov Reviewed-by: Pekka Vuorela --- src/libraries/qmfclient/qmailmessage.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libraries/qmfclient/qmailmessage.cpp b/src/libraries/qmfclient/qmailmessage.cpp index da8b74b7..867d0aa2 100644 --- a/src/libraries/qmfclient/qmailmessage.cpp +++ b/src/libraries/qmfclient/qmailmessage.cpp @@ -1149,6 +1149,9 @@ namespace findAttachments if (container.multipartType() == QMailMessagePart::MultipartMixed) { inMultipartMixed(container, found, hasAttachments); } + if (container.multipartType() == QMailMessagePart::MultipartAlternative) { + inMultipartMixed(container, found, hasAttachments); + } if (container.multipartType() == QMailMessagePart::MultipartSigned) { inMultipartSigned(container, found, hasAttachments); } @@ -1166,6 +1169,9 @@ namespace findAttachments bool isText = (contentType.type().toLower() == "text") && ((contentType.subType().toLower() == "plain") || (contentType.subType().toLower() == "html")); + bool isCalendar = (contentType.type().toLower() == "text") && + (contentType.subType().toLower() == "calendar"); + bool isInLine = (!part.contentDisposition().isNull()) && (part.contentDisposition().type() == QMailMessageContentDisposition::Inline); @@ -1177,7 +1183,7 @@ namespace findAttachments // Attached messages are considered as attachments even if content disposition // is inline instead of attachment, but only if they aren't text/plain nor text/html - if (isRFC822 || isAttachment || (isInLine && !isText)) { + if (isRFC822 || isAttachment || (isInLine && !isText && !isCalendar)) { if (found) { *found << part.location(); } @@ -1197,6 +1203,10 @@ namespace findAttachments case QMailMessagePart::MultipartNone: inMultipartNone(part, found, hasAttachments); break; + case QMailMessagePart::MultipartMixed: + case QMailMessagePart::MultipartAlternative: + inMultipartMixed(part, found, hasAttachments); + break; default: break; } -- cgit v1.2.3