1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.mail; |
19 |
|
|
20 |
|
import org.apache.camel.RuntimeCamelException; |
21 |
|
|
22 |
|
import javax.mail.Session; |
23 |
|
import java.net.URI; |
24 |
|
import java.util.Properties; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class MailConfiguration implements Cloneable { |
32 |
|
private String defaultEncoding; |
33 |
|
private String host; |
34 |
|
private Properties javaMailProperties; |
35 |
|
private String password; |
36 |
|
private String protocol; |
37 |
|
private Session session; |
38 |
|
private String username; |
39 |
8 |
private int port = -1; |
40 |
|
private String destination; |
41 |
8 |
private String from = "camel@localhost"; |
42 |
8 |
private boolean deleteProcessedMessages = true; |
43 |
8 |
private String folderName = "INBOX"; |
44 |
|
|
45 |
8 |
public MailConfiguration() { |
46 |
8 |
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public MailConfiguration copy() { |
52 |
|
try { |
53 |
12 |
return (MailConfiguration) clone(); |
54 |
|
} |
55 |
0 |
catch (CloneNotSupportedException e) { |
56 |
0 |
throw new RuntimeCamelException(e); |
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
|
public void configure(URI uri) { |
61 |
12 |
String value = uri.getHost(); |
62 |
12 |
if (value != null) { |
63 |
12 |
setHost(value); |
64 |
|
} |
65 |
|
|
66 |
12 |
String scheme = uri.getScheme(); |
67 |
12 |
if (scheme != null) { |
68 |
12 |
setProtocol(scheme); |
69 |
|
} |
70 |
12 |
String userInfo = uri.getUserInfo(); |
71 |
12 |
if (userInfo != null) { |
72 |
12 |
setUsername(userInfo); |
73 |
|
} |
74 |
12 |
int port = uri.getPort(); |
75 |
12 |
if (port >= 0) { |
76 |
5 |
setPort(port); |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
12 |
String fragment = uri.getFragment(); |
85 |
12 |
if (fragment == null || fragment.length() == 0) { |
86 |
12 |
fragment = userInfo + "@" + host; |
87 |
12 |
} |
88 |
|
else { |
89 |
0 |
setFolderName(fragment); |
90 |
|
} |
91 |
12 |
setDestination(fragment); |
92 |
12 |
} |
93 |
|
|
94 |
|
public JavaMailConnection createJavaMailConnection(MailEndpoint mailEndpoint) { |
95 |
7 |
JavaMailConnection answer = new JavaMailConnection(); |
96 |
7 |
if (defaultEncoding != null) { |
97 |
0 |
answer.setDefaultEncoding(defaultEncoding); |
98 |
|
} |
99 |
|
|
100 |
7 |
if (host != null) { |
101 |
7 |
answer.setHost(host); |
102 |
|
} |
103 |
7 |
if (javaMailProperties != null) { |
104 |
0 |
answer.setJavaMailProperties(javaMailProperties); |
105 |
|
} |
106 |
7 |
if (port >= 0) { |
107 |
0 |
answer.setPort(port); |
108 |
|
} |
109 |
7 |
if (password != null) { |
110 |
1 |
answer.setPassword(password); |
111 |
|
} |
112 |
7 |
if (protocol != null) { |
113 |
7 |
answer.setProtocol(protocol); |
114 |
|
} |
115 |
7 |
if (session != null) { |
116 |
0 |
answer.setSession(session); |
117 |
|
} |
118 |
7 |
if (username != null) { |
119 |
7 |
answer.setUsername(username); |
120 |
|
} |
121 |
7 |
return answer; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public String getDefaultEncoding() { |
128 |
0 |
return defaultEncoding; |
129 |
|
} |
130 |
|
|
131 |
|
public void setDefaultEncoding(String defaultEncoding) { |
132 |
0 |
this.defaultEncoding = defaultEncoding; |
133 |
0 |
} |
134 |
|
|
135 |
|
public String getHost() { |
136 |
3 |
return host; |
137 |
|
} |
138 |
|
|
139 |
|
public void setHost(String host) { |
140 |
12 |
this.host = host; |
141 |
12 |
} |
142 |
|
|
143 |
|
public Properties getJavaMailProperties() { |
144 |
0 |
return javaMailProperties; |
145 |
|
} |
146 |
|
|
147 |
|
public void setJavaMailProperties(Properties javaMailProperties) { |
148 |
0 |
this.javaMailProperties = javaMailProperties; |
149 |
0 |
} |
150 |
|
|
151 |
|
public String getPassword() { |
152 |
0 |
return password; |
153 |
|
} |
154 |
|
|
155 |
|
public void setPassword(String password) { |
156 |
1 |
this.password = password; |
157 |
1 |
} |
158 |
|
|
159 |
|
public int getPort() { |
160 |
3 |
return port; |
161 |
|
} |
162 |
|
|
163 |
|
public void setPort(int port) { |
164 |
5 |
this.port = port; |
165 |
5 |
} |
166 |
|
|
167 |
|
public String getProtocol() { |
168 |
7 |
return protocol; |
169 |
|
} |
170 |
|
|
171 |
|
public void setProtocol(String protocol) { |
172 |
12 |
this.protocol = protocol; |
173 |
12 |
} |
174 |
|
|
175 |
|
public Session getSession() { |
176 |
0 |
return session; |
177 |
|
} |
178 |
|
|
179 |
|
public void setSession(Session session) { |
180 |
0 |
this.session = session; |
181 |
0 |
} |
182 |
|
|
183 |
|
public String getUsername() { |
184 |
3 |
return username; |
185 |
|
} |
186 |
|
|
187 |
|
public void setUsername(String username) { |
188 |
12 |
this.username = username; |
189 |
12 |
} |
190 |
|
|
191 |
|
public String getDestination() { |
192 |
3 |
return destination; |
193 |
|
} |
194 |
|
|
195 |
|
public void setDestination(String destination) { |
196 |
12 |
this.destination = destination; |
197 |
12 |
} |
198 |
|
|
199 |
|
public String getFrom() { |
200 |
1 |
return from; |
201 |
|
} |
202 |
|
|
203 |
|
public void setFrom(String from) { |
204 |
0 |
this.from = from; |
205 |
0 |
} |
206 |
|
|
207 |
|
public boolean isDeleteProcessedMessages() { |
208 |
4 |
return deleteProcessedMessages; |
209 |
|
} |
210 |
|
|
211 |
|
public void setDeleteProcessedMessages(boolean deleteProcessedMessages) { |
212 |
0 |
this.deleteProcessedMessages = deleteProcessedMessages; |
213 |
0 |
} |
214 |
|
|
215 |
|
public String getFolderName() { |
216 |
4 |
return folderName; |
217 |
|
} |
218 |
|
|
219 |
|
public void setFolderName(String folderName) { |
220 |
0 |
this.folderName = folderName; |
221 |
0 |
} |
222 |
|
} |