Browse code

FEATBL-835 Feat: parse attachment header on imip parsing

Thomas Fricker authored on 01/08/2019 13:21:18
Showing 2 changed files
... ...
@@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.core.runtime,
19 19
  net.bluemind.mime4j.common;bundle-version="1.0.0",
20 20
  net.bluemind.icalendar.parser,
21 21
  net.bluemind.icalendar.api,
22
- net.bluemind.core.container.api
22
+ net.bluemind.core.container.api,
23
+ net.bluemind.attachment.api
23 24
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
24 25
 Bundle-ActivationPolicy: lazy
25 26
 Export-Package: net.bluemind.imip.parser
... ...
@@ -19,8 +19,11 @@
19 19
 package net.bluemind.imip.parser.impl;
20 20
 
21 21
 import java.io.IOException;
22
+import java.util.ArrayList;
22 23
 import java.util.LinkedList;
23 24
 import java.util.List;
25
+import java.util.regex.Matcher;
26
+import java.util.regex.Pattern;
24 27
 
25 28
 import org.apache.james.mime4j.dom.BinaryBody;
26 29
 import org.apache.james.mime4j.dom.Body;
... ...
@@ -30,9 +33,11 @@ import org.apache.james.mime4j.dom.Message;
30 33
 import org.apache.james.mime4j.dom.Multipart;
31 34
 import org.apache.james.mime4j.dom.field.ContentTypeField;
32 35
 import org.apache.james.mime4j.message.BodyPart;
36
+import org.apache.james.mime4j.stream.Field;
33 37
 import org.slf4j.Logger;
34 38
 import org.slf4j.LoggerFactory;
35 39
 
40
+import net.bluemind.attachment.api.AttachedFile;
36 41
 import net.bluemind.imip.parser.IIMIPParser;
37 42
 import net.bluemind.imip.parser.IMIPInfos;
38 43
 import net.bluemind.imip.parser.ITIPMethod;
... ...
@@ -68,6 +73,25 @@ public class IMIPParserImpl implements IIMIPParser {
68 73
 		List<Entity> parts = mp.getBodyParts();
69 74
 		parts = expandParts(parts);
70 75
 
76
+		List<Field> attachments = m.getHeader().getFields("X-BM-ATTACHMENT");
77
+		List<AttachedFile> attachedFiles = new ArrayList<>();
78
+		if (attachments != null) {
79
+			String headerPattern = "\\((.*)\\)(.*)";
80
+			Pattern compile = Pattern.compile(headerPattern);
81
+			for (Field field : attachments) {
82
+				Matcher matcher = compile.matcher(field.getBody());
83
+				if (matcher.find()) {
84
+					String name = matcher.group(1);
85
+					String uri = matcher.group(2);
86
+					AttachedFile file = new AttachedFile();
87
+					file.name = name;
88
+					file.publicUrl = uri;
89
+					attachedFiles.add(file);
90
+				}
91
+			}
92
+
93
+		}
94
+
71 95
 		for (Entity e : parts) {
72 96
 			String mime = e.getMimeType();
73 97
 			if (!TEXT_CALENDAR.equals(mime) && !MS_TNEF.equals(mime)) {
... ...
@@ -90,7 +114,8 @@ public class IMIPParserImpl implements IIMIPParser {
90 114
 				IMIPInfos imip = new IMIPInfos();
91 115
 				imip.method = method;
92 116
 				imip.messageId = mid;
93
-				return parseiTIP(imip, e);
117
+				IMIPInfos parseiTIP = parseiTIP(imip, e);
118
+				return parseiTIP;
94 119
 			} else {
95 120
 				// BM-5591
96 121
 				// Outlook sends application/tnef for vTodo