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