Clover Coverage Report - Atlassian Mail
Coverage timestamp: Mon Sep 29 2008 21:26:36 CDT
104   306   55   2.89
78   227   0.53   36
36     1.53  
1    
 
 
  Email       Line # 9 104 55 33% 0.33027524
 
  (10)
 
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   
 
9    public class Email
10    {
11    // mandatory fields
12    private String to;
13    private String subject;
14   
15    // optional fields
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   
 
29  9 toggle private void init(String to)
30    {
31  9 this.to = to;
32   
33    // set defaults
34  9 this.subject = "";
35  9 this.body = ""; // needs to be instantiated to empty string else send() will throw a NullPointer
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    * <b>Note</b>: By default the message has the "Precedence" header set to "bulk". Use {@link #removeHeader(java.lang.String)}
44    * to remove
45    *
46    * @param to
47    */
 
48  10 toggle 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    * <b>Note</b>: By default the message has the "Precedence" header set to "bulk". Use {@link #removeHeader(java.lang.String)}
58    * to remove
59    *
60    * @param to
61    */
 
62  0 toggle 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   
 
72  9 toggle protected void loadDefaultHeaders()
73    {
74    // Set the "Precedence" header to "bulk". All the mails coming from atlassian products likely need this header.
75    // This header should stop mail clients generating automatic messages to "answer" mail from atlassian products.
76    // For example, "away on holiday" messages. JRA-2622
77  9 headers.put("Precedence", "bulk");
78    }
79   
 
80  6 toggle public Email setFrom(String from)
81    {
82  6 this.from = from;
83  6 return this;
84    }
85   
 
86  2 toggle public Email setFromName(String fromName)
87    {
88  2 this.fromName = fromName;
89  2 return this;
90    }
91   
 
92  0 toggle public Email setTo(String to)
93    {
94  0 this.to = to;
95  0 return this;
96    }
97   
 
98  7 toggle public Email setSubject(String subject)
99    {
100  7 this.subject = subject;
101  7 return this;
102    }
103   
 
104  2 toggle public Email setCc(String cc)
105    {
106  2 this.cc = cc;
107  2 return this;
108    }
109   
 
110  1 toggle public Email setBcc(String bcc)
111    {
112  1 this.bcc = bcc;
113  1 return this;
114    }
115   
 
116  1 toggle public Email setReplyTo(String replyTo)
117    {
118  1 this.replyTo = replyTo;
119  1 return this;
120    }
121   
 
122  0 toggle public Email setInReplyTo(String inReplyTo)
123    {
124  0 this.inReplyTo = inReplyTo;
125  0 return this;
126    }
127   
 
128  7 toggle public Email setBody(String body)
129    {
130  7 this.body = body;
131  7 return this;
132    }
133   
 
134  1 toggle public Email setMimeType(String mimeType)
135    {
136  1 this.mimeType = mimeType;
137  1 return this;
138    }
139   
 
140  1 toggle public Email setEncoding(String encoding)
141    {
142  1 this.encoding = encoding;
143  1 return this;
144    }
145   
 
146  1 toggle public Email setMultipart(Multipart multipart)
147    {
148  1 this.multipart = multipart;
149  1 return this;
150    }
151   
 
152  9 toggle public String getFrom()
153    {
154  9 return from;
155    }
156   
 
157  9 toggle public String getFromName()
158    {
159  9 return fromName;
160    }
161   
 
162  9 toggle public String getTo()
163    {
164  9 return to;
165    }
166   
 
167  9 toggle public String getSubject()
168    {
169  9 return subject;
170    }
171   
 
172  9 toggle public String getCc()
173    {
174  9 return cc;
175    }
176   
 
177  9 toggle public String getBcc()
178    {
179  9 return bcc;
180    }
181   
 
182  9 toggle public String getReplyTo()
183    {
184  9 return replyTo;
185    }
186   
 
187  8 toggle public String getInReplyTo()
188    {
189  8 return inReplyTo;
190    }
191   
 
192  9 toggle public String getBody()
193    {
194  9 return body;
195    }
196   
 
197  9 toggle public String getMimeType()
198    {
199  9 return mimeType;
200    }
201   
 
202  9 toggle public String getEncoding()
203    {
204  9 return encoding;
205    }
206   
 
207  8 toggle public Multipart getMultipart()
208    {
209  8 return multipart;
210    }
211   
 
212  0 toggle public String getMessageId()
213    {
214  0 return messageId;
215    }
216   
 
217  0 toggle public void setMessageId(String messageId)
218    {
219  0 this.messageId = messageId;
220    }
221   
222    /**
223    * Body is NOT included in comparing two Email objects
224    *
225    * @param o
226    * @return
227    */
 
228  0 toggle 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    * Body is NOT included in calculating the hashCode for the object.
253    *
254    * @return
255    */
 
256  0 toggle 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   
 
274  0 toggle 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   
 
281  0 toggle public void addHeader(String headerName, String headerValue)
282    {
283  0 headers.put(headerName, headerValue);
284    }
285   
286    /**
287    * @param headerName
288    * @return the value of the removed header
289    */
 
290  0 toggle 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   
 
302  8 toggle public Map getHeaders()
303    {
304  8 return headers;
305    }
306    }