68
|
1 /*
|
|
2 Copyright (c) 2008 Franklin Schmidt <fschmidt@gmail.com>
|
|
3
|
|
4 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 of this software and associated documentation files (the "Software"), to deal
|
|
6 in the Software without restriction, including without limitation the rights
|
|
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 copies of the Software, and to permit persons to whom the Software is
|
|
9 furnished to do so, subject to the following conditions:
|
|
10
|
|
11 The above copyright notice and this permission notice shall be included in
|
|
12 all copies or substantial portions of the Software.
|
|
13
|
|
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 THE SOFTWARE.
|
|
21 */
|
|
22
|
|
23 package fschmidt.util.mail;
|
|
24
|
|
25
|
|
26 // because javamail sucks
|
|
27
|
|
28 public final class MailHome {
|
|
29 private MailHome() {} // never
|
|
30
|
|
31 private static MailFactory mailFactory = new fschmidt.util.mail.javamail.MailFactoryImpl();
|
|
32 private static SmtpServer defaultSmtpServer = null;
|
|
33
|
|
34 public static void setMailFactory(MailFactory mailFactory) {
|
|
35 MailHome.mailFactory = mailFactory;
|
|
36 }
|
|
37
|
|
38 public static SmtpServer getSmtpServer(String machineName) {
|
|
39 return mailFactory.getSmtpServer(machineName);
|
|
40 }
|
|
41
|
|
42 public static SmtpServer getSmtpServer(String machineName,String username,String password) {
|
|
43 return mailFactory.getSmtpServer(machineName,username,password);
|
|
44 }
|
|
45
|
|
46 public static SmtpServer getSmtpServerPool(String[] machineNames) {
|
|
47 SmtpServer[] servers = new SmtpServer[machineNames.length];
|
|
48 for (int i=0; i<servers.length; i++) {
|
|
49 servers[i] = mailFactory.getSmtpServer(machineNames[i]);
|
|
50 }
|
|
51 return new SmtpServerPool(servers);
|
|
52 }
|
|
53
|
|
54 public static SmtpServer getSmtpServerPool(String[] machineNames,String username,String password) {
|
|
55 SmtpServer[] servers = new SmtpServer[machineNames.length];
|
|
56 for (int i=0; i<servers.length; i++) {
|
|
57 servers[i] = mailFactory.getSmtpServer(machineNames[i],username,password);
|
|
58 }
|
|
59 return new SmtpServerPool(servers);
|
|
60 }
|
|
61
|
|
62 public static Pop3Server getPop3Server(String machineName,String username,String password) {
|
|
63 return mailFactory.getPop3Server(machineName,username,password);
|
|
64 }
|
|
65
|
|
66 public static Pop3Server getPop3ServerPool(String[] machineNames,String username,String password) {
|
|
67 Pop3Server[] servers = new Pop3Server[machineNames.length];
|
|
68 for (int i=0; i<servers.length; i++) {
|
|
69 servers[i] = mailFactory.getPop3Server(machineNames[i],username,password);
|
|
70 }
|
|
71 return new Pop3ServerPool(servers);
|
|
72 }
|
|
73
|
|
74 public synchronized static void setDefaultSmtpServer(SmtpServer smtpServer) {
|
|
75 MailHome.defaultSmtpServer = smtpServer;
|
|
76 }
|
|
77
|
|
78 public synchronized static SmtpServer getDefaultSmtpServer() {
|
|
79 if( defaultSmtpServer==null ) {
|
|
80 String server = System.getProperty("mail.smtp.host");
|
|
81 if( server==null )
|
|
82 return null;
|
|
83 defaultSmtpServer = getSmtpServer(server);
|
|
84 }
|
|
85 return defaultSmtpServer;
|
|
86 }
|
|
87
|
|
88 public static Mail newMail() {
|
|
89 return mailFactory.newMail();
|
|
90 }
|
|
91
|
|
92 public static Mail newMail(String rawInput) {
|
|
93 return mailFactory.newMail(rawInput);
|
|
94 }
|
|
95
|
|
96 public static MailAddress parseAddress(String addr) throws MailException {
|
|
97 return mailFactory.parseAddress(addr);
|
|
98 }
|
|
99
|
|
100 public static boolean isSendingMail() {
|
|
101 return mailFactory.isSendingMail();
|
|
102 }
|
|
103 }
|