package noriega.expresso.protocols; import java.rmi.*; import java.util.*; import noriega.expresso.structures.*; import noriega.expresso.server.*; import noriega.util.*; /* * Copyright (c) 1999 Noriega * * $Author: jew23 $ * $Date: 1999/04/12 02:48:35 $ * $Id: IMAPServiceImpl.java,v 1.26 1999/04/12 02:48:35 jew23 Exp $ */ /** *
* The IMAPService
implements
* all of the functions for email management
* supported by the eXpresso server.
*
* This service uses methods provided by the
* ServerDataLayer
to execute mailbox
* management features and to attain references to
* Mailbox
objects. And this service
* is user-centered.
*
* List the names of all mailboxes owned by * current eXpresso user. *
* @return Set of mailbox names * */ public Set listMailboxes() throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); Set mailboxes = null; Set serMailboxes = null; try { mailboxes = imapSDL.getMailboxNames(getUsername()); serMailboxes = new HashSet (mailboxes); } catch (Exception e) { e.printStackTrace(); } return serMailboxes; } /** ** eXpresso messages are moved to a folder * when flagged for deletions. *
* This method expunges all messages in this folder. * */ public void emptyTrash() throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); imapSDL.emptyTrash(getUsername()); } /** *
* Create a POP3Service
and open
* connection to host.
*
* Retrieve messages and add Messages
* to the Inbox for this user.
*
* Set the current mailbox. *
** This method must be called before any * message management methods are called. * Any subsequent message management calls * assume that the current mailbox is the * last mailbox selected with selectMailbox() * method. *
*/ public void selectMailbox(String mailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); this.current = imapSDL.getMailbox(getUsername(), mailbox); } /** ** Create the mailbox with specified name. *
* @param String The mailbox to create. */ public void createMailbox(String mailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); imapSDL.createMailbox(getUsername(), mailbox); this.current = imapSDL.getMailbox(getUsername(), mailbox); } /** ** Delete the mailbox with specified name. *
* @param String The mailbox to delete. */ public void deleteMailbox(String mailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); imapSDL.deleteMailbox(getUsername(), mailbox); this.current = imapSDL.getMailbox(getUsername(), ExpressoConstants.INBOX_NAME); } /** ** Rename the current mailbox to specified name. *
* @param String New name for mailbox. */ public void renameMailbox(String newname) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); imapSDL.renameMailbox(getUsername(), current.getName(), newname); } /** ** Query mailbox attributes. *
*
* Attribute can be a string name of a particular
* flag, as specified in ExpressoConstants
.
*
* Move a message from the current mailbox * to another mailbox. *
** @param Header The message header to move. * @param String The mailbox to move to. *
* @see IMAPServiceImpl.selectMailbox() */ public void moveMessage(Header header, String toMailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); Message message = current.getMessage(header); imapSDL.moveMessage (getUsername(), message, current.getName(), toMailbox); } /** *
* Move a Set
of messages from the
* current mailbox to another mailbox.
*
* @param Set The set of headers to move. * @param String The mailbox to move to. *
* @see IMAPServiceImpl.selectMailbox() */ public void moveMessage(Set headers, String toMailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); Set messages = current.getMessages(headers); imapSDL.moveMessage (getUsername(), messages, current.getName(), toMailbox); } /** ** Copy the message from the current mailbox * to another mailbox. *
** @param Header The message to move. * @param String The mailbox to copy to. *
* @see IMAPServiceImpl.selectMailbox() */ public void copyMessage (Header header, String toMailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); Message message = current.getMessage(header); imapSDL.moveMessage (getUsername(), message, current.getName(), toMailbox); current.addMessages(message); } /** *
* Copy a Set
of messages from the
* current mailbox to another mailbox.
*
* @param Set The set of headers to move. * @param String The mailbox to copy to. *
* @see IMAPServiceImpl.selectMailbox() */ public void copyMessage(Set headers, String toMailbox) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); Set messages = current.getMessages(headers); imapSDL.moveMessage (getUsername(), messages, current.getName(), toMailbox); current.addMessages(messages); } /** ** Delete a message from the current mailbox. *
** @param Header The message (header) to delete. *
* @see IMAPServiceImpl.selectMailbox() */ public void deleteMessage (Header header) throws RemoteException, ExpressoServerException { moveMessage(header, ExpressoConstants.TRASH_NAME); } /** *
* Delete a Set
of message (headers)
* from the current mailbox.
*
* @param Set The messages (headers) to delete. *
* @see IMAPServiceImpl.selectMailbox() */ public void deleteMessage (Set headers) throws RemoteException, ExpressoServerException { moveMessage(headers, ExpressoConstants.TRASH_NAME); } /** ** Retrieve the message body for the specified * header. *
** This header must be located in the current * mailbox. *
*/ public Message fetchMessage(Header header) throws RemoteException { return current.getMessage(header); } // F l a g s /** *
* Flag a message with the specified Flag
.
*
* Flag a Set
of messages with the
* specifed Flag
.
*
* Flag a message as READ. *
* @param Header The header to flag as READ. */ public void flagMessageRead(Header header) throws RemoteException { Message msg = current.getMessage(header); msg.setRead(true); } /** ** Flag a message as UNREAD. *
* @param Header The header to flag as UNREAD. */ public void flagMessageUnread(Header header) throws RemoteException { Message msg = current.getMessage(header); msg.setRead(false); } /** *
* Flag a Set
of messages as READ.
*
* Flag a Set
of messages as UNREAD.
*
* Returns a Set
of Header
s
* of messages with the specified flag set.
*
* Returns a Set
of Header
s
* of messages with the specified flag set.
*
* Returns a Set
of Header
s
* of all messages in the current mailbox.
*
* Return status of the specified flag. *
* @param Header The header to query. * @param String The flag name to query for. */ public boolean queryMessage(Header header, String attribute) throws RemoteException { boolean value = false; Message temp = current.getMessage(header); if(attribute.equals(ExpressoConstants.ISNEW_NAME) ) value = temp.isNew(); if(attribute.equals(ExpressoConstants.ISREAD_NAME) ) value = temp.isRead(); return value; } /** ** Return status of the specified flag. *
* @param Header The header to query. * @param Flag The flag to query for. */ public boolean queryMessage(Header header, Flag f) throws RemoteException { boolean value = false; Message msg = current.getMessage(header); return msg.isFlagged(f); } // U s e r M a n a g e m e n t /** ** Change the current user's password. *
* @param String The password. */ public void setPassword(String password) throws RemoteException, ExpressoServerException { ServerDataLayer imapSDL = getServerDataLayer(); User user = imapSDL.getUser(getUsername()); user.setPassword(password); } public String getServiceName () throws RemoteException { return ("IMAP"); } public String getServiceInfo () throws RemoteException { return ("Retrieve Mail"); } } /* * Version Control Log: * $Log: IMAPServiceImpl.java,v $ * Revision 1.26 1999/04/12 02:48:35 jew23 * Fixed BUG in copyMessage() * * Revision 1.25 1999/04/12 02:38:20 jew23 * Fixed BUG in moveMessage() methods. * * Revision 1.24 1999/04/12 00:52:43 ngreen * latest stuff * * Revision 1.23 1999/04/12 00:14:13 jew23 * Release 0.90 * * Revision 1.22 1999/04/11 23:35:40 jew23 * Javadoc finished. * * Revision 1.21 1999/04/11 22:24:01 jew23 * Minor change to checkNewMessages(); make sure to delete reference to * current in IMAP when checking for new Mail if we have the Inbox selected. * Eliminates any concurrency issues that might arise when we attempt to * append to the Inbox. * * Revision 1.20 1999/04/11 22:17:51 jew23 * More medicine to checkNewMail() * * Revision 1.19 1999/04/11 22:13:31 jew23 * Preemptive medicine on checkNewMail(); * Make sure we are not adding messages to the currently selected Inbox. * * Revision 1.18 1999/04/11 21:07:59 jew23 * Debug statements. * * Revision 1.17 1999/04/11 20:21:43 jew23 * Fixed BUG: null pointer current * * Revision 1.16 1999/04/11 19:50:32 ngreen * minor fix * * Revision 1.15 1999/04/11 19:35:04 jew23 * Added another queryMessage() method that accepts Flag * * Revision 1.14 1999/04/11 00:27:15 ngreen * fixed because of heinous HashMap non-serializable keyset impl!!! * * Revision 1.13 1999/04/10 23:05:39 ngreen * *** empty log message *** * * Revision 1.12 1999/04/10 22:15:50 ngreen * temporary :wq * :wq * * Revision 1.11 1999/04/10 14:37:06 jew23 * Fixed bug in listMailboxes() * * Revision 1.10 1999/04/08 21:23:40 jew23 * Removed Mailbox return from mailbox management interface. * Added implementation for query methods. * * Revision 1.9 1999/04/07 19:31:34 ngreen * fixed initialization and other bugs * * Revision 1.8 1999/04/07 09:23:20 jew23 * All methods of the IMAPService class now accept Sets as well as individual * Headers. I also added support for Sets in the mailbox class as necessary. * See CVS log for details. All project requirements met - with the exception * of user management as per conversation with ngreen. * * Revision 1.7 1999/04/07 03:42:43 jew23 * Added exception handling and getnewmessages() functionality. * * Revision 1.5 1999/04/03 18:18:56 ngreen * all are now with no-arg constructors, because that is what RMI requires. * All implement UsesServerDataLayer in order to set the SDL since it cannot * be set thru constructor. * As subclasses of DefaultServiceImpl (which implements UsesServerDataLayer), * the SDL can be accessed either by the "sdl" instance variable or the * getServerDataLayer() method. * * Revision 1.4 1999/04/03 16:24:04 ngreen * now conforms to new ExpressoService interface, as well as * new UsernameOriented interface * * Revision 1.3 1999/03/31 00:08:21 jew23 * Made IMAPService changes per conversation w/ ngreen Tue, 30 Mar 1999 * 16:38:18 -0500 (EST) * * Revision 1.2 1999/03/30 21:12:50 ngreen * fixed all compilation errors * * Revision 1.1 1999/03/30 19:27:18 jew23 * Added IMAP Interfaces. * */