From: Stig T. <jw...@us...> - 2005-03-20 15:07:56
|
Update of /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20549/net/sf/mailsomething/mail Modified Files: TransparentMailbox.java RequestHandler.java NntpAccount.java Mailbox.java ImapAccount.java MessageHolder.java MailService.java MailAccount.java MailboxHolder.java PopAccount.java Log Message: Index: ImapAccount.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/ImapAccount.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImapAccount.java 14 Mar 2005 20:27:52 -0000 1.3 --- ImapAccount.java 20 Mar 2005 15:07:40 -0000 1.4 *************** *** 1,4 **** ! package net.sf.mailsomething.mail; import net.sf.mailsomething.mail.parsers.*; --- 1,8 ---- ! package net.sf.mailsomething.mail; + import net.sf.mailsomething.mail.actions.CreateMailboxAction; + import net.sf.mailsomething.mail.actions.DeleteMailboxAction; + import net.sf.mailsomething.mail.actions.GetMessagesAction; [...1894 lines suppressed...] if(tempRequest.getErrorCount() > 3) --- 556,560 ---- * */ ! /*if (tempRequest != null) { if(tempRequest.getErrorCount() > 3) *************** *** 2118,2122 **** } ! } /** --- 569,573 ---- } ! }*/ /** Index: NntpAccount.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/NntpAccount.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NntpAccount.java 3 Apr 2004 07:56:48 -0000 1.1 --- NntpAccount.java 20 Mar 2005 15:07:39 -0000 1.2 *************** *** 18,22 **** public class NntpAccount extends MailAccount ! implements Runnable, Serializable { public static final int FETCH_ALL = 1; --- 18,22 ---- public class NntpAccount extends MailAccount ! implements Serializable { public static final int FETCH_ALL = 1; *************** *** 69,72 **** --- 69,78 ---- } + + + public void addAction(MailAction action) { + + + } public void init() { *************** *** 302,316 **** * @see lib.mail.Hierachy#setFlags(Flags) */ ! public void setFlags(Flags flags) { ! } /** * @see lib.mail.Hierachy#getFlags() */ ! public Flags getFlags() { return null; ! } ! public void handleRequest(Request r) { System.out.println("parserequest"); --- 308,322 ---- * @see lib.mail.Hierachy#setFlags(Flags) */ ! ///public void setFlags(Flags flags) { ! //} /** * @see lib.mail.Hierachy#getFlags() */ ! /*public Flags getFlags() { return null; ! }*/ ! /*public void handleRequest(Request r) { System.out.println("parserequest"); *************** *** 321,327 **** else parseRequest(r); ! } ! protected void parseRequest(Request r) { System.out.println("handlerequest"); --- 327,333 ---- else parseRequest(r); ! }*/ ! /*protected void parseRequest(Request r) { System.out.println("handlerequest"); *************** *** 387,393 **** } ! } ! public void run() { while (1 > 0) { --- 393,399 ---- } ! }*/ ! /*public void run() { while (1 > 0) { *************** *** 421,425 **** * * ! */ Request r = stack.pop(); --- 427,431 ---- * * ! * Request r = stack.pop(); *************** *** 432,436 **** } ! } /** --- 438,442 ---- } ! }*/ /** *************** *** 439,443 **** * */ ! private void updateMessages(Request r) { //System.out.println("update messages nntp account"); --- 445,449 ---- * */ ! /*private void updateMessages(Request r) { //System.out.println("update messages nntp account"); *************** *** 458,462 **** else mailbox.addMessage(messages[i]); ! }*/ if (messages != null) --- 464,468 ---- else mailbox.addMessage(messages[i]); ! }* if (messages != null) *************** *** 468,472 **** } ! } /** --- 474,478 ---- } ! }*/ /** *************** *** 475,479 **** * */ ! private void updateMailboxes(Request r) { if (groupfile == null) { --- 481,485 ---- * */ ! /*private void updateMailboxes(Request r) { if (groupfile == null) { *************** *** 504,508 **** } ! } private String getLastMessageId(String groupname) { --- 510,514 ---- } ! }*/ private String getLastMessageId(String groupname) { Index: RequestHandler.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/RequestHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RequestHandler.java 3 Apr 2004 07:56:48 -0000 1.1 --- RequestHandler.java 20 Mar 2005 15:07:39 -0000 1.2 *************** *** 10,14 **** ! public void handleRequest(Request r); --- 10,17 ---- ! //public void handleRequest(Request r); ! ! ! public void addAction(MailAction action); Index: MailAccount.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/MailAccount.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MailAccount.java 14 Mar 2005 20:27:52 -0000 1.2 --- MailAccount.java 20 Mar 2005 15:07:40 -0000 1.3 *************** *** 10,13 **** --- 10,14 ---- import net.sf.mailsomething.util.event.*; + import net.sf.mailsomething.mail.actions.CreateMailboxAction; import net.sf.mailsomething.mail.parsers.SessionHandler; *************** *** 25,29 **** *@created March 24, 2002 */ ! public abstract class MailAccount extends Account implements MailboxHolder, RequestHandler, Serializable { static final long serialVersionUID = 5168002350209084194L; --- 26,32 ---- *@created March 24, 2002 */ ! public abstract class MailAccount extends Account ! implements MailboxHolder, RequestHandler, Serializable, ! Runnable { static final long serialVersionUID = 5168002350209084194L; *************** *** 55,59 **** // the stack of commands waiting. ! protected RequestStack stack; //an alias, being used for the name used for sender, when sending mails... not appropiate for this I guess. --- 58,64 ---- // the stack of commands waiting. ! //protected RequestStack stack; ! ! protected transient Vector actions = new Vector(); //an alias, being used for the name used for sender, when sending mails... not appropiate for this I guess. *************** *** 110,113 **** --- 115,120 ---- + // is the thread running. + protected boolean runthread = true; /** *************** *** 123,127 **** listeners = new Vector(); ! stack = new RequestStack(); } --- 130,134 ---- listeners = new Vector(); ! //stack = new RequestStack(); } *************** *** 142,145 **** --- 149,166 ---- + public void addAction(MailAction action) { + + if (shouldRun()) + actions.add(action); + + else { + + action.setMailAccount(this); + action.invoke(); + } + + } + + /** * returns the mailaddress related to this mailaccount. *************** *** 537,546 **** //some field for read/write access.... if (!mailbox.isRemote() && !mailbox.getName().equals("")) { ! Request r = new Request(Request.CREATE_MAILBOX, this, mailbox.getName()); r.setDismissable(false); ! stack.add(r); } --- 558,571 ---- //some field for read/write access.... if (!mailbox.isRemote() && !mailbox.getName().equals("")) { + + CreateMailboxAction cma = new CreateMailboxAction(mailbox); ! addAction(cma); ! ! /*Request r = new Request(Request.CREATE_MAILBOX, this, mailbox.getName()); r.setDismissable(false); ! stack.add(r);*/ } *************** *** 1202,1205 **** --- 1227,1280 ---- return updateInterval; } + + + /** + * Main processing method for the ImapAccount object + */ + public void run() { + + //make sure this is set. If someone starts the account as a + //thread without calling init (which should only be done (can only) + //once, we need to make sure the thread doesnt stop imediately. + runthread = true; + + /**this is a stupid solution to following problem: request which changes mailbox/messages + * and gui-components which arent initialized proberly. + * Instead there should be some global variable or similar. Eg. wait for a go-signal from the + * main gui-initializer. (SampleGui). + */ + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } + + //if(controller == null) controller = new ImapController(this); + + while (1 > 0) { + + if (!runthread) { + break; + } + + if (actions.isEmpty()) { + + //controller.hasServerMessages(); + + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + } else { + MailAction action = (MailAction)actions.remove(0); + + action.setMailAccount(this); + + action.invoke(); + + } + + } + + } Index: MessageHolder.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/MessageHolder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MessageHolder.java 3 Apr 2004 07:56:48 -0000 1.1 --- MessageHolder.java 20 Mar 2005 15:07:40 -0000 1.2 *************** *** 45,49 **** *@param messageid Description of Parameter */ ! public void removeMessage(String messageid); --- 45,49 ---- *@param messageid Description of Parameter */ ! //public void removeMessage(String messageid); *************** *** 57,63 **** /** ! * No need for the old version where inputargument was message and not messageid. One ! * must asume that a message with an equal messageid is the same. This should be removed. ! * or changed with existsUid. If one wants to find/search for a message with a specific field * one should use a search method (which isnt done yet). * --- 57,66 ---- /** ! * No need for the old version where inputargument ! * was message and not messageid. One ! * must asume that a message with an equal messageid ! * is the same. This should be removed. ! * or changed with existsUid. If one wants to ! * find/search for a message with a specific field * one should use a search method (which isnt done yet). * Index: TransparentMailbox.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/TransparentMailbox.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TransparentMailbox.java 12 Mar 2005 15:31:30 -0000 1.2 --- TransparentMailbox.java 20 Mar 2005 15:07:38 -0000 1.3 *************** *** 63,67 **** //for specific session-consistent flags. ! transient Flags flags = null; private int state = 0; --- 63,67 ---- //for specific session-consistent flags. ! //transient Flags flags = null; private int state = 0; *************** *** 224,228 **** *@return The childCount value */ ! public int getChildCount() { if (messages != null) { --- 224,228 ---- *@return The childCount value */ ! /*public int getChildCount() { if (messages != null) { *************** *** 231,235 **** return 0; ! } /** --- 231,235 ---- return 0; ! }*/ /** *************** *** 239,243 **** *@return The child value */ ! public Object getChild(int index) { if (messages != null && index < messages.size()) { --- 239,243 ---- *@return The child value */ ! /*public Object getChild(int index) { if (messages != null && index < messages.size()) { *************** *** 246,250 **** return null; ! } /** --- 246,250 ---- return null; ! }*/ /** *************** *** 253,257 **** *@return The children value */ ! public Object[] getChildren() { if(messages != null) --- 253,257 ---- *@return The children value */ ! /*public Object[] getChildren() { if(messages != null) *************** *** 259,263 **** return new Object[]{}; ! } /** --- 259,263 ---- return new Object[]{}; ! }*/ /** *************** *** 571,575 **** } ! public Flags getFlags() { return flags; } --- 571,575 ---- } ! /*public Flags getFlags() { return flags; } *************** *** 577,581 **** public void setFlags(Flags flags) { this.flags = flags; ! } /** --- 577,581 ---- public void setFlags(Flags flags) { this.flags = flags; ! }*/ /** Index: MailboxHolder.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/MailboxHolder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MailboxHolder.java 3 Apr 2004 07:56:48 -0000 1.1 --- MailboxHolder.java 20 Mar 2005 15:07:40 -0000 1.2 *************** *** 47,57 **** ! /** ! * Description of the Method ! * ! *@param mailboxname Description of Parameter ! */ ! public void removeMailbox(String mailboxname); ! /** --- 47,51 ---- ! /** Index: PopAccount.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/PopAccount.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PopAccount.java 14 Mar 2005 20:27:52 -0000 1.2 --- PopAccount.java 20 Mar 2005 15:07:40 -0000 1.3 *************** *** 7,10 **** --- 7,11 ---- + import net.sf.mailsomething.mail.actions.GetMessagesAction; import net.sf.mailsomething.mail.parsers.*; *************** *** 24,28 **** */ ! public class PopAccount extends MailAccount implements Serializable, Runnable { static final long serialVersionUID = 8715676360363527320L; --- 25,29 ---- */ ! public class PopAccount extends MailAccount implements Serializable { static final long serialVersionUID = 8715676360363527320L; *************** *** 41,45 **** //is the thread running. ! private boolean runthread = true; //should be transient. --- 42,46 ---- //is the thread running. ! //private boolean runthread = true; //should be transient. *************** *** 183,317 **** } ! /** ! * Handles a request. Normally a client class will not use this, but it ! * is possible to construct a request and call this directly. ! */ ! public void handleRequest(Request r) { ! ! if (shouldRun()) ! stack.add(r); ! ! else ! parseRequest(r); ! ! } ! ! /** ! * Parses and handles a request, dont use this, but handleRequest, it ! * will be protected sooner or later. ! * ! */ ! public void parseRequest(Request r) { ! ! if (controller == null) { ! controller = new PopController(this); ! ! } ! ! if (controller.isConnected()) { ! ! int scheme = r.getAction(); ! ! //System.out.println("popaccount scheme " + scheme); ! ! switch (scheme) { ! case 1 : ! deleteMessage(r); ! break; ! case 2 : ! { ! //deleteMailbox(r); ! ! Mailbox mbox = (Mailbox) r.getObject(); ! ! if (mbox.getParent() != null) { ! ! System.out.println("????" + mbox.getParent()); ! ! if (mbox.getParent().equals("")) { ! ! removeMailbox(mbox); ! ! } else { ! ! Mailbox parent = getMailbox(mbox.getParent()); ! ! parent.removeMailbox(mbox); ! ! } ! ! } else { ! ! String path = mbox.getPath(); ! ! Mailbox parent = ! getMailbox( ! mbox.getPath().substring( ! 0, ! mbox.getPath().lastIndexOf( ! getDelimiter()))); ! ! parent.removeMailbox(mbox); ! ! } ! ! break; ! ! } ! case 3 : ! //createMailbox(r); ! break; ! case 4 : ! //updateMailboxes(r); ! break; ! case 5 : { ! ! ! ! getAllMessages(r); ! ! //clear the timer, this is done basicly if the user ! //or someone else calls this request and at same time ! //the timer is running, so we wont have an update ! //imediately after. ! if(timer != null) { ! ! timer.restart(); ! } ! ! break; ! ! ! } ! case 6 : ! //in case someone calls update all messages ! //getAllMessages(r); ! break; ! case 7 : ! //updateAll(r); ! break; ! case 8 : ! //moveMailbox(r); ! break; ! case 9 : ! //renameMailbox(r); ! break; ! case 11 : ! //this isnt really needed, since u can just do an add (and delete). ! copyMessage(r); ! break; ! case 12 : ! moveMessage(r); ! break; ! } ! } else { ! ! /*should probably popup some menu, eventually asking wether to keep trying ! *to connect. And interval. ! */ ! ! } ! ! } /** --- 184,189 ---- } ! ! /** *************** *** 324,372 **** } ! public void run() { ! ! while (1 > 0) { ! ! //this get reset every time the thread is restarted (which can happen several times) ! if (runthread == false) { ! break; ! } ! ! suspended = false; ! ! //this is set from userinput, and wont get changed automaticly. ! if (suspended) ! break; ! ! if (stack.isEmpty()) { ! //System.out.println("stack is empty"); ! try { ! Thread.sleep(200); ! } catch (InterruptedException e) { ! } ! } else { ! ! /** ! * After changing the delete method to not logoff after deleting ! * it works fast. But, that requires other methods to update ! * uid-list... Instead im thinking that this thread should ! * check stack for several delete requests, and then call a single ! * method which deletes all at once. And then clear uids-list. ! * It would require and improve stack, ie, for searching for ! * several requests of same type. ! * ! * ! * ! */ ! ! Request r = stack.pop(); ! ! parseRequest(r); ! ! } ! ! } ! ! } /** --- 196,200 ---- } ! /** *************** *** 420,424 **** if (m != null) { ! m.updateMessages(ImapAccount.DEFAULT); } --- 248,252 ---- if (m != null) { ! m.updateMessages(GetMessagesAction.DEFAULT); } *************** *** 440,685 **** } ! private void copyMessage(Request r) { ! ! //System.out.println("popaccount copymessage"); ! ! MessageHolder oldmailbox = (MessageHolder) r.getSource(); ! ! MessageHolder nmailbox = (MessageHolder) r.getObject(); ! ! Message clone = (Message) r.getMessage().clone(); ! ! nmailbox.addMessage(clone); ! ! System.out.println("popaccount: clone isremote " + clone.isRemote()); ! } ! ! private void moveMessage(Request r) { ! ! copyMessage(r); ! ! MessageHolder srcMailbox = (MessageHolder) r.getSource(); ! ! Message org = (Message) r.getMessage(); ! ! //System.out.println("popaccount: original isremote " + org.getRemote()); ! ! srcMailbox.removeMessage(r.getMessage()); ! ! } ! ! /** Changed but I have no possibilty of testing online at the moment. ! * See mailbox removeMessage. ! * Ive tried to change it to allow local removing without remote removing, which means that the ! * action of removing the message remote (at server) should be saved in case the program cant ! * connect to server. The old implementation meant, that deleting of non-local messages was impossible ! * which from a designpoint seems logical but from a user-perspective isnt that cool. This changed imple ! * mentation could be called lazy-serverhandling.... It requires 1 thing (especially for imap): that the stack ! * requests are executed sequentially, first in first out. ! * Specifically this is changed, so the mailbox removes the message (from mailbox), and this method dont. ! * This method just handles the server-action, based upon remote/nonremote, and if a message is remote ! * it will stay remote, when its not deleted, even though it appears in another mailbox. This means, u can ! * delete a message, it will be removed to deleted items (and not deleted at server) and then u can delete ! * it at local mailbox (deleted items). The message will still exists though, through the reference in the ! * request. Since the choosing of this method is the mailbox.isremote and not message, the second delete- ! * request will change nothing, because the second delete has a local-mailbox in request. ! */ ! private void deleteMessage(Request r) { ! ! MessageHolder mailbox = (MessageHolder) r.getSource(); ! ! Message message = r.getMessage(); ! ! //this is a stupid way to decide this. ! if (!mailbox.isRemote()) { ! ! MessageHolder trash = getStandardMailbox(Mailbox.TRASH); ! ! if (trash == null) ! return; ! ! //should have a public field TRASH with name of mailbox ! //and a boolean value: deleteFully ! if (mailbox.equals(trash)) { ! ! //here should be a check, if the setting ! //deleteWhenDeletedFromTrash ! //is true, and if so, check if the message exists ! //at server, and then delete it. ! ! return; ! ! } else { ! ! trash.addMessage(message); ! ! return; ! ! } ! ! } else { ! ! String myUID = message.getUID(); ! ! //get the uid-markers (uidmarker = uid + index) ! PopController.UIDMarker[] uids = controller.searchUid(); ! ! for (int i = 0; i < uids.length; i++) { ! //System.out.println(uids[i]); ! if (uids[i] != null) { ! ! if (uids[i].getUID().equals(myUID)) ! controller.deleteMessage(uids[i].getIndex()); ! ! } ! } ! ! message.setRemote(false); ! ! mailbox.removeMessage(message); ! ! MessageHolder trash = getStandardMailbox(Mailbox.TRASH); ! ! if (trash != null) ! trash.addMessage(message); ! ! } ! ! //controller.logof(); ! ! } ! ! /** Searches for uids and compares to current uids at mailbox. And gets those messages ! * that doesnt exists in mailbox. Which means, that if a message gets moved and not deleted ! * for some reason, it will be fetched again. But a move should delete it. ! */ ! private void updateMessages(Request r) { ! ! /*this should probably call a stat, get the difference between first stat ! * and this. and then get those messages. ! * Which will mean that the running thread should always start with a ! * getAllMessages and then a stat ! */ ! } ! ! private void getAllMessages(Request r) { ! ! if (r.getFlag() == 6) ! return; ! ! controller.clearUidBuffer(); ! ! MessageHolder mailbox = getStandardMailbox(Mailbox.INBOX); ! ! PopController.UIDMarker[] uids = controller.searchUid(); ! ! if (uids == null) ! return; ! ! Vector nmessages = new Vector(); ! ! int max = getMaxMessagesToFetch(); ! ! int startfrom = 0; ! ! /** ! * We dont call either notifyMessagesFound since we dont know ! * how many NEW messages is actually found. ! */ ! if (max < uids.length) { ! ! startfrom = uids.length - max; ! ! notifyWorkStarted(max); ! } else ! notifyWorkStarted(uids.length); ! ! int[] sizes = null; ! ! for (int i = startfrom; i < uids.length; i++) { ! ! if (uids[i] != null) { ! //problem here. ! if (!mailbox.existsUid(uids[i].getUID())) { ! ! //dont get the message sizes untill we have a new message ! if (sizes == null) ! sizes = controller.getSizeList(); ! ! //int size = controller.getMessageSize(uids[i].getIndex()); ! ! if (sizes[uids[i].getIndex() - 1] > getMaxMessageSize()) { ! ! Message m = MailService.createMessage(); ! ! m.setUID(uids[i].getUID()); ! ! m.setField(MessageConstants.SUBJECT, "unknown"); ! ! m.setField(MessageConstants.FROM, "unknown"); ! ! String message = ! "The size of this message is bigger than limit," ! + "either change sizelimit or ignore this message" ! + "completely. Some time in future it will be possible" ! + "to fetch the message anyways"; ! ! m.setObject(message.getBytes()); ! ! m.setRemote(true); ! ! m.setSize(sizes[uids[i].getIndex() - 1]); ! ! mailbox.addMessage(m); ! ! nmessages.add(m); ! ! notifyMessagesFetched(mailbox, new Message[] { m }); ! ! //continue; ! ! } else { ! ! Message m = controller.getMessage(uids[i].getIndex()); ! ! m.setRemote(true); ! ! m.setUID(uids[i].getUID()); ! ! m.setBodyFetched(true); ! ! m.setSize(sizes[uids[i].getIndex() - 1]); ! ! mailbox.addMessage(m); ! ! nmessages.add(m); ! ! notifyMessagesFetched(mailbox, new Message[] { m }); ! ! } ! } ! } ! ! notifyWorkProgress(i - startfrom + 1); ! ! } ! ! notifyWorkStopped(); ! ! //int extensions = controller.getExtension(); ! ! //System.out.println("controller supports: " + extensions); ! ! controller.logof(); ! ! //if(nmessages.size() > 0) ! //notifyMessagesFetched(mailbox, (Message[])nmessages.toArray(new Message[]{})); ! ! - } /** --- 268,290 ---- } ! ! ! ! /** ! * @return Returns the controller. ! */ ! public PopController getController() { ! return controller; } ! ! ! ! public void addAction(MailAction action) { ! //TODO } + + /** *************** *** 726,735 **** } ! public void setFlags(Flags flags) { } public Flags getFlags() { return null; ! } public int validateAccount() { --- 331,340 ---- } ! /*public void setFlags(Flags flags) { } public Flags getFlags() { return null; ! }*/ public int validateAccount() { Index: MailService.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/MailService.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MailService.java 14 Mar 2005 20:27:52 -0000 1.3 --- MailService.java 20 Mar 2005 15:07:40 -0000 1.4 *************** *** 16,19 **** --- 16,20 ---- import net.sf.mailsomething.core.*; + import net.sf.mailsomething.mail.actions.GetMessagesAction; import net.sf.mailsomething.mail.parsers.*; *************** *** 1346,1350 **** account[i].getStandardMailbox(Mailbox.INBOX); ! inbox.updateMessages(ImapAccount.DEFAULT); } else if (account[i].getProtocol() == MailAccount.IMAP) { --- 1347,1351 ---- account[i].getStandardMailbox(Mailbox.INBOX); ! inbox.updateMessages(GetMessagesAction.DEFAULT); } else if (account[i].getProtocol() == MailAccount.IMAP) { *************** *** 1360,1364 **** //we only update none-hidden mailboxes, ofcourse if ((mm.getState() & Mailbox.HIDDEN) != Mailbox.HIDDEN) ! all[j].updateMessages(ImapAccount.DEFAULT); } catch (ClassCastException f) { --- 1361,1365 ---- //we only update none-hidden mailboxes, ofcourse if ((mm.getState() & Mailbox.HIDDEN) != Mailbox.HIDDEN) ! all[j].updateMessages(GetMessagesAction.DEFAULT); } catch (ClassCastException f) { *************** *** 1366,1370 **** //unlikely to happen ! all[j].updateMessages(ImapAccount.DEFAULT); } --- 1367,1371 ---- //unlikely to happen ! all[j].updateMessages(GetMessagesAction.DEFAULT); } Index: Mailbox.java =================================================================== RCS file: /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/Mailbox.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Mailbox.java 14 Mar 2005 20:27:52 -0000 1.2 --- Mailbox.java 20 Mar 2005 15:07:40 -0000 1.3 *************** *** 6,9 **** --- 6,19 ---- import java.util.Vector; + import net.sf.mailsomething.mail.actions.AppendMessageAction; + import net.sf.mailsomething.mail.actions.CopyMessageAction; + import net.sf.mailsomething.mail.actions.CreateMailboxAction; + import net.sf.mailsomething.mail.actions.DeleteMailboxAction; + import net.sf.mailsomething.mail.actions.DeleteMessageAction; + import net.sf.mailsomething.mail.actions.GetMessagesAction; + import net.sf.mailsomething.mail.actions.MoveMessageAction; + import net.sf.mailsomething.mail.actions.RenameMailboxAction; + import net.sf.mailsomething.mail.actions.UpdateMailboxesAction; + /** * Class implementing a mailbox. The class is build on the request/request *************** *** 89,93 **** //for specific session-consistent flags. ! transient Flags flags = null; private int state = 0; --- 99,103 ---- //for specific session-consistent flags. ! //transient Flags flags = null; private int state = 0; *************** *** 159,188 **** } ! //public void setPath(); /** ! * Sets the name attribute of the Mailbox object * *@param name The new name value */ public void setName(String name) { ! ! System.out.println("setname mailbox " + name); ! ! String oldpath = getPath(); ! ! this.name = name; ! if (remote == true) { ! Request r = new Request(Request.RENAME_MAILBOX, this, oldpath); ! r.setDismissable(false); ! handler.handleRequest(r); } ! MailboxEvent e = new MailboxEvent(this, this, 0); for (int i = 0; i < mailboxListeners.size(); i++) { ((MailboxListener) mailboxListeners.elementAt(i)).mailboxRenamed(e); ! } } --- 169,206 ---- } ! /** ! * Sets the name attribute of the Mailbox object. In case ! * the mailbox is remote this will fire a mailaction to ! * rename the mailbox at server, and the actual local ! * renaming will not happen until the the mailaction ! * is invoked. This means that visual components maybe ! * have to show a 'false' name for the mailbox as long ! * as the renaming isnt finished. * *@param name The new name value */ public void setName(String name) { ! ! if (remote) { ! ! RenameMailboxAction rma = ! new RenameMailboxAction(this, name); ! ! addAction(rma); ! ! } else { ! ! rename(name); ! } ! /*MailboxEvent e = new MailboxEvent(this, this, 0); for (int i = 0; i < mailboxListeners.size(); i++) { ((MailboxListener) mailboxListeners.elementAt(i)).mailboxRenamed(e); ! }*/ } *************** *** 369,373 **** *@return The childCount value */ ! public int getChildCount() { if (messages != null) { --- 387,391 ---- *@return The childCount value */ ! /*public int getChildCount() { if (messages != null) { *************** *** 376,380 **** return mailboxes.size(); ! } /** --- 394,398 ---- return mailboxes.size(); ! }*/ /** *************** *** 384,388 **** *@return The child value */ ! public Object getChild(int index) { if (index < mailboxes.size()) { --- 402,406 ---- *@return The child value */ ! /*public Object getChild(int index) { if (index < mailboxes.size()) { *************** *** 397,401 **** return null; ! } /** --- 415,419 ---- return null; ! }*/ /** *************** *** 404,408 **** *@return The children value */ ! public Object[] getChildren() { Vector all = new Vector(mailboxes); --- 422,426 ---- *@return The children value */ ! /*public Object[] getChildren() { Vector all = new Vector(mailboxes); *************** *** 415,419 **** return buffer; ! } /** --- 433,437 ---- return buffer; ! }*/ /** *************** *** 570,577 **** messages.add(message); //TODO: use the constructor which takes the message //as argument ! Request r = new Request( Request.APPEND_MESSAGE, --- 588,598 ---- messages.add(message); + + AppendMessageAction ama = + new AppendMessageAction(this, message); //TODO: use the constructor which takes the message //as argument ! /*Request r = new Request( Request.APPEND_MESSAGE, *************** *** 579,583 **** message.getField(MessageConstants.MESSAGE_ID)); ! r.setDismissable(false); if (!disableListeners) { --- 600,604 ---- message.getField(MessageConstants.MESSAGE_ID)); ! r.setDismissable(false);*/ if (!disableListeners) { *************** *** 602,606 **** } ! handler.handleRequest(r); } } else { --- 623,629 ---- } ! handler.addAction(ama); ! ! //handler.handleRequest(r); } } else { *************** *** 730,738 **** if (name.equals("") == false) { ! Request r = new Request(Request.CREATE_MAILBOX, this, name); r.setDismissable(false); ! handler.handleRequest(r); } --- 753,765 ---- if (name.equals("") == false) { + + CreateMailboxAction cma = new CreateMailboxAction(mailbox); ! addAction(cma); ! ! /*Request r = new Request(Request.CREATE_MAILBOX, this, name); r.setDismissable(false); ! handler.handleRequest(r);*/ } *************** *** 791,800 **** *@param mailboxname Description of Parameter */ ! public synchronized void removeMailbox(String mailboxname) { Mailbox mailbox = getMailbox(mailboxname); removeMailbox(mailbox); ! } /** --- 818,827 ---- *@param mailboxname Description of Parameter */ ! /*public synchronized void removeMailbox(String mailboxname) { Mailbox mailbox = getMailbox(mailboxname); removeMailbox(mailbox); ! }*/ /** *************** *** 824,830 **** if (message.isRemote()) { ! ! Request r = new Request( this, --- 851,858 ---- if (message.isRemote()) { ! DeleteMessageAction dma = ! new DeleteMessageAction(this, message); ! /*Request r = new Request( this, *************** *** 837,841 **** r.setDismissable(false); ! handler.handleRequest(r); } else { --- 865,869 ---- r.setDismissable(false); ! handler.handleRequest(r);*/ } else { *************** *** 869,878 **** *@param messageid Description of Parameter */ ! public void removeMessage(String messageid) { if (exists(messageid) == false) { return; } removeMessage(getMessage(messageid)); ! } /** --- 897,906 ---- *@param messageid Description of Parameter */ ! /*public void removeMessage(String messageid) { if (exists(messageid) == false) { return; } removeMessage(getMessage(messageid)); ! }*/ /** *************** *** 916,919 **** --- 944,948 ---- */ public Mailbox addMailbox(Mailbox mailbox) { + for (int i = 0; i < mailboxes.size(); i++) { if (mailbox *************** *** 926,940 **** String parent = mailbox.getParent(); ! if (parent == null) { ! mailbox.setParent(getParent() + getDelimiter() + getName()); ! mailbox.setRoot(rootName); ! mailbox.setRequestHandler(handler); ! mailboxes.add(mailbox); ! Request r = new Request(Request.CREATE_MAILBOX, this, mailbox.getName()); r.setDismissable(false); --- 955,973 ---- String parent = mailbox.getParent(); ! //if (parent == null) { ! mailbox.setParent(getParent() + getDelimiter() + getName()); ! mailbox.setRoot(rootName); ! mailbox.setRequestHandler(handler); ! mailboxes.add(mailbox); ! CreateMailboxAction a = new CreateMailboxAction(mailbox); ! ! handler.addAction(a); ! ! /* Request r = new Request(Request.CREATE_MAILBOX, this, mailbox.getName()); r.setDismissable(false); *************** *** 950,954 **** handler.handleRequest(r); ! } MailboxEvent e = new MailboxEvent(this, mailbox, mailboxes.size()); --- 983,987 ---- handler.handleRequest(r); ! }*/ MailboxEvent e = new MailboxEvent(this, mailbox, mailboxes.size()); *************** *** 989,997 **** */ public void updateMailboxes() { ! Request r = new Request(Request.UPDATE_MAILBOXES, this, null); r.setDismissable(true); ! handler.handleRequest(r); } --- 1022,1035 ---- */ public void updateMailboxes() { + + UpdateMailboxesAction uma = + new UpdateMailboxesAction(this); + + handler.addAction(uma); ! /*Request r = new Request(Request.UPDATE_MAILBOXES, this, null); r.setDismissable(true); ! handler.handleRequest(r);*/ } *************** *** 1042,1052 **** */ public void updateMessages(int flag) { ! Request r = null; r = new Request(Request.FETCH, flag, this, RequestStack.URGENT, null); r.setDismissable(true); ! handler.handleRequest(r); } --- 1080,1099 ---- */ public void updateMessages(int flag) { + + GetMessagesAction a = new GetMessagesAction(); + + a.setMailbox(this); + a.setType(flag); + ! /*Request r = null; r = new Request(Request.FETCH, flag, this, RequestStack.URGENT, null); r.setDismissable(true); ! handler.handleRequest(r);*/ ! ! handler.addAction(a); ! } *************** *** 1126,1135 **** */ public void delete() { ! Request r = new Request(Request.DELETE_MAILBOX, this, getPath()); r.setDismissable(false); ! r.setUrgent(true); ! handler.handleRequest(r); } --- 1173,1184 ---- */ public void delete() { + + DeleteMailboxAction dma = new DeleteMailboxAction(getParentMailbox(), this); ! /*Request r = new Request(Request.DELETE_MAILBOX, this, getPath()); r.setDismissable(false); ! r.setUrgent(true);*/ ! handler.addAction(dma); } *************** *** 1145,1159 **** /** ! * This is for strictly copying. A better implementation than for just adding a message to the new mailbox. ! * Warning: A mailbox.copyMessage followed by a mailbox.removeMessage is dangerous. Because of sync. ! * It could happen that the deleteMessage is executed before the copy. To avoid this scenario use the * moveMessage method if thats whats wanted. * *@param message Description of Parameter ! *@param nMailbox Description of Parameter */ ! public void copyMessage(Message message, MessageHolder nMailbox) { ! Request r = new Request( this, --- 1194,1216 ---- /** ! * This is for strictly copying. A better implementation than ! * for just adding a message to the new mailbox. ! * Warning: A mailbox.copyMessage followed by a mailbox.removeMessage ! * is dangerous. Because of sync. ! * It could happen that the deleteMessage is ! * executed before the copy. To avoid this scenario use the * moveMessage method if thats whats wanted. * *@param message Description of Parameter ! *@param destMailbox the destination mailbox */ ! public void copyMessage(Message message, MessageHolder destMailbox) { ! ! CopyMessageAction cma ! = new CopyMessageAction(this, destMailbox, message); ! ! handler.addAction(cma); ! /*Request r = new Request( this, *************** *** 1166,1175 **** r.setUrgent(true); ! handler.handleRequest(r); } ! public void moveMessage(Message message, MessageHolder nMailbox) { ! Request r = new Request( this, --- 1223,1237 ---- r.setUrgent(true); ! handler.handleRequest(r);*/ } ! public void moveMessage(Message message, MessageHolder destMailbox) { ! ! MoveMessageAction mma ! = new MoveMessageAction(this, destMailbox, message); ! ! handler.addAction(mma); ! /*Request r = new Request( this, *************** *** 1182,1186 **** r.setUrgent(true); ! handler.handleRequest(r); } --- 1244,1248 ---- r.setUrgent(true); ! handler.handleRequest(r);*/ } *************** *** 1189,1193 **** //if(allreadySynchronized == true) { ! Request r = new Request( this, --- 1251,1255 ---- //if(allreadySynchronized == true) { ! /*Request r = new Request( this, *************** *** 1200,1207 **** r.setUrgent(true); ! handler.handleRequest(r); } ! public Flags getFlags() { return flags; } --- 1262,1269 ---- r.setUrgent(true); ! handler.handleRequest(r);*/ } ! /*public Flags getFlags() { return flags; } *************** *** 1209,1213 **** public void setFlags(Flags flags) { this.flags = flags; ! } public void setRequestHandler(RequestHandler handler) { --- 1271,1275 ---- public void setFlags(Flags flags) { this.flags = flags; ! }*/ public void setRequestHandler(RequestHandler handler) { *************** *** 1229,1238 **** * */ ! public void handleRequest(Request r) { if (handler != null) handler.handleRequest(r); ! } /** --- 1291,1303 ---- * */ ! /*public void handleRequest(Request r) { if (handler != null) handler.handleRequest(r); ! }*/ ! ! ! /** *************** *** 1290,1293 **** --- 1355,1369 ---- } + + + + + public void addAction(MailAction action) { + + if(handler != null) + handler.addAction(action); + + } + /** *************** *** 1323,1327 **** public void setState(int state) { ! if ((this.state & HIDDEN) != HIDDEN && (state & HIDDEN) == HIDDEN) { Request r = --- 1399,1403 ---- public void setState(int state) { ! /*if ((this.state & HIDDEN) != HIDDEN && (state & HIDDEN) == HIDDEN) { Request r = *************** *** 1338,1342 **** handleRequest(r); ! } this.state = state; --- 1414,1418 ---- handleRequest(r); ! }*/ this.state = state; *************** *** 1348,1352 **** * @param message */ ! public void store(Message message) { System.out.println("calling store on message"); --- 1424,1428 ---- * @param message */ ! /*public void store(Message message) { System.out.println("calling store on message"); *************** *** 1366,1370 **** handler.handleRequest(r); ! } /** --- 1442,1446 ---- handler.handleRequest(r); ! }*/ /** *************** *** 1381,1385 **** * @param disable */ ! protected void disableListeners(boolean disable) { disableListeners = disable; --- 1457,1461 ---- * @param disable */ ! public void disableListeners(boolean disable) { disableListeners = disable; *************** *** 1417,1421 **** * @param name */ ! protected void rename(String name) { this.name = name; --- 1493,1497 ---- * @param name */ ! public void rename(String name) { this.name = name; |