| 1 |
|
package com.atlassian.mail; |
| 2 |
|
|
| 3 |
|
import com.opensymphony.util.TextUtils; |
| 4 |
|
|
| 5 |
|
import javax.mail.Multipart; |
| 6 |
|
import java.util.HashMap; |
| 7 |
|
import java.util.Map; |
| 8 |
|
|
|
|
|
| 33% |
Uncovered Elements: 146 (218) |
Complexity: 55 |
Complexity Density: 0.53 |
|
| 9 |
|
public class Email |
| 10 |
|
{ |
| 11 |
|
|
| 12 |
|
private String to; |
| 13 |
|
private String subject; |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
private String from; |
| 17 |
|
private String fromName; |
| 18 |
|
private String cc; |
| 19 |
|
private String bcc; |
| 20 |
|
private String replyTo; |
| 21 |
|
private String inReplyTo; |
| 22 |
|
private String body; |
| 23 |
|
private String mimeType; |
| 24 |
|
private String encoding; |
| 25 |
|
private Multipart multipart; |
| 26 |
|
private String messageId; |
| 27 |
|
private Map headers; |
| 28 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 29 |
9
|
private void init(String to)... |
| 30 |
|
{ |
| 31 |
9
|
this.to = to; |
| 32 |
|
|
| 33 |
|
|
| 34 |
9
|
this.subject = ""; |
| 35 |
9
|
this.body = ""; |
| 36 |
9
|
this.mimeType = "text/plain"; |
| 37 |
9
|
this.encoding = "UTF-8"; |
| 38 |
9
|
this.headers = new HashMap(); |
| 39 |
9
|
loadDefaultHeaders(); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@link |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@param |
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 48 |
10
|
public Email(String to)... |
| 49 |
|
{ |
| 50 |
10
|
if (!TextUtils.stringSet(to)) |
| 51 |
1
|
throw new IllegalArgumentException("'To' is a required field"); |
| 52 |
|
|
| 53 |
9
|
init(to); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
@link |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@param |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 62 |
0
|
public Email(String to, String cc, String bcc)... |
| 63 |
|
{ |
| 64 |
0
|
if (!TextUtils.stringSet(to) && !TextUtils.stringSet(cc) && !TextUtils.stringSet(bcc)) |
| 65 |
0
|
throw new IllegalArgumentException("One of 'To', 'CC' or 'BCC' is required"); |
| 66 |
|
|
| 67 |
0
|
init(to); |
| 68 |
0
|
this.cc = cc; |
| 69 |
0
|
this.bcc = bcc; |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
9
|
protected void loadDefaultHeaders()... |
| 73 |
|
{ |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
9
|
headers.put("Precedence", "bulk"); |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 80 |
6
|
public Email setFrom(String from)... |
| 81 |
|
{ |
| 82 |
6
|
this.from = from; |
| 83 |
6
|
return this; |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 86 |
2
|
public Email setFromName(String fromName)... |
| 87 |
|
{ |
| 88 |
2
|
this.fromName = fromName; |
| 89 |
2
|
return this; |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 92 |
0
|
public Email setTo(String to)... |
| 93 |
|
{ |
| 94 |
0
|
this.to = to; |
| 95 |
0
|
return this; |
| 96 |
|
} |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 98 |
7
|
public Email setSubject(String subject)... |
| 99 |
|
{ |
| 100 |
7
|
this.subject = subject; |
| 101 |
7
|
return this; |
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 104 |
2
|
public Email setCc(String cc)... |
| 105 |
|
{ |
| 106 |
2
|
this.cc = cc; |
| 107 |
2
|
return this; |
| 108 |
|
} |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 110 |
1
|
public Email setBcc(String bcc)... |
| 111 |
|
{ |
| 112 |
1
|
this.bcc = bcc; |
| 113 |
1
|
return this; |
| 114 |
|
} |
| 115 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 116 |
1
|
public Email setReplyTo(String replyTo)... |
| 117 |
|
{ |
| 118 |
1
|
this.replyTo = replyTo; |
| 119 |
1
|
return this; |
| 120 |
|
} |
| 121 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 122 |
0
|
public Email setInReplyTo(String inReplyTo)... |
| 123 |
|
{ |
| 124 |
0
|
this.inReplyTo = inReplyTo; |
| 125 |
0
|
return this; |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 128 |
7
|
public Email setBody(String body)... |
| 129 |
|
{ |
| 130 |
7
|
this.body = body; |
| 131 |
7
|
return this; |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 134 |
1
|
public Email setMimeType(String mimeType)... |
| 135 |
|
{ |
| 136 |
1
|
this.mimeType = mimeType; |
| 137 |
1
|
return this; |
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 140 |
1
|
public Email setEncoding(String encoding)... |
| 141 |
|
{ |
| 142 |
1
|
this.encoding = encoding; |
| 143 |
1
|
return this; |
| 144 |
|
} |
| 145 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 146 |
1
|
public Email setMultipart(Multipart multipart)... |
| 147 |
|
{ |
| 148 |
1
|
this.multipart = multipart; |
| 149 |
1
|
return this; |
| 150 |
|
} |
| 151 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 152 |
9
|
public String getFrom()... |
| 153 |
|
{ |
| 154 |
9
|
return from; |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 157 |
9
|
public String getFromName()... |
| 158 |
|
{ |
| 159 |
9
|
return fromName; |
| 160 |
|
} |
| 161 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 162 |
9
|
public String getTo()... |
| 163 |
|
{ |
| 164 |
9
|
return to; |
| 165 |
|
} |
| 166 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 167 |
9
|
public String getSubject()... |
| 168 |
|
{ |
| 169 |
9
|
return subject; |
| 170 |
|
} |
| 171 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 172 |
9
|
public String getCc()... |
| 173 |
|
{ |
| 174 |
9
|
return cc; |
| 175 |
|
} |
| 176 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 177 |
9
|
public String getBcc()... |
| 178 |
|
{ |
| 179 |
9
|
return bcc; |
| 180 |
|
} |
| 181 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 182 |
9
|
public String getReplyTo()... |
| 183 |
|
{ |
| 184 |
9
|
return replyTo; |
| 185 |
|
} |
| 186 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 187 |
8
|
public String getInReplyTo()... |
| 188 |
|
{ |
| 189 |
8
|
return inReplyTo; |
| 190 |
|
} |
| 191 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 192 |
9
|
public String getBody()... |
| 193 |
|
{ |
| 194 |
9
|
return body; |
| 195 |
|
} |
| 196 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 197 |
9
|
public String getMimeType()... |
| 198 |
|
{ |
| 199 |
9
|
return mimeType; |
| 200 |
|
} |
| 201 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 202 |
9
|
public String getEncoding()... |
| 203 |
|
{ |
| 204 |
9
|
return encoding; |
| 205 |
|
} |
| 206 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 207 |
8
|
public Multipart getMultipart()... |
| 208 |
|
{ |
| 209 |
8
|
return multipart; |
| 210 |
|
} |
| 211 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 212 |
0
|
public String getMessageId()... |
| 213 |
|
{ |
| 214 |
0
|
return messageId; |
| 215 |
|
} |
| 216 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 217 |
0
|
public void setMessageId(String messageId)... |
| 218 |
|
{ |
| 219 |
0
|
this.messageId = messageId; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
@param |
| 226 |
|
@return |
| 227 |
|
|
|
|
|
| 0% |
Uncovered Elements: 80 (80) |
Complexity: 15 |
Complexity Density: 0.5 |
|
| 228 |
0
|
public boolean equals(Object o)... |
| 229 |
|
{ |
| 230 |
0
|
if (this == o) return true; |
| 231 |
0
|
if (!(o instanceof Email)) return false; |
| 232 |
|
|
| 233 |
0
|
final Email email = (Email) o; |
| 234 |
|
|
| 235 |
0
|
if (bcc != null ? !bcc.equals(email.bcc) : email.bcc != null) return false; |
| 236 |
0
|
if (cc != null ? !cc.equals(email.cc) : email.cc != null) return false; |
| 237 |
0
|
if (encoding != null ? !encoding.equals(email.encoding) : email.encoding != null) return false; |
| 238 |
0
|
if (from != null ? !from.equals(email.from) : email.from != null) return false; |
| 239 |
0
|
if (fromName != null ? !fromName.equals(email.fromName) : email.fromName != null) return false; |
| 240 |
0
|
if (inReplyTo != null ? !inReplyTo.equals(email.inReplyTo) : email.inReplyTo != null) return false; |
| 241 |
0
|
if (messageId != null ? !messageId.equals(email.messageId) : email.messageId != null) return false; |
| 242 |
0
|
if (mimeType != null ? !mimeType.equals(email.mimeType) : email.mimeType != null) return false; |
| 243 |
0
|
if (multipart != null ? !multipart.equals(email.multipart) : email.multipart != null) return false; |
| 244 |
0
|
if (replyTo != null ? !replyTo.equals(email.replyTo) : email.replyTo != null) return false; |
| 245 |
0
|
if (subject != null ? !subject.equals(email.subject) : email.subject != null) return false; |
| 246 |
0
|
if (!to.equals(email.to)) return false; |
| 247 |
|
|
| 248 |
0
|
return true; |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
|
| 252 |
|
|
| 253 |
|
|
| 254 |
|
@return |
| 255 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 1 |
Complexity Density: 0.07 |
|
| 256 |
0
|
public int hashCode()... |
| 257 |
|
{ |
| 258 |
0
|
int result; |
| 259 |
0
|
result = to.hashCode(); |
| 260 |
0
|
result = 29 * result + (subject != null ? subject.hashCode() : 0); |
| 261 |
0
|
result = 29 * result + (from != null ? from.hashCode() : 0); |
| 262 |
0
|
result = 29 * result + (fromName != null ? fromName.hashCode() : 0); |
| 263 |
0
|
result = 29 * result + (cc != null ? cc.hashCode() : 0); |
| 264 |
0
|
result = 29 * result + (bcc != null ? bcc.hashCode() : 0); |
| 265 |
0
|
result = 29 * result + (replyTo != null ? replyTo.hashCode() : 0); |
| 266 |
0
|
result = 29 * result + (inReplyTo != null ? inReplyTo.hashCode() : 0); |
| 267 |
0
|
result = 29 * result + (mimeType != null ? mimeType.hashCode() : 0); |
| 268 |
0
|
result = 29 * result + (encoding != null ? encoding.hashCode() : 0); |
| 269 |
0
|
result = 29 * result + (multipart != null ? multipart.hashCode() : 0); |
| 270 |
0
|
result = 29 * result + (messageId != null ? messageId.hashCode() : 0); |
| 271 |
0
|
return result; |
| 272 |
|
} |
| 273 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 274 |
0
|
public String toString()... |
| 275 |
|
{ |
| 276 |
0
|
return "To='" + to + "' Subject='" + subject + "' From='" + from + "' FromName='" + fromName + "' Cc='" + cc + |
| 277 |
|
"' Bcc='" + bcc + "' ReplyTo='" + replyTo + "' InReplyTo='" + inReplyTo + "' MimeType='" + mimeType + |
| 278 |
|
"' Encoding='" + encoding + "' Multipart='" + multipart + "' MessageId='" + messageId + "'"; |
| 279 |
|
} |
| 280 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 281 |
0
|
public void addHeader(String headerName, String headerValue)... |
| 282 |
|
{ |
| 283 |
0
|
headers.put(headerName, headerValue); |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
|
| 287 |
|
@param |
| 288 |
|
@return |
| 289 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 290 |
0
|
public String removeHeader(String headerName)... |
| 291 |
|
{ |
| 292 |
0
|
if (headers.containsKey(headerName)) |
| 293 |
|
{ |
| 294 |
0
|
return (String) headers.remove(headerName); |
| 295 |
|
} |
| 296 |
|
else |
| 297 |
|
{ |
| 298 |
0
|
return null; |
| 299 |
|
} |
| 300 |
|
} |
| 301 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 302 |
8
|
public Map getHeaders()... |
| 303 |
|
{ |
| 304 |
8
|
return headers; |
| 305 |
|
} |
| 306 |
|
} |