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/17 18:29:40 UTC

How to intercept and filter outgoing mails?

Hi,

i need to check mails which are forwarded by james to the next MTA.
If they are expired i want to delete them.

How can i do this with james?

Thanks,
Marcel

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


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

Posted by Marcel Ruff <mr...@marcelruff.info>.
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


Re: Handling the Expired: Header

Posted by Marcel Ruff <mr...@marcelruff.info>.
Noel J. Bergman wrote:
>>> http://issues.apache.org/jira/browse/JAMES-444
>>>       
>> What about have the feature configurable:
>> onExpires=off      // default
>> onExpires=drop   // discard expired mail without notice (my patch)
>> onExpires=bounce  // or other actions??
>>     
>
> If we were to introduce this into RemoteDelivery, it would be necessary only
> because RemoteDelivery does its own internal queuing.
>
> If you have not seen the discussion on server-dev@ for a new approach to
> spooling, you may want to read the thread starting with Message-ID:
> <NB...@devtech.com> in the archives.  In brief,
> part of that proposal includes moving rescheduling outside of the mailets
> and to the processor boundary, allowing us more flexibility on what to
> reschedule.
>
> As a nearer-term thing, even in the absence of the additional work required
> to change the spool store and wrap processors into transactions, if we can
> allow you to have something like:
>
>   <processor name="RemoteDelivery">
>     <schedule>
>       ...
>     </schedule>
>
>     <mailet match="Expired" class="[Null|Bounce|...]"
>     </mailet>
>
>     <mailet class="RemoteDelivery">
>     </mailet>
>   </processor>
>
> would that satisfy your requirements?
>   
Yes, great!

You can see my use case under
 
   
http://www.xmlblaster.org/xmlBlaster/doc/requirements/protocol.email.html#expires

here it could happen that if there was some network problem some 100000 ping
emails where queuing up in james (but only the most recent ping email is 
of relevance)
and when the network recovered all 100000 emails flushed.

I did assume that Expires follows the time format

    Expires: Thu, 15 Dec 2005 21:45:01 +0100 (CET)

instead of a more standard (ISO 8601) format:
 
   Expires: 2005-12-15T21:44:56.296Z

correct?
Does it make sense to support both?

best regards
Marcel






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


RE: Handling the Expired: Header

Posted by "Noel J. Bergman" <no...@devtech.com>.
Marcel,

> > http://issues.apache.org/jira/browse/JAMES-444

> What about have the feature configurable:
> onExpires=off      // default
> onExpires=drop   // discard expired mail without notice (my patch)
> onExpires=bounce  // or other actions??

If we were to introduce this into RemoteDelivery, it would be necessary only
because RemoteDelivery does its own internal queuing.

If you have not seen the discussion on server-dev@ for a new approach to
spooling, you may want to read the thread starting with Message-ID:
<NB...@devtech.com> in the archives.  In brief,
part of that proposal includes moving rescheduling outside of the mailets
and to the processor boundary, allowing us more flexibility on what to
reschedule.

As a nearer-term thing, even in the absence of the additional work required
to change the spool store and wrap processors into transactions, if we can
allow you to have something like:

  <processor name="RemoteDelivery">
    <schedule>
      ...
    </schedule>

    <mailet match="Expired" class="[Null|Bounce|...]"
    </mailet>

    <mailet class="RemoteDelivery">
    </mailet>
  </processor>

would that satisfy your requirements?

	--- Noel


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


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

Posted by Marcel Ruff <mr...@marcelruff.info>.
What about have the feature configurable:

onExpires=off      // default
onExpires=drop   // discard expired mail without notice (my patch)
onExpires=bounce  // or other actions??
...

i think only the 'off' and 'drop' actions make sense!

If we 'bounce' an expired mail, other MTAs would/could drop it (as it is 
expired),
so the behavior would be unexpected - thus remains the 'drop' action to 
be the only
useful.

regards,

Marcel


