[email] Get recipient from email instead of command line

This commit is contained in:
maike 2020-07-12 20:07:55 +02:00 committed by dl6tom
parent 2215470bd2
commit a6ce618ca8

View file

@ -9,17 +9,11 @@ import requests
from logging import getLogger from logging import getLogger
from kibicara.model import Hood from kibicara.model import Hood
from kibicara.platforms.email.model import Email from kibicara.platforms.email.model import Email
import argparse
async def main(): async def main():
logger = getLogger(__name__) logger = getLogger(__name__)
# the MDA passes the recipient address as command line argument
parser = argparse.ArgumentParser()
parser.add_argument("recipient_address")
args = parser.parse_args()
# read mail from STDIN # read mail from STDIN
mailbytes = bytes(sys.stdin.read()) mailbytes = bytes(sys.stdin.read())
@ -39,7 +33,7 @@ async def main():
logger.error('No suitable message body') logger.error('No suitable message body')
exit(1) exit(1)
# extract hood name from the envelope recipient address # extract hood name from the envelope recipient address
hood_name = args.recipient_address.split('@')[0] hood_name = mail.get("Envelope-to").split('@')[0]
hood = await Hood.objects.get(name=hood_name) hood = await Hood.objects.get(name=hood_name)
email_row = await Email.objects.get(hood=hood) email_row = await Email.objects.get(hood=hood)
body = { body = {
@ -48,5 +42,5 @@ async def main():
'secret': email_row.secret, 'secret': email_row.secret,
} }
requests.post( requests.post(
'http://localhost:8000/api/hoods/%d/email/messages/' % (hood.id), json=body 'http://localhost:8000/api/hoods/%d/email/messages/' % hood.id, json=body
) )