1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.mailsender

File Mail.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

16
59
24
1
225
158
32
0.54
2.46
24
1.33

Classes

Class Line # Actions
Mail 31 59 0% 32 19
0.808080880.8%
 

Contributing tests

This file is covered by 12 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.plugin.mailsender;
21   
22    import java.util.List;
23    import java.util.Map;
24    import java.util.TreeMap;
25   
26    import com.xpn.xwiki.api.Attachment;
27   
28    /**
29    * The variables to, cc, bcc can contain several email addresses, separated by commas.
30    */
 
31    public class Mail
32    {
33    private String from;
34   
35    private String to;
36   
37    private String cc;
38   
39    private String bcc;
40   
41    private String subject;
42   
43    private String textPart;
44   
45    private String htmlPart;
46   
47    private List<Attachment> attachments;
48   
49    private Map<String, String> headers;
50   
 
51  15 toggle public Mail()
52    {
53  15 this.headers = new TreeMap<String, String>();
54    }
55   
 
56  0 toggle public Mail(String from, String to, String cc, String bcc, String subject, String textPart, String htmlPart)
57    {
58  0 this();
59   
60  0 this.from = from;
61  0 this.to = to;
62  0 this.cc = cc;
63  0 this.bcc = bcc;
64  0 this.subject = subject;
65  0 this.textPart = textPart;
66  0 this.htmlPart = htmlPart;
67    }
68   
 
69  5 toggle public List<Attachment> getAttachments()
70    {
71  5 return this.attachments;
72    }
73   
 
74  1 toggle public void setAttachments(List<Attachment> attachments)
75    {
76  1 this.attachments = attachments;
77    }
78   
 
79  18 toggle public String getFrom()
80    {
81  18 return this.from;
82    }
83   
 
84  8 toggle public void setFrom(String from)
85    {
86  8 this.from = from;
87    }
88   
 
89  14 toggle public String getTo()
90    {
91  14 return this.to;
92    }
93   
 
94  5 toggle public void setTo(String to)
95    {
96  5 this.to = to;
97    }
98   
 
99  9 toggle public String getCc()
100    {
101  9 return this.cc;
102    }
103   
 
104  1 toggle public void setCc(String cc)
105    {
106  1 this.cc = cc;
107    }
108   
 
109  9 toggle public String getBcc()
110    {
111  9 return this.bcc;
112    }
113   
 
114  1 toggle public void setBcc(String bcc)
115    {
116  1 this.bcc = bcc;
117    }
118   
 
119  21 toggle public String getSubject()
120    {
121  21 return this.subject;
122    }
123   
 
124  10 toggle public void setSubject(String subject)
125    {
126  10 this.subject = subject;
127    }
128   
 
129  22 toggle public String getTextPart()
130    {
131  22 return this.textPart;
132    }
133   
 
134  13 toggle public void setTextPart(String message)
135    {
136  13 this.textPart = message;
137    }
138   
 
139  5 toggle @Override
140    public String toString()
141    {
142  5 StringBuilder buffer = new StringBuilder();
143   
144  5 if (getFrom() != null) {
145  5 buffer.append("From [" + getFrom() + "]");
146    }
147   
148  5 if (getTo() != null) {
149  5 buffer.append(", To [" + getTo() + "]");
150    }
151   
152  5 if (getCc() != null) {
153  0 buffer.append(", Cc [" + getCc() + "]");
154    }
155   
156  5 if (getBcc() != null) {
157  0 buffer.append(", Bcc [" + getBcc() + "]");
158    }
159   
160  5 if (getSubject() != null) {
161  5 buffer.append(", Subject [" + getSubject() + "]");
162    }
163   
164  5 if (getTextPart() != null) {
165  5 buffer.append(", Text [" + getTextPart() + "]");
166    }
167   
168  5 if (getHtmlPart() != null) {
169  1 buffer.append(", HTML [" + getHtmlPart() + "]");
170    }
171   
172  5 if (!getHeaders().isEmpty()) {
173  3 buffer.append(", Headers [" + toStringHeaders() + "]");
174    }
175   
176  5 return buffer.toString();
177    }
178   
 
179  3 toggle private String toStringHeaders()
180    {
181  3 StringBuilder buffer = new StringBuilder();
182  3 for (Map.Entry<String, String> header : getHeaders().entrySet()) {
183  5 buffer.append('[');
184  5 buffer.append(header.getKey());
185  5 buffer.append(']');
186  5 buffer.append(' ');
187  5 buffer.append('=');
188  5 buffer.append(' ');
189  5 buffer.append('[');
190  5 buffer.append(header.getValue());
191  5 buffer.append(']');
192    }
193  3 return buffer.toString();
194    }
195   
 
196  13 toggle public String getHtmlPart()
197    {
198  13 return this.htmlPart;
199    }
200   
 
201  1 toggle public void setHtmlPart(String htmlPart)
202    {
203  1 this.htmlPart = htmlPart;
204    }
205   
 
206  6 toggle public void setHeader(String header, String value)
207    {
208  6 this.headers.put(header, value);
209    }
210   
 
211  12 toggle public String getHeader(String header)
212    {
213  12 return this.headers.get(header);
214    }
215   
 
216  0 toggle public void setHeaders(Map<String, String> headers)
217    {
218  0 this.headers = headers;
219    }
220   
 
221  20 toggle public Map<String, String> getHeaders()
222    {
223  20 return this.headers;
224    }
225    }