StringContentHandler.java

1
package fr.sii.ogham.email.sender.impl.javamail;
2
3
import java.nio.charset.Charset;
4
5
import javax.mail.MessagingException;
6
import javax.mail.Multipart;
7
import javax.mail.internet.MimeBodyPart;
8
import javax.mail.internet.MimePart;
9
10
import fr.sii.ogham.core.charset.CharsetDetector;
11
import fr.sii.ogham.core.exception.mimetype.MimeTypeDetectionException;
12
import fr.sii.ogham.core.message.content.Content;
13
import fr.sii.ogham.core.message.content.MayHaveStringContent;
14
import fr.sii.ogham.core.mimetype.MimeTypeProvider;
15
import fr.sii.ogham.email.exception.handler.ContentHandlerException;
16
import fr.sii.ogham.email.message.Email;
17
18
/**
19
 * Content handler that adds string contents (HTML, text, ...). It needs to
20
 * detect Mime Type for indicating the type of the added content.
21
 * 
22
 * @author Aurélien Baudet
23
 *
24
 */
25
public class StringContentHandler implements JavaMailContentHandler {
26
	/**
27
	 * The Mime Type detector
28
	 */
29
	private MimeTypeProvider mimetypeProvider;
30
31
	/**
32
	 * The charset provider
33
	 */
34
	private CharsetDetector charsetProvider;
35
36
	public StringContentHandler(MimeTypeProvider mimetypeProvider, CharsetDetector charsetProvider) {
37
		super();
38
		this.mimetypeProvider = mimetypeProvider;
39
		this.charsetProvider = charsetProvider;
40
	}
41
42
	@Override
43
	public void setContent(MimePart message, Multipart multipart, Email email, Content content) throws ContentHandlerException {
44
		try {
45
			String strContent = ((MayHaveStringContent) content).asString();
46
			Charset charset = charsetProvider.detect(strContent);
47 3 1. setContent : negated conditional → SURVIVED
2. setContent : negated conditional → TIMED_OUT
3. setContent : negated conditional → KILLED
			String charsetParam = charset == null ? "" : (";charset=" + charset.name());
48
			String contentType = mimetypeProvider.detect(strContent).toString() + charsetParam;
49
			// add the part
50
			MimeBodyPart part = new MimeBodyPart();
51 3 1. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → TIMED_OUT
2. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED
3. setContent : removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED
			part.setContent(strContent, contentType);
52 3 1. setContent : removed call to javax/mail/internet/MimeBodyPart::setHeader → TIMED_OUT
2. setContent : removed call to javax/mail/internet/MimeBodyPart::setHeader → KILLED
3. setContent : removed call to javax/mail/internet/MimeBodyPart::setHeader → KILLED
			part.setHeader("Content-Type", contentType);
53 3 1. setContent : removed call to javax/mail/Multipart::addBodyPart → TIMED_OUT
2. setContent : removed call to javax/mail/Multipart::addBodyPart → KILLED
3. setContent : removed call to javax/mail/Multipart::addBodyPart → KILLED
			multipart.addBodyPart(part);
54
		} catch (MessagingException e) {
55
			throw new ContentHandlerException("failed to set content on mime message", content, e);
56
		} catch (MimeTypeDetectionException e) {
57
			throw new ContentHandlerException("failed to determine mimetype for the content", content, e);
58
		}
59
	}
60
61
}

Mutations

47

1.1
Location : setContent
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : setContent
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
negated conditional → KILLED

3.3
Location : setContent
Killed by : none
negated conditional → SURVIVED

51

1.1
Location : setContent
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED

2.2
Location : setContent
Killed by : none
removed call to javax/mail/internet/MimeBodyPart::setContent → TIMED_OUT

3.3
Location : setContent
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
removed call to javax/mail/internet/MimeBodyPart::setContent → KILLED

52

1.1
Location : setContent
Killed by : oghamjavamail.it.JavaMailStructureTest.htmlBody(oghamjavamail.it.JavaMailStructureTest)
removed call to javax/mail/internet/MimeBodyPart::setHeader → KILLED

2.2
Location : setContent
Killed by : oghamall.it.email.EmailEmptyTemplateTest.emptyFreemarkerTemplateShouldNotReportAnError(oghamall.it.email.EmailEmptyTemplateTest)
removed call to javax/mail/internet/MimeBodyPart::setHeader → KILLED

3.3
Location : setContent
Killed by : none
removed call to javax/mail/internet/MimeBodyPart::setHeader → TIMED_OUT

53

1.1
Location : setContent
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
removed call to javax/mail/Multipart::addBodyPart → KILLED

2.2
Location : setContent
Killed by : none
removed call to javax/mail/Multipart::addBodyPart → TIMED_OUT

3.3
Location : setContent
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
removed call to javax/mail/Multipart::addBodyPart → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM