From a6ce618ca8fd387bce0433bcd4a2f52de33da2bc Mon Sep 17 00:00:00 2001
From: maike <maike@systemli.org>
Date: Sun, 12 Jul 2020 20:07:55 +0200
Subject: [PATCH] [email] Get recipient from email instead of command line

---
 kibicara/kibicara_mda.py | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/kibicara/kibicara_mda.py b/kibicara/kibicara_mda.py
index d8971a8..9b7095f 100644
--- a/kibicara/kibicara_mda.py
+++ b/kibicara/kibicara_mda.py
@@ -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
     )