1 | package fr.sii.ogham.email.message; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import fr.sii.ogham.core.message.Message; | |
8 | import fr.sii.ogham.core.message.capability.HasContentFluent; | |
9 | import fr.sii.ogham.core.message.capability.HasRecipients; | |
10 | import fr.sii.ogham.core.message.capability.HasRecipientsFluent; | |
11 | import fr.sii.ogham.core.message.capability.HasSubject; | |
12 | import fr.sii.ogham.core.message.capability.HasSubjectFluent; | |
13 | import fr.sii.ogham.core.message.capability.HasToFluent; | |
14 | import fr.sii.ogham.core.message.content.Content; | |
15 | import fr.sii.ogham.core.message.content.MultiContent; | |
16 | import fr.sii.ogham.core.message.content.StringContent; | |
17 | import fr.sii.ogham.core.message.fluent.SingleContentBuilder; | |
18 | import fr.sii.ogham.core.util.Loggable; | |
19 | import fr.sii.ogham.core.util.EqualsBuilder; | |
20 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
21 | import fr.sii.ogham.core.util.StringUtils; | |
22 | import fr.sii.ogham.email.attachment.Attachment; | |
23 | import fr.sii.ogham.email.attachment.ContentDisposition; | |
24 | import fr.sii.ogham.email.message.fluent.AttachBuilder; | |
25 | import fr.sii.ogham.email.message.fluent.BodyBuilder; | |
26 | import fr.sii.ogham.email.message.fluent.EmbedBuilder; | |
27 | ||
28 | /** | |
29 | * Email message that contains the following information: | |
30 | * <ul> | |
31 | * <li>The subject of the mail</li> | |
32 | * <li>The body of the mail (see {@link Content} and sub classes for more | |
33 | * information)</li> | |
34 | * <li>The sender address</li> | |
35 | * <li>The list of recipient addresses with the type (to, cc, bcc)</li> | |
36 | * <li>The list of attachments to join to the mail</li> | |
37 | * </ul> | |
38 | * | |
39 | * @author Aurélien Baudet | |
40 | * | |
41 | */ | |
42 | public class Email implements Message, HasContentFluent<Email>, HasSubject, HasSubjectFluent<Email>, HasRecipients<Recipient>, HasRecipientsFluent<Email, Recipient>, HasToFluent<Email>, Loggable { | |
43 | /** | |
44 | * The subject | |
45 | */ | |
46 | private String subject; | |
47 | ||
48 | /** | |
49 | * The email body content | |
50 | */ | |
51 | private Content content; | |
52 | ||
53 | /** | |
54 | * The sender address | |
55 | */ | |
56 | private EmailAddress from; | |
57 | ||
58 | /** | |
59 | * The list of recipient addresses with the associated type (to, cc, bcc) | |
60 | */ | |
61 | private List<Recipient> recipients; | |
62 | ||
63 | /** | |
64 | * The list of attachments to send with the email | |
65 | */ | |
66 | private List<Attachment> attachments; | |
67 | ||
68 | private final SingleContentBuilder<Email> htmlBuilder; | |
69 | private final SingleContentBuilder<Email> textBuilder; | |
70 | private final BodyBuilder bodyBuilder; | |
71 | private final AttachBuilder attachBuilder; | |
72 | private final EmbedBuilder embedBuilder; | |
73 | ||
74 | /** | |
75 | * Instantiates an empty email | |
76 | */ | |
77 | public Email() { | |
78 | super(); | |
79 | recipients = new ArrayList<>(); | |
80 | attachments = new ArrayList<>(); | |
81 | htmlBuilder = new SingleContentBuilder<>(this); | |
82 | textBuilder = new SingleContentBuilder<>(this); | |
83 | bodyBuilder = new BodyBuilder(this); | |
84 | attachBuilder = new AttachBuilder(this); | |
85 | embedBuilder = new EmbedBuilder(this); | |
86 | } | |
87 | ||
88 | // ----------------------- Getter/Setters -----------------------// | |
89 | ||
90 | @Override | |
91 | public Content getContent() { | |
92 |
5
1. getContent : negated conditional → NO_COVERAGE 2. getContent : negated conditional → TIMED_OUT 3. getContent : negated conditional → KILLED 4. getContent : negated conditional → KILLED 5. getContent : negated conditional → KILLED |
if (content != null) { |
93 |
5
1. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → NO_COVERAGE 2. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → TIMED_OUT 3. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → KILLED 4. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → KILLED 5. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → KILLED |
return content; |
94 | } | |
95 |
4
1. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → SURVIVED 2. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → NO_COVERAGE 3. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → KILLED 4. getContent : replaced return value with null for fr/sii/ogham/email/message/Email::getContent → KILLED |
return buildContent(); |
96 | } | |
97 | ||
98 | @Override | |
99 | public void setContent(Content content) { | |
100 | this.content = content; | |
101 | } | |
102 | ||
103 | /** | |
104 | * Get the sender address | |
105 | * | |
106 | * @return the sender address | |
107 | */ | |
108 | public EmailAddress getFrom() { | |
109 |
5
1. getFrom : replaced return value with null for fr/sii/ogham/email/message/Email::getFrom → NO_COVERAGE 2. getFrom : replaced return value with null for fr/sii/ogham/email/message/Email::getFrom → TIMED_OUT 3. getFrom : replaced return value with null for fr/sii/ogham/email/message/Email::getFrom → KILLED 4. getFrom : replaced return value with null for fr/sii/ogham/email/message/Email::getFrom → KILLED 5. getFrom : replaced return value with null for fr/sii/ogham/email/message/Email::getFrom → KILLED |
return from; |
110 | } | |
111 | ||
112 | /** | |
113 | * Set the sender address. | |
114 | * | |
115 | * @param from | |
116 | * the sender address | |
117 | */ | |
118 | public void setFrom(EmailAddress from) { | |
119 | this.from = from; | |
120 | } | |
121 | ||
122 | /** | |
123 | * Set the sender address as string (typical address syntax is of the form | |
124 | * "user@host.domain" or "Personal Name <user@host.domain>"). | |
125 | * | |
126 | * @param from | |
127 | * the sender address string (typical address syntax is of the | |
128 | * form "user@host.domain" or "Personal Name | |
129 | * <user@host.domain>"). | |
130 | */ | |
131 | public void setFrom(String from) { | |
132 |
4
1. setFrom : removed call to fr/sii/ogham/email/message/Email::setFrom → NO_COVERAGE 2. setFrom : removed call to fr/sii/ogham/email/message/Email::setFrom → TIMED_OUT 3. setFrom : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED 4. setFrom : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED |
setFrom(new EmailAddress(from)); |
133 | } | |
134 | ||
135 | /** | |
136 | * Get the list of recipients of the mail. | |
137 | * | |
138 | * @return the list of recipients | |
139 | */ | |
140 | @Override | |
141 | public List<Recipient> getRecipients() { | |
142 |
5
1. getRecipients : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getRecipients → NO_COVERAGE 2. getRecipients : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getRecipients → TIMED_OUT 3. getRecipients : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getRecipients → KILLED 4. getRecipients : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getRecipients → KILLED 5. getRecipients : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getRecipients → KILLED |
return recipients; |
143 | } | |
144 | ||
145 | /** | |
146 | * Set the whole list of recipients. | |
147 | * | |
148 | * @param recipients | |
149 | * the list of recipients | |
150 | */ | |
151 | @Override | |
152 | public void setRecipients(List<Recipient> recipients) { | |
153 | this.recipients = recipients; | |
154 | } | |
155 | ||
156 | /** | |
157 | * Get the subject of the mail. | |
158 | * | |
159 | * @return the subject of the mail | |
160 | */ | |
161 | public String getSubject() { | |
162 |
5
1. getSubject : replaced return value with "" for fr/sii/ogham/email/message/Email::getSubject → NO_COVERAGE 2. getSubject : replaced return value with "" for fr/sii/ogham/email/message/Email::getSubject → TIMED_OUT 3. getSubject : replaced return value with "" for fr/sii/ogham/email/message/Email::getSubject → KILLED 4. getSubject : replaced return value with "" for fr/sii/ogham/email/message/Email::getSubject → KILLED 5. getSubject : replaced return value with "" for fr/sii/ogham/email/message/Email::getSubject → KILLED |
return subject; |
163 | } | |
164 | ||
165 | /** | |
166 | * Set the subject of the mail. | |
167 | * | |
168 | * @param subject | |
169 | * the subject of the mail | |
170 | */ | |
171 | public void setSubject(String subject) { | |
172 | this.subject = subject; | |
173 | } | |
174 | ||
175 | /** | |
176 | * Get the list of attachments. | |
177 | * | |
178 | * @return the list of attachments | |
179 | */ | |
180 | public List<Attachment> getAttachments() { | |
181 | List<Attachment> merged = new ArrayList<>(); | |
182 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
183 | // set it to null | |
184 |
5
1. getAttachments : negated conditional → NO_COVERAGE 2. getAttachments : negated conditional → TIMED_OUT 3. getAttachments : negated conditional → KILLED 4. getAttachments : negated conditional → KILLED 5. getAttachments : negated conditional → KILLED |
if (attachments != null) { |
185 | merged.addAll(attachments); | |
186 | } | |
187 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
188 | // set it to null | |
189 |
5
1. getAttachments : negated conditional → NO_COVERAGE 2. getAttachments : negated conditional → TIMED_OUT 3. getAttachments : negated conditional → KILLED 4. getAttachments : negated conditional → KILLED 5. getAttachments : negated conditional → KILLED |
if (attachBuilder != null) { |
190 | merged.addAll(attachBuilder.build()); | |
191 | } | |
192 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
193 | // set it to null | |
194 |
5
1. getAttachments : negated conditional → NO_COVERAGE 2. getAttachments : negated conditional → TIMED_OUT 3. getAttachments : negated conditional → KILLED 4. getAttachments : negated conditional → KILLED 5. getAttachments : negated conditional → KILLED |
if (embedBuilder != null) { |
195 | merged.addAll(embedBuilder.build()); | |
196 | } | |
197 |
5
1. getAttachments : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getAttachments → NO_COVERAGE 2. getAttachments : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getAttachments → TIMED_OUT 3. getAttachments : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getAttachments → KILLED 4. getAttachments : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getAttachments → KILLED 5. getAttachments : replaced return value with Collections.emptyList for fr/sii/ogham/email/message/Email::getAttachments → KILLED |
return merged; |
198 | } | |
199 | ||
200 | /** | |
201 | * Set the whole list of attachments. | |
202 | * | |
203 | * @param attachments | |
204 | * the list of attachments | |
205 | */ | |
206 | public void setAttachments(List<Attachment> attachments) { | |
207 | this.attachments = attachments; | |
208 | } | |
209 | ||
210 | // ----------------------- Fluent API -----------------------// | |
211 | ||
212 | /** | |
213 | * Set the subject of the mail. | |
214 | * | |
215 | * @param subject | |
216 | * the subject of the mail | |
217 | * @return this instance for fluent chaining | |
218 | */ | |
219 | public Email subject(String subject) { | |
220 |
5
1. subject : removed call to fr/sii/ogham/email/message/Email::setSubject → NO_COVERAGE 2. subject : removed call to fr/sii/ogham/email/message/Email::setSubject → SURVIVED 3. subject : removed call to fr/sii/ogham/email/message/Email::setSubject → TIMED_OUT 4. subject : removed call to fr/sii/ogham/email/message/Email::setSubject → KILLED 5. subject : removed call to fr/sii/ogham/email/message/Email::setSubject → KILLED |
setSubject(subject); |
221 |
5
1. subject : replaced return value with null for fr/sii/ogham/email/message/Email::subject → NO_COVERAGE 2. subject : replaced return value with null for fr/sii/ogham/email/message/Email::subject → TIMED_OUT 3. subject : replaced return value with null for fr/sii/ogham/email/message/Email::subject → KILLED 4. subject : replaced return value with null for fr/sii/ogham/email/message/Email::subject → KILLED 5. subject : replaced return value with null for fr/sii/ogham/email/message/Email::subject → KILLED |
return this; |
222 | } | |
223 | ||
224 | /** | |
225 | * Set the content (body) of the message. | |
226 | * | |
227 | * <p> | |
228 | * You can use this method to explicitly set a particular {@link Content} | |
229 | * instance. For example: | |
230 | * | |
231 | * <pre> | |
232 | * {@code | |
233 | * .content(new TemplateContent("path/to/template", obj)); | |
234 | * } | |
235 | * </pre> | |
236 | * | |
237 | * <p> | |
238 | * If you prefer, you can instead use the fluent API to set the email | |
239 | * content (body): | |
240 | * | |
241 | * <pre> | |
242 | * {@code | |
243 | * .body().template("path/to/template", obj) | |
244 | * } | |
245 | * </pre> | |
246 | * | |
247 | * @param content | |
248 | * the content of the message | |
249 | * @return this instance for fluent chaining | |
250 | * @see #body() | |
251 | * @see #html() | |
252 | * @see #text() | |
253 | */ | |
254 | public Email content(Content content) { | |
255 |
5
1. content : removed call to fr/sii/ogham/email/message/Email::setContent → NO_COVERAGE 2. content : removed call to fr/sii/ogham/email/message/Email::setContent → TIMED_OUT 3. content : removed call to fr/sii/ogham/email/message/Email::setContent → KILLED 4. content : removed call to fr/sii/ogham/email/message/Email::setContent → KILLED 5. content : removed call to fr/sii/ogham/email/message/Email::setContent → KILLED |
setContent(content); |
256 |
5
1. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → NO_COVERAGE 2. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → TIMED_OUT 3. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED 4. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED 5. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED |
return this; |
257 | } | |
258 | ||
259 | /** | |
260 | * Set the content (body) of the message. This is a shortcut to | |
261 | * | |
262 | * <pre> | |
263 | * {@code .content(new StringContent(content))} | |
264 | * </pre> | |
265 | * | |
266 | * <p> | |
267 | * If you prefer, you can instead use the fluent API to set the email | |
268 | * content (body): | |
269 | * | |
270 | * <pre> | |
271 | * {@code | |
272 | * .body().string(content) | |
273 | * } | |
274 | * </pre> | |
275 | * | |
276 | * | |
277 | * @param content | |
278 | * the content of the message | |
279 | * @return this instance for fluent chaining | |
280 | * @see #body() | |
281 | * @see #html() | |
282 | * @see #text() | |
283 | */ | |
284 | public Email content(String content) { | |
285 |
6
1. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → NO_COVERAGE 2. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → TIMED_OUT 3. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED 4. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED 5. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED 6. content : replaced return value with null for fr/sii/ogham/email/message/Email::content → KILLED |
return content(new StringContent(content)); |
286 | } | |
287 | ||
288 | /** | |
289 | * Set the content (body) of the message (HTML part). | |
290 | * | |
291 | * <p> | |
292 | * You can use this method in addition to {@link #text()} to provide both a | |
293 | * main body and an alternative textual body (that is used when HTML format | |
294 | * is not supported by the email client). | |
295 | * | |
296 | * <p> | |
297 | * This method provides fluent chaining to guide developer. It has the same | |
298 | * effect has using {@link #content(Content)}. | |
299 | * | |
300 | * <p> | |
301 | * If you also call either {@link #content(Content)}, | |
302 | * {@link #content(String)} or {@link #setContent(Content)} then this method | |
303 | * has no effect. | |
304 | * | |
305 | * @return the builder for building HTML part | |
306 | * @since 3.0.0 | |
307 | */ | |
308 | public SingleContentBuilder<Email> html() { | |
309 |
3
1. html : replaced return value with null for fr/sii/ogham/email/message/Email::html → NO_COVERAGE 2. html : replaced return value with null for fr/sii/ogham/email/message/Email::html → KILLED 3. html : replaced return value with null for fr/sii/ogham/email/message/Email::html → KILLED |
return htmlBuilder; |
310 | } | |
311 | ||
312 | /** | |
313 | * Set the content (body) of the message (text part). | |
314 | * | |
315 | * <p> | |
316 | * You can use this method in addition to {@link #html()} to provide both a | |
317 | * main body and an alternative textual body (that is used when HTML format | |
318 | * is not supported by the email client). If you only call {@link #text()}, | |
319 | * then the textual content is used as the main body. | |
320 | * | |
321 | * <p> | |
322 | * This method provides fluent chaining to guide developer. It has the same | |
323 | * effect has using {@link #content(Content)}. | |
324 | * | |
325 | * <p> | |
326 | * If you also call either {@link #content(Content)}, | |
327 | * {@link #content(String)} or {@link #setContent(Content)} then this method | |
328 | * has no effect. | |
329 | * | |
330 | * @return the builder for building text part | |
331 | * @since 3.0.0 | |
332 | */ | |
333 | public SingleContentBuilder<Email> text() { | |
334 |
3
1. text : replaced return value with null for fr/sii/ogham/email/message/Email::text → NO_COVERAGE 2. text : replaced return value with null for fr/sii/ogham/email/message/Email::text → KILLED 3. text : replaced return value with null for fr/sii/ogham/email/message/Email::text → KILLED |
return textBuilder; |
335 | } | |
336 | ||
337 | /** | |
338 | * Set the content (body) of the message. | |
339 | * | |
340 | * <p> | |
341 | * This is the method that you can use in main circumstances to set the | |
342 | * body: | |
343 | * <ul> | |
344 | * <li>When you want to set a single textual body (no alternative): | |
345 | * | |
346 | * <pre> | |
347 | * {@code .body().string("text")} | |
348 | * </pre> | |
349 | * | |
350 | * </li> | |
351 | * <li>When you want to set a single HTML body (no alternative): | |
352 | * | |
353 | * <pre> | |
354 | * {@code .body().string("<html><body>Hello world</body></html>")} | |
355 | * </pre> | |
356 | * | |
357 | * </li> | |
358 | * <li>When you want to set a single text body (no alternative) based on a | |
359 | * template (extension depends on template parser): | |
360 | * | |
361 | * <pre> | |
362 | * {@code .body().template("path/to/text/template.txt", obj)} | |
363 | * </pre> | |
364 | * | |
365 | * </li> | |
366 | * <li>When you want to set a single HTML body (no alternative) based on a | |
367 | * template (extension depends on template parser): | |
368 | * | |
369 | * <pre> | |
370 | * {@code .body().template("path/to/text/template.html", obj)} | |
371 | * </pre> | |
372 | * | |
373 | * </li> | |
374 | * <li>When you want to set both HTML and textual alternative based on two | |
375 | * different templates (same path but without extension): | |
376 | * | |
377 | * <pre> | |
378 | * {@code .body().template("path/to/text/template", obj)} | |
379 | * </pre> | |
380 | * | |
381 | * </li> | |
382 | * </ul> | |
383 | * | |
384 | * <p> | |
385 | * This method provides fluent chaining to guide developer. It has the same | |
386 | * effect has using {@link #content(Content)}. | |
387 | * | |
388 | * <p> | |
389 | * If you also call either {@link #content(Content)}, | |
390 | * {@link #content(String)}, {@link #setContent(Content)}, {@link #html()} | |
391 | * or {@link #text()} then this method has no effect because they are more | |
392 | * specific. | |
393 | * | |
394 | * @return the builder for building the body | |
395 | * @since 3.0.0 | |
396 | */ | |
397 | public BodyBuilder body() { | |
398 |
3
1. body : replaced return value with null for fr/sii/ogham/email/message/Email::body → NO_COVERAGE 2. body : replaced return value with null for fr/sii/ogham/email/message/Email::body → KILLED 3. body : replaced return value with null for fr/sii/ogham/email/message/Email::body → KILLED |
return bodyBuilder; |
399 | } | |
400 | ||
401 | /** | |
402 | * Attach a file to the email. The attachment must have a name. | |
403 | * | |
404 | * <p> | |
405 | * The file is attached with the {@link ContentDisposition#ATTACHMENT} | |
406 | * disposition. | |
407 | * | |
408 | * <p> | |
409 | * This method provides fluent chaining to guide the developer. This method | |
410 | * has the same effect has using {@link #attach(Attachment)}, | |
411 | * {@link #attach(Attachment...)} or {@link #attach(List)}. | |
412 | * | |
413 | * @return the builder for building the attachments | |
414 | * @since 3.0.0 | |
415 | */ | |
416 | public AttachBuilder attach() { | |
417 |
3
1. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → NO_COVERAGE 2. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → KILLED 3. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → KILLED |
return attachBuilder; |
418 | } | |
419 | ||
420 | /** | |
421 | * Embed a file in the email. This is mainly used for images. The embedded | |
422 | * file must be referenced in the body of the email using a | |
423 | * <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID | |
424 | * (or CID)</a>. | |
425 | * | |
426 | * <p> | |
427 | * The file is attached {@link ContentDisposition#INLINE} disposition. | |
428 | * | |
429 | * <p> | |
430 | * This method provides fluent chaining to guide the developer. This method | |
431 | * has the same effect has using {@link #attach(Attachment)}, | |
432 | * {@link #attach(Attachment...)} or {@link #attach(List)}. | |
433 | * | |
434 | * @return the builder for building the attachments | |
435 | * @since 3.0.0 | |
436 | */ | |
437 | public EmbedBuilder embed() { | |
438 |
3
1. embed : replaced return value with null for fr/sii/ogham/email/message/Email::embed → NO_COVERAGE 2. embed : replaced return value with null for fr/sii/ogham/email/message/Email::embed → KILLED 3. embed : replaced return value with null for fr/sii/ogham/email/message/Email::embed → KILLED |
return embedBuilder; |
439 | } | |
440 | ||
441 | /** | |
442 | * Set the sender address. It supports both "user@domain.host" and "Personal | |
443 | * Name <user@host.domain>" formats. | |
444 | * | |
445 | * @param from | |
446 | * the sender address | |
447 | * @return this instance for fluent chaining | |
448 | */ | |
449 | public Email from(EmailAddress from) { | |
450 |
3
1. from : removed call to fr/sii/ogham/email/message/Email::setFrom → NO_COVERAGE 2. from : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED 3. from : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED |
setFrom(from); |
451 |
3
1. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → NO_COVERAGE 2. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → KILLED 3. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → KILLED |
return this; |
452 | } | |
453 | ||
454 | /** | |
455 | * Set the sender address as string (typical address syntax is of the form | |
456 | * "user@host.domain" or "Personal Name <user@host.domain>"). | |
457 | * | |
458 | * @param from | |
459 | * the sender address string (typical address syntax is of the | |
460 | * form "user@host.domain" or "Personal Name | |
461 | * <user@host.domain>"). | |
462 | * @return this instance for fluent chaining | |
463 | */ | |
464 | public Email from(String from) { | |
465 |
4
1. from : removed call to fr/sii/ogham/email/message/Email::setFrom → NO_COVERAGE 2. from : removed call to fr/sii/ogham/email/message/Email::setFrom → TIMED_OUT 3. from : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED 4. from : removed call to fr/sii/ogham/email/message/Email::setFrom → KILLED |
setFrom(from); |
466 |
4
1. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → NO_COVERAGE 2. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → TIMED_OUT 3. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → KILLED 4. from : replaced return value with null for fr/sii/ogham/email/message/Email::from → KILLED |
return this; |
467 | } | |
468 | ||
469 | /** | |
470 | * Set the whole list of recipients. | |
471 | * | |
472 | * @param recipients | |
473 | * the list of recipients | |
474 | * @return this instance for fluent chaining | |
475 | */ | |
476 | @Override | |
477 | public Email recipients(List<Recipient> recipients) { | |
478 |
1
1. recipients : removed call to fr/sii/ogham/email/message/Email::setRecipients → NO_COVERAGE |
setRecipients(recipients); |
479 |
1
1. recipients : replaced return value with null for fr/sii/ogham/email/message/Email::recipients → NO_COVERAGE |
return this; |
480 | } | |
481 | ||
482 | /** | |
483 | * Set the whole list of attachments. | |
484 | * | |
485 | * @param attachments | |
486 | * the list of attachments | |
487 | * @return this instance for fluent chaining | |
488 | */ | |
489 | public Email attach(List<Attachment> attachments) { | |
490 |
1
1. attach : removed call to fr/sii/ogham/email/message/Email::setAttachments → NO_COVERAGE |
setAttachments(attachments); |
491 |
1
1. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → NO_COVERAGE |
return this; |
492 | } | |
493 | ||
494 | /** | |
495 | * Set the whole list of attachments. | |
496 | * | |
497 | * @param attachments | |
498 | * the list of attachments | |
499 | * @return this instance for fluent chaining | |
500 | */ | |
501 | public Email attach(Attachment... attachments) { | |
502 | for (Attachment attachment : attachments) { | |
503 | attach(attachment); | |
504 | } | |
505 |
1
1. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → NO_COVERAGE |
return this; |
506 | } | |
507 | ||
508 | /** | |
509 | * Add an attachment to join to the mail. | |
510 | * | |
511 | * @param attachment | |
512 | * the attachment to add | |
513 | * @return this instance for fluent chaining | |
514 | */ | |
515 | public Email attach(Attachment attachment) { | |
516 | attachments.add(attachment); | |
517 |
3
1. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → NO_COVERAGE 2. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → KILLED 3. attach : replaced return value with null for fr/sii/ogham/email/message/Email::attach → KILLED |
return this; |
518 | } | |
519 | ||
520 | /** | |
521 | * Add a recipient of the mail. | |
522 | * | |
523 | * @param recipients | |
524 | * one or several recipient to add | |
525 | * @return this instance for fluent chaining | |
526 | */ | |
527 | @Override | |
528 | public Email recipient(Recipient... recipients) { | |
529 | this.recipients.addAll(Arrays.asList(recipients)); | |
530 |
3
1. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → SURVIVED 2. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → NO_COVERAGE 3. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → TIMED_OUT |
return this; |
531 | } | |
532 | ||
533 | /** | |
534 | * Add a "to" recipient address. It supports both "user@domain.host" and | |
535 | * "Personal Name <user@host.domain>" formats. | |
536 | * | |
537 | * @param to | |
538 | * one or several recipient addresses | |
539 | * @return this instance for fluent chaining | |
540 | */ | |
541 | public Email to(String... to) { | |
542 | for (String t : to) { | |
543 | to(new EmailAddress(t)); | |
544 | } | |
545 |
4
1. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → NO_COVERAGE 2. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → TIMED_OUT 3. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → KILLED 4. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → KILLED |
return this; |
546 | } | |
547 | ||
548 | /** | |
549 | * Add a "to" recipient address. | |
550 | * | |
551 | * @param to | |
552 | * one or several recipient addresses | |
553 | * @return this instance for fluent chaining | |
554 | */ | |
555 | public Email to(EmailAddress... to) { | |
556 | for (EmailAddress t : to) { | |
557 | recipient(t, RecipientType.TO); | |
558 | } | |
559 |
3
1. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → NO_COVERAGE 2. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → SURVIVED 3. to : replaced return value with null for fr/sii/ogham/email/message/Email::to → TIMED_OUT |
return this; |
560 | } | |
561 | ||
562 | /** | |
563 | * Add a "cc" recipient address. It supports both "user@domain.host" and | |
564 | * "Personal Name <user@host.domain>" formats. | |
565 | * | |
566 | * @param cc | |
567 | * one or several recipient addresses | |
568 | * @return this instance for fluent chaining | |
569 | */ | |
570 | public Email cc(String... cc) { | |
571 | for (String c : cc) { | |
572 | cc(new EmailAddress(c)); | |
573 | } | |
574 |
2
1. cc : replaced return value with null for fr/sii/ogham/email/message/Email::cc → SURVIVED 2. cc : replaced return value with null for fr/sii/ogham/email/message/Email::cc → NO_COVERAGE |
return this; |
575 | } | |
576 | ||
577 | /** | |
578 | * Add a "cc" recipient address. | |
579 | * | |
580 | * @param cc | |
581 | * one or several recipient addresses | |
582 | * @return this instance for fluent chaining | |
583 | */ | |
584 | public Email cc(EmailAddress... cc) { | |
585 | for (EmailAddress c : cc) { | |
586 | recipient(c, RecipientType.CC); | |
587 | } | |
588 |
2
1. cc : replaced return value with null for fr/sii/ogham/email/message/Email::cc → SURVIVED 2. cc : replaced return value with null for fr/sii/ogham/email/message/Email::cc → NO_COVERAGE |
return this; |
589 | } | |
590 | ||
591 | /** | |
592 | * Add a "bcc" recipient address. It supports both "user@domain.host" and | |
593 | * "Personal Name <user@host.domain>" formats. | |
594 | * | |
595 | * @param bcc | |
596 | * one or several recipient addresses | |
597 | * @return this instance for fluent chaining | |
598 | */ | |
599 | public Email bcc(String... bcc) { | |
600 | for (String b : bcc) { | |
601 | bcc(new EmailAddress(b)); | |
602 | } | |
603 |
2
1. bcc : replaced return value with null for fr/sii/ogham/email/message/Email::bcc → SURVIVED 2. bcc : replaced return value with null for fr/sii/ogham/email/message/Email::bcc → NO_COVERAGE |
return this; |
604 | } | |
605 | ||
606 | /** | |
607 | * Add a "bcc" recipient address. | |
608 | * | |
609 | * @param bcc | |
610 | * one or several recipient addresses | |
611 | * @return this instance for fluent chaining | |
612 | */ | |
613 | public Email bcc(EmailAddress... bcc) { | |
614 | for (EmailAddress b : bcc) { | |
615 | recipient(b, RecipientType.BCC); | |
616 | } | |
617 |
2
1. bcc : replaced return value with null for fr/sii/ogham/email/message/Email::bcc → SURVIVED 2. bcc : replaced return value with null for fr/sii/ogham/email/message/Email::bcc → NO_COVERAGE |
return this; |
618 | } | |
619 | ||
620 | /** | |
621 | * Add a recipient specifying its address and the type (to, cc, bcc). | |
622 | * | |
623 | * @param recipient | |
624 | * the recipient address | |
625 | * @param type | |
626 | * the type (to, cc, bcc) | |
627 | * @return this instance for fluent chaining | |
628 | */ | |
629 | public Email recipient(EmailAddress recipient, RecipientType type) { | |
630 | recipient(new Recipient(recipient, type)); | |
631 |
3
1. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → NO_COVERAGE 2. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → SURVIVED 3. recipient : replaced return value with null for fr/sii/ogham/email/message/Email::recipient → TIMED_OUT |
return this; |
632 | } | |
633 | ||
634 | // ----------------------- Utilities -----------------------// | |
635 | ||
636 | /** | |
637 | * Converts a list of string to a list of recipients. Each recipient will | |
638 | * have the type {@link RecipientType#TO}. | |
639 | * | |
640 | * @param to | |
641 | * the list of addresses to convert (typical address syntax is of | |
642 | * the form "user@host.domain" or "Personal Name | |
643 | * <user@host.domain>") | |
644 | * @return the list of recipients | |
645 | */ | |
646 | public static Recipient[] toRecipient(List<String> to) { | |
647 | Recipient[] addresses = new Recipient[to.size()]; | |
648 | int i = 0; | |
649 | for (String t : to) { | |
650 | addresses[i] = new Recipient(t); | |
651 |
1
1. toRecipient : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
652 | } | |
653 |
1
1. toRecipient : replaced return value with null for fr/sii/ogham/email/message/Email::toRecipient → NO_COVERAGE |
return addresses; |
654 | } | |
655 | ||
656 | /** | |
657 | * Converts a list of {@link EmailAddress} to a list of recipients. Each | |
658 | * recipient will have the type {@link RecipientType#TO}. | |
659 | * | |
660 | * @param to | |
661 | * the list of addresses to convert | |
662 | * @return the list of recipients | |
663 | */ | |
664 | public static Recipient[] toRecipient(EmailAddress[] to) { | |
665 | Recipient[] addresses = new Recipient[to.length]; | |
666 | int i = 0; | |
667 | for (EmailAddress t : to) { | |
668 | addresses[i] = new Recipient(t); | |
669 |
1
1. toRecipient : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
670 | } | |
671 |
1
1. toRecipient : replaced return value with null for fr/sii/ogham/email/message/Email::toRecipient → NO_COVERAGE |
return addresses; |
672 | } | |
673 | ||
674 | /** | |
675 | * Converts a list of string to a list of recipients. Each recipient will | |
676 | * have the type {@link RecipientType#TO}. | |
677 | * | |
678 | * @param to | |
679 | * the list of addresses to convert (typical address syntax is of | |
680 | * the form "user@host.domain" or "Personal Name | |
681 | * <user@host.domain>") | |
682 | * @return the list of recipients | |
683 | */ | |
684 | public static Recipient[] toRecipient(String[] to) { | |
685 | Recipient[] addresses = new Recipient[to.length]; | |
686 | int i = 0; | |
687 | for (String t : to) { | |
688 | addresses[i] = new Recipient(t); | |
689 |
1
1. toRecipient : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
690 | } | |
691 |
1
1. toRecipient : replaced return value with null for fr/sii/ogham/email/message/Email::toRecipient → NO_COVERAGE |
return addresses; |
692 | } | |
693 | ||
694 | @Override | |
695 | public String toString() { | |
696 |
3
1. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → TIMED_OUT |
return toString(false); |
697 | } | |
698 | ||
699 | @Override | |
700 | public String toLogString() { | |
701 |
1
1. toLogString : replaced return value with "" for fr/sii/ogham/email/message/Email::toLogString → NO_COVERAGE |
return toString(true); |
702 | } | |
703 | ||
704 | @Override | |
705 | public int hashCode() { | |
706 |
2
1. hashCode : replaced int return with 0 for fr/sii/ogham/email/message/Email::hashCode → NO_COVERAGE 2. hashCode : replaced int return with 0 for fr/sii/ogham/email/message/Email::hashCode → KILLED |
return new HashCodeBuilder().append(subject, getContent(), from, recipients, getAttachments()).hashCode(); |
707 | } | |
708 | ||
709 | @Override | |
710 | public boolean equals(Object obj) { | |
711 |
6
1. equals : replaced boolean return with false for fr/sii/ogham/email/message/Email::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/email/message/Email::equals → NO_COVERAGE 3. equals : replaced boolean return with true for fr/sii/ogham/email/message/Email::equals → SURVIVED 4. equals : replaced boolean return with false for fr/sii/ogham/email/message/Email::equals → KILLED 5. equals : replaced boolean return with false for fr/sii/ogham/email/message/Email::equals → KILLED 6. equals : replaced boolean return with true for fr/sii/ogham/email/message/Email::equals → KILLED |
return new EqualsBuilder(this, obj).appendFields("subject", "content", "from", "recipients", "attachments").isEqual(); |
712 | } | |
713 | ||
714 | private String toString(boolean includeContent) { | |
715 | StringBuilder builder = new StringBuilder(); | |
716 | builder.append("Email message\r\nFrom: ").append(from); | |
717 | for (RecipientType type : RecipientType.values()) { | |
718 | List<EmailAddress> addresses = new ArrayList<>(); | |
719 | for (Recipient recipient : recipients) { | |
720 |
3
1. toString : negated conditional → SURVIVED 2. toString : negated conditional → NO_COVERAGE 3. toString : negated conditional → TIMED_OUT |
if (type == recipient.getType()) { |
721 | addresses.add(recipient.getAddress()); | |
722 | } | |
723 | } | |
724 |
3
1. toString : negated conditional → NO_COVERAGE 2. toString : negated conditional → SURVIVED 3. toString : negated conditional → TIMED_OUT |
if (!addresses.isEmpty()) { |
725 | builder.append("\r\n"); | |
726 | builder.append(type).append(": "); | |
727 | builder.append(StringUtils.join(addresses, ", ")); | |
728 | } | |
729 | } | |
730 | builder.append("\r\nSubject: ").append(subject); | |
731 |
3
1. toString : negated conditional → NO_COVERAGE 2. toString : negated conditional → SURVIVED 3. toString : negated conditional → TIMED_OUT |
builder.append("\r\n----------------------------------\r\n").append(includeContent ? getContent() : "<Content skipped>"); |
732 |
6
1. toString : negated conditional → NO_COVERAGE 2. toString : negated conditional → SURVIVED 3. toString : negated conditional → NO_COVERAGE 4. toString : negated conditional → SURVIVED 5. toString : negated conditional → TIMED_OUT 6. toString : negated conditional → TIMED_OUT |
if (attachments != null && !attachments.isEmpty()) { |
733 | builder.append("\r\n----------------------------------").append("\r\nAttachments: ").append(getAttachments()); | |
734 | } | |
735 | builder.append("\r\n==================================\r\n"); | |
736 |
3
1. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/email/message/Email::toString → TIMED_OUT |
return builder.toString(); |
737 | } | |
738 | ||
739 | private Content buildContent() { | |
740 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
741 | // set it to null | |
742 |
4
1. buildContent : negated conditional → NO_COVERAGE 2. buildContent : negated conditional → KILLED 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
Content html = htmlBuilder == null ? null : htmlBuilder.build(); |
743 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
744 | // set it to null | |
745 |
4
1. buildContent : negated conditional → NO_COVERAGE 2. buildContent : negated conditional → KILLED 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
Content text = textBuilder == null ? null : textBuilder.build(); |
746 |
7
1. buildContent : negated conditional → SURVIVED 2. buildContent : negated conditional → NO_COVERAGE 3. buildContent : negated conditional → NO_COVERAGE 4. buildContent : negated conditional → KILLED 5. buildContent : negated conditional → KILLED 6. buildContent : negated conditional → KILLED 7. buildContent : negated conditional → KILLED |
if (html != null && text != null) { |
747 |
3
1. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → NO_COVERAGE 2. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED 3. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED |
return new MultiContent(text, html); |
748 | } | |
749 |
4
1. buildContent : negated conditional → NO_COVERAGE 2. buildContent : negated conditional → SURVIVED 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
if (html != null) { |
750 |
2
1. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → NO_COVERAGE 2. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED |
return html; |
751 | } | |
752 |
4
1. buildContent : negated conditional → SURVIVED 2. buildContent : negated conditional → NO_COVERAGE 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
if (text != null) { |
753 |
2
1. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → NO_COVERAGE 2. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED |
return text; |
754 | } | |
755 | // NOTE: normally it can't be null but EqualsVerifier uses reflection to | |
756 | // set it to null | |
757 |
4
1. buildContent : negated conditional → NO_COVERAGE 2. buildContent : negated conditional → KILLED 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
Content body = bodyBuilder == null ? null : bodyBuilder.build(); |
758 |
4
1. buildContent : negated conditional → NO_COVERAGE 2. buildContent : negated conditional → SURVIVED 3. buildContent : negated conditional → KILLED 4. buildContent : negated conditional → KILLED |
if (body != null) { |
759 |
3
1. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → NO_COVERAGE 2. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED 3. buildContent : replaced return value with null for fr/sii/ogham/email/message/Email::buildContent → KILLED |
return body; |
760 | } | |
761 | return null; | |
762 | } | |
763 | ||
764 | } | |
Mutations | ||
92 |
1.1 2.2 3.3 4.4 5.5 |
|
93 |
1.1 2.2 3.3 4.4 5.5 |
|
95 |
1.1 2.2 3.3 4.4 |
|
109 |
1.1 2.2 3.3 4.4 5.5 |
|
132 |
1.1 2.2 3.3 4.4 |
|
142 |
1.1 2.2 3.3 4.4 5.5 |
|
162 |
1.1 2.2 3.3 4.4 5.5 |
|
184 |
1.1 2.2 3.3 4.4 5.5 |
|
189 |
1.1 2.2 3.3 4.4 5.5 |
|
194 |
1.1 2.2 3.3 4.4 5.5 |
|
197 |
1.1 2.2 3.3 4.4 5.5 |
|
220 |
1.1 2.2 3.3 4.4 5.5 |
|
221 |
1.1 2.2 3.3 4.4 5.5 |
|
255 |
1.1 2.2 3.3 4.4 5.5 |
|
256 |
1.1 2.2 3.3 4.4 5.5 |
|
285 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
309 |
1.1 2.2 3.3 |
|
334 |
1.1 2.2 3.3 |
|
398 |
1.1 2.2 3.3 |
|
417 |
1.1 2.2 3.3 |
|
438 |
1.1 2.2 3.3 |
|
450 |
1.1 2.2 3.3 |
|
451 |
1.1 2.2 3.3 |
|
465 |
1.1 2.2 3.3 4.4 |
|
466 |
1.1 2.2 3.3 4.4 |
|
478 |
1.1 |
|
479 |
1.1 |
|
490 |
1.1 |
|
491 |
1.1 |
|
505 |
1.1 |
|
517 |
1.1 2.2 3.3 |
|
530 |
1.1 2.2 3.3 |
|
545 |
1.1 2.2 3.3 4.4 |
|
559 |
1.1 2.2 3.3 |
|
574 |
1.1 2.2 |
|
588 |
1.1 2.2 |
|
603 |
1.1 2.2 |
|
617 |
1.1 2.2 |
|
631 |
1.1 2.2 3.3 |
|
651 |
1.1 |
|
653 |
1.1 |
|
669 |
1.1 |
|
671 |
1.1 |
|
689 |
1.1 |
|
691 |
1.1 |
|
696 |
1.1 2.2 3.3 |
|
701 |
1.1 |
|
706 |
1.1 2.2 |
|
711 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
720 |
1.1 2.2 3.3 |
|
724 |
1.1 2.2 3.3 |
|
731 |
1.1 2.2 3.3 |
|
732 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
736 |
1.1 2.2 3.3 |
|
742 |
1.1 2.2 3.3 4.4 |
|
745 |
1.1 2.2 3.3 4.4 |
|
746 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
747 |
1.1 2.2 3.3 |
|
749 |
1.1 2.2 3.3 4.4 |
|
750 |
1.1 2.2 |
|
752 |
1.1 2.2 3.3 4.4 |
|
753 |
1.1 2.2 |
|
757 |
1.1 2.2 3.3 4.4 |
|
758 |
1.1 2.2 3.3 4.4 |
|
759 |
1.1 2.2 3.3 |