|
1
|
|
package fr.sii.ogham.email.builder; |
|
2
|
|
|
|
3
|
|
import fr.sii.ogham.core.builder.Builder; |
|
4
|
|
import fr.sii.ogham.core.builder.context.BuildContext; |
|
5
|
|
import fr.sii.ogham.core.exception.builder.BuildException; |
|
6
|
|
import fr.sii.ogham.core.fluent.AbstractParent; |
|
7
|
|
import fr.sii.ogham.core.id.generator.IdGenerator; |
|
8
|
|
import fr.sii.ogham.email.message.Email; |
|
9
|
|
import fr.sii.ogham.html.inliner.EveryImageInliner; |
|
10
|
|
import fr.sii.ogham.html.inliner.ImageInliner; |
|
11
|
|
import fr.sii.ogham.html.inliner.impl.jsoup.JsoupAttachImageInliner; |
|
12
|
|
import fr.sii.ogham.html.inliner.impl.regexp.RegexAttachBackgroudImageInliner; |
|
13
|
|
|
|
14
|
|
/** |
|
15
|
|
* Configures how attachment of images is handled. |
|
16
|
|
* |
|
17
|
|
* Image defined in a html must be referenced by a |
|
18
|
|
* <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID (or |
|
19
|
|
* CID)</a> if the image is attached to the email. |
|
20
|
|
* |
|
21
|
|
* For example, if your template contains the following HTML code: |
|
22
|
|
* |
|
23
|
|
* <pre> |
|
24
|
|
* {@code |
|
25
|
|
* <img src="classpath:/foo.png" data-inline-image="attach" /> |
|
26
|
|
* } |
|
27
|
|
* </pre> |
|
28
|
|
* |
|
29
|
|
* Then the image will be loaded from the classpath and attached to the email. |
|
30
|
|
* The src attribute will be replaced by the Content-ID. |
|
31
|
|
* |
|
32
|
|
* The Content-ID is generated using an {@link IdGenerator} that is configured |
|
33
|
|
* through the {@link #cid()} method. |
|
34
|
|
* |
|
35
|
|
* <p> |
|
36
|
|
* In the same way, if your template contains the following code: |
|
37
|
|
* |
|
38
|
|
* <pre> |
|
39
|
|
* <code> |
|
40
|
|
* <style> |
|
41
|
|
* .some-class { |
|
42
|
|
* background: url('classpath:/foo.png'); |
|
43
|
|
* --inline-image: attach; |
|
44
|
|
* } |
|
45
|
|
* </style> |
|
46
|
|
* </code> |
|
47
|
|
* </pre> |
|
48
|
|
* |
|
49
|
|
* Or directly on {@code style} attribute: |
|
50
|
|
* |
|
51
|
|
* <pre> |
|
52
|
|
* {@code |
|
53
|
|
* <div style="background: url('classpath:/foo.png'); --inline-image: attach;"></div> |
|
54
|
|
* } |
|
55
|
|
* </pre> |
|
56
|
|
* |
|
57
|
|
* Then the image will be loaded from the classpath and attached to the email. |
|
58
|
|
* The url will be replaced by the Content-ID. |
|
59
|
|
* |
|
60
|
|
* @author Aurélien Baudet |
|
61
|
|
* |
|
62
|
|
*/ |
|
63
|
|
public class AttachImageBuilder extends AbstractParent<ImageInliningBuilder> implements Builder<ImageInliner> { |
|
64
|
|
private final BuildContext buildContext; |
|
65
|
|
private CidBuilder cidBuilder; |
|
66
|
|
|
|
67
|
|
/** |
|
68
|
|
* Initializes with the parent (used when calling {@link #and()} method for |
|
69
|
|
* fluent chaining). |
|
70
|
|
* |
|
71
|
|
* @param parent |
|
72
|
|
* the parent builder |
|
73
|
|
* @param buildContext |
|
74
|
|
* for registering instances and property evaluation |
|
75
|
|
*/ |
|
76
|
|
public AttachImageBuilder(ImageInliningBuilder parent, BuildContext buildContext) { |
|
77
|
|
super(parent); |
|
78
|
|
this.buildContext = buildContext; |
|
79
|
|
} |
|
80
|
|
|
|
81
|
|
/** |
|
82
|
|
* Configures how images are attached to {@link Email}s. |
|
83
|
|
* |
|
84
|
|
* Image defined in a html must be referenced by a |
|
85
|
|
* <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID |
|
86
|
|
* (or CID)</a> if the image is attached to the email. You can define how |
|
87
|
|
* CIDs are generated. |
|
88
|
|
* |
|
89
|
|
* @return the builder to configure CID generation |
|
90
|
|
*/ |
|
91
|
|
public CidBuilder cid() { |
|
92
|
8
1. cid : negated conditional → NO_COVERAGE
2. cid : negated conditional → KILLED
3. cid : negated conditional → KILLED
4. cid : negated conditional → KILLED
5. cid : negated conditional → KILLED
6. cid : negated conditional → KILLED
7. cid : negated conditional → KILLED
8. cid : negated conditional → KILLED
|
if (cidBuilder == null) { |
|
93
|
|
cidBuilder = new CidBuilder(this, buildContext); |
|
94
|
|
} |
|
95
|
8
1. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → NO_COVERAGE
2. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
3. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
4. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
5. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
6. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
7. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
8. cid : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
|
return cidBuilder; |
|
96
|
|
} |
|
97
|
|
|
|
98
|
|
@Override |
|
99
|
|
public ImageInliner build() { |
|
100
|
8
1. build : negated conditional → NO_COVERAGE
2. build : negated conditional → KILLED
3. build : negated conditional → KILLED
4. build : negated conditional → KILLED
5. build : negated conditional → KILLED
6. build : negated conditional → KILLED
7. build : negated conditional → KILLED
8. build : negated conditional → KILLED
|
if (cidBuilder == null) { |
|
101
|
|
throw new BuildException("Can't build inliner that attaches images because no identifier generator configured"); |
|
102
|
|
} |
|
103
|
|
IdGenerator idGenerator = cidBuilder.build(); |
|
104
|
8
1. build : negated conditional → NO_COVERAGE
2. build : negated conditional → KILLED
3. build : negated conditional → KILLED
4. build : negated conditional → KILLED
5. build : negated conditional → KILLED
6. build : negated conditional → KILLED
7. build : negated conditional → KILLED
8. build : negated conditional → KILLED
|
if (idGenerator == null) { |
|
105
|
|
throw new BuildException("Can't build inliner that attaches images because no identifier generator configured"); |
|
106
|
|
} |
|
107
|
|
EveryImageInliner inliner = buildContext.register(new EveryImageInliner()); |
|
108
|
|
inliner.addInliner(buildContext.register(new JsoupAttachImageInliner(idGenerator))); |
|
109
|
|
inliner.addInliner(buildContext.register(new RegexAttachBackgroudImageInliner(idGenerator))); |
|
110
|
3
1. build : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → NO_COVERAGE
2. build : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → SURVIVED
3. build : replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → KILLED
|
return inliner; |
|
111
|
|
} |
|
112
|
|
} |
| | Mutations |
| 92 |
|
1.1 Location : cid Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED 2.2 Location : cid Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest) negated conditional → KILLED 3.3 Location : cid Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) negated conditional → KILLED 4.4 Location : cid Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED 5.5 Location : cid Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest) negated conditional → KILLED 6.6 Location : cid Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED 7.7 Location : cid Killed by : none negated conditional → NO_COVERAGE 8.8 Location : cid Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED
|
| 95 |
|
1.1 Location : cid Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 2.2 Location : cid Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 3.3 Location : cid Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 4.4 Location : cid Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 5.5 Location : cid Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 6.6 Location : cid Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED 7.7 Location : cid Killed by : none replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → NO_COVERAGE 8.8 Location : cid Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::cid → KILLED
|
| 100 |
|
1.1 Location : build Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest) negated conditional → KILLED 2.2 Location : build Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED 3.3 Location : build Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED 4.4 Location : build Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest) negated conditional → KILLED 5.5 Location : build Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndImageInliningEnabledButUnconfiguredResourceResolutionCantInlineImages(oghamall.it.configuration.EmptyBuilderTest) negated conditional → KILLED 6.6 Location : build Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED 7.7 Location : build Killed by : none negated conditional → NO_COVERAGE 8.8 Location : build Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED
|
| 104 |
|
1.1 Location : build Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED 2.2 Location : build Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest) negated conditional → KILLED 3.3 Location : build Killed by : none negated conditional → NO_COVERAGE 4.4 Location : build Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED 5.5 Location : build Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndImageInliningEnabledButUnconfiguredResourceResolutionCantInlineImages(oghamall.it.configuration.EmptyBuilderTest) negated conditional → KILLED 6.6 Location : build Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED 7.7 Location : build Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest) negated conditional → KILLED 8.8 Location : build Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED
|
| 110 |
|
1.1 Location : build Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests) replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → KILLED 2.2 Location : build Killed by : none replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → NO_COVERAGE 3.3 Location : build Killed by : none replaced return value with null for fr/sii/ogham/email/builder/AttachImageBuilder::build → SURVIVED
|