|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.james.fetchmail.ProcessorAbstract org.apache.james.fetchmail.MessageProcessor
public class MessageProcessor
Class MessageProcessor
handles the delivery of
MimeMessages
to the James input spool.
Messages written to the input spool always have the following Mail Attributes set:
Messages written to the input spool have the following Mail Attributes set if the corresponding condition is satisfied:
remoteReceivedHeaderIndex
is invalid.Configuration settings -
see org.apache.james.fetchmail.ParsedConfiguration
- control the messages that are written to the James input spool, those that
are rejected and what happens to messages that are rejected.
Rejection processing is based on the following filters:
Rejection processing is intentionally limited to managing the status of the messages that are rejected on the server from which they were fetched. View it as a simple automation of the manual processing an end-user would perform through a mail client. Messages may be marked as seen or be deleted.
Further processing can be achieved by configuring to disable rejection for one or more filters. This enables Messages that would have been rejected to be written to the James input spool. The conditional Mail Attributes described above identify the filter states. The Matcher/Mailet chain can then be used to perform any further processing required, such as notifying the Postmaster and/or sender, marking the message for error processing, etc.
Note that in the case of a message exceeding the message size limit, the message that is written to the input spool has no content. This enables configuration of a mailet notifying the sender that their mail has not been delivered due to its size while maintaining the purpose of the filter which is to avoid injecting excessively large messages into the input spool.
Delivery is to a sole intended recipient. The recipient is determined in the following manner:
If a recipient cannot be determined after these steps, the message is rejected.
Every delivered message CURRENTLY has an "X-fetched-from" header added
containing the name of the fetch task. Its primary uses are to detect bouncing
mail and provide backwards compatibility with the fetchPop task that inserted
this header to enable injected messages to be detected in the Matcher/Mailet
chain. This header is DEPRECATED and WILL BE REMOVED in a future version of
fetchmail. Use the Mail Attribute org.apache.james.fetchmail.taskName
instead.
MessageProcessor
is as agnostic as it can be about the format
and contents of the messages it delivers. There are no RFCs that govern its
behavior. The most releveant RFCs relate to the exchange of messages between
MTA servers, but not POP3 or IMAP servers which are normally end-point
servers and not expected to re-inject mail into MTAs. None the less, the
intent is to conform to the 'spirit' of the RFCs.
MessageProcessor
relies on the MTA (James in this
implementation) to manage and validate the injected mail just as it would
when receiving mail from an upstream MTA.
The only correction applied by MessageProcessor
is to correct a
missing or partial sender address. If the sender address can not be obtained,
the default local part and default domain part is added. If the sender domain
part is absent, the default domain part is added.
Mail with corrections applied to the sender address will most likely pass
Matcher tests on the sender that they might otherwise fail. The
Mail Attributes org.apache.james.fetchmail.isDefaultSenderLocalPart
and org.apache.james.fetchmail.isDefaultSenderDomainPart
are added
to the injected mail to enable such mail to be detected and processed accordingly.
The status of messages on the server from which they were fetched that cannot be injected into the input spool due to non-correctable errors is determined by the undeliverable configuration options.
Method Summary | |
---|---|
protected void |
addErrorMessages(Mail mail)
Adds any required error messages to a Mail . |
protected void |
addMailAttributes(Mail aMail)
Adds the mail attributes to a Mail . |
protected java.lang.Boolean |
computeMaxMessageSizeExceeded()
Compute the maxMessageSizeExceeded. |
protected java.lang.String |
computeRemoteAddress()
Answer the IP Address of the remote server for the message being processed. |
protected java.lang.String |
computeRemoteDomain()
Method computeRemoteDomain answers a String that is the
RFC2822 compliant "Received : from" domain extracted from the message
being processed for the remote domain that sent the message. |
protected java.lang.String |
computeRemoteHostName()
Answer the Canonical host name of the remote server for the message being processed. |
protected java.lang.Boolean |
computeRemoteReceivedHeaderInvalid()
Computes the remoteReceivedHeaderInvalid. |
protected javax.mail.internet.MimeMessage |
createEmptyMessage()
Method createEmptyMessage answers a new MimeMessage from the fetched message with the message
contents removed. |
protected Mail |
createMail(javax.mail.internet.MimeMessage message,
MailAddress recipient)
Method createMail creates a new Mail . |
protected javax.mail.internet.MimeMessage |
createMessage()
Method createMessage answers a new MimeMessage from the
fetched message. |
protected java.lang.String |
getEnvelopeRecipient(javax.mail.internet.MimeMessage msg)
Method getEnvelopeRecipient answers the recipient if found else null. |
protected MailAddress |
getIntendedRecipient()
Method getIntendedRecipient answers the sole intended recipient else null. |
protected javax.mail.internet.MimeMessage |
getMessageIn()
Returns the messageIn. |
protected java.lang.String |
getRemoteAddress()
Returns the remoteAddress, lazily initialised as required. |
protected java.lang.String |
getRemoteDomain()
Returns the remoteDomain, lazily initialised as required. |
protected java.lang.String |
getRemoteHostName()
Returns the remoteHostName, lazily initialised as required. |
static java.lang.String |
getRFC2822RECEIVEDHeaderFields()
Returns the rFC2822RECEIVEDHeaderFields. |
protected MailAddress |
getSender()
Method getSender answers a MailAddress for the sender. |
protected java.lang.StringBuffer |
getStatusReport(java.lang.String detailMsg)
Answer a StringBuffer containing a message reflecting
the current status of the message being processed. |
protected void |
handleBouncing(Mail mail)
Method handleBouncing sets the Mail state to ERROR and delete from the message store. |
protected void |
handleMarkSeenNotPermanent()
Handler for when the folder does not support the SEEN flag. |
protected void |
handleParseException(javax.mail.internet.ParseException ex)
Method handleParseException. |
protected void |
handleUnknownHostException(java.net.UnknownHostException ex)
Method handleUnknownHostException. |
protected boolean |
isBlacklistedRecipient()
Returns the Blacklisted. |
protected boolean |
isBlacklistedRecipient(MailAddress recipient)
Method isBlacklistedRecipient. |
protected boolean |
isBouncing()
Check if this mail has been bouncing by counting the X-fetched-from headers for this task |
protected boolean |
isDefaultRemoteAddress()
Returns the defaultRemoteAddress. |
protected boolean |
isDefaultSenderDomainPart()
Returns the defaultSenderDomainPart. |
protected boolean |
isDefaultSenderLocalPart()
Returns the defaultSenderLocalPart. |
protected boolean |
isLocalRecipient(MailAddress recipient)
Method isLocalRecipient. |
protected boolean |
isLocalServer(MailAddress recipient)
Method isLocalServer. |
protected boolean |
isLocalUser(MailAddress recipient)
Method isLocalUser. |
protected java.lang.Boolean |
isMaxMessageSizeExceeded()
Returns the maxMessageSizeExceeded, lazily initialised as required. |
protected boolean |
isMessageDeleted()
Is the DELETED flag set? |
protected boolean |
isMessageSeen()
Is the SEEN flag set? |
protected boolean |
isPreviouslyUnprocessed()
Returns boolean indicating if the message to be delivered
was unprocessed in a previous delivery attempt. |
protected boolean |
isRecipientNotFound()
Returns the recipientNotFound. |
protected java.lang.Boolean |
isRemoteReceivedHeaderInvalid()
Returns the remoteReceivedHeaderInvalid, lazily initialised. |
protected boolean |
isRemoteRecipient()
Returns the localRecipient. |
protected boolean |
isUserUndefined()
Returns the userUndefined. |
protected void |
logStatusError(java.lang.String detailMsg)
Log the status the current message as ERROR. |
protected void |
logStatusInfo(java.lang.String detailMsg)
Log the status of the current message as INFO. |
protected void |
logStatusWarn(java.lang.String detailMsg)
Log the status the current message as WARN. |
void |
process()
Method process attempts to deliver a fetched message. |
protected void |
rejectBlacklistedRecipient(MailAddress recipient)
Method rejectBlacklistedRecipient. |
protected void |
rejectMaxMessageSizeExceeded(int messageSize)
Method rejectMaxMessageSizeExceeded. |
protected void |
rejectRecipientNotFound()
Method rejectRecipientNotFound. |
protected void |
rejectRemoteReceivedHeaderInvalid()
Method rejectRemoteReceivedHeaderInvalid. |
protected void |
rejectRemoteRecipient(MailAddress recipient)
Method rejectRemoteRecipient. |
protected void |
rejectUserUndefined(MailAddress recipient)
Method rejectUserUndefined. |
protected void |
sendMail(Mail mail)
Method sendMail. |
protected void |
setBlacklistedRecipient(boolean blacklisted)
Sets the Blacklisted. |
protected void |
setDefaultRemoteAddress(boolean defaultRemoteAddress)
Sets the defaultRemoteAddress. |
protected void |
setDefaultSenderDomainPart(boolean defaultSenderDomainPart)
Sets the defaultSenderDomainPart. |
protected void |
setDefaultSenderLocalPart(boolean defaultSenderLocalPart)
Sets the defaultSenderLocalPart. |
protected void |
setMaxMessageSizeExceeded(java.lang.Boolean maxMessageSizeExceeded)
Sets the maxMessageSizeExceeded. |
protected void |
setMessageDeleted()
Set the DELETED flag. |
protected void |
setMessageIn(javax.mail.internet.MimeMessage messageIn)
Sets the messageIn. |
protected void |
setMessageSeen()
|
protected void |
setRecipientNotFound(boolean recipientNotFound)
Sets the recipientNotFound. |
protected void |
setRemoteAddress(java.lang.String remoteAddress)
Sets the remoteAddress. |
protected void |
setRemoteDomain(java.lang.String remoteDomain)
Sets the remoteDomain. |
protected void |
setRemoteHostName(java.lang.String remoteHostName)
Sets the remoteHostName. |
protected void |
setRemoteReceivedHeaderInvalid(java.lang.Boolean remoteReceivedHeaderInvalid)
Sets the remoteReceivedHeaderInvalid. |
protected void |
setRemoteRecipient(boolean localRecipient)
Sets the localRecipient. |
protected void |
setUserUndefined(boolean userUndefined)
Sets the userUndefined. |
protected void |
updateMaxMessageSizeExceeded()
Refreshes the maxMessageSizeExceeded. |
protected void |
updateRemoteAddress()
Updates the remoteAddress. |
protected void |
updateRemoteDomain()
Updates the remoteDomain. |
protected void |
updateRemoteHostName()
Updates the remoteHostName. |
protected void |
updateRemoteReceivedHeaderInvalid()
Updates the remoteReceivedHeaderInvalid. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void process() throws javax.mail.MessagingException
process
in class ProcessorAbstract
javax.mail.MessagingException
ProcessorAbstract.process()
protected void rejectRemoteRecipient(MailAddress recipient) throws javax.mail.MessagingException
recipient
-
javax.mail.MessagingException
protected void rejectBlacklistedRecipient(MailAddress recipient) throws javax.mail.MessagingException
recipient
-
javax.mail.MessagingException
protected void rejectRecipientNotFound() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void rejectUserUndefined(MailAddress recipient) throws javax.mail.MessagingException
recipient
-
javax.mail.MessagingException
protected void rejectMaxMessageSizeExceeded(int messageSize) throws javax.mail.MessagingException
message
- size
javax.mail.MessagingException
protected void rejectRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected javax.mail.internet.MimeMessage createMessage() throws javax.mail.MessagingException
Method createMessage answers a new MimeMessage
from the
fetched message.
If the maximum message size is exceeded, an empty message is created, else the new message is a copy of the received message.
javax.mail.MessagingException
protected javax.mail.internet.MimeMessage createEmptyMessage() throws javax.mail.MessagingException
MimeMessage
from the fetched message with the message
contents removed.
javax.mail.MessagingException
protected Mail createMail(javax.mail.internet.MimeMessage message, MailAddress recipient) throws javax.mail.MessagingException, java.net.UnknownHostException
Mail
.
message
- recipient
-
javax.mail.MessagingException
java.net.UnknownHostException
protected MailAddress getSender() throws javax.mail.MessagingException
Method getSender answers a MailAddress
for the sender.
When the sender local part and/or domain part can not be obtained
from the mail, default values are used. The flags
'defaultSenderLocalPart' and 'defaultSenderDomainPart' are set
accordingly.
javax.mail.MessagingException
protected java.lang.String computeRemoteDomain() throws javax.mail.MessagingException
Method computeRemoteDomain answers a String
that is the
RFC2822 compliant "Received : from" domain extracted from the message
being processed for the remote domain that sent the message.
Often the remote domain is the domain that sent the message to the host of the message store, the second "received" header, which has an index of 1. Other times, messages may be received by a edge mail server and relayed internally through one or more internal mail servers prior to arriving at the message store host. In these cases the index is 1 + the number of internal servers through which a mail passes.
The index of the header to use is specified by the configuration
parameter RemoteReceivedHeaderIndex
. This is set to
point to the received header prior to the remote mail server, the one
prior to the edge mail server.
"received" headers are searched starting at the specified index. If a domain in the "received" header is not found, successively closer "received" headers are tried. If a domain is not found in this way, the local machine is used as the domain. Finally, if the local domain cannot be determined, the local address 127.0.0.1 is used.
javax.mail.MessagingException
protected void handleBouncing(Mail mail) throws javax.mail.MessagingException
mail
-
javax.mail.MessagingException
protected void handleParseException(javax.mail.internet.ParseException ex) throws javax.mail.MessagingException
ex
-
javax.mail.MessagingException
protected void handleUnknownHostException(java.net.UnknownHostException ex) throws javax.mail.MessagingException
ex
-
javax.mail.MessagingException
protected boolean isLocalRecipient(MailAddress recipient)
recipient
-
protected boolean isLocalServer(MailAddress recipient)
recipient
-
protected boolean isLocalUser(MailAddress recipient)
recipient
-
protected boolean isBlacklistedRecipient(MailAddress recipient)
recipient
-
protected boolean isBouncing() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void sendMail(Mail mail) throws javax.mail.MessagingException
mail
-
javax.mail.MessagingException
protected java.lang.String getEnvelopeRecipient(javax.mail.internet.MimeMessage msg) throws javax.mail.MessagingException
msg
-
javax.mail.MessagingException
protected MailAddress getIntendedRecipient() throws javax.mail.MessagingException
javax.mail.MessagingException
protected javax.mail.internet.MimeMessage getMessageIn()
protected void setMessageIn(javax.mail.internet.MimeMessage messageIn)
messageIn
- The messageIn to setprotected boolean isRemoteRecipient()
protected boolean isPreviouslyUnprocessed()
boolean
indicating if the message to be delivered
was unprocessed in a previous delivery attempt.
protected void logStatusInfo(java.lang.String detailMsg) throws javax.mail.MessagingException
detailMsg
-
javax.mail.MessagingException
protected void logStatusWarn(java.lang.String detailMsg) throws javax.mail.MessagingException
detailMsg
-
javax.mail.MessagingException
protected void logStatusError(java.lang.String detailMsg) throws javax.mail.MessagingException
detailMsg
-
javax.mail.MessagingException
protected java.lang.StringBuffer getStatusReport(java.lang.String detailMsg) throws javax.mail.MessagingException
StringBuffer
containing a message reflecting
the current status of the message being processed.
detailMsg
-
javax.mail.MessagingException
protected boolean isUserUndefined()
protected boolean isMessageDeleted() throws javax.mail.MessagingException
javax.mail.MessagingException
protected boolean isMessageSeen() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setMessageDeleted() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setMessageSeen() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void handleMarkSeenNotPermanent() throws javax.mail.MessagingException
Handler for when the folder does not support the SEEN flag. The default behaviour implemented here is to log a warning and set the flag anyway.
Subclasses may choose to override this and implement their own solutions.
javax.mail.MessagingException
protected boolean isBlacklistedRecipient()
protected void setRemoteRecipient(boolean localRecipient)
localRecipient
- The localRecipient to setprotected void setUserUndefined(boolean userUndefined)
userUndefined
- The userUndefined to setprotected void addMailAttributes(Mail aMail) throws javax.mail.MessagingException
Mail
.
aMail
- a Mail instance
javax.mail.MessagingException
protected void addErrorMessages(Mail mail) throws javax.mail.MessagingException
Mail
.
aMail
- a Mail instance
javax.mail.MessagingException
protected void setBlacklistedRecipient(boolean blacklisted)
blacklisted
- The blacklisted to setprotected boolean isRecipientNotFound()
protected void setRecipientNotFound(boolean recipientNotFound)
recipientNotFound
- The recipientNotFound to setprotected java.lang.String getRemoteDomain() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setRemoteDomain(java.lang.String remoteDomain)
remoteDomain
- The remoteDomain to setprotected void updateRemoteDomain() throws javax.mail.MessagingException
javax.mail.MessagingException
protected java.lang.String computeRemoteAddress() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
protected java.lang.String computeRemoteHostName() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
protected java.lang.String getRemoteAddress() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
protected java.lang.String getRemoteHostName() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
protected void setRemoteAddress(java.lang.String remoteAddress)
remoteAddress
- The remoteAddress to setprotected void updateRemoteAddress() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
protected void setRemoteHostName(java.lang.String remoteHostName)
remoteHostName
- The remoteHostName to setprotected void updateRemoteHostName() throws javax.mail.MessagingException, java.net.UnknownHostException
javax.mail.MessagingException
java.net.UnknownHostException
public static java.lang.String getRFC2822RECEIVEDHeaderFields()
protected java.lang.Boolean isMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void updateMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected java.lang.Boolean computeMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setMaxMessageSizeExceeded(java.lang.Boolean maxMessageSizeExceeded)
maxMessageSizeExceeded
- The maxMessageSizeExceeded to setprotected java.lang.Boolean isRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected java.lang.Boolean computeRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setRemoteReceivedHeaderInvalid(java.lang.Boolean remoteReceivedHeaderInvalid)
remoteReceivedHeaderInvalid
- The remoteReceivedHeaderInvalid to setprotected void updateRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected boolean isDefaultSenderDomainPart()
protected boolean isDefaultSenderLocalPart()
protected void setDefaultSenderDomainPart(boolean defaultSenderDomainPart)
defaultSenderDomainPart
- The defaultSenderDomainPart to setprotected void setDefaultSenderLocalPart(boolean defaultSenderLocalPart)
defaultSenderLocalPart
- The defaultSenderLocalPart to setprotected boolean isDefaultRemoteAddress()
protected void setDefaultRemoteAddress(boolean defaultRemoteAddress)
defaultRemoteAddress
- The defaultRemoteAddress to set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |