james-server-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Charles <e...@apache.org>
Subject Re: RemoteDelivery queue
Date Thu, 07 Jun 2012 18:01:06 GMT
Hi Marco,

Great! Can you please open a JIRA on [1] and attach there the patch file 
(granting apache for the licence).

Thx a lot,

Eric

[1] https://issues.apache.org/jira/browse/JAMES

On 06/07/2012 06:27 PM, Marco Caimi wrote:
> Hi eric this is a patch supporting the Expires header
> The check is activated only if you define an expireProcessor. I modified the run method
because is the mail is expired it must not enter the delivery process.
> The patch is included here.
> Bye
>
> 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)
> @@ -60,6 +60,7 @@
>   import java.net.UnknownHostException;
>   import java.util.ArrayList;
>   import java.util.Arrays;
> +import java.util.Calendar;
>   import java.util.Collection;
>   import java.util.Date;
>   import java.util.Hashtable;
> @@ -154,6 +155,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 +260,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 +368,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 +785,27 @@
>                               String message = Thread.currentThread().getName() + " will
process mail " + key;
>                               log(message);
>                           }
> +                        //if expire processor is configured take into account Expires
header
> +                        //log("Expires processor: "+expireProcessor);
> +                        if(expireProcessor!=null&&  isExpired(mail)){
> +                        	//log("Mail is expired "+expireProcessor);
> +                        	//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 +875,44 @@
>           }
>       }
>
> -    /**
> +    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();
> +			    //log("Now is: "+now+" Expires is: "+expire);
> +				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
>
>
>
>
>
>
> Il giorno 31/mag/2012, alle ore 10.27, Eric Charles ha scritto:
>
>> Hi,
>>
>> You will need to implement your own RemoteDelivery [1]. (look at  the deliver(Mail
mail, Session session) method)
>>
>> If you like to code in the existing one and submit a pathc, we will be happy to review
it to integrate it in trunk.
>>
>> This being said, I don't know how geronimo mailclient (we use it to send the remote
mails via SMTP) behaves regarding any Expires header. You could check this and see if it's
not already covered.
>>
>> Thx,
>>
>> Eric
>>
>> [1] http://svn.apache.org/repos/asf/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
>>
>>
>> On 05/30/2012 10:49 AM, Marco Caimi wrote:
>>> Hi All,
>>> I'm looking for a way to intercept the queue of the remote delivery servlet in
order to attach some processing.
>>> I need to implement the 'Expires' headers and discard emails that are expired
but already in the queue. 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:-)
i need to discard these emails but there is no processor where to apply my matchers/mailet
for the outgoing queue.
>>>
>>> Emails remain in the remotedelivery queue that is indipendetly managed and i
cannot us the matcher/mailet paradigm.
>>>
>>> I'm using james 3 beta 4.
>>>
>>> Thank you.
>>>
>>> ----------------------------------
>>> Marco Caimi
>>> marco.caimi@gmail.com
>>> ----------------------------------
>>>
>>> Considera la responsabilità che hai verso l'ambiente e prima di stampare
>>> questa e-mail domandati: ho davvero bisogno di una copia cartacea ?
>>> Please consider your environmental responsability and before printing this
>>> e-mail ask yourself: do I need an hard copy?
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>
>>
>> --
>> eric | http://about.echarles.net | @echarles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>
> ----------------------------------
> Marco Caimi
> marco.caimi@gmail.com
> ----------------------------------
>
> Considera la responsabilità che hai verso l'ambiente e prima di stampare
> questa e-mail domandati: ho davvero bisogno di una copia cartacea ?
> Please consider your environmental responsability and before printing this
> e-mail ask yourself: do I need an hard copy?
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>

-- 
eric | http://about.echarles.net | @echarles

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


Mime
View raw message