1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.mailsender; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.apache.velocity.VelocityContext; |
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.slf4j.LoggerFactory; |
28 |
|
|
29 |
|
import com.xpn.xwiki.XWikiContext; |
30 |
|
import com.xpn.xwiki.api.Attachment; |
31 |
|
import com.xpn.xwiki.api.XWiki; |
32 |
|
import com.xpn.xwiki.plugin.PluginApi; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@see |
38 |
|
@version |
39 |
|
|
|
|
| 31.2% |
Uncovered Elements: 55 (80) |
Complexity: 19 |
Complexity Density: 0.31 |
|
40 |
|
public class MailSenderPluginApi extends PluginApi<MailSenderPlugin> implements MailSender |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(MailSenderPluginApi.class); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@param |
51 |
|
@param |
52 |
|
@see |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
4 |
public MailSenderPluginApi(MailSenderPlugin plugin, XWikiContext context)... |
55 |
|
{ |
56 |
4 |
super(plugin, context); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
59 |
0 |
@Override... |
60 |
|
public int sendHtmlMessage(String from, String to, String cc, String bcc, String subject, String body, |
61 |
|
String alternative, List<Attachment> attachments) |
62 |
|
{ |
63 |
0 |
Mail email = new Mail(); |
64 |
0 |
email.setSubject(subject); |
65 |
0 |
email.setFrom(from); |
66 |
0 |
email.setTo(to); |
67 |
0 |
email.setCc(cc); |
68 |
0 |
email.setBcc(bcc); |
69 |
0 |
email.setTextPart(alternative); |
70 |
0 |
email.setHtmlPart(body); |
71 |
0 |
email.setAttachments(attachments); |
72 |
0 |
return sendMail(email); |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
75 |
0 |
@Override... |
76 |
|
public int sendTextMessage(String from, String to, String subject, String message) |
77 |
|
{ |
78 |
0 |
Mail email = new Mail(); |
79 |
0 |
email.setSubject(subject); |
80 |
0 |
email.setTextPart(message); |
81 |
0 |
email.setFrom(from); |
82 |
0 |
email.setTo(to); |
83 |
0 |
return sendMail(email); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
86 |
0 |
@Override... |
87 |
|
public int sendTextMessage(String from, String to, String cc, String bcc, String subject, String message, |
88 |
|
List<Attachment> attachments) |
89 |
|
{ |
90 |
0 |
Mail email = new Mail(); |
91 |
0 |
email.setSubject(subject); |
92 |
0 |
email.setTextPart(message); |
93 |
0 |
email.setFrom(from); |
94 |
0 |
email.setTo(to); |
95 |
0 |
email.setCc(cc); |
96 |
0 |
email.setBcc(bcc); |
97 |
0 |
email.setAttachments(attachments); |
98 |
0 |
return sendMail(email); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
101 |
1 |
@Override... |
102 |
|
public int sendRawMessage(String from, String to, String rawMessage) |
103 |
|
{ |
104 |
1 |
Mail email = new Mail(); |
105 |
1 |
email.setFrom(from); |
106 |
1 |
email.setTo(to); |
107 |
|
|
108 |
1 |
getProtectedPlugin().parseRawMessage(rawMessage, email); |
109 |
1 |
return sendMail(email); |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
112 |
0 |
@Override... |
113 |
|
public int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, |
114 |
|
String documentFullName, VelocityContext vcontext) |
115 |
|
{ |
116 |
0 |
try { |
117 |
0 |
return getProtectedPlugin().sendMailFromTemplate(documentFullName, from, to, cc, bcc, language, vcontext, |
118 |
|
this.context); |
119 |
|
} catch (Exception e) { |
120 |
|
|
121 |
0 |
if (e.getMessage() != null) { |
122 |
0 |
this.context.put("error", e.getMessage()); |
123 |
|
} |
124 |
0 |
LOGGER.error("sendMessageFromTemplate", e); |
125 |
0 |
return -1; |
126 |
|
} |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
@param |
135 |
|
@param |
136 |
|
@param |
137 |
|
@param |
138 |
|
@param |
139 |
|
|
140 |
|
@param |
141 |
|
@return |
142 |
|
|
143 |
|
|
|
|
| 25% |
Uncovered Elements: 6 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
144 |
1 |
public int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language,... |
145 |
|
String documentFullName, Map<String, Object> parameters) |
146 |
|
{ |
147 |
1 |
try { |
148 |
1 |
return getProtectedPlugin().sendMailFromTemplate(documentFullName, from, to, cc, bcc, language, parameters, |
149 |
|
this.context); |
150 |
|
} catch (Exception e) { |
151 |
|
|
152 |
0 |
if (e.getMessage() != null) { |
153 |
0 |
this.context.put("error", e.getMessage()); |
154 |
|
} |
155 |
0 |
LOGGER.error("sendMessageFromTemplate", e); |
156 |
0 |
return -1; |
157 |
|
} |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
2 |
@Override... |
161 |
|
public Mail createMail() |
162 |
|
{ |
163 |
2 |
return new Mail(); |
164 |
|
} |
165 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
166 |
2 |
@Override... |
167 |
|
public int sendMail(Mail mail) |
168 |
|
{ |
169 |
2 |
int result = 0; |
170 |
2 |
try { |
171 |
2 |
getProtectedPlugin().sendMail(mail, this.context); |
172 |
|
} catch (Exception e) { |
173 |
|
|
174 |
0 |
if (e.getMessage() != null) { |
175 |
0 |
this.context.put("error", e.getMessage()); |
176 |
|
} |
177 |
0 |
LOGGER.error("Failed to send email [" + mail.toString() + "]", e); |
178 |
0 |
result = -1; |
179 |
|
} |
180 |
|
|
181 |
2 |
return result; |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
1 |
@Override... |
185 |
|
public MailConfiguration createMailConfiguration(XWiki xwiki) |
186 |
|
{ |
187 |
1 |
return new MailConfiguration(xwiki); |
188 |
|
} |
189 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
190 |
1 |
@Override... |
191 |
|
public int sendMail(Mail mail, MailConfiguration mailConfiguration) |
192 |
|
{ |
193 |
1 |
int result = 0; |
194 |
1 |
try { |
195 |
1 |
getProtectedPlugin().sendMail(mail, mailConfiguration, this.context); |
196 |
|
} catch (Exception e) { |
197 |
|
|
198 |
0 |
if (e.getMessage() != null) { |
199 |
0 |
this.context.put("error", e.getMessage()); |
200 |
|
} |
201 |
0 |
LOGGER.error("Failed to send email [" + mail.toString() + "] using mail configuration [" |
202 |
|
+ mailConfiguration.toString() + "]", e); |
203 |
0 |
result = -1; |
204 |
|
} |
205 |
|
|
206 |
1 |
return result; |
207 |
|
} |
208 |
|
} |