Class MailboxClient
- java.lang.Object
-
- com.adaptris.mail.MailClientImp
-
- com.adaptris.mail.MailboxClient
-
- All Implemented Interfaces:
MailReceiver,java.io.Closeable,java.lang.AutoCloseable,java.lang.Iterable<javax.mail.internet.MimeMessage>
public final class MailboxClient extends MailClientImp
Wrapper around the JavaMail API supporting all the standard protocols that are available.POP3 folders also differ from IMAP folders in how they are manipulated.
POP3 supports only a single folder named "INBOX".POP3 supports no permanent flags (
Folder.getPermanentFlags()).In this implementation all messages in a POP3 mailbox are considered new. Therefore in order to avoid re-processing messages,
purge(true)should be called prior to disconnectionIf getNextMessage() is invoked, then that message is immediatedly marked as "SEEN" and "DELETED" to avoid processing by other connections.
Message.saveChanges() is invoked to commit the change to an IMAP folder, if
purge(true)is called prior to disconnection, then those messages are deleted.It is possible to use this mailbox client to filter messages based on the subject, sender and a pre-defined customHeader field.
Subject / Sender / recipient / custom Filtering is supported via the use of the org.apache.oro suite, specify your preferred regular expression type using the
setRegularExpressionCompiler()method and then you can specify the filter using your preferred regular expression using the varioussetXXXFiltermethods.MailboxClient pop3 = new MailboxClient ("pop3://username:password@mymailhost:110/INBOX"); pop3.setSenderFilter("FromMe*"); pop3.setSubjectFilter("Test*"); pop3.connect(); System.out.println(pop3.getMessageCount() + " new matched messages"); Message payload; while ((payload = pop3.getNextMessage()) != null) { payload.writeTo(System.out); } pop3.disconnect();
-
-
Field Summary
-
Fields inherited from class com.adaptris.mail.MailClientImp
deleteFlag, log
-
-
Constructor Summary
Constructors Constructor Description MailboxClient(java.lang.String mailboxUrl)Constructor.MailboxClient(java.lang.String host, int port, java.lang.String username, java.lang.String password)Constructor.MailboxClient(java.lang.String host, java.lang.String username, java.lang.String password)Constructor.MailboxClient(javax.mail.URLName name)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconnectLocal()Connect to the mailbox.protected voiddisconnectLocal()Disconnect from the mail server.java.util.Iterator<javax.mail.internet.MimeMessage>iterator()Iterate over the list of messages in the mailbox.voidsetSessionProperties(java.util.Properties p)-
Methods inherited from class com.adaptris.mail.MailClientImp
accept, addCustomFilter, close, connect, getMessages, purge, resetMessage, setFromFilter, setMessageRead, setRecipientFilter, setRegularExpressionCompiler, setSubjectFilter, wrapException
-
-
-
-
Constructor Detail
-
MailboxClient
public MailboxClient(javax.mail.URLName name)
Constructor.- Parameters:
name- the host to poll for messages pop3://user:pw@hostname:port/INBOX or imap://user:pw@hostname:port/
-
MailboxClient
public MailboxClient(java.lang.String mailboxUrl)
Constructor.- Parameters:
mailboxUrl- the POP3 host to poll for messages pop3://user:pw@hostname:port/INBOX or imap://user:pw@hostname:port/
-
MailboxClient
public MailboxClient(java.lang.String host, java.lang.String username, java.lang.String password)Constructor.If this constructor is used, then we assume that a POP3 connection is required.
- Parameters:
host- the hostusername- the usernamepassword- the password.
-
MailboxClient
public MailboxClient(java.lang.String host, int port, java.lang.String username, java.lang.String password)Constructor.If this constructor is used, then we assume that a POP3 connection is required.
- Parameters:
host- the hostusername- the usernamepassword- the password.port- the port
-
-
Method Detail
-
setSessionProperties
public void setSessionProperties(java.util.Properties p)
-
connectLocal
protected void connectLocal() throws MailExceptionDescription copied from class:MailClientImpConnect to the mailbox.This will get and open the inbox folder
- Specified by:
connectLocalin classMailClientImp- Throws:
MailException- if the connection failed.
-
iterator
public java.util.Iterator<javax.mail.internet.MimeMessage> iterator()
Description copied from interface:MailReceiverIterate over the list of messages in the mailbox.- Returns:
- an iterator of filtered messages.
-
disconnectLocal
protected void disconnectLocal()
Disconnect from the mail server.- Specified by:
disconnectLocalin classMailClientImp
-
-