Stefano Bagnara wrote:
> Marcel Ruff wrote:
>> Hi,
>>
>> is it possible to add the "Expires" patch (according to 
>> http://www.faqs.org/rfcs/rfc2156.html)
>> to the new james release 2.3?
>> (I had posted it already on 2006-02-21)
>
> As you can read from the rfc you linked:
>
> --------------
>    Expiry Date Indication
>       Supported as new RFC 822 header (Expires:).  In general, no
>       automatic action can be expected.
> -----------------
>
> No automatic action can be expected.
>
> Furthermore the proposed patch act like it delivered the message 
> without returning bounces or anything else.
>
> So, before deciding wether to include this or not I would like to at 
> least know what other mail servers support this header and how do they 
> handle the expiration.
>
> Stefano
>
> PS: I already added an issue and comments for this request:
> http://issues.apache.org/jira/browse/JAMES-444
>
>
>
> ---------------------------------------------------------------------
> 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


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

Posted by Stefano Bagnara <ap...@bago.org>.
Marcel Ruff wrote:
> Hi,
> 
> is it possible to add the "Expires" patch (according to 
> http://www.faqs.org/rfcs/rfc2156.html)
> to the new james release 2.3?
> (I had posted it already on 2006-02-21)

As you can read from the rfc you linked:

--------------
    Expiry Date Indication
       Supported as new RFC 822 header (Expires:).  In general, no
       automatic action can be expected.
-----------------

No automatic action can be expected.

Furthermore the proposed patch act like it delivered the message without 
returning bounces or anything else.

So, before deciding wether to include this or not I would like to at 
least know what other mail servers support this header and how do they 
handle the expiration.

Stefano

PS: I already added an issue and comments for this request:
http://issues.apache.org/jira/browse/JAMES-444



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


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

Posted by Marcel Ruff <mr...@marcelruff.info>.
Hi,

is it possible to add the "Expires" patch (according to http://www.faqs.org/rfcs/rfc2156.html)
to the new james release 2.3?
(I had posted it already on 2006-02-21)

This would be very helpful for us.

thanks a lot,
Marcel

PS: Details:


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



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


Re: How to intercept and filter outgoing mails?

Posted by Stefano Bagnara <ap...@bago.org>.
> 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


Re: How to intercept and filter outgoing mails?

Posted by Marcel Ruff <mr...@marcelruff.info>.
Stefano Bagnara wrote:
> Marcel Ruff wrote:
>> Hi,
>>
>> i need to check mails which are forwarded by james to the next MTA.
>> If they are expired i want to delete them.
>>
>> How can i do this with james?
Every of our emails has a

Expires: Thu, 15 Dec 2005 21:45:01 +0100 (CET)



header (new RFC 822 'Expires:' header and 
http://www.faqs.org/rfcs/rfc2156.html).

If the follow-up MTA is down for say one day all mails
are hold by james in its outgoing queue.
As most of our mails expire after one minute there
may be say 20000 mails which are expired during a day.
I don't want to forward them when the folloup MTA comes
up again but just silently erase them.

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?

thanks for some insight,
Marcel


>
> What do you mean by "expired"?
> James already bounce messages (and remove them from the outgoing 
> spool) when it reach the "<maxRetries>" limit.
>
> If you want to filter messages before passing them to the 
> remoteDelivery then you can simply add a matcher/mailet before the 
> remotedelivery in the same processor.
>
> If you want to process bounces coming from the remotedelivery then you 
> simply add a <bounceprocessor> configuration to the remotedelivery and 
> create a dedicated processor.
>
> 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


Re: How to intercept and filter outgoing mails?

Posted by Stefano Bagnara <ap...@bago.org>.
Marcel Ruff wrote:
> Hi,
> 
> i need to check mails which are forwarded by james to the next MTA.
> If they are expired i want to delete them.
> 
> How can i do this with james?

What do you mean by "expired"?
James already bounce messages (and remove them from the outgoing spool) 
when it reach the "<maxRetries>" limit.

If you want to filter messages before passing them to the remoteDelivery 
then you can simply add a matcher/mailet before the remotedelivery in 
the same processor.

If you want to process bounces coming from the remotedelivery then you 
simply add a <bounceprocessor> configuration to the remotedelivery and 
create a dedicated processor.

Stefano


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