18 package org.turro.mail.reader;
20 import java.util.Properties;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import javax.mail.Flags;
24 import javax.mail.Folder;
25 import javax.mail.Message;
26 import javax.mail.MessagingException;
27 import javax.mail.Session;
28 import javax.mail.Store;
29 import org.turro.collections.KeyValueMap;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.impl.abstracts.AbstractImplementation;
40 private Folder emailFolder;
49 public boolean isSeen(Message message) {
51 return message.isSet(Flags.Flag.SEEN);
52 }
catch (MessagingException ex) {
58 public void seen(Message message) {
60 message.setFlag(Flags.Flag.SEEN,
true);
61 }
catch (MessagingException ex) {
66 public void delete(Message message) {
68 message.setFlag(Flags.Flag.DELETED,
true);
69 }
catch (MessagingException ex) {
76 if (emailFolder !=
null) {
77 emailFolder.close(
false);
82 }
catch (MessagingException ex) {
90 Properties properties =
new Properties();
92 if(kvm.get(
"type").startsWith(
"pop3")) {
93 properties.put(
"mail.pop3.host", kvm.get(
"mailhost"));
94 properties.put(
"mail.pop3.port", kvm.get(
"port"));
95 properties.put(
"mail.pop3.starttls.enable", kvm.get(
"tls"));
96 properties.put(
"mail.pop3.ssl.enable", kvm.get(
"ssl"));
97 }
else if(kvm.get(
"type").startsWith(
"imap")) {
98 properties.put(
"mail.imap.host", kvm.get(
"mailhost"));
99 properties.put(
"mail.imap.port", kvm.get(
"port"));
100 properties.put(
"mail.imap.starttls.enable", kvm.get(
"tls"));
101 properties.put(
"mail.imap.ssl.enable", kvm.get(
"ssl"));
103 Session emailSession = Session.getDefaultInstance(properties);
105 store = emailSession.getStore(kvm.get(
"type"));
107 String password = kvm.get(
"password");
108 if (password ==
null) {
111 }
catch (Exception ex) {
117 kvm.get(Integer.class,
"port"),
121 emailFolder = store.getFolder(kvm.get(String.class,
"folder",
"INBOX"));
122 emailFolder.open(Folder.READ_WRITE);
124 int count = kvm.get(Integer.class,
"count", 50) - 1;
126 int messageCount = emailFolder.getMessageCount();
128 return emailFolder.getMessages(messageCount - count, messageCount);
129 }
catch (MessagingException ex) {
static String logMsg(String msg)
static byte[] decrypt(byte[] value)
KeyValueMap getAttributes()
boolean isSeen(Message message)
void seen(Message message)