1 package org.columba.mail.smtp.command; 17 18 import java.util.List ; 19 import java.util.Vector ; 20 21 import javax.swing.Action ; 22 23 import org.columba.api.command.ICommandReference; 24 import org.columba.api.command.IWorkerStatusController; 25 import org.columba.core.command.Command; 26 import org.columba.core.command.CommandProcessor; 27 import org.columba.core.command.Worker; 28 import org.columba.mail.command.IMailFolderCommandReference; 29 import org.columba.mail.command.MailFolderCommandReference; 30 import org.columba.mail.composer.SendableMessage; 31 import org.columba.mail.config.AccountItem; 32 import org.columba.mail.config.MailConfig; 33 import org.columba.mail.folder.IMailbox; 34 import org.columba.mail.folder.command.MoveMessageCommand; 35 import org.columba.mail.folder.outbox.OutboxFolder; 36 import org.columba.mail.folder.outbox.SendListManager; 37 import org.columba.mail.gui.tree.FolderTreeModel; 38 import org.columba.mail.smtp.SMTPServer; 39 import org.columba.mail.util.MailResourceLoader; 40 41 47 public class SendAllMessagesCommand extends Command { 48 protected SendListManager sendListManager = new SendListManager(); 49 50 protected OutboxFolder outboxFolder; 51 52 private Action action; 53 54 public SendAllMessagesCommand(Action action, ICommandReference reference) { 55 super(reference); 56 57 this.action = action; 58 } 59 60 63 public void execute(IWorkerStatusController worker) throws Exception { 64 IMailFolderCommandReference r = (IMailFolderCommandReference) getReference(); 65 66 worker.setDisplayText(MailResourceLoader.getString("statusbar", 68 "message", "send_message")); 69 70 outboxFolder = (OutboxFolder) r.getSourceFolder(); 72 73 Object [] uids = outboxFolder.getUids(); 75 76 for (int i = 0; i < uids.length; i++) { 78 if (outboxFolder.exists(uids[i]) == true) { 79 SendableMessage message = outboxFolder 80 .getSendableMessage(uids[i]); 81 sendListManager.add(message); 82 } 83 } 84 85 int actAccountUid = -1; 86 List sentList = new Vector (); 87 88 SMTPServer smtpServer = null; 89 IMailbox sentFolder = null; 90 91 while (sendListManager.hasMoreMessages()) { 93 SendableMessage message = sendListManager.getNextMessage(); 94 95 if (message.getAccountUid() != actAccountUid) { 97 actAccountUid = message.getAccountUid(); 98 99 AccountItem accountItem = MailConfig.getInstance() 100 .getAccountList().uidGet(actAccountUid); 101 102 if (accountItem == null) { 103 accountItem = MailConfig.getInstance().getAccountList() 105 .getDefaultAccount(); 106 107 if (accountItem == null) 108 continue; } 111 112 sentFolder = (IMailbox) FolderTreeModel 114 .getInstance() 115 .getFolder( 116 accountItem.getSpecialFoldersItem().get("sent")); 117 118 smtpServer = new SMTPServer(accountItem); 120 } 121 smtpServer.sendMessage(message, worker); 122 123 sentList.add(message.getHeader().get("columba.uid")); 124 } 125 126 worker.clearDisplayTextWithDelay(); 130 131 if (sentList.size() > 0) { 133 moveToSentFolder(sentList, sentFolder); 134 sentList.clear(); 135 } 136 } 137 138 148 protected void moveToSentFolder(List v, IMailbox sentFolder) { 149 IMailFolderCommandReference r = new MailFolderCommandReference( 150 outboxFolder, sentFolder, v.toArray()); 151 152 MoveMessageCommand c = new MoveMessageCommand(r); 154 155 CommandProcessor.getInstance().addOp(c); 156 } 157 158 161 public void updateGUI() throws Exception { 162 if (action != null) 163 action.setEnabled(true); 164 } 165 } | Popular Tags |