james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [16/21] james-project git commit: JAMES-2048 Parser message in case of empty or blank CID and its tests
Date Wed, 07 Jun 2017 10:46:26 GMT
JAMES-2048 Parser message in case of empty or blank CID and its tests


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/730f44ff
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/730f44ff
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/730f44ff

Branch: refs/heads/master
Commit: 730f44ff5fac3dd4736e6c0a20b31b03f2e7fca6
Parents: d8c7063
Author: quynhn <qnguyen@linagora.com>
Authored: Tue Jun 6 13:47:08 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:35:51 2017 +0700

----------------------------------------------------------------------
 .../store/mail/model/impl/MessageParser.java    | 34 +++++----
 .../mail/model/impl/MessageParserTest.java      | 18 ++++-
 ...AttachmentsWithOneWrongInlinedAttachment.eml | 73 --------------------
 .../eml/oneInlinedAttachmentWithBlankCid.eml    | 62 +++++++++++++++++
 .../eml/oneInlinedAttachmentWithEmptyCid.eml    | 62 +++++++++++++++++
 .../eml/oneInlinedAttachmentWithNoCid.eml       | 61 ++++++++++++++++
 6 files changed, 222 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index 8692375..3e7e42e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -69,6 +69,25 @@ public class MessageParser {
             ContentDispositionField.DISPOSITION_TYPE_ATTACHMENT.toLowerCase(Locale.US),
             ContentDispositionField.DISPOSITION_TYPE_INLINE.toLowerCase(Locale.US));
     private static final Logger LOGGER = LoggerFactory.getLogger(MessageParser.class);
+    private static final Function<String, Optional<Cid>> STRING_TO_CID_FUNCTION
= new Function<String, Optional<Cid>>() {
+        @Override
+        public Optional<Cid> apply(String cid) {
+            try {
+                return Optional.of(Cid.from(cid));
+            } catch (IllegalArgumentException e) {
+                return Optional.absent();
+            }
+        }
+    };
+
+    private static final Function<ContentIdField, Optional<Cid>> CONTENT_ID_FIELD_TO_OPTIONAL_CID_FUNCTION
= new Function<ContentIdField, Optional<Cid>>() {
+        @Override
+        public Optional<Cid> apply(ContentIdField field) {
+            return Optional.fromNullable(field.getId())
+                    .transform(STRING_TO_CID_FUNCTION)
+                    .or(Optional.<Cid>absent());
+        }
+    };
 
     public List<MessageAttachment> retrieveAttachments(InputStream fullContent) throws
