1 | package fr.sii.ogham.email.sender.impl.javamail; | |
2 | ||
3 | import javax.mail.MessagingException; | |
4 | import javax.mail.Multipart; | |
5 | import javax.mail.internet.MimeBodyPart; | |
6 | import javax.mail.internet.MimeMultipart; | |
7 | import javax.mail.internet.MimePart; | |
8 | ||
9 | import fr.sii.ogham.core.message.content.Content; | |
10 | import fr.sii.ogham.core.message.content.MultiContent; | |
11 | import fr.sii.ogham.email.exception.handler.ContentHandlerException; | |
12 | import fr.sii.ogham.email.message.Email; | |
13 | ||
14 | /** | |
15 | * Handle multiple contents. It adds several parts to the mail. It creates a | |
16 | * part for each sub content. It delegates the management of each sub content to | |
17 | * another content handler. | |
18 | * | |
19 | * @author Aurélien Baudet | |
20 | * | |
21 | */ | |
22 | public class MultiContentHandler implements JavaMailContentHandler { | |
23 | /** | |
24 | * The content handler used for each sub content | |
25 | */ | |
26 | private JavaMailContentHandler delegate; | |
27 | ||
28 | public MultiContentHandler(JavaMailContentHandler delegate) { | |
29 | super(); | |
30 | this.delegate = delegate; | |
31 | } | |
32 | ||
33 | @Override | |
34 | public void setContent(MimePart message, Multipart multipart, Email email, Content content) throws ContentHandlerException { | |
35 | try { | |
36 | MultiContent multiContent = (MultiContent) content; | |
37 | MimeMultipart mp = new MimeMultipart("alternative"); | |
38 | for (Content c : multiContent.getContents()) { | |
39 |
3
1. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → NO_COVERAGE 2. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED 3. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED |
delegate.setContent(message, mp, email, c); |
40 | } | |
41 | // add the part | |
42 | MimeBodyPart part = new MimeBodyPart(); | |
43 |
3
1. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → NO_COVERAGE 2. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED 3. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED |
part.setContent(mp); |
44 |
3
1. setContent : removed call to javax/mail/Multipart::addBodyPart → NO_COVERAGE 2. setContent : removed call to javax/mail/Multipart::addBodyPart → KILLED 3. setContent : removed call to javax/mail/Multipart::addBodyPart → KILLED |
multipart.addBodyPart(part); |
45 | } catch (MessagingException e) { | |
46 | throw new ContentHandlerException("Failed to generate alternative content", content, e); | |
47 | } | |
48 | } | |
49 | ||
50 | } | |
Mutations | ||
39 |
1.1 2.2 3.3 |
|
43 |
1.1 2.2 3.3 |
|
44 |
1.1 2.2 3.3 |