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: private ImapMailControllerImpl() {
026: super ();
027: }
028:
029: public ImapMailControllerImpl(AuthProfile auth,
030: ConnectionProfile profile, ConnectionMetaHandler handler,
031: String folder) {
032: this .auth = auth;
033: this .profile = profile;
034: this .handler = handler;
035: this .folder = folder;
036: }
037:
038: /* (non-Javadoc)
039: * @see org.claros.groupware.webmail.controllers.MailController#getEmailById(java.lang.Long)
040: */
041: public Email getEmailById(Long emailId) throws Exception {
042: ProtocolFactory factory = new ProtocolFactory(profile, auth,
043: handler);
044: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
045: .getProtocol(folder);
046: Message msg = protocol.getMessage(emailId.intValue());
047: /*
048: if (!msg.getFolder().isOpen()) {
049: msg.getFolder().open(Constants.CONNECTION_READ_WRITE);
050: }
051: */
052: Email email = MessageParser.parseMessage(msg);
053: // msg.getFolder().close(true);
054: email.setMsgId(emailId);
055: return email;
056: }
057:
058: /* (non-Javadoc)
059: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmail(java.lang.Long)
060: */
061: public void deleteEmail(Long emailId) throws Exception {
062: ProtocolFactory factory = new ProtocolFactory(profile, auth,
063: handler);
064: Protocol protocol = factory.getProtocol(folder);
065: protocol.deleteMessages(new int[] { emailId.intValue() });
066: }
067:
068: /* (non-Javadoc)
069: * @see org.claros.groupware.webmail.controllers.MailController#moveEmail(java.lang.Long, java.lang.String)
070: */
071: public void moveEmail(Long msgId, String destFolder)
072: throws Exception {
073: ProtocolFactory factory = new ProtocolFactory(profile, auth,
074: handler);
075: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
076: .getImap(folder);
077: protocol.moveEmail(msgId, destFolder);
078: }
079:
080: /* (non-Javadoc)
081: * @see org.claros.groupware.webmail.controllers.MailController#appendEmail(org.claros.groupware.webmail.models.EmailDbItem)
082: */
083: public void appendEmail(MsgDbObject item) throws Exception {
084: ProtocolFactory factory = new ProtocolFactory(profile, auth,
085: handler);
086: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
087: .getImap(folder);
088: protocol.appendEmail(item.getEmail());
089: }
090:
091: /* (non-Javadoc)
092: * @see org.claros.groupware.webmail.controllers.MailController#markAsRead(java.lang.Long)
093: */
094: public void markAsRead(Long msgId) throws Exception {
095: ProtocolFactory factory = new ProtocolFactory(profile, auth,
096: handler);
097: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
098: .getImap(folder);
099: protocol.markAsRead(msgId);
100: }
101:
102: /* (non-Javadoc)
103: * @see org.claros.groupware.webmail.controllers.MailController#deleteEmails(int[])
104: */
105: public void deleteEmails(int[] msgs) throws Exception {
106: ProtocolFactory factory = new ProtocolFactory(profile, auth,
107: handler);
108: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
109: .getImap(folder);
110: protocol.deleteMessages(msgs);
111: }
112:
113: /**
114: *
115: */
116: public void moveEmails(int[] msgs, String destFolder)
117: throws Exception {
118: ProtocolFactory factory = new ProtocolFactory(profile, auth,
119: handler);
120: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
121: .getImap(folder);
122: protocol.moveEmails(msgs, destFolder);
123: }
124:
125: /**
126: *
127: */
128: public void moveEmails(int[] msgs, String destFolders[])
129: throws Exception {
130: ProtocolFactory factory = new ProtocolFactory(profile, auth,
131: handler);
132: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
133: .getImap(folder);
134: protocol.moveEmails(msgs, destFolders);
135: }
136:
137: /**
138: *
139: */
140: public void markAsDeleted(int[] ids) throws Exception {
141: ProtocolFactory factory = new ProtocolFactory(profile, auth,
142: handler);
143: ImapProtocolImpl protocol = (ImapProtocolImpl) factory
144: .getImap(folder);
145: protocol.flagAsDeleted(ids);
146: }
147: }
|