public class MessageProcessor extends ProcessorAbstract
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.
Modifier and Type | Method and Description |
---|---|
protected void |
addErrorMessages(org.apache.mailet.Mail mail)
Adds any required error messages to a
Mail . |
protected void |
addMailAttributes(org.apache.mailet.Mail aMail)
Adds the mail attributes to a
Mail . |
protected Boolean |
computeMaxMessageSizeExceeded()
Compute the maxMessageSizeExceeded.
|
protected String |
computeRemoteAddress()
Answer the IP Address of the remote server for the message being
processed.
|
protected 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 String |
computeRemoteHostName()
Answer the Canonical host name of the remote server for the message being
processed.
|
protected 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 org.apache.mailet.Mail |
createMail(javax.mail.internet.MimeMessage message,
org.apache.mailet.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 String |
getEnvelopeRecipient(javax.mail.internet.MimeMessage msg)
Method getEnvelopeRecipient answers the recipient if found else null.
|
protected org.apache.mailet.MailAddress |
getIntendedRecipient()
Method getIntendedRecipient answers the sole intended recipient else
null.
|
protected javax.mail.internet.MimeMessage |
getMessageIn()
Returns the messageIn.
|
protected String |
getRemoteAddress()
Returns the remoteAddress, lazily initialised as required.
|
protected String |
getRemoteDomain()
Returns the remoteDomain, lazily initialised as required.
|
protected String |
getRemoteHostName()
Returns the remoteHostName, lazily initialised as required.
|
static String |
getRFC2822RECEIVEDHeaderFields()
Returns the rFC2822RECEIVEDHeaderFields.
|
protected org.apache.mailet.MailAddress |
getSender()
Method getSender answers a
MailAddress for the sender. |
protected StringBuilder |
getStatusReport(String detailMsg)
Answer a
StringBuilder containing a message reflecting the
current status of the message being processed. |
protected void |
handleBouncing(org.apache.mailet.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(UnknownHostException ex)
Method handleUnknownHostException.
|
protected boolean |
isBlacklistedRecipient()
Returns the Blacklisted.
|
protected boolean |
isBlacklistedRecipient(org.apache.mailet.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(org.apache.mailet.MailAddress recipient)
Method isLocalRecipient.
|
protected boolean |
isLocalServer(org.apache.mailet.MailAddress recipient)
Method isLocalServer.
|
protected 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 Boolean |
isRemoteReceivedHeaderInvalid()
Returns the remoteReceivedHeaderInvalid, lazily initialised.
|
protected boolean |
isRemoteRecipient()
Returns the localRecipient.
|
protected boolean |
isUserUndefined()
Returns the userUndefined.
|
protected void |
logStatusError(String detailMsg)
Log the status the current message as ERROR.
|
protected void |
logStatusInfo(String detailMsg)
Log the status of the current message as INFO.
|
protected void |
logStatusWarn(String detailMsg)
Log the status the current message as WARN.
|
void |
process()
Method process attempts to deliver a fetched message.
|
protected void |
rejectBlacklistedRecipient(org.apache.mailet.MailAddress recipient)
Method rejectBlacklistedRecipient.
|
protected void |
rejectMaxMessageSizeExceeded(int messageSize)
Method rejectMaxMessageSizeExceeded.
|
protected void |
rejectRecipientNotFound()
Method rejectRecipientNotFound.
|
protected void |
rejectRemoteReceivedHeaderInvalid()
Method rejectRemoteReceivedHeaderInvalid.
|
protected void |
rejectRemoteRecipient(org.apache.mailet.MailAddress recipient)
Method rejectRemoteRecipient.
|
protected void |
rejectUserUndefined(org.apache.mailet.MailAddress recipient)
Method rejectUserUndefined.
|
protected void |
sendMail(org.apache.mailet.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(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()
Set the SEEN flag.
|
protected void |
setRecipientNotFound(boolean recipientNotFound)
Sets the recipientNotFound.
|
protected void |
setRemoteAddress(String remoteAddress)
Sets the remoteAddress.
|
protected void |
setRemoteDomain(String remoteDomain)
Sets the remoteDomain.
|
protected void |
setRemoteHostName(String remoteHostName)
Sets the remoteHostName.
|
protected void |
setRemoteReceivedHeaderInvalid(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.
|
computeAttributePrefix, getAccount, getAttributePrefix, getBlacklist, getConfiguration, getCustomRecipientHeader, getDefaultDomainName, getDefaultLocalPart, getDeferredRecipientNotFoundMessageIDs, getDNSServer, getFetchTaskName, getHost, getJavaMailFolderName, getJavaMailProviderName, getLocalUsers, getLogger, getMailQueue, getMaxMessageSizeLimit, getPassword, getRecipient, getRemoteReceivedHeaderIndex, getSession, getUser, isDeferRecipientNotFound, isFetchAll, isIgnoreRecipientHeader, isLeave, isLeaveBlacklisted, isLeaveMaxMessageSizeExceeded, isLeaveRecipientNotFound, isLeaveRemoteReceivedHeaderInvalid, isLeaveRemoteRecipient, isLeaveUndeliverable, isLeaveUserUndefined, isMarkBlacklistedSeen, isMarkMaxMessageSizeExceededSeen, isMarkRecipientNotFoundSeen, isMarkRemoteReceivedHeaderInvalidSeen, isMarkRemoteRecipientSeen, isMarkSeen, isMarkUndeliverableSeen, isMarkUserUndefinedSeen, isOpenReadOnly, isRecurse, isRejectBlacklisted, isRejectMaxMessageSizeExceeded, isRejectRecipientNotFound, isRejectRemoteReceivedHeaderInvalid, isRejectRemoteRecipient, isRejectUserUndefined, setAccount, setAttributePrefix, updateAttributePrefix
public void process() throws javax.mail.MessagingException
process
in class ProcessorAbstract
javax.mail.MessagingException
ProcessorAbstract.process()
protected void rejectRemoteRecipient(org.apache.mailet.MailAddress recipient) throws javax.mail.MessagingException
recipient
- javax.mail.MessagingException
protected void rejectBlacklistedRecipient(org.apache.mailet.MailAddress recipient) throws javax.mail.MessagingException
recipient
- javax.mail.MessagingException
protected void rejectRecipientNotFound() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void rejectUserUndefined(org.apache.mailet.MailAddress recipient) throws javax.mail.MessagingException
recipient
- javax.mail.MessagingException
protected void rejectMaxMessageSizeExceeded(int messageSize) throws javax.mail.MessagingException
messageSize
- sizejavax.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 org.apache.mailet.Mail createMail(javax.mail.internet.MimeMessage message, org.apache.mailet.MailAddress recipient) throws javax.mail.MessagingException, UnknownHostException
Mail
.message
- recipient
- javax.mail.MessagingException
UnknownHostException
protected org.apache.mailet.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 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(org.apache.mailet.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(UnknownHostException ex) throws javax.mail.MessagingException
ex
- javax.mail.MessagingException
protected boolean isLocalRecipient(org.apache.mailet.MailAddress recipient) throws UsersRepositoryException
recipient
- UsersRepositoryException
protected boolean isLocalServer(org.apache.mailet.MailAddress recipient)
recipient
- protected boolean isBlacklistedRecipient(org.apache.mailet.MailAddress recipient)
recipient
- protected boolean isBouncing() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void sendMail(org.apache.mailet.Mail mail) throws javax.mail.MessagingException
mail
- javax.mail.MessagingException
protected String getEnvelopeRecipient(javax.mail.internet.MimeMessage msg) throws javax.mail.MessagingException
msg
- javax.mail.MessagingException
protected org.apache.mailet.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(String detailMsg) throws javax.mail.MessagingException
detailMsg
- javax.mail.MessagingException
protected void logStatusWarn(String detailMsg) throws javax.mail.MessagingException
detailMsg
- javax.mail.MessagingException
protected void logStatusError(String detailMsg) throws javax.mail.MessagingException
detailMsg
- javax.mail.MessagingException
protected StringBuilder getStatusReport(String detailMsg) throws javax.mail.MessagingException
StringBuilder
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(org.apache.mailet.Mail aMail) throws javax.mail.MessagingException
Mail
.aMail
- a Mail instancejavax.mail.MessagingException
protected void addErrorMessages(org.apache.mailet.Mail mail) throws javax.mail.MessagingException
Mail
.mail
- a Mail instancejavax.mail.MessagingException
protected void setBlacklistedRecipient(boolean blacklisted)
blacklisted
- The blacklisted to setprotected boolean isRecipientNotFound()
protected void setRecipientNotFound(boolean recipientNotFound)
recipientNotFound
- The recipientNotFound to setprotected String getRemoteDomain() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setRemoteDomain(String remoteDomain)
remoteDomain
- The remoteDomain to setprotected void updateRemoteDomain() throws javax.mail.MessagingException
javax.mail.MessagingException
protected String computeRemoteAddress() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
protected String computeRemoteHostName() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
protected String getRemoteAddress() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
protected String getRemoteHostName() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
protected void setRemoteAddress(String remoteAddress)
remoteAddress
- The remoteAddress to setprotected void updateRemoteAddress() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
protected void setRemoteHostName(String remoteHostName)
remoteHostName
- The remoteHostName to setprotected void updateRemoteHostName() throws javax.mail.MessagingException, UnknownHostException
javax.mail.MessagingException
UnknownHostException
public static String getRFC2822RECEIVEDHeaderFields()
protected Boolean isMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void updateMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected Boolean computeMaxMessageSizeExceeded() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setMaxMessageSizeExceeded(Boolean maxMessageSizeExceeded)
maxMessageSizeExceeded
- The maxMessageSizeExceeded to setprotected Boolean isRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected Boolean computeRemoteReceivedHeaderInvalid() throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setRemoteReceivedHeaderInvalid(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 setCopyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.