1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.mailsender; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.util.Properties; |
26 |
|
import java.util.Map.Entry; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.xwiki.mail.MailSenderConfiguration; |
30 |
|
|
31 |
|
import com.xpn.xwiki.api.XWiki; |
32 |
|
import com.xpn.xwiki.web.Utils; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
|
|
|
| 44.8% |
Uncovered Elements: 53 (96) |
Complexity: 32 |
Complexity Density: 0.56 |
|
39 |
|
public class MailConfiguration |
40 |
|
{ |
41 |
|
private int port; |
42 |
|
|
43 |
|
private String host; |
44 |
|
|
45 |
|
private String from; |
46 |
|
|
47 |
|
private String smtpUsername; |
48 |
|
|
49 |
|
private String smtpPassword; |
50 |
|
|
51 |
|
private Properties extraProperties; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private MailSenderConfiguration mailSenderConfiguration; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
4 |
public MailConfiguration()... |
59 |
|
{ |
60 |
4 |
this.mailSenderConfiguration = Utils.getComponent(MailSenderConfiguration.class); |
61 |
4 |
setPort(25); |
62 |
4 |
setHost("localhost"); |
63 |
|
} |
64 |
|
|
|
|
| 68% |
Uncovered Elements: 8 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
65 |
4 |
public MailConfiguration(XWiki xwiki)... |
66 |
|
{ |
67 |
4 |
this(); |
68 |
|
|
69 |
4 |
String smtpServer = this.mailSenderConfiguration.getHost(); |
70 |
4 |
if (!StringUtils.isBlank(smtpServer)) { |
71 |
4 |
setHost(smtpServer); |
72 |
|
} |
73 |
|
|
74 |
4 |
int port = this.mailSenderConfiguration.getPort(); |
75 |
4 |
setPort(port); |
76 |
|
|
77 |
4 |
String from = this.mailSenderConfiguration.getFromAddress(); |
78 |
4 |
if (!StringUtils.isBlank(from)) { |
79 |
0 |
setFrom(from); |
80 |
|
} |
81 |
|
|
82 |
4 |
String smtpServerUsername = this.mailSenderConfiguration.getUsername(); |
83 |
4 |
String smtpServerPassword = this.mailSenderConfiguration.getPassword(); |
84 |
4 |
if (!StringUtils.isEmpty(smtpServerUsername) && !StringUtils.isEmpty(smtpServerPassword)) { |
85 |
0 |
setSmtpUsername(smtpServerUsername); |
86 |
0 |
setSmtpPassword(smtpServerPassword); |
87 |
|
} |
88 |
|
|
89 |
4 |
Properties javaMailExtraProps = this.mailSenderConfiguration.getAdditionalProperties(); |
90 |
4 |
if (!javaMailExtraProps.isEmpty()) { |
91 |
0 |
setExtraProperties(javaMailExtraProps); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
8 |
public void setHost(String host)... |
96 |
|
{ |
97 |
8 |
this.host = host; |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
5 |
public String getHost()... |
101 |
|
{ |
102 |
5 |
return this.host; |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
8 |
public void setPort(int port)... |
106 |
|
{ |
107 |
8 |
this.port = port; |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
5 |
public int getPort()... |
111 |
|
{ |
112 |
5 |
return this.port; |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
1 |
public void setFrom(String from)... |
116 |
|
{ |
117 |
1 |
this.from = from; |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
6 |
public String getFrom()... |
121 |
|
{ |
122 |
6 |
return this.from; |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
public void setSmtpUsername(String smtpUsername)... |
126 |
|
{ |
127 |
0 |
this.smtpUsername = smtpUsername; |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
8 |
public String getSmtpUsername()... |
131 |
|
{ |
132 |
8 |
return this.smtpUsername; |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
0 |
public void setSmtpPassword(String smtpPassword)... |
136 |
|
{ |
137 |
0 |
this.smtpPassword = smtpPassword; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
public String getSmtpPassword()... |
141 |
|
{ |
142 |
0 |
return this.smtpPassword; |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
8 |
public boolean usesAuthentication()... |
146 |
|
{ |
147 |
8 |
return !StringUtils.isEmpty(getSmtpUsername()) && !StringUtils.isEmpty(getSmtpPassword()); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
public void setExtraProperties(Properties extraProperties)... |
151 |
|
{ |
152 |
0 |
this.extraProperties = extraProperties; |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
155 |
0 |
public void setExtraProperties(String extraPropertiesString)... |
156 |
|
{ |
157 |
0 |
if (StringUtils.isEmpty(extraPropertiesString)) { |
158 |
0 |
this.extraProperties = null; |
159 |
|
} else { |
160 |
0 |
InputStream is = new ByteArrayInputStream(extraPropertiesString.getBytes()); |
161 |
0 |
this.extraProperties = new Properties(); |
162 |
0 |
try { |
163 |
0 |
this.extraProperties.load(is); |
164 |
|
} catch (IOException e) { |
165 |
|
|
166 |
0 |
throw new RuntimeException("Error configuring mail connection.", e); |
167 |
|
} |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
@param |
176 |
|
|
|
|
| 28.6% |
Uncovered Elements: 10 (14) |
Complexity: 6 |
Complexity Density: 0.75 |
|
177 |
4 |
public void appendExtraPropertiesTo(Properties externalProperties, boolean overwrite)... |
178 |
|
{ |
179 |
|
|
180 |
4 |
if (externalProperties == null) { |
181 |
0 |
throw new IllegalArgumentException("externalProperties can't be null"); |
182 |
|
} |
183 |
|
|
184 |
4 |
if (this.extraProperties != null && this.extraProperties.size() > 0) { |
185 |
0 |
for (Entry<Object, Object> e : this.extraProperties.entrySet()) { |
186 |
0 |
String propName = (String) e.getKey(); |
187 |
0 |
String propValue = (String) e.getValue(); |
188 |
0 |
if (overwrite || externalProperties.getProperty(propName) == null) { |
189 |
0 |
externalProperties.setProperty(propName, propValue); |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
195 |
0 |
@Override... |
196 |
|
public String toString() |
197 |
|
{ |
198 |
0 |
StringBuilder buffer = new StringBuilder(); |
199 |
|
|
200 |
0 |
if (getHost() != null) { |
201 |
0 |
buffer.append("Host [" + getHost() + "]"); |
202 |
|
} |
203 |
|
|
204 |
0 |
if (getFrom() != null) { |
205 |
0 |
buffer.append(", From [" + getFrom() + "]"); |
206 |
|
} |
207 |
|
|
208 |
0 |
buffer.append(", Port [" + getPort() + "]"); |
209 |
|
|
210 |
0 |
if (usesAuthentication()) { |
211 |
0 |
buffer.append(", Username [" + getSmtpUsername() + "]"); |
212 |
0 |
buffer.append(", Password [*****]"); |
213 |
|
} |
214 |
|
|
215 |
0 |
return buffer.toString(); |
216 |
|
} |
217 |
|
} |