1 |
|
package org.europa.together.domain; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
|
import jakarta.activation.FileDataSource; |
6 |
|
import jakarta.mail.internet.AddressException; |
7 |
|
import jakarta.mail.internet.InternetAddress; |
8 |
|
import org.europa.together.application.LogbackLogger; |
9 |
|
import org.europa.together.business.Logger; |
10 |
|
import org.europa.together.utils.Validator; |
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (75) |
Complexity: 24 |
Complexity Density: 0.51 |
|
15 |
|
public class Mail { |
16 |
|
|
17 |
|
private static final Logger LOGGER = new LogbackLogger(Mail.class); |
18 |
|
|
19 |
|
private String subject; |
20 |
|
private String message; |
21 |
|
private String mimeType; |
22 |
|
private long attachmentSize; |
23 |
|
private List<FileDataSource> attachmentList; |
24 |
|
private List<InternetAddress> recipientList; |
25 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
26 |
19 |
public Mail() {... |
27 |
19 |
mimeType = "plain"; |
28 |
19 |
attachmentSize = -1; |
29 |
19 |
attachmentList = new ArrayList<>(); |
30 |
19 |
recipientList = new ArrayList<>(); |
31 |
|
} |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@param |
37 |
|
@throws |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
1 |
public void addRecipientList(final List<String> recipients)... |
40 |
|
throws AddressException { |
41 |
1 |
for (String recipient : recipients) { |
42 |
5 |
addRecipent(recipient); |
43 |
|
} |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
1 |
public void addAttachmentList(final List<String> attachments) {... |
52 |
1 |
for (String attachment : attachments) { |
53 |
2 |
addAttachment(attachment); |
54 |
|
} |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@return |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
14 |
public List<FileDataSource> getAttachmentList() {... |
63 |
14 |
return List.copyOf(attachmentList); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@param |
72 |
|
@return |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
74 |
10 |
public boolean addAttachment(final String resource) {... |
75 |
10 |
boolean success = false; |
76 |
10 |
FileDataSource file = new FileDataSource(resource); |
77 |
10 |
if (file.getFile().exists()) { |
78 |
9 |
long size = file.getFile().length(); |
79 |
9 |
if (size > 0) { |
80 |
8 |
if (attachmentSize >= size || attachmentSize == -1) { |
81 |
7 |
attachmentList.add(file); |
82 |
7 |
success = true; |
83 |
7 |
LOGGER.log(file.getName() + " added. (" + size + ") bytes", LogLevel.DEBUG); |
84 |
|
} else { |
85 |
1 |
long difference = size - attachmentSize; |
86 |
1 |
LOGGER.log("Filesize is " + difference + " bigger than allowed.", |
87 |
|
LogLevel.WARN); |
88 |
|
} |
89 |
|
} else { |
90 |
1 |
LOGGER.log("File is empty.", LogLevel.WARN); |
91 |
|
} |
92 |
|
} else { |
93 |
1 |
LOGGER.log("File " + resource + " don't exist.", LogLevel.ERROR); |
94 |
|
} |
95 |
10 |
return success; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
1 |
public void clearAttachments() {... |
102 |
1 |
attachmentList.clear(); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@return |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
8 |
public List<InternetAddress> getRecipentList() {... |
111 |
8 |
return List.copyOf(recipientList); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
@return |
122 |
|
@throws |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
124 |
19 |
public boolean addRecipent(final String recipient)... |
125 |
|
throws AddressException { |
126 |
19 |
boolean success = false; |
127 |
19 |
InternetAddress mailAdress; |
128 |
19 |
if (!Validator.validate(recipient, Validator.E_MAIL_ADDRESS)) { |
129 |
4 |
throw new AddressException("[" + recipient + "] is not a valid email Adress."); |
130 |
|
} |
131 |
15 |
mailAdress = new InternetAddress(recipient); |
132 |
15 |
mailAdress.validate(); |
133 |
|
|
134 |
|
|
135 |
15 |
if (recipientList.contains(mailAdress)) { |
136 |
3 |
LOGGER.log("Address " + recipient + " already exist and will be ignored.", |
137 |
|
LogLevel.WARN); |
138 |
|
} else { |
139 |
12 |
recipientList.add(mailAdress); |
140 |
12 |
success = true; |
141 |
12 |
LOGGER.log("Add " + recipient + " to the recipient list.", LogLevel.DEBUG); |
142 |
|
} |
143 |
15 |
return success; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
1 |
public void clearRecipents() {... |
150 |
1 |
recipientList.clear(); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
3 |
public void setMimeTypeToHTML() {... |
157 |
3 |
mimeType = "html"; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
1 |
public void setMimeTypeToText() {... |
164 |
1 |
mimeType = "plain"; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
7 |
public String getMimeType() {... |
173 |
7 |
return mimeType; |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
@return |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
5 |
public String getSubject() {... |
183 |
5 |
return subject; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@param |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
5 |
public void setSubject(final String subject) {... |
192 |
5 |
this.subject = subject; |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
@return |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
5 |
public String getMessage() {... |
201 |
5 |
return message; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@param |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
209 |
5 |
public void setMessage(final String message) {... |
210 |
5 |
this.message = message; |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
@return |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
2 |
public long getAttachmentSize() {... |
219 |
2 |
return attachmentSize; |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@param |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
2 |
public void setAttachmentSize(final long attachmentSize) {... |
228 |
2 |
this.attachmentSize = attachmentSize; |
229 |
|
} |
230 |
|
|
231 |
|
} |