librelist archives

« back to archive

Re: Routing help- multiple addresses

Re: Routing help- multiple addresses

From:
Scott Montgomerie
Date:
2009-07-28 @ 08:23
Mm... that doesn't seem to have worked.  Here's the test message  
headers:

Message-Id: <7CF59FE7-9D09-437E-963A-8F249A98FDC5@gmail.com>
From: Scott Montgomerie <montgomerie.scott@gmail.com>
To: AH <ah@gmail.com>,
jeff@xyz.net
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-Smtp-Server: smtp.gmail.com:montgomerie.scott@gmail.com
Mime-Version: 1.0 (Apple Message framework v935.3)
Subject: SPAM
Date: Thu, 23 Jul 2009 16:15:03 -0600

And the lamson log output:
2009-07-23 22:15:22,622 - routing - DEBUG - Message to u'AH <ah@gmail.com 
 >,\n jeff@xyz.net' from u'Scott Montgomerie <montgomerie.scott@gmail.com 
 >' didn't match any handlers.

This is the output from

lamson routes --test "AH <ah@gmail.com>,jeff@xyz.net"

TEST address 'AH<ah@gmail.com>,jeff@xyz.net' matches:
   '^(?P<address>.+)@(?P<host>xyz\\.net)$' app.handlers.sample.FORWARD
   -  {'host': 'xyz.net', 'address': 'AH <ah@gmail.com>,jeff'}

Here it appears to be matching "AH <ah@gmail.com>,jeff" as the  
address, and correctly matching the host.  Shouldn't it be running the  
handler once per address?

On 23-Jul-09, at 4:10 PM, Zed A. Shaw wrote:

> On Thu, Jul 23, 2009 at 09:50:48PM +0000, Scott Montgomerie wrote:
>> Hey guys,
>> I've got a route defined as such:
>>
>> @route(".*@xyz.net")
>> @stateless
>> def FORWARD(message, address=None, host=None):
>> ...
>
> So, in your route you need to use parenthesis to setup some "captures"
> that match address and host.  Change it to be like this:
>
> @route("(address)@(host)", address='.+', host='xyz\\.net')
>
> That will make sure that your address=None and host=None parameters  
> get
> filled in.  What the (address) syntax does is tells Lamson "I want you
> to take this part of the pattern and make it into a parameter for my
> handler called 'address'."
>
> Eventually you'll find you use host and other patterns over and  
> over, so
> put them into your config/settings.py file like this:
>
> router_defaults = {
>    'host': 'xyz\\.net',
>    'address': '.+',
> }
>
> Then you only need this for your route:
>
> @route("(address)@(host)")
>
> Since Lamson will look in the router defaults first, and then your
> @route parameters.
>
>> It appears this route doesn't like multiple recipients, because I see
>> this in the logs (and mail isn't getting delivered to jeff@xyz.net):
>
> Next, to debug this use the "lamson routes" command to see what's
> getting matched and why.  Make sure you're in your app's directory and
> type that.  You can also use the --test parameter to feed it an  
> address
> and see if it matches.
>
> The #1 cause of this is that you didn't put the handler in the  
> handlers
> list in your config/settings.py file:
>
> handlers = ['app.handlers.bounce', 'app.handlers.admin']
>
> Like the above from librelist.  Or, that you have them in the wrong
> order.  The patterns are matched in the order you give above, so if  
> you
> don't have them in there they won't get found.
>
> If you run "lamson routes" and it doesn't pring anything out, just go
> make sure you have the modules in your config/setting.py:handlers and
> run it again.  Then make sure it matches some test addresses you feed
> it.
>
>> 2009-07-23 21:04:11,537 - routing - DEBUG - Message to u'AH <ah@gmail.com
>>> ,\n jeff@xyz.net' from u'Scott Montgomerie <montgomerie.scott@gmail.com
>>> ' didn't match any handlers.
>
> Let me know if the above helps.
>
>
> -- 
> Zed A. Shaw
> http://zedshaw.com/