001: package org.claros.mini.controllers;
002:
003: import javax.mail.Message;
004:
005: import org.claros.commons.mail.models.ConnectionMetaHandler;
006: import org.claros.commons.mail.models.ConnectionProfile;
007: import org.claros.commons.mail.models.Email;
008: import org.claros.commons.mail.parser.MessageParser;
009: import org.claros.commons.mail.protocols.ImapProtocolImpl;
010: import org.claros.commons.mail.protocols.Protocol;
011: import org.claros.commons.mail.protocols.ProtocolFactory;
012: import org.claros.commons.mail.utility.Constants;
013: import org.claros.commons.models.AuthProfile;
014: import org.claros.mini.models.EmailDbItem;
015:
016: /**
017: * @author Umut Gokbayrak
018: */
019: public class ImapMailControllerImpl implements MailController {
020: // private static Log log = LogFactory.getLog(DbMailController.class);
021: private AuthProfile auth;
022: private ConnectionProfile profile;
023: private ConnectionMetaHandler handler;
024: private String folder;
025:
026: private ImapMailControllerImpl() {
027: super ();
028: }
029:
030: public ImapMailControllerImpl(AuthProfile auth,
031: ConnectionProfile profile, ConnectionMetaHandler handler,
032: String folder) {
033: this .auth = auth;
034: this .profile = profile;
035: this .handler = handler;
036: this .folder = folder;
037: }
038:
039: /* (non-Javadoc)
040: * @see org.claros.groupware.webmail.controllers.MailController#getEmailById(java.lang.Long)
041: */
042: public Email getEmailById(Long emailId) throws Exception {
043: ProtocolFactory factory = new ProtocolFactory(profile, auth,
044: handler);
045: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
046: .getProtocol(folder);
047: Message msg = protocol.getMessage(emailId.intValue());
048: if (!msg.getFolder().isOpen()) {
049: msg.getFolder().open(Constants.CONNECTION_READ_WRITE);
050: }
051: Email email = MessageParser.parseMessage(msg);
052: email.setMsgId(emailId);
053: return email;
054: }
055:
056: /* (non-Javadoc)
057: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmail(java.lang.Long)
058: */
059: public void deleteEmail(Long emailId) throws Exception {
060: ProtocolFactory factory = new ProtocolFactory(profile, auth,
061: handler);
062: Protocol protocol = factory.getProtocol(folder);
063: protocol.deleteMessages(new int[] { emailId.intValue() });
064: }
065:
066: /* (non-Javadoc)
067: * @see org.claros.groupware.webmail.controllers.MailController#moveEmail(java.lang.Long, java.lang.String)
068: */
069: public void moveEmail(Long msgId, String destFolder)
070: throws Exception {
071: ProtocolFactory factory = new ProtocolFactory(profile, auth,
072: handler);
073: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
074: .getImap(folder);
075: protocol.moveEmail(msgId, destFolder);
076: }
077:
078: /* (non-Javadoc)
079: * @see org.claros.groupware.webmail.controllers.MailController#appendEmail(org.claros.groupware.webmail.models.EmailDbItem)
080: */
081: public void appendEmail(EmailDbItem item) throws Exception {
082: ProtocolFactory factory = new ProtocolFactory(profile, auth,
083: handler);
084: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
085: .getImap(folder);
086: protocol.appendEmail(item.getEmail());
087: }
088:
089: /* (non-Javadoc)
090: * @see org.claros.groupware.webmail.controllers.MailController#markAsRead(java.lang.Long)
091: */
092: public void markAsRead(Long msgId) throws Exception {
093: ProtocolFactory factory = new ProtocolFactory(profile, auth,
094: handler);
095: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
096: .getImap(folder);
097: protocol.markAsRead(msgId);
098: }
099:
100: /* (non-Javadoc)
101: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmails(int[])
102: */
103: public void deleteEmails(int[] msgs) throws Exception {
104: ProtocolFactory factory = new ProtocolFactory(profile, auth,
105: handler);
106: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
107: .getImap(folder);
108: protocol.deleteMessages(msgs);
109: }
110: }
|