Browse code

BM-15520 Fix: enable SMTP authentication for mail sent by core

Anthony Prades authored on 30/12/2019 15:33:51
Showing 63 changed files
... ...
@@ -40,4 +40,5 @@ Require-Bundle: org.junit,
40 40
  net.bluemind.icalendar.parser,
41 41
  org.apache.commons.io,
42 42
  net.bluemind.core.tests.testshelper,
43
- net.bluemind.document.persistence.fs
43
+ net.bluemind.document.persistence.fs,
44
+ net.bluemind.core.sendmail.testhelper
44 45
deleted file mode 100644
... ...
@@ -1,74 +0,0 @@
1
-/* BEGIN LICENSE
2
-  * Copyright © Blue Mind SAS, 2012-2016
3
-  *
4
-  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
-  * solution.
6
-  *
7
-  * This program is free software; you can redistribute it and/or modify
8
-  * it under the terms of either the GNU Affero General Public License as
9
-  * published by the Free Software Foundation (version 3 of the License).
10
-  *
11
-  *
12
-  * This program is distributed in the hope that it will be useful,
13
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
-  *
16
-  * See LICENSE.txt
17
-  * END LICENSE
18
-  */
19
-package net.bluemind.calendar.hook.ics;
20
-
21
-import java.util.ArrayList;
22
-import java.util.HashSet;
23
-import java.util.List;
24
-import java.util.Set;
25
-
26
-import org.apache.james.mime4j.dom.Message;
27
-import org.apache.james.mime4j.dom.address.Mailbox;
28
-import org.apache.james.mime4j.dom.address.MailboxList;
29
-
30
-import net.bluemind.core.api.fault.ServerFault;
31
-import net.bluemind.core.sendmail.ISendmail;
32
-import net.bluemind.core.sendmail.Mail;
33
-
34
-public class FakeSendmail implements ISendmail {
35
-
36
-	public class TestMail {
37
-		public Message message;
38
-		public Set<String> to = new HashSet<>();
39
-		public String from;
40
-	}
41
-
42
-	public boolean mailSent = false;
43
-	public List<TestMail> messages = new ArrayList<TestMail>();;
44
-
45
-	@Override
46
-	public void send(Mail m) throws ServerFault {
47
-	}
48
-
49
-	@Override
50
-	public void send(String fromEmail, String userDomain, Message m) throws ServerFault {
51
-	}
52
-
53
-	@Override
54
-	public void send(Mailbox sender, Message m) throws ServerFault {
55
-	}
56
-
57
-	@Override
58
-	public void send(String domainUid, Message m) throws ServerFault {
59
-	}
60
-
61
-	@Override
62
-	public void send(String fromEmail, String userDomain, MailboxList rcptTo, Message m) throws ServerFault {
63
-		mailSent = true;
64
-
65
-		TestMail tm = new TestMail();
66
-		tm.from = fromEmail;
67
-		for (Mailbox mbox : rcptTo) {
68
-			tm.to.add(mbox.getAddress());
69
-		}
70
-
71
-		tm.message = m;
72
-		messages.add(tm);
73
-	}
74
-}
... ...
@@ -70,7 +70,6 @@ import net.bluemind.calendar.api.VEventOccurrence;
70 70
 import net.bluemind.calendar.api.VEventSeries;
71 71
 import net.bluemind.calendar.helper.ical4j.VEventServiceHelper;
72 72
 import net.bluemind.calendar.hook.IcsHook;
73
-import net.bluemind.calendar.hook.ics.FakeSendmail.TestMail;
74 73
 import net.bluemind.calendar.hook.internal.VEventMessage;
75 74
 import net.bluemind.calendar.service.internal.VEventSanitizer;
76 75
 import net.bluemind.config.InstallationId;
... ...
@@ -86,6 +85,8 @@ import net.bluemind.core.context.SecurityContext;
86 85
 import net.bluemind.core.jdbc.JdbcActivator;
87 86
 import net.bluemind.core.jdbc.JdbcTestHelper;
88 87
 import net.bluemind.core.rest.ServerSideServiceProvider;
88
+import net.bluemind.core.sendmail.testhelper.FakeSendmail;
89
+import net.bluemind.core.sendmail.testhelper.TestMail;
89 90
 import net.bluemind.core.sessions.Sessions;
90 91
 import net.bluemind.core.tests.BmTestContext;
91 92
 import net.bluemind.domain.api.Domain;
... ...
@@ -72,6 +72,7 @@ import net.bluemind.core.rest.IServiceProvider;
72 72
 import net.bluemind.core.rest.ServerSideServiceProvider;
73 73
 import net.bluemind.core.sendmail.ISendmail;
74 74
 import net.bluemind.core.sendmail.Sendmail;
75
+import net.bluemind.core.sendmail.SendmailCredentials;
75 76
 import net.bluemind.core.sendmail.SendmailHelper;
76 77
 import net.bluemind.directory.api.DirEntry;
77 78
 import net.bluemind.directory.api.IDirectory;
