|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.keel.core.container.AbstractKeelServiceable
org.keel.services.mail.javamail.DefaultReader
This service implements the Keel Reader service. It provides the capability to retrieve and parse email from a POP3 or IMAP server. This implementation of the Reader interface is meant to be used with a server for which this is the only client that consumes messages. In other words, don't use this on an POP3/IMAP account where other clients will concurrently modify the state of read/deleted messages. In particular, the "msgIndex" parameter used throughout the API is guranteed to work after a read() only if messages are not deleted on the server until this client itself does it. This implementation over JavaMail does not use message listeners. Therefore when messgaes are added/deleted on the server by other clients and MUAs, this client is completely unaware. To read the new set of messages a new read() call must be issued. To consume a message, users of this service must use the setSeen(msgIndex, true) method call. To delete, setDelete(msgIndex, true) must be called, but messages will be deleted only when disconnect() is called. However, for deletion to work, the folder must have been opened in read-write mode, and the folderExpunge flag must be set to true. POP3 functionality is a bit different, since POP3 is a "read-only" service. If the content of a POP3 message is retrieved (using getFile, getFileName, etc.), then the server will automatically mark the message as "read". Also, POP3 servers typically do not support the "SEEN" flag but use the "Status:" header instead. This implementation supports a workaround, activated by the "useStatusHeader" config. parameter, which will use the Status header to determine is a message has been read or not.
| Field Summary | |
private java.lang.String |
attachDirFolder where attachments will be placed |
private java.lang.String |
attachExtAttachment extension when filename/content-type is not provided |
private java.lang.String |
attachNameAttachment name when fileName is not provided |
private Configuration |
configurationThe configuraton for this service - from mailer-system.xconf |
private Folder |
folderThe folder on the POP3/IMAP store that mail is retrieved from |
private boolean |
folderExpungeFolder close mode - expunge deleted messages on close |
private boolean |
folderReadWriteFolder open mode - read-only, or, read-write |
private Logger |
loggerThe logger for info/debug messages |
private boolean |
mailAuthSMTP server requires authentication |
private boolean |
mailDebugTurn on JavaMail session debug |
private java.lang.String |
mailFolderFolder name where mail is stored |
private java.lang.String |
mailHostThe POP3/IMAP host |
private java.lang.String |
mailPasswordPassword for account |
private java.lang.String |
mailProtocolThe server protocol - POP3 or IMAP |
private java.lang.String |
mailUserUsername for account |
private Message[] |
messagesThe messages retrieved from the folder |
private boolean |
nullAllowedIf set, this config value will chgeck for null returns on String and array returns. |
private Session |
sessionThe session context of the mail-server |
private Store |
storeThe POP3/IMAP store |
private boolean |
useStatusHeaderSome POP3 servers will not send the "SEEN" status, so the seen/read state has to be inferred from the "Status" header |
| Fields inherited from class org.keel.core.container.AbstractKeelServiceable |
|
| Fields inherited from interface org.keel.services.mail.Reader |
ROLE |
| Constructor Summary | |
DefaultReader() |
|
| Method Summary | |
private java.lang.String[] |
addrToString(Address[] addr)Method to convert an array of javax.mail.Address to an array of Strings |
private void |
checkMsgIndex(int msgIndex)Convenience method to bounds-check the emssage index. |
void |
configure(Configuration configuration)This method reads the container-provided configuration |
void |
connect()Get the client in a state connected to the server so that it is ready to retrieve messages. |
void |
connect(java.lang.String host, java.lang.String user, java.lang.String password)Connect while overriding the user and password supplied by configuration Saying "connect(null, null, null)" is the same as "connect()" |
int |
count()Return a count of messages retrieved from the server. |
private java.io.File |
createFile(Part p)Take the content of a message-part and put it in a file. |
void |
disconnect()Close the client-server connection. |
void |
enableLogging(Logger logger)This method associates this service with a logger |
java.lang.String[] |
getBcc(int msgIndex)Get the contents of the Bcc: header |
private Part |
getBodyPart(int msgIndex)Method to extract the body of a single-part message |
java.lang.String[] |
getCc(int msgIndex)Get the contents of the Cc: header |
java.lang.String |
getContentType(int msgIndex)Get the content of the ContentType header of a single-part message |
java.lang.String |
getContentType(int msgIndex, int partIndex)Get the content of the ContentType header of a part of a multi-part message |
java.lang.String |
getDisposition(int msgIndex)Get the content of the disposition header of a single-part message |
java.lang.String |
getDisposition(int msgIndex, int partIndex)Get the content of the disposition header of a part of a multi-part message |
java.io.File |
getFile(int msgIndex)Get the contents of a single-part message |
java.io.File |
getFile(int msgIndex, int partIndex)Get the contents of a particular part of a multi-part message |
java.lang.String |
getFileName(int msgIndex)Get the file name in the header of a single-part message |
java.lang.String |
getFileName(int msgIndex, int partIndex)Get the file name in the header of a part in the multi-part message |
java.lang.String[] |
getFrom(int msgIndex)Get the contents of the From: header |
private java.util.Enumeration |
getHeader(int msgIndex, java.lang.String str)Convenience method to take the string arg and make an array out of it before calling the JavaMail method |
java.util.Enumeration |
getHeaders(int msgIndex)Get all headers for a message |
java.lang.String |
getInline(int msgIndex)Get the content of an inline message |
int |
getLineCount(int msgIndex)Get the number of lines in a message (meaningless for multi-part messages) |
int |
getMultiPartCount(int msgIndex)Get the number of parts in a multi-part message |
private Part |
getOneBodyPart(int msgIndex, int partIndex)Method to get a particular part of a multi-part message |
java.lang.String[] |
getReplyTo(int msgIndex)Get the contents of the ReplyTo: header |
java.util.Date |
getSentDate(int msgIndex)Get the date a message was sent (Date header) |
int |
getSize(int msgIndex)Get the size of a message |
java.lang.String |
getSubject(int msgIndex)Get the subject header from a message |
java.lang.String[] |
getTo(int msgIndex)Get the contents of the To: header |
boolean |
isAnswered(int msgIndex)Check if this message has been marked as "answered" by a client |
boolean |
isDeleted(int msgIndex)Check if this message has been marked by a client as "deleted" or not |
boolean |
isDraft(int msgIndex)Check if this message has been marked by some client as "draft" or not |
boolean |
isFlagged(int msgIndex)Check if this message has been marked by a client as "flagged" |
boolean |
isInline(int msgIndex)Check if the message content is inline |
boolean |
isMultiPart(int msgIndex)Check if the message content is formatted as MIME multi-part |
boolean |
isRecent(int msgIndex)Check if this message is amrked by the server as "recent" or not |
boolean |
isSeen(int msgIndex)Check if this message has already been read or not |
boolean |
isSinglePart(int msgIndex)Check if the message content is formatted as MIME single-part |
private boolean |
matchFlag(int msgIndex, Flags.Flag flag)Convenience method to retrieve flags from a particular message and then to check if a particular flag is set. |
void |
read()Retrieve all messages from the server |
void |
send() |
void |
setAnswered(int msgIndex, boolean state)Mark a message as "answered" |
void |
setDeleted(int msgIndex, boolean state)Mark a message as "deleted" |
void |
setDraft(int msgIndex, boolean state)Mark a message as "draft |
private void |
setFlag(int msgIndex, Flags.Flag flag, boolean state)Convenience method to set a flasg in a message NOTE: The connection must have been opened in READ/WRITE mode. |
void |
setFlagged(int msgIndex, boolean state)Mark a message as "flagged |
void |
setSeen(int msgIndex, boolean state)Mark a message as "read" |
| Methods inherited from class org.keel.core.container.AbstractKeelServiceable |
getService, getService, getService, getService, getServiceManager, getServiceSelector, releaseService, releaseServices, service |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private Logger logger
private Configuration configuration
private java.lang.String mailHost
private java.lang.String mailProtocol
private boolean mailDebug
private boolean mailAuth
private java.lang.String mailUser
private java.lang.String mailPassword
private java.lang.String mailFolder
private boolean folderReadWrite
private boolean folderExpunge
private boolean useStatusHeader
private boolean nullAllowed
private java.lang.String attachDir
private java.lang.String attachName
private java.lang.String attachExt
private Session session
private Store store
private Folder folder
private Message[] messages
| Constructor Detail |
public DefaultReader()
| Method Detail |
public void send()
throws NestedException
NestedExceptionMailer.send()
public void configure(Configuration configuration)
throws ConfigurationException
configure in interface Configurableconfiguration - the class configurations. Must not be null.ConfigurationException - if an error occursConfigurable.configure(org.apache.avalon.framework.configuration.Configuration)public void enableLogging(Logger logger)
enableLogging in interface LogEnabledlogger - the logger. Must not be null.LogEnabled.enableLogging(org.apache.avalon.framework.logger.Logger)
public void connect()
throws NestedException
Readerconnect in interface ReaderNestedExceptionReader.connect()
public void connect(java.lang.String host,
java.lang.String user,
java.lang.String password)
throws NestedException
Readerconnect in interface Readeruser - Username to use for connect - leave null to use configuration defaultspassword - Password to use to authenticate user - leave null to use configuration defaultNestedException - If the connect does not succeedReader.connect()
public void disconnect()
throws NestedException
Readerdisconnect in interface ReaderNestedExceptionReader.disconnect()
public void read()
throws NestedException
Readerread in interface ReaderNestedExceptionReader.read()public int count()
Readercount in interface ReaderReader.count()
public java.lang.String[] getBcc(int msgIndex)
throws NestedException
ReadergetBcc in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getBcc(int)
public java.lang.String[] getCc(int msgIndex)
throws NestedException
ReadergetCc in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getCc(int)
public java.lang.String[] getFrom(int msgIndex)
throws NestedException
ReadergetFrom in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getFrom(int)
public java.util.Enumeration getHeaders(int msgIndex)
throws NestedException
ReadergetHeaders in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getHeaders(int)
public int getLineCount(int msgIndex)
throws NestedException
ReadergetLineCount in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getLineCount(int)
public java.lang.String[] getReplyTo(int msgIndex)
throws NestedException
ReadergetReplyTo in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getReplyTo(int)
public java.util.Date getSentDate(int msgIndex)
throws NestedException
ReadergetSentDate in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getSentDate(int)
public int getSize(int msgIndex)
throws NestedException
ReadergetSize in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getSize(int)
public java.lang.String getSubject(int msgIndex)
throws NestedException
ReadergetSubject in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getSubject(int)
public java.lang.String[] getTo(int msgIndex)
throws NestedException
ReadergetTo in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getTo(int)
public java.lang.String getContentType(int msgIndex,
int partIndex)
throws NestedException
ReadergetContentType in interface ReadermsgIndex - A number from 0 to count()-1partIndex - A number from 0 to getMultiPartCount()-1NestedExceptionReader.getContentType(int, int)
public java.lang.String getContentType(int msgIndex)
throws NestedException
ReadergetContentType in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getContentType(int)
public java.lang.String getDisposition(int msgIndex,
int partIndex)
throws NestedException
ReadergetDisposition in interface ReadermsgIndex - A number from 0 to count()-1partIndex - A number from 0 to getMultiPartCount()-1NestedExceptionReader.getDisposition(int, int)
public java.lang.String getDisposition(int msgIndex)
throws NestedException
ReadergetDisposition in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getDisposition(int)
public java.io.File getFile(int msgIndex,
int partIndex)
throws NestedException
ReadergetFile in interface ReadermsgIndex - A number from 0 to count()-1partIndex - A number from 0 to getMultiPartCount()-1NestedExceptionReader.getFile(int, int)
public java.io.File getFile(int msgIndex)
throws NestedException
ReadergetFile in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getFile(int)
public java.lang.String getFileName(int msgIndex,
int partIndex)
throws NestedException
ReadergetFileName in interface ReadermsgIndex - A number from 0 to count()-1partIndex - A number from 0 to getMultiPartCount()-1NestedExceptionReader.getFileName(int, int)
public java.lang.String getFileName(int msgIndex)
throws NestedException
ReadergetFileName in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getFileName(int)
public int getMultiPartCount(int msgIndex)
throws NestedException
ReadergetMultiPartCount in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getMultiPartCount(int)
public boolean isMultiPart(int msgIndex)
throws NestedException
ReaderisMultiPart in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isMultiPart(int)
public boolean isSinglePart(int msgIndex)
throws NestedException
ReaderisSinglePart in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isSinglePart(int)
public boolean isInline(int msgIndex)
throws NestedException
ReaderisInline in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isInline(int)
public java.lang.String getInline(int msgIndex)
throws NestedException
ReadergetInline in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.getInline(int)
public boolean isAnswered(int msgIndex)
throws NestedException
ReaderisAnswered in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isAnswered(int)
public boolean isDeleted(int msgIndex)
throws NestedException
ReaderisDeleted in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isDeleted(int)
public boolean isDraft(int msgIndex)
throws NestedException
ReaderisDraft in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isDraft(int)
public boolean isFlagged(int msgIndex)
throws NestedException
ReaderisFlagged in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isFlagged(int)
public boolean isRecent(int msgIndex)
throws NestedException
ReaderisRecent in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isRecent(int)
public boolean isSeen(int msgIndex)
throws NestedException
ReaderisSeen in interface ReadermsgIndex - A number from 0 to count()-1NestedExceptionReader.isSeen(int)
public void setAnswered(int msgIndex,
boolean state)
throws NestedException
ReadersetAnswered in interface ReadermsgIndex - A number from 0 to count()-1state - true=set, false=clearNestedExceptionorg.keel.services.mail.Reader#setAnswered(int)
public void setDeleted(int msgIndex,
boolean state)
throws NestedException
ReadersetDeleted in interface ReadermsgIndex - A number from 0 to count()-1state - true=set, false=clearNestedExceptionorg.keel.services.mail.Reader#setDeleted(int)
public void setDraft(int msgIndex,
boolean state)
throws NestedException
ReadersetDraft in interface ReadermsgIndex - A number from 0 to count()-1state - true=set, false=clearNestedExceptionorg.keel.services.mail.Reader#setDraft(int)
public void setFlagged(int msgIndex,
boolean state)
throws NestedException
ReadersetFlagged in interface ReadermsgIndex - A number from 0 to count()-1state - true=set, false=clearNestedExceptionorg.keel.services.mail.Reader#setFlagged(int)
public void setSeen(int msgIndex,
boolean state)
throws NestedException
ReadersetSeen in interface ReadermsgIndex - A number from 0 to count()-1state - true=set, false=clearNestedExceptionorg.keel.services.mail.Reader#setSeen(int)
private boolean matchFlag(int msgIndex,
Flags.Flag flag)
throws NestedException
msgIndex - The message number from 0 to count()-1flag - The particular flag to checkNestedException
private void setFlag(int msgIndex,
Flags.Flag flag,
boolean state)
throws NestedException
msgIndex -flag -state -NestedException
private java.util.Enumeration getHeader(int msgIndex,
java.lang.String str)
throws NestedException
msgIndex -NestedException
private void checkMsgIndex(int msgIndex)
throws NestedException
msgIndex -NestedException
private Part getBodyPart(int msgIndex)
throws NestedException
msgIndex -NestedException
private Part getOneBodyPart(int msgIndex,
int partIndex)
throws NestedException
msgIndex -partIndex -NestedExceptionprivate java.lang.String[] addrToString(Address[] addr)
addr -
private java.io.File createFile(Part p)
throws NestedException
p -NestedException
|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||