[
https://issues.apache.org/jira/browse/JAMES-1415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13291640#comment-13291640
]
Marco Caimi commented on JAMES-1415:
------------------------------------
I solved the problem by adding support for an 'expireProcessor'.
In the run method before passing to the deliver method i introduces a check for
the expires header. The check is activated only if a expireProcessor is defined
for the remotedeliver mailet. In this case i check the header against the
actual datetime, if the mail is expired it will be passed to the expires
processor.
This is the diff. I agree to apache license for using the piece of code.
Index: src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
===================================================================
--- src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
(revision 1347556)
+++ src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
(working copy)
@@ -154,6 +154,8 @@
/** Compiled pattern of the above String. */
private static Pattern PATTERN = null;
+
+ private static String RFC_1036_EXPIRES_HEADER= "Expires";
/** The DNSService */
private DNSService dnsServer;
@@ -257,6 +259,8 @@
private boolean startTLS = false;
private boolean isSSLEnable = false;
+ /**the processor to handle expired mail */
+ private String expireProcessor = null;
@Resource(name = "domainlist")
public void setDomainList(DomainList domainList) {
@@ -363,6 +367,8 @@
sendPartial = (getInitParameter("sendpartial") == null) ? false :
Boolean.valueOf(getInitParameter("sendpartial"));
bounceProcessor = getInitParameter("bounceProcessor");
+
+ expireProcessor = getInitParameter("expireProcessor");
String sTLS = getInitParameter("startTLS");
if (sTLS != null) {
@@ -778,9 +784,25 @@
String message = Thread.currentThread().getName()
+ " will process mail " + key;
log(message);
}
+ //if expire processor is configured take into account
Expires header
+ if(expireProcessor!=null && isExpired(mail)){
+ //pass the mail to expireprocess if exists,
otherway discard it
+ //mail.setAttribute("time-exeeded", );
+ mail.setState(expireProcessor);
+ // re-insert the mail into the spool for
getting it passed to the
+ // dsn-processor
+ MailetContext mc = getMailetContext();
+ try {
+ mc.sendMail(mail);
+ } catch (MessagingException e) {
+ // we shouldn't get an exception, because
the mail was already
+ // processed
+ log("Exception re-inserting failed mail:
", e);
+ }
- // Deliver message
- if (deliver(mail, session)) {
+ LifecycleUtil.dispose(mail);
+ // Deliver message
+ }else if (deliver(mail, session)) {
// Message was successfully delivered/fully
// failed...
// delete it
@@ -850,7 +872,43 @@
}
}
- /**
+ private boolean isExpired(Mail mail) {
+ try {
+ String[] expireHeaders =
mail.getMessage().getHeader(RFC_1036_EXPIRES_HEADER);
+ if(expireHeaders!=null && expireHeaders.length>0){
+ String value = expireHeaders[0].trim();
+ //convert into date and check
+ java.text.DateFormat df = new
javax.mail.internet.MailDateFormat();
+ java.util.Date expire = df.parse(value);
+ java.util.Date now = new java.util.Date();
+ if(expire!=null && now.getTime() >
expire.getTime()){
+ StringBuilder logMessageBuffer =
+ new StringBuilder(256)
+ .append("Mail ")
+ .append(mail.getName())
+ .append(" to host ")
+ .append(mail.getRemoteHost())
+ .append(" to addresses ")
+ .append(Arrays.asList(mail.getRecipients()))
+ .append(" is expired since ")
+ .append(expire);
+ if(expireProcessor !=null){
+ logMessageBuffer.append(" and
is be passed to processor ")
+ .append(expireProcessor);
+ }else{
+ logMessageBuffer.append(" and is
discarded");
+ }
+ log(logMessageBuffer.toString());
+ return true;
+ }
+ }
+ } catch (MessagingException e) {
+ } catch (java.text.ParseException e) {
+ }
+ return false;
+ }
+
+ /**
* We can assume that the recipients of this message are all going to the
* same mail server. We will now rely on the DNS server to do DNS MX record
* lookup and try to deliver to the multiple mail servers. If it fails, it
> Manage Expires header in RemoteDelivery mailet
> ----------------------------------------------
>
> Key: JAMES-1415
> URL: https://issues.apache.org/jira/browse/JAMES-1415
> Project: JAMES Server
> Issue Type: Bug
> Components: Remote Delivery
> Affects Versions: 3.0-beta4
> Environment: any
> Reporter: Marco Caimi
> Fix For: 3.0-beta4
>
>
> Manage the 'Expires' headers in the RemoteDelivery mailet.
> For example if a mail send fail the remotedelivery puts the mail in the
> outgoing queue, the next time it processes the mail the expires header can be
> expired. The header is now ignored, i need to discard these emails but there
> is no way to apply a processor on the outgoing queue.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]