1 package org.columba.mail.folder.imap; 17 18 import java.io.IOException ; 19 20 import javax.swing.Action ; 21 22 import org.columba.api.command.ICommandReference; 23 import org.columba.api.command.IWorkerStatusController; 24 import org.columba.core.command.Command; 25 import org.columba.core.command.CommandCancelledException; 26 import org.columba.core.command.StatusObservableImpl; 27 import org.columba.mail.command.IMailFolderCommandReference; 28 import org.columba.mail.command.MailFolderCommandReference; 29 import org.columba.mail.mailchecking.MailCheckingManager; 30 31 37 public class CheckForNewMessagesCommand extends Command { 38 39 IMAPFolder imapFolder; 40 41 private Action action; 42 private boolean triggerNotification; 43 44 45 public CheckForNewMessagesCommand(ICommandReference reference) { 46 super(reference); 47 triggerNotification = false; 48 49 IMailFolderCommandReference r = (IMailFolderCommandReference) getReference(); 51 52 imapFolder = (IMAPFolder) r.getSourceFolder(); 53 54 imapFolder.setMailboxSyncEnabled(false); 55 56 } 57 58 public CheckForNewMessagesCommand(Action action, ICommandReference reference) { 59 super(reference); 60 this.action = action; 61 triggerNotification = true; 62 63 IMailFolderCommandReference r = (IMailFolderCommandReference) getReference(); 65 66 imapFolder = (IMAPFolder) r.getSourceFolder(); 67 68 imapFolder.setMailboxSyncEnabled(false); 69 } 70 71 76 public void execute(IWorkerStatusController worker) throws Exception { 77 78 ((StatusObservableImpl) imapFolder.getObservable()).setWorker(worker); 80 81 82 int total = imapFolder.getMessageFolderInfo().getExists(); 84 85 Object [] uids = new Object [0]; 87 try { 88 uids = imapFolder.synchronizeHeaderlist(); 89 } catch (IOException e) { 90 imapFolder.setMailboxSyncEnabled(true); 91 worker.cancel(); 92 throw new CommandCancelledException(e); 93 } 94 95 int newTotal = imapFolder.getMessageFolderInfo().getExists(); 97 98 if (triggerNotification && (newTotal != total) ) { 100 if( ((IMAPRootFolder)imapFolder.getRootFolder()).getAccountItem().getImapItem().getBoolean("enable_sound")) { 101 IMailFolderCommandReference ref = new MailFolderCommandReference(imapFolder, uids); 103 MailCheckingManager.getInstance().fireNewMessageArrived(ref); 105 106 } 107 } 108 } 109 110 113 public void updateGUI() throws Exception { 114 if( action != null) action.setEnabled(true); 116 } 117 } | Popular Tags |