You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Marcel Ruff <mr...@marcelruff.info> on 2006/02/21 13:05:31 UTC

Re: How to intercept and filter outgoing mails? -> Expires: patch

Hi Stefano,

if have added following code snippet to
  src/java/org/apache/james/transport/mailets/RemoteDelivery.java
method
  private boolean deliver(MailImpl mail, Session session) :
 
---------------------------------------------------------------------------------------
 HostAddress outgoingMailServer = (HostAddress) targetServers.next(); // 
<--- Existing line
 //====== Expires patch start
 try {
     //
     // Expiry Date Indication
     // Supported as new RFC 822 header (Expires:).
     // @see http://www.faqs.org/rfcs/rfc2156.html
     // @see james/logs/mailet-*.log
     //
    final String EXPIRES_HEADER_RFC2156 = "Expires";
    String[] expires = mail.getMessage().getHeader(EXPIRES_HEADER_RFC2156);
    if (expires != null && expires.length > 0) {
       // Date: Thu, 17 Nov 2005 16:45:12 +0100 (CET)
       String value = expires[0].trim();
       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 (now.getTime() > expire.getTime()) {
           StringBuffer logMessageBuffer =
             new StringBuffer(256)
             .append("Mail ")
             .append(mail.getName())
             .append(" to host ")
             .append(outgoingMailServer.getHostName())
             .append(" at ")
             .append(outgoingMailServer.getHost())
             .append(" to addresses ")
             .append(Arrays.asList(addr))
             .append(" is expired since ")
             .append(value)
             .append(" and is discarded");
          log(logMessageBuffer.toString());
          return true;
       }
    }
 }
 catch (Throwable e) {
    e.printStackTrace(); // Ignore Expires: problems
 }
//====== Expires patch end
 StringBuffer logMessageBuffer = ...  // <--- Existing line
---------------------------------------------------

now expired mails are nicely discarded.

This header is well established for 'news' (RFC1036) and
specified in RFC2156 for X.400 -> RCF822(email) gateways as an optional 
header.
(In the predecessor document RFC1327 it was called "Expiry-Date:" but 
changed later to "Expires:") 

This is tested with james 2.2.0 and should work fine
with the current svn code as well.

Is it possible to add this to james as a new feature?

thanks

Marcel


Stefano Bagnara wrote:
>> Every of our emails has a
>>
>> Expires: Thu, 15 Dec 2005 21:45:01 +0100 (CET)
>> [...]
>> I think the mailet interface is invoked when the mail
>> arrives to james (and is not expired at this point)
>> but not when james tries to forward them - true?
>
> The only solution I can find now is to alter the remotedelivery 
> behaviour to take into account the Expire header (look in the "fail" 
> method, where the remotedelivery decide wether to keep the mail for 
> the next retry or to bounce it. It should be a difficult task if you 
> know java.
>
> Stefano
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org