001: package org.claros.intouch.webmail.controllers;
002:
003: import javax.mail.Message;
004:
005: import org.claros.commons.auth.models.AuthProfile;
006: import org.claros.commons.mail.models.ConnectionMetaHandler;
007: import org.claros.commons.mail.models.ConnectionProfile;
008: import org.claros.commons.mail.models.Email;
009: import org.claros.commons.mail.parser.MessageParser;
010: import org.claros.commons.mail.protocols.ImapProtocolImpl;
011: import org.claros.commons.mail.protocols.Protocol;
012: import org.claros.commons.mail.protocols.ProtocolFactory;
013: import org.claros.intouch.webmail.models.MsgDbObject;
014:
015: /**
016: * @author Umut Gokbayrak
017: */
018: public class ImapMailControllerImpl implements MailController {
019: // private static Log log = LogFactory.getLog(DbMailController.class);
020: private AuthProfile auth;
021: private ConnectionProfile profile;
022: private ConnectionMetaHandler handler;
023: private String folder;
024:
025: @SuppressWarnings("unused")
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: /*
049: if (!msg.getFolder().isOpen()) {
050: msg.getFolder().open(Constants.CONNECTION_READ_WRITE);
051: }
052: */
053: Email email = MessageParser.parseMessage(msg);
054: // msg.getFolder().close(true);
055: email.setMsgId(emailId);
056: return email;
057: }
058:
059: /* (non-Javadoc)
060: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmail(java.lang.Long)
061: */
062: public void deleteEmail(Long emailId) throws Exception {
063: ProtocolFactory factory = new ProtocolFactory(profile, auth,
064: handler);
065: Protocol protocol = factory.getProtocol(folder);
066: protocol.deleteMessages(new int[] { emailId.intValue() });
067: }
068:
069: /* (non-Javadoc)
070: * @see org.claros.groupware.webmail.controllers.MailController#moveEmail(java.lang.Long, java.lang.String)
071: */
072: public void moveEmail(Long msgId, String destFolder)
073: throws Exception {
074: ProtocolFactory factory = new ProtocolFactory(profile, auth,
075: handler);
076: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
077: .getImap(folder);
078: protocol.moveEmail(msgId, destFolder);
079: }
080:
081: /* (non-Javadoc)
082: * @see org.claros.groupware.webmail.controllers.MailController#appendEmail(org.claros.groupware.webmail.models.EmailDbItem)
083: */
084: public void appendEmail(MsgDbObject item) throws Exception {
085: ProtocolFactory factory = new ProtocolFactory(profile, auth,
086: handler);
087: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
088: .getImap(folder);
089: protocol.appendEmail(item.getEmail());
090: }
091:
092: /* (non-Javadoc)
093: * @see org.claros.groupware.webmail.controllers.MailController#markAsRead(java.lang.Long)
094: */
095: public void markAsRead(Long msgId) throws Exception {
096: ProtocolFactory factory = new ProtocolFactory(profile, auth,
097: handler);
098: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
099: .getImap(folder);
100: protocol.markAsRead(msgId);
101: }
102:
103: /* (non-Javadoc)
104: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmails(int[])
105: */
106: public void deleteEmails(int[] msgs) throws Exception {
107: ProtocolFactory factory = new ProtocolFactory(profile, auth,
108: handler);
109: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
110: .getImap(folder);
111: protocol.deleteMessages(msgs);
112: }
113:
114: /**
115: *
116: */
117: public void moveEmails(int[] msgs, String destFolder)
118: throws Exception {
119: ProtocolFactory factory = new ProtocolFactory(profile, auth,
120: handler);
121: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
122: .getImap(folder);
123: protocol.moveEmails(msgs, destFolder);
124: }
125:
126: /**
127: *
128: */
129: public void moveEmails(int[] msgs, String destFolders[])
130: throws Exception {
131: ProtocolFactory factory = new ProtocolFactory(profile, auth,
132: handler);
133: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
134: .getImap(folder);
135: protocol.moveEmails(msgs, destFolders);
136: }
137:
138: /**
139: *
140: */
141: public void markAsDeleted(int[] ids) throws Exception {
142: ProtocolFactory factory = new ProtocolFactory(profile, auth,
143: handler);
144: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
145: .getImap(folder);
146: protocol.flagAsDeleted(ids);
147: }
148: }
|