MimeException, IOException {
         DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
@@ -178,19 +197,8 @@ public class MessageParser {
     }
 
     private Optional<Cid> cid(Optional<ContentIdField> contentIdField) {
-        return contentIdField.transform(new Function<ContentIdField, Optional<Cid>>()
{
-            @Override
-            public Optional<Cid> apply(ContentIdField field) {
-                return Optional.fromNullable(field.getId())
-                        .transform(new Function<String, Cid>() {
-
-                            @Override
-                            public Cid apply(String cid) {
-                                return Cid.from(cid);
-                            }
-                        });
-            }
-        }).or(Optional.<Cid> absent());
+        return contentIdField.transform(CONTENT_ID_FIELD_TO_OPTIONAL_CID_FUNCTION)
+                .or(Optional.<Cid>absent());
     }
 
     private boolean isMultipart(Entity entity) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index 4fc4979..ceb3df9 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -201,9 +201,23 @@ public class MessageParserTest {
 
     @Test
     public void getAttachmentsShouldRetrieveAttachmentsWhenNoCidForInlined() throws Exception
{
-        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/multiAttachmentsWithOneWrongInlinedAttachment.eml"));
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithNoCid.eml"));
 
-        assertThat(attachments).hasSize(2);
+        assertThat(attachments).hasSize(1);
+    }
+
+    @Test
+    public void getAttachmentsShouldRetrieveAttachmentsWhenEmptyCidForInlined() throws Exception
{
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithEmptyCid.eml"));
+
+        assertThat(attachments).hasSize(1);
+    }
+
+    @Test
+    public void getAttachmentsShouldRetrieveAttachmentsWhenBlankCidForInlined() throws Exception
{
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithBlankCid.eml"));
+
+        assertThat(attachments).hasSize(1);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
b/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
deleted file mode 100644
index c7cd548..0000000
--- a/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
+++ /dev/null
@@ -1,73 +0,0 @@
-Return-Path: <from@linagora.com>
-Received: from alderaan.linagora.com (smtp.linagora.dc1 [172.16.18.53])
-	 by imap (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA;
-	 Mon, 27 Feb 2017 05:24:55 +0100
-X-Sieve: CMU Sieve 2.2
-Received: from [192.168.12.138] (unknown [1.55.245.4])
-	(using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
-	(No client certificate requested)
-	by alderaan.linagora.com (Postfix) with ESMTPSA id 688BF7A9
-	for <from@linagora.com>; Mon, 27 Feb 2017 05:24:54 +0100 (CET)
-To: to@linagora.com
-From: Lina <from@linagora.com>
-Subject: MultiAttachment
-Message-ID: <13d4375e-a4a9-f613-06a1-7e8cb1e0ea93@linagora.com>
-Date: Mon, 27 Feb 2017 11:24:48 +0700
-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
- Thunderbird/45.2.0
-MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------64D8D789FC30153D6ED18258"
-
-This is a multi-part message in MIME format.
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=utf-8; format=flowed
-Content-Transfer-Encoding: 7bit
-
-Send
-
-
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=UTF-8;
- name="text1"
-Content-Transfer-Encoding: base64
-Content-Disposition: wrongDisposition;
- filename="text1"
-
-LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb2dJQkFBS0NBUUVBeDdQRzAr
-RS8vRU1wbTdJZ0k1UTlUTURTRnlhLzFoRSt2dlRKcmswaUdGbGxQZUhMCkE1L1ZsVE0wWVdn
-RzZYNTBxaU1mRTNWTGF6ZjJjMTlpWHJUMG1xLzIxUFoxd0Zub2d2NHp4VU5haWgrQm5nNjIK
-RjBTeXJ1RS9PL05qcXhoL0NjcTZLL2UwNVRWNFQ2NDNVU3hBZUcwS3BwbVlXOXg4SEEvR3ZW
-ODMyYXBadXhrVgppNk5Wa0RCcmZ6YVVDd3U0ekgrSHdPdi9wSTg3RTdLY2NIWUMrK0JpYWoz
-Cg==
---------------64D8D789FC30153D6ED18258
-Content-Type: application/vnd.ms-publisher;
- name="text2"
-Content-Transfer-Encoding: base64
-Content-Disposition: inline;
- filename="text2"
-
-c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFESHM4YlQ0VC84UXltYnNp
-QWpsRDFNd05JWEpyL1dFVDYrOU1tdVRTSVlXV1U5NGNzRG45V1ZNelJoYUFicGZuU3FJeDhU
-ZFV0ck4vWnpYMkpldFBTYXIvYlU5blhBV2VpQy9qUEZRMXFLSDRHZURyWVhSTEt1NFQ4Nzgy
-T3JHSDhKeXJvcjk3VGxOWGhQcmpkUkxFQjRiUXFtbVpoYjNId2NEOGE5WHpmWnFsbTdHUldM
-bzFXUU1HdC9OcFFMQzdqTWY0ZkE2LytranpzVHNweHdkZ0w3NEdKcVBmT1hPaXdnTEhYOENa
-Ni81UnlUcWhUNnBEM01rdFNOV2F6L3pJSFBORXFmNUJZOUNCTTFURlI1dys2TURIbzBnbWlJ
-c1hGRUpUUG5maEJ2SERoU2pCMVJJMEt4VUNseVlySjRmQmxVVmVLZm5hd29WY3U3WXZDcUY0
-RjUgcXV5bmhubkBsaW5hZ29yYQo=
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=UTF-8;
- name="text3"
-Content-Transfer-Encoding: base64
-Content-Disposition: attachment;
- filename="text3"
-
-fDF8b1M3NU9nTDN2RjJHZGw5OUNKRGJFcGFKM3lFPXxJTkdxbGpDVzFYTWY0Z2dPUW0yNi9C
-Tm5LR2M9IHNzaC1yc2EgQUFBQUIzTnphQzF5YzJFQUFBQUJJd0FBQVFFQXEyQTdoUkdtZG5t
-OXRVRGJPOUlEU3dCSzZUYlFhK1BYWVBDUHk2cmJUclR0dzdQSGtjY0tycHAweVZocDVIZEVJ
-Y0tyNnBMbFZEQmZPTFg5UVVzeUNPVjB3emZqSUpObEdFWXNkbExKaXpIaGJuMm1VanZTQUhR
-cVpFVFlQODFlRnpMUU5uUEh0NEVWVlVoN1ZmREVTVTg0S2V6bUQ1UWxXcFhMbXZVMzEveU1m
-K1NlOHhoSFR2S1NDWklGSW1Xd29HNm1iVW9XZjluenBJb2FTakIrd2VxcVVVbXBhYWFzWFZh
-bDcySitVWDJCKzJSUFczUmNUMGVPelFncWxKTDNSS3JUSnZkc2pFM0pFQXZHcTNsR0hTWlh5
-TjZtNVU0aHBwaDl1T3Y1NGFIYzRYcjhqaEFhL1NYNU1KCg==
---------------64D8D789FC30153D6ED18258--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
new file mode 100644
index 0000000..6b2ec2e
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
@@ -0,0 +1,62 @@
+Return-Path: <test@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <test@local.com>
+From: Test <test@local.com>
+Subject: Inline attachment
+Message-ID: <26d91590-b995-8d45-f66a-0433c65745bb@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-ID: <  >
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
new file mode 100644
index 0000000..9316235
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
@@ -0,0 +1,62 @@
+Return-Path: <test@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <test@local.com>
+From: Test <test@local.com>
+Subject: Inline attachment
+Message-ID: <26d91590-b995-8d45-f66a-0433c65745bb@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-ID:
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
new file mode 100644
index 0000000..16573b5
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
@@ -0,0 +1,61 @@
+Return-Path: <test@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <test@local.com>
+From: Test <test@local.com>
+Subject: Inline attachment
+Message-ID: <26d91590-b995-8d45-f66a-0433c65745bb@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message