use of javax.mail.Store in project camel by apache.
the class MailSortTermTwoTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "bill", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
Message[] messages = new Message[3];
messages[0] = new MimeMessage(sender.getSession());
messages[0].setText("Earlier date");
messages[0].setHeader("Message-ID", "0");
messages[0].setSentDate(new Date(10000));
messages[0].setSubject("Camel");
messages[1] = new MimeMessage(sender.getSession());
messages[1].setText("Later date");
messages[1].setHeader("Message-ID", "1");
messages[1].setSentDate(new Date(20000));
messages[1].setSubject("Camel");
messages[2] = new MimeMessage(sender.getSession());
messages[2].setText("Even later date");
messages[2].setHeader("Message-ID", "2");
messages[2].setSentDate(new Date(30000));
messages[2].setSubject("Invalid");
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Store in project jodd by oblac.
the class Pop3Server method createSession.
/**
* {@inheritDoc}
*/
public ReceiveMailSession createSession() {
Session session = Session.getInstance(sessionProperties, authenticator);
Store store;
try {
store = getStore(session);
} catch (NoSuchProviderException nspex) {
throw new MailException("Failed to create POP3 session", nspex);
}
return new ReceiveMailSession(session, store);
}
use of javax.mail.Store in project gocd by gocd.
the class Pop3MailClient method getInboxFolder.
private Folder getInboxFolder() throws MessagingException {
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.host", host);
Authenticator auth = new PopupAuthenticator();
Session session = Session.getInstance(pop3Props, auth);
URLName url = new URLName("pop3", host, port, "", username, password);
Store store = session.getStore(url);
store.connect();
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
return folder;
}
use of javax.mail.Store in project nhin-d by DirectProject.
the class MessageServiceImplService method requestStatus.
@Override
public StatusResponseType requestStatus(StatusRefType body) {
List<String> msgs = body.getMessageID();
StatusResponseType response = new StatusResponseType();
try {
checkAuth(response);
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(imapProps, auth);
session.setDebug(true);
if (msgs.size() > 0) {
Store store = session.getStore(new javax.mail.URLName("imaps://" + username));
store.connect(getImapHost(), Integer.valueOf(getImapPort()).intValue(), username, password);
for (int x = 0; x < msgs.size(); x++) {
String msgid = msgs.get(x);
MessageIDTerm messageIdTerm = new MessageIDTerm(msgid);
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
SearchTerm st = messageIdTerm;
IMAPMessage[] msgsearch = (IMAPMessage[]) folder.search(st);
if (msgsearch.length > 0) {
Flags flags = msgsearch[0].getFlags();
Flag[] inboxflags = flags.getSystemFlags();
String[] listofflags = new String[inboxflags.length];
listofflags = setSystemFlags(inboxflags);
setMessageIdStatus(msgid, listofflags, response.getMessageIDAndStatus());
}
}
}
} catch (AddressException e) {
log.error(e);
} catch (MessagingException e) {
log.error(e);
} catch (Exception e) {
log.error(e);
}
return response;
}
use of javax.mail.Store in project opennms by OpenNMS.
the class MailTransportMonitor method readTestMessage.
private PollStatus readTestMessage(final MailTransportParameters mailParms) {
LOG.debug("readTestMessage: Beginning read mail test.");
PollStatus status = PollStatus.unavailable("Test not completed.");
final long interval = mailParms.getReadTestAttemptInterval();
if (mailParms.isEnd2EndTestInProgress()) {
LOG.debug("Initially delaying read test: {} because end to end test is in progress.", mailParms.getReadTestAttemptInterval());
if (delayTest(status, interval) == PollStatus.SERVICE_UNKNOWN) {
return status;
}
}
Store mailStore = null;
Folder mailFolder = null;
try {
final JavaMailer readMailer = new JavaMailer(mailParms.getJavamailProperties());
setReadMailProperties(mailParms, readMailer);
final TimeoutTracker tracker = new TimeoutTracker(mailParms.getParameterMap(), mailParms.getRetries(), mailParms.getTimeout());
for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) {
tracker.startAttempt();
if (tracker.getAttempt() > 0) {
if (delayTest(status, interval) == PollStatus.SERVICE_UNKNOWN) {
LOG.warn("readTestMessage: Status set to: {} during delay, exiting test.", status);
break;
}
}
LOG.debug("readTestMessage: reading mail attempt: {}, elapsed time: {}ms.", (tracker.getAttempt() + 1), String.format("%.2f", tracker.elapsedTimeInMillis()));
try {
mailStore = readMailer.getSession().getStore();
mailFolder = retrieveMailFolder(mailParms, mailStore);
mailFolder.open(Folder.READ_WRITE);
} catch (final MessagingException e) {
if (tracker.shouldRetry()) {
LOG.warn("readTestMessage: error reading INBOX", e);
closeStore(mailStore, mailFolder);
// try again to get mail Folder from Store
continue;
} else {
LOG.warn("readTestMessage: error reading INBOX", e);
return PollStatus.down(e.getLocalizedMessage());
}
}
if (mailFolder.isOpen() && (mailParms.getReadTest().getSubjectMatch() != null || mailParms.isEnd2EndTestInProgress())) {
status = processMailSubject(mailParms, mailFolder);
if (status.getStatusCode() == PollStatus.SERVICE_AVAILABLE) {
break;
}
}
}
} catch (final JavaMailerException e) {
status = PollStatus.down(e.getLocalizedMessage());
} finally {
closeStore(mailStore, mailFolder);
}
return status;
}
Aggregations