1 package SnowMailClient.view.actions; 2 3 import SnowMailClient.model.folders.*; 4 import SnowMailClient.model.accounts.*; 5 import SnowMailClient.model.*; 6 import snow.utils.gui.*; 7 8 import SnowMailClient.MailEngine.*; 9 import SnowMailClient.MailEngine.transfer.TransferFunctions; 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.EventQueue ; 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 26 public class SendAction extends AbstractAction 27 { 28 FolderTreeNode sent, outbox; 29 30 MailFolder sentFolder, outboxFolder; 31 FolderView folderView; 32 33 private SendAction( ) 34 { 35 super(Language.translate("Send")); 36 37 this.sent = SnowMailClientApp.getInstance().getFoldersModel().getSentFolder(); 38 this.outbox = SnowMailClientApp.getInstance().getFoldersModel().getOutboxFolder(); 39 this.folderView = SnowMailClientApp.getInstance().getFolderView(); 40 41 putValue(AbstractAction.SMALL_ICON, 42 SnowMailClientApp.loadImageIcon("pics/sendmail2.PNG") ); 43 44 47 48 putValue(AbstractAction.SHORT_DESCRIPTION, 49 Language.translate("Send selected mails and outbox content")); 50 51 folderView.getTableSelectionModel().addListSelectionListener( 52 new ListSelectionListener() 53 { 54 public void valueChanged(ListSelectionEvent e) 55 { 56 updateButtonVisibility(); 57 } 58 } 59 ); 60 61 try 62 { 63 sentFolder = sent.getMailFolder(); 64 outboxFolder = outbox.getMailFolder(); 65 outboxFolder.addTableModelListener(new TableModelListener() 66 { 67 public void tableChanged(TableModelEvent e) 68 { 69 updateButtonVisibility(); 70 } 71 }); 72 } 73 catch(Exception ex) 74 { 75 ex.printStackTrace(); 76 } 77 78 updateButtonVisibility(); 79 } 81 82 85 private void updateButtonVisibility() 86 { 87 int n = outboxFolder.getRowCount() + folderView.getTableSelectionCount(); 88 this.setEnabled( n>0 ); 89 } 90 91 public void actionPerformed(ActionEvent e) 92 { 93 if(folderView.getMailFolder()!=this.outboxFolder) 98 { 99 MailMessage[] messs = folderView.getSelectedMessages(); 100 for(MailMessage m: messs) 101 { 102 try 103 { 104 outboxFolder.addMessage(m); folderView.removeMail(m); 106 m.selectedInView = false; 107 } 108 catch(Exception ee) 109 { 110 ee.printStackTrace(); 111 } 112 } 113 } 114 115 final ProgressModalDialog progressDialog = new ProgressModalDialog( 119 SnowMailClientApp.getInstance(), "Sending mail", true, false); 120 progressDialog.start(); 121 122 Thread t = new Thread () 123 { 124 125 public void run() 126 { 127 try 128 { 129 sendAction(progressDialog); 130 } 131 finally 132 { 133 progressDialog.closeDialog(); 134 } 135 136 } 137 }; 138 t.start(); 139 } 140 141 144 public void sendAction(final ProgressModalDialog progressDialog) 145 { 146 if(outboxFolder.getRowCount()==0) 147 { 148 JOptionPane.showMessageDialog(progressDialog, 149 Language.translate("There are no messages to send in the outbox"), 150 "No messages to send", JOptionPane.INFORMATION_MESSAGE); 151 return; 152 } 153 154 progressDialog.setProgressBounds(outboxFolder.getRowCount()); 155 EventQueue.invokeLater(new Runnable () { public void run() { 156 progressDialog.setTitle(Language.translate("Sending mail")); 157 }}); 158 159 AddressBook addressBook = SnowMailClientApp.getInstance().getAddressBook(); 160 161 int count = outboxFolder.getRowCount(); 163 164 List<MailMessage> mailsToSend = new Vector<MailMessage>(); 166 mailsToSend.addAll( outboxFolder.getAllMessages() ); 167 168 int counter = 0; 170 for(MailMessage mess: mailsToSend) 171 { 172 counter++; 173 String toAddress = mess.getToAddressesText(); 174 175 progressDialog.setProgressValue(counter, Language.translate("Message")+" "+counter+" / "+count); 176 progressDialog.setCommentLabel(Language.translate("Sending mail to %",toAddress)); 177 178 if(progressDialog.wasCancelled()) break; 179 180 try 181 { 182 List<Address> addresses = Address.parseAddressList(toAddress); 184 for(Address a : addresses) 185 { 186 addressBook.incrementMailsSendedTo( a ); 187 } 188 } 189 catch(Exception e) 190 { 191 JOptionPane.showMessageDialog(SnowMailClientApp.getInstance().getContentPane(), 192 ""+e.getMessage(), 193 Language.translate("Cannot send mail"), JOptionPane.ERROR_MESSAGE); 194 195 e.printStackTrace(); 196 197 } 198 } 199 } 200 201 202 203 204 205 206 } | Popular Tags |