1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal.factory.text; |
21 |
|
|
22 |
|
import java.nio.charset.StandardCharsets; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Singleton; |
27 |
|
import javax.mail.MessagingException; |
28 |
|
import javax.mail.internet.MimeBodyPart; |
29 |
|
|
30 |
|
import org.apache.commons.lang3.StringUtils; |
31 |
|
import org.slf4j.Logger; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.mail.internal.factory.AbstractMimeBodyPartFactory; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
41 |
|
@Component |
42 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
43 |
|
public class TextMimeBodyPartFactory extends AbstractMimeBodyPartFactory<String> |
44 |
|
{ |
45 |
|
private static final String TEXT_PLAIN_CONTENT_TYPE = "text/plain; charset=" + StandardCharsets.UTF_8.name(); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@Inject |
51 |
|
private Logger logger; |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
53 |
17 |
@Override... |
54 |
|
public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException |
55 |
|
{ |
56 |
|
|
57 |
17 |
MimeBodyPart bodyPart = new MimeBodyPart(); |
58 |
|
|
59 |
17 |
bodyPart.setContent(content, TEXT_PLAIN_CONTENT_TYPE); |
60 |
|
|
61 |
17 |
bodyPart.setHeader("Content-Type", getMimetype(parameters)); |
62 |
|
|
63 |
|
|
64 |
17 |
addHeaders(bodyPart, parameters); |
65 |
|
|
66 |
17 |
return bodyPart; |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@param |
73 |
|
@return |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
75 |
17 |
protected String getMimetype(Map<String, Object> parameters)... |
76 |
|
{ |
77 |
17 |
String mimeType = (String) parameters.get("mimetype"); |
78 |
17 |
if (StringUtils.isEmpty(mimeType)) { |
79 |
7 |
mimeType = TEXT_PLAIN_CONTENT_TYPE; |
80 |
|
} |
81 |
17 |
return mimeType; |
82 |
|
} |
83 |
|
} |