[email] Get recipient from email instead of command line
This commit is contained in:
parent
2215470bd2
commit
a6ce618ca8
|
@ -9,17 +9,11 @@ import requests
|
|||
from logging import getLogger
|
||||
from kibicara.model import Hood
|
||||
from kibicara.platforms.email.model import Email
|
||||
import argparse
|
||||
|
||||
|
||||
async def main():
|
||||
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
|
||||
mailbytes = bytes(sys.stdin.read())
|
||||
|
||||
|
@ -39,7 +33,7 @@ async def main():
|
|||
logger.error('No suitable message body')
|
||||
exit(1)
|
||||
# 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)
|
||||
email_row = await Email.objects.get(hood=hood)
|
||||
body = {
|
||||
|
@ -48,5 +42,5 @@ async def main():
|
|||
'secret': email_row.secret,
|
||||
}
|
||||
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
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue