1 package SnowMailClient.MailEngine.transfer; 2 3 import SnowMailClient.model.folders.*; 4 import SnowMailClient.model.accounts.*; 5 import SnowMailClient.model.*; 6 import snow.utils.gui.*; 7 import snow.concurrent.*; 8 9 import SnowMailClient.MailEngine.*; 10 import SnowMailClient.SnowMailClientApp; 11 import SnowMailClient.view.folders.*; 12 import SnowMailClient.view.FolderView; 13 import SnowMailClient.Language.Language; 14 import SnowMailClient.gnupg.*; 15 import SnowMailClient.gnupg.model.GnuPGKeyID; 16 17 import java.awt.*; 18 import java.util.*; 19 import java.awt.event.*; 20 import javax.swing.*; 21 import javax.swing.event.*; 22 import javax.swing.tree.*; 23 24 public class TransferFunctions 25 { 26 private TransferFunctions() 27 { 28 } 29 30 32 public static void sendMail(final MailMessage mess, Interrupter interrupter, Counter counter) throws Exception 33 { 34 if( SwingUtilities.isEventDispatchThread()) 36 { 37 new Throwable ("Must be called from another thread than EDT").printStackTrace(); 38 } 39 SnowMailClientApp.getInstance().saveAllMails(false); 40 41 SecureSmtpConnection ssmtp = null; 42 43 try 44 { 45 String fromMailAddress = mess.getFromAddress().getMailAddress(); 46 MailAccount account = SnowMailClientApp.getInstance().getAccounts().getMailAccount(fromMailAddress); 47 if(account==null) 48 { 49 throw new Exception (Language.translate("No mail account found to send message, use a valid from address")); 50 } 51 52 if(mess.getMustBeSigned()) 53 { 54 try 55 { 56 MessageActions.prepare_Signing_Mail(mess, interrupter); 57 } 58 catch(Exception e) 59 { 60 throw e; 61 } 62 } 63 64 if(mess.getMustBeEncrypted()) 65 { 66 try 67 { 68 MessageActions.prepareEncryptMail(mess); 69 } 70 catch(Exception e) 71 { 72 throw e; 73 } 74 } 75 76 ssmtp = account.getSMTPConnection(); 77 78 ssmtp.sendMessage( mess, interrupter, counter ); 80 81 mess.setIsNoMoreNew(); 83 mess.setEditable(false); 85 86 87 EventQueue.invokeLater(new Runnable () 88 { 89 public void run() 90 { 91 try 92 { 93 SnowMailClientApp.getInstance().getFoldersModel().getSentFolder().getMailFolder().addMessage(mess); 94 SnowMailClientApp.getInstance().getFoldersModel().getOutboxFolder().getMailFolder().removeMessage(mess); 96 } 97 catch(Exception e) 98 { 99 JOptionPane.showMessageDialog(SnowMailClientApp.getInstance().getContentPane(), 100 ""+e.getMessage(), 101 Language.translate("Cannot move mail message from outbox to sent folder." 102 +"\nHowever, the message was succesfully sent."), 103 JOptionPane.ERROR_MESSAGE); 104 e.printStackTrace(); 105 } 106 } 107 }); 108 109 for(Address a : mess.getToAddresses()) 111 { 112 SnowMailClientApp.getInstance().getAddressBook().incrementMailsSendedTo( a ); 113 } 114 115 } 116 catch(Exception e) 117 { 118 throw e; 119 } 120 finally 121 { 122 if(ssmtp!=null) 123 { 124 try 125 { 126 ssmtp.terminateSession(); 127 } 128 catch(Exception bof) {} 129 } 130 } 131 } 132 133 134 135 136 } | Popular Tags |