Forwarded mail returns raw MIME message.
- From:
- Don Spaulding
- Date:
- 2009-08-06 @ 02:46
Hi all,
I'm hoping to use lamson to run a forwarding service for our business.
It replaces a hacked-up postfix install that only I understand how to
fix and that fails in miserable, awful, catastrophic ways about once a
year. I've run into a bit of a snag when testing the server out where
it seems to be relaying the entire email as a raw string containing
the entirety of the MIME message. As in, what is actually delivered
as the body of the message to the recipient is the MIME text of the
entire message.
I've included my simple handler and settings, plus an example of a
message that was round-tripped through the forwarder.
What am I doing wrong?
#####################
# app/handlers/forwarder.py:
#####################
# <snip> standard imports for brevity </snip>
os.environ['DJANGO_SETTINGS_MODULE'] = 'florence.storage.settings'
from florence.storage.models import EmailRedirect, EmailLog
@route("(virtual)", virtual=".+?@.+")
@stateless
def FORWARD(message, virtual):
try:
redirect = EmailRedirect.objects.get(virtual=virtual.lower())
except EmailRedirect.DoesNotExist:
relay.deliver(message, To='support+badredirects@mysupportaddress.com')
return
EmailLog.objects.create(to=virtual, real_to=redirect.real,
sender=message.From, subject=message['subject'])
relay.deliver(message, To=str(redirect.real))
#####################
# config/settings.py:
#####################
# This file contains python variables that configure Lamson for email
processing.
import logging
relay_config = {'host': 'localhost', 'port': 8825}
receiver_config = {'host': '0.0.0.0', 'port': 25}
handlers = ['app.handlers.forwarder']
router_defaults = {}
template_config = {'dir': 'app', 'module': 'templates'}
# the config/boot.py will turn these values into variables set in settings
#####################
# Example forwarded email:
#####################
---------- Forwarded message ----------
From: <donspauldingii@gmail.com>
Date: Wed, Aug 5, 2009 at 3:48 PM
Subject:
To:
From nobody Wed Aug 5 15:48:52 2009
MIME-Version: 1.0
Date: Wed, 5 Aug 2009 15:48:30 -0500
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
h=domainkey-signature:mime-version:received:in-reply-to:references
:date:message-id:subject:from:to:content-type
:content-transfer-encoding;
bh=KAlcMm/B+KwxgpNra/Rmsm4gVupXdC5+uxW3xCRLzko=;
b=RC7Pf70ZSO9iBtrovCyVBDm5FE6BVZ0wLlPjhVjLrkm0lNhPRLm8f0d70sKzJL7eSy
hFMLkokBJ7h1EFA6+ahekYAp1eO/5Aq5qaHXzv2wDVnD80Z03sJ5WMvSDZ5qPlSoGFge
GImGhCwUePczVruM01AOGNRGbKL/HA4dPhkuM=
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type:content-transfer-encoding;
b=igpIa3RlaPbIxuKz5IkfQjy7Z+Cji82HJgsNk0rXW1MCOSCY+sWu3wl/Qp42a714nn
+JKsD3FZTa6cmY8UFSB0oU1CbMAcHkU0nrZZUoAdxQyla6f7GmFtSXiFu0/79mT/y+a2
25OWSSneQ/SHXwCKabUV2Z9WpTBnSjtxg0lSg=
From: Don Spaulding <donspauldingii@gmail.com>
In-Reply-To: <23dae2e70908051306p43e2a252vf5b49d5271e3c221@mail.gmail.com>
Message-Id: <23dae2e70908051348g67f97f7dh15189ee8230d8fe2@mail.gmail.com>
Received: by ewy18 with SMTP id 18so484015ewy.38
for <test@1001ships.com>; Wed, 05 Aug 2009 13:48:30 -0700 (PDT)
References: <23dae2e70908051306p43e2a252vf5b49d5271e3c221@mail.gmail.com>
Subject: Fwd: Still getting raw mime messages back?
To: test@1001ships.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
---------- Forwarded message ----------
From: Don Spaulding <donspauldingii@gmail.com>
Date: Wed, Aug 5, 2009 at 3:06 PM
Subject: Still getting raw mime messages back?
To: test@1001ships.com
Here's a quick question, am I still getting the raw string version of
the whole message?
--
Don Spaulding II
--
Don Spaulding II
Re: Forwarded mail returns raw MIME message.
- From:
- Zed A. Shaw
- Date:
- 2009-08-06 @ 03:05
On Wed, Aug 05, 2009 at 09:46:41PM -0500, Don Spaulding wrote:
> Hi all,
> ....
> I've included my simple handler and settings, plus an example of a
> message that was round-tripped through the forwarder.
Alright, first make sure you got the latest. I think you do since you
were playing with the standalone gear.
> os.environ['DJANGO_SETTINGS_MODULE'] = 'florence.storage.settings'
>
> from florence.storage.models import EmailRedirect, EmailLog
>
> @route("(virtual)", virtual=".+?@.+")
> @stateless
> def FORWARD(message, virtual):
> try:
> redirect = EmailRedirect.objects.get(virtual=virtual.lower())
> except EmailRedirect.DoesNotExist:
> relay.deliver(message, To='support+badredirects@mysupportaddress.com')
> return
> EmailLog.objects.create(to=virtual, real_to=redirect.real,
> sender=message.From, subject=message['subject'])
> relay.deliver(message, To=str(redirect.real))
Hmm, looking at that it should simply deliver the same message but use a
different envelope header to the SMTP server. The code in
lamson.server.Relay.deliver just takes the message and str(message) to
send it.
Do this, take this code out and put it in a test case. Then have your
test load one of these sample messages into a MailRequest, and then
convert it to a str, and then see what you get. Also, look a the the
MailRequest.base variable (a lamson.encoding.MailBase object) to see
what it has in it. That is kind of the "true state" of the MailRequest.
See if you can't replicate it in a test case and then narrow it down.
I should be on IRC tonight if you want help debugging it. I'm sure it's
something retarded like a bad test input or something simple.
--
Zed A. Shaw
http://zedshaw.com/