... ...
@@ -737,8 +738,8 @@ public class IcsHook implements ICalendarHook {
737 738
 				try (Message mail = buildMailMessage(from, from, attendeeListTo, attendeeListCc, subjectTemplate,
738 739
 						template, messagesResolverProvider.getResolver(new Locale(getLocale(settings))), data,
739 740
 						createBodyPart(message.itemUid, ics), settings, event, method, attachments)) {
740
-					mailer.send(from.getAddress(), from.getDomain(), new MailboxList(Arrays.asList(recipient), true),
741
-							mail);
741
+					mailer.send(SendmailCredentials.asAdmin0(), from.getAddress(), from.getDomain(),
742
+							new MailboxList(Arrays.asList(recipient), true), mail);
742 743
 				} catch (Exception e) {
743 744
 					throw new RuntimeException(e);
744 745
 				}
... ...
@@ -43,8 +43,6 @@ import net.bluemind.calendar.api.ICalendar;
43 43
 import net.bluemind.calendar.api.ICalendarUids;
44 44
 import net.bluemind.calendar.api.VEvent;
45 45
 import net.bluemind.calendar.helper.mail.EventMailHelper;
46
-import net.bluemind.calendar.service.eventdeferredaction.EventDeferredAction;
47
-import net.bluemind.calendar.service.eventdeferredaction.EventDeferredActionExecutor;
48 46
 import net.bluemind.core.api.fault.ServerFault;
49 47
 import net.bluemind.core.container.model.ItemValue;
50 48
 import net.bluemind.core.context.SecurityContext;
... ...
@@ -53,6 +51,7 @@ import net.bluemind.core.jdbc.JdbcTestHelper;
53 51
 import net.bluemind.core.rest.ServerSideServiceProvider;
54 52
 import net.bluemind.core.sendmail.ISendmail;
55 53
 import net.bluemind.core.sendmail.Mail;
54
+import net.bluemind.core.sendmail.SendmailCredentials;
56 55
 import net.bluemind.deferredaction.api.DeferredAction;
57 56
 import net.bluemind.deferredaction.api.IDeferredAction;
58 57
 import net.bluemind.deferredaction.api.IDeferredActionContainerUids;
... ...
@@ -178,7 +177,7 @@ class MockedSendmail implements ISendmail {
178 177
 	}
179 178
 
180 179
 	@Override
181
-	public void send(String fromEmail, String userDomain, Message m) throws ServerFault {
180
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, Message m) {
182 181
 		wasCalled();
183 182
 	}
184 183
 
... ...
@@ -194,12 +193,13 @@ class MockedSendmail implements ISendmail {
194 193
 	}
195 194
 
196 195
 	@Override
197
-	public void send(String domainUid, Message m) throws ServerFault {
196
+	public void send(SendmailCredentials creds, String domainUid, Message m) throws ServerFault {
198 197
 		wasCalled();
199 198
 	}
200 199
 
201 200
 	@Override
202
-	public void send(String fromEmail, String userDomain, MailboxList rcptTo, Message m) throws ServerFault {
201
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, MailboxList rcptTo, Message m)
202
+			throws ServerFault {
203 203
 		wasCalled();
204 204
 	}
205 205
 
... ...
@@ -210,5 +210,4 @@ class MockedSendmail implements ISendmail {
210 210
 	public boolean hasBeenCalled() {
211 211
 		return wasCalled;
212 212
 	}
213
-
214 213
 }
215 214
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="output" path="bin"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.core.sendmail.testhelper</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.core.sendmail.testhelper
4
+Bundle-SymbolicName: net.bluemind.core.sendmail.testhelper;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Vendor: bluemind.net
7
+Automatic-Module-Name: net.bluemind.core.sendmail.testhelper
8
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Require-Bundle: net.bluemind.core.sendmail,
10
+ net.bluemind.core.commons,
11
+ org.apache.james.apache-mime4j-dom
12
+Export-Package: net.bluemind.core.sendmail.testhelper
0 13
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .,\
5
+               plugin.xml
0 6
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<plugin>
4
+   <extension
5
+         point="net.bluemind.core.sendmail.mailer">
6
+      <mailer
7
+            impl="net.bluemind.core.sendmail.testhelper.FakeSendmail"
8
+            priority="1000">
9
+      </mailer>
10
+   </extension>
11
+
12
+</plugin>
0 13
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <artifactId>net.bluemind.core.plugins</artifactId>
6
+    <version>4.1.0-SNAPSHOT</version>
7
+  </parent>
8
+  <artifactId>net.bluemind.core.sendmail.testhelper</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+</project>
0 11
new file mode 100644
... ...
@@ -0,0 +1,65 @@
1
+package net.bluemind.core.sendmail.testhelper;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+import java.util.Set;
6
+import java.util.stream.Collectors;
7
+
8
+import org.apache.james.mime4j.dom.Message;
9
+import org.apache.james.mime4j.dom.address.Mailbox;
10
+import org.apache.james.mime4j.dom.address.MailboxList;
11
+
12
+import net.bluemind.core.api.fault.ServerFault;
13
+import net.bluemind.core.sendmail.ISendmail;
14
+import net.bluemind.core.sendmail.Mail;
15
+import net.bluemind.core.sendmail.SendmailCredentials;
16
+
17
+public class FakeSendmail implements ISendmail {
18
+	public boolean mailSent = false;
19
+	public List<TestMail> messages = new ArrayList<TestMail>();
20
+
21
+	public Set<String> messagesTo() {
22
+		return messages.stream().flatMap(m -> m.to.stream()).collect(Collectors.toSet());
23
+	}
24
+
25
+	public Set<String> messagesFrom() {
26
+		return messages.stream().map(m -> m.from).collect(Collectors.toSet());
27
+	}
28
+
29
+	@Override
30
+	public void send(Mail m) throws ServerFault {
31
+		mailSent = true;
32
+	}
33
+
34
+	@Override
35
+	public void send(Mailbox sender, Message m) throws ServerFault {
36
+		mailSent = true;
37
+		messages.add(TestMail.fromMessage(m));
38
+	}
39
+
40
+	@Override
41
+	public void send(SendmailCredentials creds, String domainUid, Message m) throws ServerFault {
42
+		mailSent = true;
43
+		messages.add(TestMail.fromMessage(m));
44
+	}
45
+
46
+	@Override
47
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, Message m) {
48
+		mailSent = true;
49
+	}
50
+
51
+	@Override
52
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, MailboxList rcptTo, Message m)
53
+			throws ServerFault {
54
+		mailSent = true;
55
+
56
+		TestMail tm = new TestMail();
57
+		tm.from = fromEmail;
58
+		for (Mailbox mbox : rcptTo) {
59
+			tm.to.add(mbox.getAddress());
60
+		}
61
+
62
+		tm.message = m;
63
+		messages.add(tm);
64
+	}
65
+}
0 66
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+package net.bluemind.core.sendmail.testhelper;
2
+
3
+import java.util.HashSet;
4
+import java.util.Iterator;
5
+import java.util.Set;
6
+
7
+import org.apache.james.mime4j.dom.Message;
8
+import org.apache.james.mime4j.dom.address.Address;
9
+import org.apache.james.mime4j.dom.address.Mailbox;
10
+
11
+public class TestMail {
12
+	public Message message;
13
+	public String from;
14
+	public Set<String> to = new HashSet<>();
15
+
16
+	public static TestMail fromMessage(Message m) {
17
+		TestMail testMail = new TestMail();
18
+		testMail.message = m;
19
+		testMail.from = m.getFrom().get(0).getAddress();
20
+		Iterator<Address> it = m.getTo().iterator();
21
+		while (it.hasNext()) {
22
+			testMail.to.add(((Mailbox) it.next()).getAddress());
23
+		}
24
+
25
+		return testMail;
26
+	}
27
+}
0 28
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src/"/>
6
+	<classpathentry kind="output" path="target/classes"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?xml version="1.0"?>
2
+<projectDescription>
3
+	<name>net.bluemind.core.sendmail</name>
4
+	<comment/>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+		
24
+	</buildSpec>
25
+	<natures>
26
+		
27
+		<nature>org.eclipse.pde.PluginNature</nature>
28
+		<nature>org.eclipse.jdt.core.javanature</nature>
29
+	</natures>
30
+</projectDescription>
0 31
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.core.sendmail
4
+Bundle-SymbolicName: net.bluemind.core.sendmail;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Activator: net.bluemind.core.sendmail.Activator
7
+Bundle-Vendor: blue-mind.net
8
+Require-Bundle: org.eclipse.core.runtime,
9
+ net.bluemind.mime4j.common;bundle-version="1.0.0",
10
+ net.bluemind.lib.ristretto;bundle-version="1.0.0",
11
+ slf4j.api,
12
+ net.bluemind.locator.client;bundle-version="1.0.0",
13
+ net.bluemind.core.commons;bundle-version="1.0.0",
14
+ net.bluemind.lib.vertx,
15
+ net.bluemind.core.rest,
16
+ net.bluemind.config,
17
+ net.bluemind.network.topology
18
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
19
+Bundle-ActivationPolicy: lazy
20
+Export-Package: net.bluemind.core.sendmail
21
+Eclipse-RegisterBuddy: net.bluemind.lib.vertx
22
+Automatic-Module-Name: net.bluemind.core.sendmail
0 23
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+source.. = src/
2
+bin.includes = META-INF/,\
3
+               .,\
4
+               plugin.xml,\
5
+               schema/
0 6
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<plugin>
4
+   <extension-point id="net.bluemind.core.sendmail.mailer" name="mailer" schema="schema/net.bluemind.mailer.exsd"/>
5
+   <extension
6
+         point="net.bluemind.lib.vertx.verticles">
7
+      <verticle
8
+            impl="net.bluemind.core.sendmail.SendMailVerticleFactory">
9
+      </verticle>
10
+   </extension>
11
+   <extension
12
+         point="net.bluemind.core.sendmail.mailer">
13
+         <mailer
14
+         	impl="net.bluemind.core.sendmail.Sendmail"
15
+         	priority="1" >
16
+         </mailer>
17
+   </extension>
18
+
19
+</plugin>
0 20
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+
6
+	<parent>
7
+		<groupId>net.bluemind</groupId>
8
+		<artifactId>net.bluemind.core.plugins</artifactId>
9
+		<version>4.1.0-SNAPSHOT</version>
10
+	</parent>
11
+
12
+	<artifactId>net.bluemind.core.sendmail</artifactId>
13
+
14
+	<packaging>eclipse-plugin</packaging>
15
+</project>
0 16
new file mode 100644
... ...
@@ -0,0 +1,109 @@
1
+<?xml version='1.0' encoding='UTF-8'?>
2
+<!-- Schema file written by PDE -->
3
+<schema targetNamespace="net.bluemind.core.sendmail" xmlns="http://www.w3.org/2001/XMLSchema">
4
+<annotation>
5
+      <appinfo>
6
+         <meta.schema plugin="net.bluemind.core.sendmail" id="net.bluemind.mailer" name="mailer"/>
7
+      </appinfo>
8
+      <documentation>
9
+         [Enter description of this extension point.]
10
+      </documentation>
11
+   </annotation>
12
+
13
+   <element name="extension">
14
+      <annotation>
15
+         <appinfo>
16
+            <meta.element />
17
+         </appinfo>
18
+      </annotation>
19
+      <complexType>
20
+         <sequence>
21
+            <element ref="mailer"/>
22
+         </sequence>
23
+         <attribute name="point" type="string" use="required">
24
+            <annotation>
25
+               <documentation>
26
+                  
27
+               </documentation>
28
+            </annotation>
29
+         </attribute>
30
+         <attribute name="id" type="string">
31
+            <annotation>
32
+               <documentation>
33
+                  
34
+               </documentation>
35
+            </annotation>
36
+         </attribute>
37
+         <attribute name="name" type="string">
38
+            <annotation>
39
+               <documentation>
40
+                  
41
+               </documentation>
42
+               <appinfo>
43
+                  <meta.attribute translatable="true"/>
44
+               </appinfo>
45
+            </annotation>
46
+         </attribute>
47
+      </complexType>
48
+   </element>
49
+
50
+   <element name="mailer">
51
+      <complexType>
52
+         <attribute name="priority" type="string" use="required">
53
+            <annotation>
54
+               <documentation>
55
+                  
56
+               </documentation>
57
+            </annotation>
58
+         </attribute>
59
+         <attribute name="impl" type="string" use="required">
60
+            <annotation>
61
+               <documentation>
62
+                  
63
+               </documentation>
64
+               <appinfo>
65
+                  <meta.attribute kind="java" basedOn=":net.bluemind.core.sendmail.ISendmail"/>
66
+               </appinfo>
67
+            </annotation>
68
+         </attribute>
69
+      </complexType>
70
+   </element>
71
+
72
+   <annotation>
73
+      <appinfo>
74
+         <meta.section type="since"/>
75
+      </appinfo>
76
+      <documentation>
77
+         [Enter the first release in which this extension point appears.]
78
+      </documentation>
79
+   </annotation>
80
+
81
+   <annotation>
82
+      <appinfo>
83
+         <meta.section type="examples"/>
84
+      </appinfo>
85
+      <documentation>
86
+         [Enter extension point usage example here.]
87
+      </documentation>
88
+   </annotation>
89
+
90
+   <annotation>
91
+      <appinfo>
92
+         <meta.section type="apiinfo"/>
93
+      </appinfo>
94
+      <documentation>
95
+         [Enter API information here.]
96
+      </documentation>
97
+   </annotation>
98
+
99
+   <annotation>
100
+      <appinfo>
101
+         <meta.section type="implementation"/>
102
+      </appinfo>
103
+      <documentation>
104
+         [Enter information about supplied implementation of this extension point.]
105
+      </documentation>
106
+   </annotation>
107
+
108
+
109
+</schema>
0 110
new file mode 100644
... ...
@@ -0,0 +1,52 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import org.osgi.framework.BundleActivator;
22
+import org.osgi.framework.BundleContext;
23
+
24
+public class Activator implements BundleActivator {
25
+
26
+	private static BundleContext context;
27
+
28
+	static BundleContext getContext() {
29
+		return context;
30
+	}
31
+
32
+	/*
33
+	 * (non-Javadoc)
34
+	 * 
35
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
36
+	 * BundleContext)
37
+	 */
38
+	public void start(BundleContext bundleContext) throws Exception {
39
+		Activator.context = bundleContext;
40
+	}
41
+
42
+	/*
43
+	 * (non-Javadoc)
44
+	 * 
45
+	 * @see
46
+	 * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
47
+	 */
48
+	public void stop(BundleContext bundleContext) throws Exception {
49
+		Activator.context = null;
50
+	}
51
+
52
+}
0 53
new file mode 100644
... ...
@@ -0,0 +1,83 @@
1
+/* BEGIN LICENSE
2
+  * Copyright © Blue Mind SAS, 2012-2016
3
+  *
4
+  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+  * solution.
6
+  *
7
+  * This program is free software; you can redistribute it and/or modify
8
+  * it under the terms of either the GNU Affero General Public License as
9
+  * published by the Free Software Foundation (version 3 of the License).
10
+  *
11
+  *
12
+  * This program is distributed in the hope that it will be useful,
13
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+  *
16
+  * See LICENSE.txt
17
+  * END LICENSE
18
+  */
19
+package net.bluemind.core.sendmail;
20
+
21
+import org.apache.james.mime4j.dom.Message;
22
+import org.apache.james.mime4j.dom.address.Mailbox;
23
+import org.apache.james.mime4j.dom.address.MailboxList;
24
+
25
+import net.bluemind.core.api.fault.ServerFault;
26
+
27
+public interface ISendmail {
28
+
29
+	/**
30
+	 * Send an email using specific SMTP authentication. This API is usable from
31
+	 * outside core JVM.
32
+	 * 
33
+	 * @param creds
34
+	 *                       SMTP credentials
35
+	 * @param fromEmail
36
+	 *                       Envelope from
37
+	 * @param userDomain
38
+	 *                       Used to locate a valid SMTP
39
+	 * @param m
40
+	 * @throws ServerFault
41
+	 */
42
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, Message m);
43
+
44
+	/**
45
+	 * @param m
46
+	 * @throws ServerFault
47
+	 */
48
+	void send(Mail m) throws ServerFault;
49
+
50
+	/**
51
+	 * @param from
52
+	 * @param m
53
+	 * @throws ServerFault
54
+	 */
55
+	void send(Mailbox from, Message m) throws ServerFault;
56
+
57
+	/**
58
+	 * @param creds
59
+	 *                      SMTP credentials
60
+	 * @param domainUid
61
+	 * @param m
62
+	 * @throws ServerFault
63
+	 */
64
+	void send(SendmailCredentials creds, String domainUid, Message m) throws ServerFault;
65
+
66
+	/**
67
+	 * Send an email using specific SMTP authentication. This API is usable from
68
+	 * outside core JVM.
69
+	 * 
70
+	 * @param creds
71
+	 *                       SMTP credentials
72
+	 * @param fromEmail
73
+	 *                       Envelope from
74
+	 * @param userDomain
75
+	 *                       Used to locate a valid SMTP
76
+	 * @param rcptTo
77
+	 *                       the real recipients
78
+	 * @param m
79
+	 * @throws ServerFault
80
+	 */
81
+	void send(SendmailCredentials creds, String fromEmail, String userDomain, MailboxList rcptTo, Message m)
82
+			throws ServerFault;
83
+}
0 84
\ No newline at end of file
1 85
new file mode 100644
... ...
@@ -0,0 +1,84 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import java.io.UnsupportedEncodingException;
22
+import java.util.ArrayList;
23
+import java.util.Date;
24
+import java.util.List;
25
+
26
+import org.apache.james.mime4j.codec.DecodeMonitor;
27
+import org.apache.james.mime4j.dom.Header;
28
+import org.apache.james.mime4j.dom.Message;
29
+import org.apache.james.mime4j.dom.TextBody;
30
+import org.apache.james.mime4j.dom.address.Mailbox;
31
+import org.apache.james.mime4j.dom.field.UnstructuredField;
32
+import org.apache.james.mime4j.field.Fields;
33
+import org.apache.james.mime4j.field.UnstructuredFieldImpl;
34
+import org.apache.james.mime4j.message.BasicBodyFactory;
35
+import org.apache.james.mime4j.message.BodyPart;
36
+import org.apache.james.mime4j.message.HeaderImpl;
37
+import org.apache.james.mime4j.message.MessageImpl;
38
+import org.apache.james.mime4j.stream.RawField;
39
+
40
+public class Mail {
41
+	public Mailbox from;
42
+	public Mailbox sender;
43
+	public Mailbox to;
44
+
45
+	public String subject;
46
+	public String html;
47
+
48
+	public List<RawField> headers = new ArrayList<RawField>();
49
+
50
+	public Message getMessage() {
51
+		MessageImpl m = new MessageImpl();
52
+		Header h = new HeaderImpl();
53
+		h.addField(Fields.date(new Date()));
54
+		h.addField(Fields.subject(subject));
55
+		h.addField(Fields.sender(sender));
56
+		h.addField(Fields.from(from));
57
+		h.addField(Fields.to(to));
58
+		h.setField(Fields.contentType("text/html; charset=UTF-8;"));
59
+		h.setField(Fields.contentTransferEncoding("quoted-printable"));
60
+		for (RawField rf : headers) {
61
+			UnstructuredField field = UnstructuredFieldImpl.PARSER.parse(rf, DecodeMonitor.SILENT);
62
+			h.setField(field);
63
+		}
64
+		m.setHeader(h);
65
+
66
+		BodyPart body = createTextPart(html);
67
+		m.setBody(body.getBody());
68
+
69
+		return m;
70
+	}
71
+
72
+	private static BodyPart createTextPart(String text) {
73
+		BasicBodyFactory bodyFactory = new BasicBodyFactory();
74
+		TextBody body;
75
+		try {
76
+			body = bodyFactory.textBody(text, "UTF-8");
77
+		} catch (UnsupportedEncodingException e) {
78
+			throw new RuntimeException("unsupported encoding");
79
+		}
80
+		BodyPart bodyPart = new BodyPart();
81
+		bodyPart.setText(body);
82
+		return bodyPart;
83
+	}
84
+}
0 85
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+public final class SendMailAddress {
22
+	public static final String SEND = "bm.calendar.core.sendmail.send";
23
+
24
+}
0 25
new file mode 100644
... ...
@@ -0,0 +1,49 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import org.slf4j.Logger;
22
+import org.slf4j.LoggerFactory;
23
+import org.vertx.java.core.Handler;
24
+import org.vertx.java.core.eventbus.Message;
25
+import org.vertx.java.platform.Verticle;
26
+
27
+import net.bluemind.core.api.fault.ServerFault;
28
+import net.bluemind.core.rest.LocalJsonObject;
29
+
30
+public class SendMailVerticle extends Verticle {
31
+
32
+	private static final Logger logger = LoggerFactory.getLogger(SendMailVerticle.class);
33
+
34
+	@Override
35
+	public void start() {
36
+		final ISendmail mailer = new Sendmail();
37
+		vertx.eventBus().registerHandler(SendMailAddress.SEND, new Handler<Message<LocalJsonObject<Mail>>>() {
38
+			public void handle(Message<LocalJsonObject<Mail>> message) {
39
+				try {
40
+					mailer.send(message.body().getValue());
41
+				} catch (ServerFault e) {
42
+					logger.error(e.getMessage(), e);
43
+				}
44
+
45
+			}
46
+		});
47
+
48
+	}
49
+}
0 50
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import org.vertx.java.platform.Verticle;
22
+
23
+import net.bluemind.lib.vertx.IVerticleFactory;
24
+
25
+public class SendMailVerticleFactory implements IVerticleFactory {
26
+
27
+	@Override
28
+	public boolean isWorker() {
29
+		return true;
30
+	}
31
+
32
+	@Override
33
+	public Verticle newInstance() {
34
+		return new SendMailVerticle();
35
+	}
36
+
37
+}
0 38
new file mode 100644
... ...
@@ -0,0 +1,143 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import java.net.InetAddress;
22
+import java.util.LinkedList;
23
+
24
+import org.apache.james.mime4j.dom.Message;
25
+import org.apache.james.mime4j.dom.address.AddressList;
26
+import org.apache.james.mime4j.dom.address.Mailbox;
27
+import org.apache.james.mime4j.dom.address.MailboxList;
28
+import org.columba.ristretto.message.Address;
29
+import org.columba.ristretto.smtp.SMTPProtocol;
30
+import org.slf4j.Logger;
31
+import org.slf4j.LoggerFactory;
32
+
33
+import net.bluemind.core.api.fault.ServerFault;
34
+import net.bluemind.mime4j.common.Mime4JHelper;
35
+import net.bluemind.network.topology.Topology;
36
+
37
+public class Sendmail implements ISendmail {
38
+
39
+	private static final Logger logger = LoggerFactory.getLogger(Sendmail.class);
40
+
41
+	/*
42
+	 * (non-Javadoc)
43
+	 * 
44
+	 * @see net.bluemind.core.sendmail.ISendmail#send(java.lang.String,
45
+	 * java.lang.String, java.lang.String, org.apache.james.mime4j.dom.Message)
46
+	 */
47
+	@Override
48
+	public void send(SendmailCredentials creds, String domainUid, Message m) throws ServerFault {
49
+		send(creds, m.getFrom().iterator().next().getAddress(), domainUid, allRecipients(m), m);
50
+	}
51
+
52
+	/*
53
+	 * (non-Javadoc)
54
+	 * 
55
+	 * @see net.bluemind.core.sendmail.ISendmail#send(java.lang.String,
56
+	 * java.lang.String, org.apache.james.mime4j.dom.Message)
57
+	 */
58
+	@Override
59
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, Message m) throws ServerFault {
60
+		send(creds, fromEmail, userDomain, allRecipients(m), m);
61
+	}
62
+
63
+	/*
64
+	 * (non-Javadoc)
65
+	 * 
66
+	 * @see net.bluemind.core.sendmail.ISendmail#send(net.bluemind.core.sendmail.
67
+	 * Mail)
68
+	 */
69
+	@Override
70
+	public void send(Mail m) throws ServerFault {
71
+		send(m.from, m.getMessage());
72
+	}
73
+
74
+	/*
75
+	 * (non-Javadoc)
76
+	 * 
77
+	 * @see net.bluemind.core.sendmail.ISendmail#send(org.apache.james.mime4j.dom.
78
+	 * address.Mailbox, org.apache.james.mime4j.dom.Message)
79
+	 */
80
+	@Override
81
+	public void send(Mailbox from, Message m) throws ServerFault {
82
+		send(SendmailCredentials.asAdmin0(), from.getAddress(), from.getDomain(), allRecipients(m), m);
83
+	}
84
+
85
+	private MailboxList allRecipients(Message m) throws ServerFault {
86
+		LinkedList<Mailbox> rcpt = new LinkedList<>();
87
+		AddressList tos = m.getTo();
88
+		if (tos != null) {
89
+			rcpt.addAll(tos.flatten());
90
+		}
91
+		AddressList ccs = m.getCc();
92
+		if (ccs != null) {
93
+			rcpt.addAll(ccs.flatten());
94
+		}
95
+		AddressList bccs = m.getBcc();
96
+		if (bccs != null) {
97
+			rcpt.addAll(bccs.flatten());
98
+		}
99
+		if (rcpt.isEmpty()) {
100
+			throw new ServerFault("Empty recipients list.");
101
+		}
102
+		return new MailboxList(rcpt, true);
103
+	}
104
+
105
+	/*
106
+	 * (non-Javadoc)
107
+	 * 
108
+	 * @see
109
+	 * net.bluemind.core.sendmail.ISendmail#send(java.lang.String,java.lang.String,
110
+	 * java.lang.String, java.lang.String,
111
+	 * org.apache.james.mime4j.dom.address.MailboxList,
112
+	 * org.apache.james.mime4j.dom.Message)
113
+	 */
114
+	@Override
115
+	public void send(SendmailCredentials creds, String fromEmail, String userDomain, MailboxList rcptTo, Message m)
116
+			throws ServerFault {
117
+		if (rcptTo == null) {
118
+			throw new ServerFault("null To: field in message");
119
+		}
120
+
121
+		String ip = Topology.get().any("mail/smtp").value.address();
122
+		try {
123
+			SMTPProtocol smtp = new SMTPProtocol(ip, 587);
124
+
125
+			smtp.openPort();
126
+			smtp.startTLS();
127
+			smtp.auth("PLAIN", creds.loginAtDomain, creds.authKey.toCharArray());
128
+			smtp.ehlo(InetAddress.getLocalHost());
129
+			smtp.mail(new Address(fromEmail));
130
+
131
+			for (Mailbox to : rcptTo) {
132
+				smtp.rcpt(new Address(to.getAddress()));
133
+			}
134
+
135
+			smtp.data(Mime4JHelper.asStream(m));
136
+			smtp.quit();
137
+
138
+		} catch (Exception se) {
139
+			logger.error(se.getMessage(), se);
140
+			throw new ServerFault(se.getMessage());
141
+		}
142
+	}
143
+}
0 144
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+package net.bluemind.core.sendmail;
2
+
3
+import net.bluemind.config.Token;
4
+
5
+public class SendmailCredentials {
6
+
7
+	public final String loginAtDomain;
8
+	public final String authKey;
9
+
10
+	private SendmailCredentials(String loginAtDomain, String authKey) {
11
+		this.loginAtDomain = loginAtDomain;
12
+		this.authKey = authKey;
13
+	}
14
+
15
+	public static SendmailCredentials as(String loginAtDomain, String authKey) {
16
+		return new SendmailCredentials(loginAtDomain, authKey);
17
+	}
18
+
19
+	public static SendmailCredentials asAdmin0() {
20
+		return new SendmailCredentials("admin0@global.virt", Token.admin0());
21
+	}
22
+}
0 23
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.core.sendmail;
20
+
21
+import org.apache.james.mime4j.codec.EncoderUtil;
22
+import org.apache.james.mime4j.dom.address.Mailbox;
23
+import org.apache.james.mime4j.field.address.AddressBuilder;
24
+import org.apache.james.mime4j.field.address.ParseException;
25
+import org.slf4j.Logger;
26
+import org.slf4j.LoggerFactory;
27
+
28
+public class SendmailHelper {
29
+
30
+	private static final Logger logger = LoggerFactory.getLogger(SendmailHelper.class);
31
+
32
+	public static Mailbox formatAddress(String displayName, String em) {
33
+		String email = em != null ? em : "no-reply@blue-mind.net";
34
+		try {
35
+			return AddressBuilder.DEFAULT
36
+					.parseMailbox((displayName != null ? EncoderUtil.encodeAddressDisplayName(displayName) : "") + " <"
37
+							+ email + ">");
38
+		} catch (ParseException e) {
39
+			logger.error("addr parse exception for dn: " + displayName + " e: " + email + " (" + e.getMessage() + ")");
40
+			return null;
41
+		}
42
+	}
43
+}
... ...
@@ -67,6 +67,9 @@
67 67
 		<module>net.bluemind.application.launcher</module>
