After some effort, I seem to have TMDA working with sendmail as an MTA,
but without installing procmail as the LDA (since I am not root
on this particular box).

The general idea is to run the email through a python script which
attempts to reconstruct the envelope sender and receiver from the
headers (mostly Received).  This is not guaranteed to work in general,
but for a reasonable sendmail setup, it seems to work ok.

In case someone else finds this useful, here is the python script
Note that it hard codes my email address, and the extension delimiter.


# fake-envelope.py
# David Bremner [EMAIL PROTECTED], 2003/02/28
# grab the extension and recipient.  
# this is my first python program. Beware!

import sys
import email
import re
from email.Utils import parseaddr, getaddresses
from email.Parser import HeaderParser

# parameters.  Should be in some config file I suppose. 
EXTENSION_DELIMITER='+';


my_addr=re.compile(r'(bremner.*@(unb.ca|.*mathematik.tu-muenchen.de))')

header_parser=HeaderParser();


# The incoming message as an email.Message object.
msgin = header_parser.parsestr(sys.stdin.read())


for_re = re.compile(r'for\s+\<?([^\s\>\;]+)\>?[\s;]')



found=0
for header in  msgin.get_all("Received",()):
        match=for_re.search(header)
        if match:
                recipient=match.group(1)
                found=1

# now we are getting pretty heuristic.

if found==0:
    for addr in msgin.get("To").split(','):
        match=my_addr.search(addr)
        if match:
            recipient=match.group(1)
            print recipient
            found=1
                


if recipient.count('@')>0:
        local_part= recipient.split('@',1)[0]
else:
        local_part=recipient



if local_part.count(EXTENSION_DELIMITER)>0:
        extension=local_part.split(EXTENSION_DELIMITER,1)[1];
else:
        extension=''

msgin.add_header("X-FakeEnv-Recipient",recipient)
msgin.add_header("X-FakeEnv-Extension",extension)

# note, the following needs a well formed From_ header.
if 'Return-Path' in msgin:
        pass
else:
        from_re=re.compile(r'From (\S+)\s')
        match=from_re.search(msgin.get_unixfrom())
        msgin.add_header('Return-Path',match.group(1))

print msgin;



######################################################################

And here is a procmailrc that calls the script, and
retrieves the results


SHELL=/bin/sh
LINEBUF=4096 
PATH=$HOME/bin:/bin:/usr/bin:/usr/bsd:/usr/sbin:/usr/freeware/bin

VERBOSE=off     

# Default Program & file locations

MAILDIR=${HOME}/spool         
SPOOLDIR=${HOME}/spool
BACKDIR=${SPOOLDIR}/backup

DEFAULT="/var/mail/bremner"   
                              


SENTMAIL=${SPOOLDIR}/sent-mail

LOGFILE=${HOME}/log/procmail.log


# Regenerate "From" lines to make sure they are valid
:0 fhw
| formail -I "From " -a "From " 

# TMDA setup

:0 fhw
|python ${HOME}/bin/fake-envelope.py


EXTENSION=`formail -zxX-FakeEnv-Extension`

:0
* EXTENSION ?? .
{
  DELIMITER="+"
}
RECIPIENT=`formail -zxX-FakeEnv-Recipient`
SENDER=`formail -zxReturn-Path`


LOGABSTRACT=off

:0 w
|python ${HOME}/bin/tmda-filter


EXITCODE=$?
LOGABSTRACT=on

# If tmda-filter fails, for the moment deliver the mail to DEFAULT




_____________________________________________
tmda-users mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-users

Reply via email to