1 package SnowMailClient.model.accounts; 2 3 import SnowMailClient.utils.*; 4 import SnowMailClient.view.*; 5 import SnowMailClient.view.dialogs.*; 6 import SnowMailClient.MailEngine.*; 7 import SnowMailClient.*; 8 import SnowMailClient.crypto.*; 9 10 import snow.utils.storage.*; 11 import snow.crypto.*; 12 import snow.concurrent.*; 13 14 import java.util.*; 15 import java.util.concurrent.*; 16 import java.net.*; 17 18 19 21 public final class MailAccount implements Vectorizable { 22 23 private String address = "?"; 24 private String name = "?"; 25 private String smtp = "?"; 26 private String pop = "?"; 27 private String accountUserName = "?"; 28 private String accountPassword = "?"; 29 private boolean useToRead = true; 30 private boolean useToSend = true; 31 private int popPort = 110; 32 private int sslPopPort = 995; 33 private int sslSMTPPort = 21; private int smtpPort = 25; 35 private boolean signOutgoingMails = false; 36 private boolean allowUnsecurePasswordProtocols = false; 38 39 public final TaskManager messagesDownloadExecutor = new TaskManager(); 41 42 43 public boolean storeAccountLogInVectorRepresentation = false; 45 46 47 private final AccountLog accountLog = new AccountLog(); 49 50 private SecurePopConnection securePopConnection; 51 private SecureSmtpConnection secureSmtpConnection; 52 53 54 public MailAccount() { } 55 56 57 public final AccountLog getAccountLog() { return accountLog; } 58 59 public final String getAddress() { return address; } 60 public void setAddress(String a) { address = a; } 61 62 public final String getName() { return name; } 63 public final void setName(String a) { name = a; } 64 65 public final String getAccountUserName() { return accountUserName; } 66 public final void setAccountUserName(String a) { accountUserName = a; } 67 68 public final String getAccountPassword() { return accountPassword; } 69 public final void setAccountPassword(String a) { accountPassword = a; } 70 71 public final String getPop() { return pop; } 72 public final void setPop(String a) { pop = a; } 73 74 public final int getSSLPopPort() { return sslPopPort; } 75 public final int getSSLSMTPPort() { return sslSMTPPort;} 76 77 public final void setSSLPOPPort(int p) { sslPopPort = p; } 78 public final void setSSLSMTPPort(int p) { sslSMTPPort = p;} 79 80 public final int getPopPort() { return popPort; } 81 public final void setPopPort(int a) { popPort = a; } 82 83 public final String getSMTP() { return smtp; } 84 public final void setSMTP(String a) { smtp = a; } 85 86 public final int getSMTPPort() { return smtpPort; } 87 public final void setSMTPPort(int a) { smtpPort = a; } 88 89 public final boolean getUseToReadMails() { return useToRead; } 90 public final void setUseToReadMails(boolean doIt) { useToRead = doIt; } 91 92 public final boolean getUseToSendMails() { return useToSend; } 93 public final void setUseToSendMails(boolean doIt) { useToSend = doIt; } 94 95 public final boolean getAllowUnsecurePasswordProtocols() { return this.allowUnsecurePasswordProtocols; } 96 public final void setAllowUnsecurePasswordProtocols(boolean doIt) { this.allowUnsecurePasswordProtocols = doIt; } 97 98 100 public final boolean isSnowraverAccount() 101 { 102 return address.toLowerCase().endsWith("snowraver.org"); 103 } 105 106 107 private String rsan = ""; 111 private String rsad = ""; 112 private String rsae = ""; 113 private int rsalength = 0; 114 115 116 public final String getRSA_n() { return rsan; } 117 public final void setRSA_n(String n) { rsan=n; } 118 public final String getRSA_e() { return rsae; } 119 public final void setRSA_e(String e) { rsae=e; } 120 public final String getRSA_d() { return rsad; } 121 public final void setRSA_d(String d) { rsad=d; } 122 public final int getRSA_Length() { return rsalength; } 123 public final void setRSA_Length(int l) { rsalength=l; } 124 125 128 public final synchronized void closePOPConnection() 129 { 130 try 131 { 132 if( securePopConnection!=null && securePopConnection.isAlive()) 133 { 134 securePopConnection.terminateSession(); 135 } 136 } 137 catch(Exception e) 138 { 139 e.printStackTrace(); 140 } 141 } 142 143 public final String toString() { return "Mail account "+this.getAddress(); } 144 145 149 public final synchronized SecurePopConnection getCheckedPopConnection() throws Exception 150 { 151 if( securePopConnection!=null && securePopConnection.isAlive()) 152 { 153 return securePopConnection; 154 } 155 else 156 { 157 try 158 { 159 securePopConnection = new SecurePopConnection(this); 160 return securePopConnection; 161 } 162 catch(BadPasswordException e) 163 { 164 throw new Exception ("Bad Password for "+this.address+"\n Error="+e.getMessage()); 165 } 166 } 167 } 168 169 170 172 public final synchronized SecureSmtpConnection getSMTPConnection() throws Exception 173 { 174 if( secureSmtpConnection!=null && secureSmtpConnection.isAlive()) 175 { 176 return secureSmtpConnection; 177 } 178 else 179 { 180 String hname = "?"; 182 try 183 { 184 InetAddress local = InetAddress.getLocalHost(); 185 hname = local.getHostName(); 186 } 187 catch(Exception ignored){} 188 189 try 190 { 191 secureSmtpConnection = new SecureSmtpConnection(this, 192 hname, 193 false 194 ); 195 return secureSmtpConnection; 196 } 197 catch(BadPasswordException ee) 198 { 199 throw new Exception ("Bad Password for "+this.address 200 +"\n Error="+ee.getMessage()); 201 } 202 } 203 } 204 205 206 208 @SuppressWarnings ("unchecked") 209 public final void createFromVectorRepresentation(Vector<Object > v) throws VectorizeException 210 { 211 int ver = (Integer ) v.get(0); 212 213 if(ver==6) 214 { 215 address = (String ) v.get(1); 216 name = (String ) v.get(2); 217 pop = (String ) v.get(3); 218 smtp = (String ) v.get(4); 219 accountUserName = (String ) v.get(5); 220 accountPassword = (String ) v.get(6); 221 useToRead = (Boolean ) v.get(7); 222 useToSend = (Boolean ) v.get(8); 223 popPort = (Integer ) v.get(9); 224 smtpPort = (Integer ) v.get(10); 225 rsan = (String ) v.get(11); 226 rsad = (String ) v.get(12); 227 rsae = (String ) v.get(13); 228 rsalength = (Integer ) v.get(14); 229 230 accountLog.createFromVectorRepresentation((Vector<Object >) v.get(15)); 231 this.sslPopPort = (Integer ) v.get(16); 232 this.sslSMTPPort = (Integer ) v.get(17); 233 useSSL_POP = (Boolean ) v.get(18); 234 useSSL_SMTP = (Boolean ) v.get(19); 235 if(v.size()>20) 236 { 237 signOutgoingMails = (Boolean ) v.get(20); 238 } 239 if(v.size()>21) 240 { 241 this.allowUnsecurePasswordProtocols = (Boolean ) v.get(21); 242 } 243 244 } 245 } 246 247 248 private boolean useSSL_POP = false; 249 private boolean useSSL_SMTP = false; 250 251 public final boolean useSSLPOP() { return useSSL_POP;} 252 public final boolean useSSLSMTP() { return useSSL_SMTP;} 253 254 public final void setUseSSLPOP(boolean b) { useSSL_POP = b; } 255 public final void setUseSSLSMTP(boolean b) { useSSL_SMTP = b; } 256 257 258 public final Vector<Object > getVectorRepresentation() throws VectorizeException 261 { 262 Vector<Object > v = new Vector<Object >(); 263 v.addElement(6); v.addElement(address); 265 v.addElement(name); 266 v.addElement(pop); 267 v.addElement(smtp); 268 v.addElement(accountUserName); 269 v.addElement(accountPassword); 270 v.addElement(useToRead); 271 v.addElement(useToSend); 272 v.addElement(popPort); 273 v.addElement(smtpPort); 274 v.addElement(rsan); 275 v.addElement(rsad); 276 v.addElement(rsae); 277 v.addElement(rsalength); 278 if(storeAccountLogInVectorRepresentation==false) 279 { 280 accountLog.maxLength = 5000; 281 accountLog.checkLength(); 282 } 283 v.addElement(accountLog.getVectorRepresentation()); 285 v.addElement(this.sslPopPort); 286 v.addElement(this.sslSMTPPort); 287 v.addElement(this.useSSL_POP); 288 v.addElement(this.useSSL_SMTP); 289 v.addElement(signOutgoingMails); v.addElement(allowUnsecurePasswordProtocols); 291 return v; 292 } 293 } | Popular Tags |