68 68
 		<module>net.bluemind.locator.vertxclient</module>
69 69
 		<module>net.bluemind.core.auditlog</module>
70
+
71
+		<module>net.bluemind.core.sendmail</module>
72
+		<module>net.bluemind.core.sendmail.testhelper/</module>
70 73
 	</modules>
71 74
 
72 75
 	<build>
... ...
@@ -43,6 +43,7 @@ import net.bluemind.core.context.SecurityContext;
43 43
 import net.bluemind.core.rest.ServerSideServiceProvider;
44 44
 import net.bluemind.core.sendmail.ISendmail;
45 45
 import net.bluemind.core.sendmail.Sendmail;
46
+import net.bluemind.core.sendmail.SendmailCredentials;
46 47
 import net.bluemind.core.sendmail.SendmailHelper;
47 48
 import net.bluemind.domain.api.Domain;
48 49
 import net.bluemind.domain.api.IDomains;
... ...
@@ -70,7 +71,7 @@ public class SendGroupChatHistory implements Runnable {
70 71
 	public void run() {
71 72
 		try {
72 73
 			Message m = getMessage();
73
-			mailer.send(sender, m);
74
+			mailer.send(SendmailCredentials.asAdmin0(), sender, m);
74 75
 		} catch (Exception e) {
75 76
 			logger.error(e.getMessage(), e);
76 77
 		}
... ...
@@ -52,10 +52,10 @@ Require-Bundle: org.junit,
52 52
  org.freemarker.freemarker,
53 53
  net.bluemind.directory.service,
54 54
  net.bluemind.hsm.service;bundle-version="4.1.0",
55
- net.bluemind.core.sendmail,
56 55
  net.bluemind.system.api,
57 56
  net.bluemind.lib.vertx,
58
- net.bluemind.locator
57
+ net.bluemind.locator,
58
+ net.bluemind.core.sendmail.testhelper
59 59
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
60 60
 Bundle-ActivationPolicy: lazy
61 61
 Automatic-Module-Name: net.bluemind.backend.mail.replica.service.tests
62 62
deleted file mode 100644
... ...
@@ -1,43 +0,0 @@
1
-package net.bluemind.backend.mail.replica.service.tests;
2
-
3
-import org.apache.james.mime4j.dom.Message;
4
-import org.apache.james.mime4j.dom.address.Mailbox;
5
-import org.apache.james.mime4j.dom.address.MailboxList;
6
-
7
-import net.bluemind.core.api.fault.ServerFault;
8
-import net.bluemind.core.sendmail.ISendmail;
9
-import net.bluemind.core.sendmail.Mail;
10
-
11
-public class FakeSendmail implements ISendmail {
12
-
13
-	@Override
14
-	public void send(String fromEmail, String userDomain, Message m) throws ServerFault {
15
-		// TODO Auto-generated method stub
16
-		
17
-	}
18
-
19
-	@Override
20
-	public void send(Mail m) throws ServerFault {
21
-		// TODO Auto-generated method stub
22
-		
23
-	}
24
-
25
-	@Override
26
-	public void send(Mailbox from, Message m) throws ServerFault {
27
-		// TODO Auto-generated method stub
28
-		
29
-	}
30
-
31
-	@Override
32
-	public void send(String domainUid, Message m) throws ServerFault {
33
-		// TODO Auto-generated method stub
34
-		
35
-	}
36
-
37
-	@Override
38
-	public void send(String fromEmail, String userDomain, MailboxList rcptTo, Message m) throws ServerFault {
39
-		// TODO Auto-generated method stub
40
-		
41
-	}
42
-
43
-}
... ...
@@ -16,14 +16,16 @@ import org.slf4j.LoggerFactory;
16 16
 import com.google.common.collect.Iterables;
17 17
 
18 18
 import io.netty.buffer.ByteBufInputStream;
19
+import net.bluemind.authentication.api.AuthUser;
20
+import net.bluemind.authentication.api.IAuthentication;
19 21
 import net.bluemind.backend.mail.api.IMailboxFolders;
20 22
 import net.bluemind.backend.mail.api.IMailboxFoldersByContainer;
21 23
 import net.bluemind.backend.mail.api.IMailboxItems;
22 24
 import net.bluemind.backend.mail.api.IOutbox;
23 25
 import net.bluemind.backend.mail.api.ImportMailboxItemSet;
24 26
 import net.bluemind.backend.mail.api.ImportMailboxItemSet.MailboxItemId;
25
-import net.bluemind.backend.mail.api.ImportMailboxItemsStatus.ImportedMailboxItem;
26 27
 import net.bluemind.backend.mail.api.ImportMailboxItemsStatus;
28
+import net.bluemind.backend.mail.api.ImportMailboxItemsStatus.ImportedMailboxItem;
27 29
 import net.bluemind.backend.mail.api.MailboxFolder;
28 30
 import net.bluemind.backend.mail.api.MailboxItem;
29 31
 import net.bluemind.backend.mail.replica.api.IMailReplicaUids;
... ...
@@ -36,6 +38,7 @@ import net.bluemind.core.container.service.internal.RBACManager;
36 38
 import net.bluemind.core.rest.BmContext;
37 39
 import net.bluemind.core.rest.IServiceProvider;
38 40
 import net.bluemind.core.sendmail.ISendmail;
41
+import net.bluemind.core.sendmail.SendmailCredentials;
39 42
 import net.bluemind.core.task.api.TaskRef;
40 43
 import net.bluemind.core.task.service.IServerTaskMonitor;
41 44
 import net.bluemind.core.task.service.ITasksManager;
... ...
@@ -48,6 +51,7 @@ public class OutboxService implements IOutbox {
48 51
 
49 52
 	private static final Logger logger = LoggerFactory.getLogger(OutboxService.class);
50 53
 
54
+	private final BmContext context;
51 55
 	private final String domainUid;
52 56
 	private final ItemValue<Mailbox> mailboxItem;
53 57
 	private final IServiceProvider serviceProvider;
... ...
@@ -56,6 +60,7 @@ public class OutboxService implements IOutbox {
56 60
 	private ISendmail mailer;
57 61
 
58 62
 	public OutboxService(BmContext context, String domainUid, ItemValue<Mailbox> mailboxItem, ISendmail mailer) {
63
+		this.context = context;
59 64
 		this.domainUid = domainUid;
60 65
 		this.mailboxItem = mailboxItem;
61 66
 		this.serviceProvider = context.getServiceProvider();
... ...
@@ -83,6 +88,8 @@ public class OutboxService implements IOutbox {
83 88
 		List<ItemValue<MailboxItem>> mails = retrieveOutboxItems(mailboxItemsService);
84 89
 		monitor.begin(mails.size(), "FLUSHING OUTBOX - have " + mails.size() + " mails to send.");
85 90
 
91
+		AuthUser user = serviceProvider.instance(IAuthentication.class).getCurrentUser();
92
+
86 93
 		List<CompletableFuture<Void>> promises = new ArrayList<>();
87 94
 		final List<ImportedMailboxItem> importedMailboxItems = new ArrayList<>(mails.size());
88 95
 		mails.forEach(item -> {
... ...
@@ -90,7 +97,8 @@ public class OutboxService implements IOutbox {
90 97
 					SyncStreamDownload.read(mailboxItemsService.fetchComplete(item.value.imapUid)).thenAccept(buf -> {
91 98
 						InputStream in = new ByteBufInputStream(buf);
92 99
 						try (Message msg = Mime4JHelper.parse(in)) {
93
-							mailer.send(domainUid, msg);
100
+							mailer.send(SendmailCredentials.as(String.format("%s@%s", user.value.login, domainUid),
101
+									context.getSecurityContext().getSessionId()), domainUid, msg);
94 102
 
95 103
 							final ImportMailboxItemsStatus importMailboxItemsStatus = mailboxFoldersService
96 104
 									.importItems(sentInternalId, ImportMailboxItemSet.moveIn(outboxInternalId,
... ...
@@ -36,4 +36,5 @@ Require-Bundle: org.junit,
36 36
  net.bluemind.group.persistence,
37 37
  net.bluemind.user.service,
38 38
  net.bluemind.core.tests.testshelper,
39
- net.bluemind.group.service
39
+ net.bluemind.group.service,
40
+ net.bluemind.core.sendmail.testhelper
40 41
deleted file mode 100644
... ...
@@ -1,63 +0,0 @@
1
-/* BEGIN LICENSE
2
-  * Copyright © Blue Mind SAS, 2012-2016
3
-  *
4
-  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
-  * solution.
6
-  *
7
-  * This program is free software; you can redistribute it and/or modify
8
-  * it under the terms of either the GNU Affero General Public License as
9
-  * published by the Free Software Foundation (version 3 of the License).
10
-  *
11
-  *
12
-  * This program is distributed in the hope that it will be useful,
13
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
-  *
16
-  * See LICENSE.txt
17
-  * END LICENSE
18
-  */
19
-package net.bluemind.resource.hook.ics;
20
-
21
-import java.util.HashSet;
22
-import java.util.Set;
23
-
24
-import org.apache.james.mime4j.dom.Message;
25
-import org.apache.james.mime4j.dom.address.Mailbox;
26
-import org.apache.james.mime4j.dom.address.MailboxList;
27
-
28
-import net.bluemind.core.api.fault.ServerFault;
29
-import net.bluemind.core.sendmail.ISendmail;
30
-import net.bluemind.core.sendmail.Mail;
31
-
32
-public class FakeSendmail implements ISendmail {
33
-	public boolean mailSent = false;
34
-	public Set<String> from = new HashSet<>();
35
-	public Set<String> to = new HashSet<>();
36
-
37
-	@Override
38
-	public void send(Mail m) throws ServerFault {
39
-		mailSent = true;
40
-	}
41
-
42
-	@Override
43
-	public void send(String fromEmail, String userDomain, Message m) throws ServerFault {
44
-		mailSent = true;
45
-	}
46
-
47
-	@Override
48
-	public void send(Mailbox sender, Message m) throws ServerFault {
49
-		mailSent = true;
50
-		from.add(m.getFrom().get(0).getAddress());
51
-		to.add(((Mailbox) m.getTo().get(0)).getAddress());
52
-	}
53
-
54
-	@Override
55
-	public void send(String domainUid, Message m) throws ServerFault {
56
-	}
57
-
58
-	@Override
59
-	public void send(String fromEmail, String userDomain, MailboxList rcptTo, Message m) throws ServerFault {
60
-		// TODO Auto-generated method stub
61
-
62
-	}
63
-}
... ...
@@ -68,6 +68,7 @@ import net.bluemind.core.context.SecurityContext;
68 68
 import net.bluemind.core.jdbc.JdbcActivator;
69 69
 import net.bluemind.core.jdbc.JdbcTestHelper;
70 70
 import net.bluemind.core.rest.ServerSideServiceProvider;
71
+import net.bluemind.core.sendmail.testhelper.FakeSendmail;
71 72
 import net.bluemind.core.sessions.Sessions;
72 73
 import net.bluemind.core.tests.BmTestContext;
73 74
 import net.bluemind.domain.api.Domain;
... ...
@@ -353,12 +354,12 @@ public class IcsHookTests {
353 354
 		new ResourceIcsHook(fakeSendmail).onEventCreated(veventMessage);
354 355
 		assertTrue(fakeSendmail.mailSent);
355 356
 
356
-		assertEquals(1, fakeSendmail.from.size());
357
-		assertEquals(rd.emails.iterator().next().address, fakeSendmail.from.iterator().next());
357
+		assertEquals(1, fakeSendmail.messagesFrom().size());
358
+		assertEquals(rd.emails.iterator().next().address, fakeSendmail.messagesFrom().iterator().next());
358 359
 
359
-		assertEquals(2, fakeSendmail.to.size());
360
-		assertTrue(fakeSendmail.to.contains(user1.value.emails.iterator().next().address));
361
-		assertTrue(fakeSendmail.to.contains(user2.value.emails.iterator().next().address));
360
+		assertEquals(2, fakeSendmail.messagesTo().size());
361
+		assertTrue(fakeSendmail.messagesTo().contains(user1.value.emails.iterator().next().address));
362
+		assertTrue(fakeSendmail.messagesTo().contains(user2.value.emails.iterator().next().address));
362 363
 	}
363 364
 
364 365
 	@Test
... ...
@@ -383,12 +384,12 @@ public class IcsHookTests {
383 384
 		FakeSendmail fakeSendmail = new FakeSendmail();
384 385
 		new ResourceIcsHook(fakeSendmail).onEventUpdated(veventMessage);
385 386
 
386
-		assertEquals(1, fakeSendmail.from.size());
387
-		assertEquals(rd.emails.iterator().next().address, fakeSendmail.from.iterator().next());
387
+		assertEquals(1, fakeSendmail.messagesFrom().size());
388
+		assertEquals(rd.emails.iterator().next().address, fakeSendmail.messagesFrom().iterator().next());
388 389
 
389
-		assertEquals(2, fakeSendmail.to.size());
390
-		assertTrue(fakeSendmail.to.contains(user1.value.emails.iterator().next().address));
391
-		assertTrue(fakeSendmail.to.contains(user2.value.emails.iterator().next().address));
390
+		assertEquals(2, fakeSendmail.messagesTo().size());