|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package javax.mail; |
|
19 |
| |
|
20 |
| import java.io.BufferedReader; |
|
21 |
| import java.io.File; |
|
22 |
| import java.io.FileInputStream; |
|
23 |
| import java.io.IOException; |
|
24 |
| import java.io.InputStream; |
|
25 |
| import java.io.InputStreamReader; |
|
26 |
| import java.io.PrintStream; |
|
27 |
| import java.lang.reflect.Constructor; |
|
28 |
| import java.lang.reflect.InvocationTargetException; |
|
29 |
| import java.net.InetAddress; |
|
30 |
| import java.net.URL; |
|
31 |
| import java.util.ArrayList; |
|
32 |
| import java.util.Enumeration; |
|
33 |
| import java.util.HashMap; |
|
34 |
| import java.util.List; |
|
35 |
| import java.util.Map; |
|
36 |
| import java.util.Properties; |
|
37 |
| import java.util.StringTokenizer; |
|
38 |
| import java.util.WeakHashMap; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public final class Session { |
|
55 |
| private static final Class[] PARAM_TYPES = {Session.class, URLName.class}; |
|
56 |
| private static final WeakHashMap addressMapsByClassLoader = new WeakHashMap(); |
|
57 |
| private static Session DEFAULT_SESSION; |
|
58 |
| |
|
59 |
| private Map passwordAuthentications = new HashMap(); |
|
60 |
| |
|
61 |
| private final Properties properties; |
|
62 |
| private final Authenticator authenticator; |
|
63 |
| private boolean debug; |
|
64 |
| private PrintStream debugOut = System.out; |
|
65 |
| |
|
66 |
| private static final WeakHashMap providersByClassLoader = new WeakHashMap(); |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
16
| private Session(Properties properties, Authenticator authenticator) {
|
|
72 |
16
| this.properties = properties;
|
|
73 |
16
| this.authenticator = authenticator;
|
|
74 |
16
| debug = Boolean.valueOf(properties.getProperty("mail.debug")).booleanValue();
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
16
| public static Session getInstance(Properties properties, Authenticator authenticator) {
|
|
95 |
16
| return new Session(new Properties(properties), authenticator);
|
|
96 |
| } |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
10
| public static Session getInstance(Properties properties) {
|
|
106 |
10
| return getInstance(properties, null);
|
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
15
| public synchronized static Session getDefaultInstance(Properties properties) {
|
|
117 |
15
| return getDefaultInstance(properties, null);
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
17
| public synchronized static Session getDefaultInstance(Properties properties, Authenticator authenticator) {
|
|
130 |
17
| if (DEFAULT_SESSION == null) {
|
|
131 |
1
| DEFAULT_SESSION = getInstance(properties, authenticator);
|
|
132 |
| } else { |
|
133 |
16
| if (authenticator != DEFAULT_SESSION.authenticator) {
|
|
134 |
0
| if (authenticator == null || DEFAULT_SESSION.authenticator == null || authenticator.getClass().getClassLoader() != DEFAULT_SESSION.authenticator.getClass().getClassLoader()) {
|
|
135 |
0
| throw new SecurityException();
|
|
136 |
| } |
|
137 |
| } |
|
138 |
| |
|
139 |
| } |
|
140 |
17
| return DEFAULT_SESSION;
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
1
| public void setDebug(boolean debug) {
|
|
151 |
1
| this.debug = debug;
|
|
152 |
| } |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
16
| public boolean getDebug() {
|
|
160 |
16
| return debug;
|
|
161 |
| } |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
0
| public void setDebugOut(PrintStream out) {
|
|
170 |
0
| debugOut = out == null ? System.out : out;
|
|
171 |
| } |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
0
| public PrintStream getDebugOut() {
|
|
179 |
0
| return debugOut;
|
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
0
| public Provider[] getProviders() {
|
|
194 |
0
| ProviderInfo info = getProviderInfo();
|
|
195 |
0
| return (Provider[]) info.all.toArray(new Provider[info.all.size()]);
|
|
196 |
| } |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
2
| public Provider getProvider(String protocol) throws NoSuchProviderException {
|
|
211 |
2
| ProviderInfo info = getProviderInfo();
|
|
212 |
2
| Provider provider = null;
|
|
213 |
2
| String providerName = properties.getProperty("mail." + protocol + ".class");
|
|
214 |
2
| if (providerName != null) {
|
|
215 |
0
| provider = (Provider) info.byClassName.get(providerName);
|
|
216 |
0
| if (debug) {
|
|
217 |
0
| writeDebug("DEBUG: new provider loaded: " + provider.toString());
|
|
218 |
| } |
|
219 |
| } |
|
220 |
| |
|
221 |
| |
|
222 |
2
| if (provider == null) {
|
|
223 |
2
| provider = (Provider) info.byProtocol.get(protocol);
|
|
224 |
| } |
|
225 |
| |
|
226 |
2
| if (provider == null) {
|
|
227 |
0
| throw new NoSuchProviderException("Unable to locate provider for protocol: " + protocol);
|
|
228 |
| } |
|
229 |
2
| if (debug) {
|
|
230 |
0
| writeDebug("DEBUG: getProvider() returning provider " + provider.toString());
|
|
231 |
| } |
|
232 |
2
| return provider;
|
|
233 |
| } |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
| |
|
240 |
| |
|
241 |
0
| public void setProvider(Provider provider) throws NoSuchProviderException {
|
|
242 |
0
| ProviderInfo info = getProviderInfo();
|
|
243 |
0
| info.byProtocol.put(provider.getProtocol(), provider);
|
|
244 |
| } |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
| |
|
251 |
| |
|
252 |
0
| public Store getStore() throws NoSuchProviderException {
|
|
253 |
0
| String protocol = properties.getProperty("mail.store.protocol");
|
|
254 |
0
| if (protocol == null) {
|
|
255 |
0
| throw new NoSuchProviderException("mail.store.protocol property is not set");
|
|
256 |
| } |
|
257 |
0
| return getStore(protocol);
|
|
258 |
| } |
|
259 |
| |
|
260 |
| |
|
261 |
| |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
0
| public Store getStore(String protocol) throws NoSuchProviderException {
|
|
268 |
0
| Provider provider = getProvider(protocol);
|
|
269 |
0
| return getStore(provider);
|
|
270 |
| } |
|
271 |
| |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
0
| public Store getStore(URLName url) throws NoSuchProviderException {
|
|
280 |
0
| return (Store) getService(getProvider(url.getProtocol()), url);
|
|
281 |
| } |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
0
| public Store getStore(Provider provider) throws NoSuchProviderException {
|
|
291 |
0
| if (Provider.Type.STORE != provider.getType()) {
|
|
292 |
0
| throw new NoSuchProviderException("Not a Store Provider: " + provider);
|
|
293 |
| } |
|
294 |
0
| return (Store) getService(provider, null);
|
|
295 |
| } |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
0
| public Folder getFolder(URLName name) throws MessagingException {
|
|
309 |
0
| Store store = getStore(name);
|
|
310 |
0
| return store.getFolder(name);
|
|
311 |
| } |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
0
| public Transport getTransport() throws NoSuchProviderException {
|
|
321 |
0
| String protocol = properties.getProperty("mail.transport.protocol");
|
|
322 |
0
| if (protocol == null) {
|
|
323 |
0
| throw new NoSuchProviderException("mail.transport.protocol property is not set");
|
|
324 |
| } |
|
325 |
0
| return getTransport(protocol);
|
|
326 |
| } |
|
327 |
| |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
2
| public Transport getTransport(String protocol) throws NoSuchProviderException {
|
|
336 |
2
| Provider provider = getProvider(protocol);
|
|
337 |
2
| return getTransport(provider);
|
|
338 |
| } |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
0
| public Transport getTransport(URLName name) throws NoSuchProviderException {
|
|
348 |
0
| return (Transport) getService(getProvider(name.getProtocol()), name);
|
|
349 |
| } |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
1
| public Transport getTransport(Address address) throws NoSuchProviderException {
|
|
359 |
1
| String type = address.getType();
|
|
360 |
| |
|
361 |
1
| Map addressMap = getAddressMap();
|
|
362 |
1
| String protocolName = (String)addressMap.get(type);
|
|
363 |
1
| if (protocolName == null) {
|
|
364 |
0
| throw new NoSuchProviderException("No provider for address type " + type);
|
|
365 |
| } |
|
366 |
1
| return getTransport(protocolName);
|
|
367 |
| } |
|
368 |
| |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
2
| public Transport getTransport(Provider provider) throws NoSuchProviderException {
|
|
377 |
2
| return (Transport) getService(provider, null);
|
|
378 |
| } |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
0
| public void setPasswordAuthentication(URLName name, PasswordAuthentication authenticator) {
|
|
387 |
0
| if (authenticator == null) {
|
|
388 |
0
| passwordAuthentications.remove(name);
|
|
389 |
| } else { |
|
390 |
0
| passwordAuthentications.put(name, authenticator);
|
|
391 |
| } |
|
392 |
| } |
|
393 |
| |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
0
| public PasswordAuthentication getPasswordAuthentication(URLName name) {
|
|
401 |
0
| return (PasswordAuthentication) passwordAuthentications.get(name);
|
|
402 |
| } |
|
403 |
| |
|
404 |
| |
|
405 |
| |
|
406 |
| |
|
407 |
| |
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
0
| public PasswordAuthentication requestPasswordAuthentication(InetAddress host, int port, String protocol, String prompt, String defaultUserName) {
|
|
415 |
0
| if (authenticator == null) {
|
|
416 |
0
| return null;
|
|
417 |
| } |
|
418 |
0
| return authenticator.authenticate(host, port, protocol, prompt, defaultUserName);
|
|
419 |
| } |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
97
| public Properties getProperties() {
|
|
427 |
97
| return properties;
|
|
428 |
| } |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
97
| public String getProperty(String property) {
|
|
437 |
97
| return getProperties().getProperty(property);
|
|
438 |
| } |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
1
| public synchronized void addProvider(Provider provider) {
|
|
447 |
1
| ProviderInfo info = getProviderInfo();
|
|
448 |
1
| info.addProvider(provider);
|
|
449 |
| } |
|
450 |
| |
|
451 |
| |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
1
| public void setProtocolForAddress(String addressType, String protocol) {
|
|
462 |
1
| Map addressMap = getAddressMap();
|
|
463 |
| |
|
464 |
| |
|
465 |
1
| if (protocol == null) {
|
|
466 |
0
| addressMap.remove(addressType);
|
|
467 |
| } |
|
468 |
| else { |
|
469 |
1
| addressMap.put(addressType, protocol);
|
|
470 |
| } |
|
471 |
| } |
|
472 |
| |
|
473 |
| |
|
474 |
2
| private Service getService(Provider provider, URLName name) throws NoSuchProviderException {
|
|
475 |
2
| try {
|
|
476 |
2
| ClassLoader cl = getClassLoader();
|
|
477 |
2
| Class clazz = cl.loadClass(provider.getClassName());
|
|
478 |
2
| Constructor ctr = clazz.getConstructor(PARAM_TYPES);
|
|
479 |
2
| return (Service) ctr.newInstance(new Object[]{this, name});
|
|
480 |
| } catch (ClassNotFoundException e) { |
|
481 |
0
| throw (NoSuchProviderException) new NoSuchProviderException("Unable to load class for provider: " + provider).initCause(e);
|
|
482 |
| } catch (NoSuchMethodException e) { |
|
483 |
0
| throw (NoSuchProviderException) new NoSuchProviderException("Provider class does not have a constructor(Session, URLName): " + provider).initCause(e);
|
|
484 |
| } catch (InstantiationException e) { |
|
485 |
0
| throw (NoSuchProviderException) new NoSuchProviderException("Unable to instantiate provider class: " + provider).initCause(e);
|
|
486 |
| } catch (IllegalAccessException e) { |
|
487 |
0
| throw (NoSuchProviderException) new NoSuchProviderException("Unable to instantiate provider class: " + provider).initCause(e);
|
|
488 |
| } catch (InvocationTargetException e) { |
|
489 |
0
| throw (NoSuchProviderException) new NoSuchProviderException("Exception from constructor of provider class: " + provider).initCause(e.getCause());
|
|
490 |
| } |
|
491 |
| } |
|
492 |
| |
|
493 |
3
| private ProviderInfo getProviderInfo() {
|
|
494 |
3
| ClassLoader cl = getClassLoader();
|
|
495 |
3
| ProviderInfo info = (ProviderInfo) providersByClassLoader.get(cl);
|
|
496 |
3
| if (info == null) {
|
|
497 |
1
| info = loadProviders(cl);
|
|
498 |
| } |
|
499 |
3
| return info;
|
|
500 |
| } |
|
501 |
| |
|
502 |
2
| private Map getAddressMap() {
|
|
503 |
2
| ClassLoader cl = getClassLoader();
|
|
504 |
2
| Map addressMap = (Map)addressMapsByClassLoader.get(cl);
|
|
505 |
2
| if (addressMap == null) {
|
|
506 |
1
| addressMap = loadAddressMap(cl);
|
|
507 |
| } |
|
508 |
2
| return addressMap;
|
|
509 |
| } |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
7
| private ClassLoader getClassLoader() {
|
|
522 |
7
| ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
523 |
7
| if (cl == null) {
|
|
524 |
0
| if (authenticator != null) {
|
|
525 |
0
| cl = authenticator.getClass().getClassLoader();
|
|
526 |
| } |
|
527 |
| else { |
|
528 |
0
| cl = this.getClass().getClassLoader();
|
|
529 |
| } |
|
530 |
| } |
|
531 |
7
| return cl;
|
|
532 |
| } |
|
533 |
| |
|
534 |
1
| private ProviderInfo loadProviders(ClassLoader cl) {
|
|
535 |
| |
|
536 |
| |
|
537 |
| |
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
1
| ProviderInfo info = new ProviderInfo();
|
|
542 |
| |
|
543 |
| |
|
544 |
1
| providersByClassLoader.put(cl, info);
|
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
1
| try {
|
|
551 |
1
| Enumeration e = cl.getResources("META-INF/javamail.default.providers");
|
|
552 |
1
| while (e.hasMoreElements()) {
|
|
553 |
0
| URL url = (URL) e.nextElement();
|
|
554 |
0
| if (debug) {
|
|
555 |
0
| writeDebug("Loading javamail.default.providers from " + url.toString());
|
|
556 |
| } |
|
557 |
| |
|
558 |
0
| InputStream is = url.openStream();
|
|
559 |
0
| try {
|
|
560 |
0
| loadProviders(info, is);
|
|
561 |
| } finally{ |
|
562 |
0
| is.close();
|
|
563 |
| } |
|
564 |
| } |
|
565 |
| } catch (SecurityException e) { |
|
566 |
| |
|
567 |
| } catch (IOException e) { |
|
568 |
| |
|
569 |
| } |
|
570 |
| |
|
571 |
| |
|
572 |
1
| try {
|
|
573 |
1
| File file = new File(System.getProperty("java.home"), "lib/javamail.providers");
|
|
574 |
1
| InputStream is = new FileInputStream(file);
|
|
575 |
0
| try {
|
|
576 |
0
| loadProviders(info, is);
|
|
577 |
0
| if (debug) {
|
|
578 |
0
| writeDebug("Loaded lib/javamail.providers from " + file.toString());
|
|
579 |
| } |
|
580 |
| } finally{ |
|
581 |
0
| is.close();
|
|
582 |
| } |
|
583 |
| } catch (SecurityException e) { |
|
584 |
| |
|
585 |
| } catch (IOException e) { |
|
586 |
| |
|
587 |
| } |
|
588 |
| |
|
589 |
1
| try {
|
|
590 |
1
| Enumeration e = cl.getResources("META-INF/javamail.providers");
|
|
591 |
1
| while (e.hasMoreElements()) {
|
|
592 |
0
| URL url = (URL) e.nextElement();
|
|
593 |
0
| if (debug) {
|
|
594 |
0
| writeDebug("Loading META-INF/javamail.providers from " + url.toString());
|
|
595 |
| } |
|
596 |
0
| InputStream is = url.openStream();
|
|
597 |
0
| try {
|
|
598 |
0
| loadProviders(info, is);
|
|
599 |
| } finally{ |
|
600 |
0
| is.close();
|
|
601 |
| } |
|
602 |
| } |
|
603 |
| } catch (SecurityException e) { |
|
604 |
| |
|
605 |
| } catch (IOException e) { |
|
606 |
| |
|
607 |
| } |
|
608 |
| |
|
609 |
1
| return info;
|
|
610 |
| } |
|
611 |
| |
|
612 |
0
| private void loadProviders(ProviderInfo info, InputStream is) throws IOException {
|
|
613 |
0
| BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
614 |
0
| String line;
|
|
615 |
0
| while ((line = reader.readLine()) != null) {
|
|
616 |
0
| StringTokenizer tok = new StringTokenizer(line, ";");
|
|
617 |
0
| String protocol = null;
|
|
618 |
0
| Provider.Type type = null;
|
|
619 |
0
| String className = null;
|
|
620 |
0
| String vendor = null;
|
|
621 |
0
| String version = null;
|
|
622 |
0
| while (tok.hasMoreTokens()) {
|
|
623 |
0
| String property = tok.nextToken();
|
|
624 |
0
| int index = property.indexOf('=');
|
|
625 |
0
| if (index == -1) {
|
|
626 |
0
| continue;
|
|
627 |
| } |
|
628 |
0
| String key = property.substring(0, index).trim().toLowerCase();
|
|
629 |
0
| String value = property.substring(index+1).trim();
|
|
630 |
0
| if (protocol == null && "protocol".equals(key)) {
|
|
631 |
0
| protocol = value;
|
|
632 |
0
| } else if (type == null && "type".equals(key)) {
|
|
633 |
0
| if ("store".equals(value)) {
|
|
634 |
0
| type = Provider.Type.STORE;
|
|
635 |
0
| } else if ("transport".equals(value)) {
|
|
636 |
0
| type = Provider.Type.TRANSPORT;
|
|
637 |
| } |
|
638 |
0
| } else if (className == null && "class".equals(key)) {
|
|
639 |
0
| className = value;
|
|
640 |
0
| } else if ("vendor".equals(key)) {
|
|
641 |
0
| vendor = value;
|
|
642 |
0
| } else if ("version".equals(key)) {
|
|
643 |
0
| version = value;
|
|
644 |
| } |
|
645 |
| } |
|
646 |
0
| if (protocol == null || type == null || className == null) {
|
|
647 |
| |
|
648 |
0
| continue;
|
|
649 |
| } |
|
650 |
| |
|
651 |
0
| if (debug) {
|
|
652 |
0
| writeDebug("DEBUG: loading new provider protocol=" + protocol + ", className=" + className + ", vendor=" + vendor + ", version=" + version);
|
|
653 |
| } |
|
654 |
0
| Provider provider = new Provider(type, protocol, className, vendor, version);
|
|
655 |
| |
|
656 |
0
| info.addProvider(provider);
|
|
657 |
| } |
|
658 |
| } |
|
659 |
| |
|
660 |
| |
|
661 |
| |
|
662 |
| |
|
663 |
| |
|
664 |
| |
|
665 |
| |
|
666 |
| |
|
667 |
| |
|
668 |
| |
|
669 |
1
| private static Map loadAddressMap(ClassLoader cl) {
|
|
670 |
| |
|
671 |
| |
|
672 |
| |
|
673 |
| |
|
674 |
| |
|
675 |
| |
|
676 |
| |
|
677 |
| |
|
678 |
| |
|
679 |
| |
|
680 |
1
| Properties addressMap = new Properties();
|
|
681 |
| |
|
682 |
| |
|
683 |
1
| addressMapsByClassLoader.put(cl, addressMap);
|
|
684 |
| |
|
685 |
| |
|
686 |
| |
|
687 |
| |
|
688 |
1
| try {
|
|
689 |
1
| Enumeration e = cl.getResources("META-INF/javamail.default.address.map");
|
|
690 |
1
| while (e.hasMoreElements()) {
|
|
691 |
0
| URL url = (URL) e.nextElement();
|
|
692 |
0
| InputStream is = url.openStream();
|
|
693 |
0
| try {
|
|
694 |
| |
|
695 |
0
| addressMap.load(is);
|
|
696 |
| } finally{ |
|
697 |
0
| is.close();
|
|
698 |
| } |
|
699 |
| } |
|
700 |
| } catch (SecurityException e) { |
|
701 |
| |
|
702 |
| } catch (IOException e) { |
|
703 |
| |
|
704 |
| } |
|
705 |
| |
|
706 |
| |
|
707 |
1
| try {
|
|
708 |
1
| Enumeration e = cl.getResources("META-INF/javamail.address.map");
|
|
709 |
1
| while (e.hasMoreElements()) {
|
|
710 |
0
| URL url = (URL) e.nextElement();
|
|
711 |
0
| InputStream is = url.openStream();
|
|
712 |
0
| try {
|
|
713 |
| |
|
714 |
0
| addressMap.load(is);
|
|
715 |
| } finally{ |
|
716 |
0
| is.close();
|
|
717 |
| } |
|
718 |
| } |
|
719 |
| } catch (SecurityException e) { |
|
720 |
| |
|
721 |
| } catch (IOException e) { |
|
722 |
| |
|
723 |
| } |
|
724 |
| |
|
725 |
| |
|
726 |
1
| try {
|
|
727 |
1
| File file = new File(System.getProperty("java.home"), "lib/javamail.address.map");
|
|
728 |
1
| InputStream is = new FileInputStream(file);
|
|
729 |
0
| try {
|
|
730 |
| |
|
731 |
0
| addressMap.load(is);
|
|
732 |
| } finally{ |
|
733 |
0
| is.close();
|
|
734 |
| } |
|
735 |
| } catch (SecurityException e) { |
|
736 |
| |
|
737 |
| } catch (IOException e) { |
|
738 |
| |
|
739 |
| } |
|
740 |
| |
|
741 |
1
| try {
|
|
742 |
1
| Enumeration e = cl.getResources("META-INF/javamail.address.map");
|
|
743 |
1
| while (e.hasMoreElements()) {
|
|
744 |
0
| URL url = (URL) e.nextElement();
|
|
745 |
0
| InputStream is = url.openStream();
|
|
746 |
0
| try {
|
|
747 |
| |
|
748 |
0
| addressMap.load(is);
|
|
749 |
| } finally{ |
|
750 |
0
| is.close();
|
|
751 |
| } |
|
752 |
| } |
|
753 |
| } catch (SecurityException e) { |
|
754 |
| |
|
755 |
| } catch (IOException e) { |
|
756 |
| |
|
757 |
| } |
|
758 |
| |
|
759 |
| |
|
760 |
| |
|
761 |
1
| if (addressMap.isEmpty()) {
|
|
762 |
1
| addressMap.put("rfc822", "smtp");
|
|
763 |
| } |
|
764 |
| |
|
765 |
1
| return addressMap;
|
|
766 |
| } |
|
767 |
| |
|
768 |
| |
|
769 |
| |
|
770 |
| |
|
771 |
| |
|
772 |
| |
|
773 |
0
| private void writeDebug(String msg) {
|
|
774 |
0
| debugOut.println(msg);
|
|
775 |
| } |
|
776 |
| |
|
777 |
| |
|
778 |
| private static class ProviderInfo { |
|
779 |
| private final Map byClassName = new HashMap(); |
|
780 |
| private final Map byProtocol = new HashMap(); |
|
781 |
| private final List all = new ArrayList(); |
|
782 |
| |
|
783 |
1
| public void addProvider(Provider provider) {
|
|
784 |
1
| String className = provider.getClassName();
|
|
785 |
| |
|
786 |
1
| if (!byClassName.containsKey(className)) {
|
|
787 |
1
| byClassName.put(className, provider);
|
|
788 |
| } |
|
789 |
| |
|
790 |
1
| String protocol = provider.getProtocol();
|
|
791 |
1
| if (!byProtocol.containsKey(protocol)) {
|
|
792 |
1
| byProtocol.put(protocol, provider);
|
|
793 |
| } |
|
794 |
1
| all.add(provider);
|
|
795 |
| } |
|
796 |
| } |
|
797 |
| } |