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