[email] Add MDA script to setup.py
This commit is contained in:
parent
a9c9f4f1c0
commit
e24a0f8738
|
@ -10,18 +10,18 @@ from logging import getLogger
|
|||
from kibicara.platforms.email.model import Email
|
||||
|
||||
|
||||
logger = getLogger(__name__)
|
||||
def main():
|
||||
logger = getLogger(__name__)
|
||||
|
||||
# read mail from STDIN
|
||||
mailbytes = bytes(sys.stdin.read())
|
||||
|
||||
# read mail from STDIN
|
||||
mailbytes = bytes(sys.stdin.read())
|
||||
# parse plaintext to email.EmailMessage object
|
||||
myparser = email.parser.BytesParser()
|
||||
mail = myparser.parsebytes(mailbytes)
|
||||
|
||||
# parse plaintext to email.EmailMessage object
|
||||
myparser = email.parser.BytesParser()
|
||||
mail = myparser.parsebytes(mailbytes)
|
||||
|
||||
# extract relevant data from mail
|
||||
for part in mail.walk():
|
||||
# extract relevant data from mail
|
||||
for part in mail.walk():
|
||||
try:
|
||||
text = part.get_body(('plain',))
|
||||
if not text:
|
||||
|
@ -32,15 +32,15 @@ for part in mail.walk():
|
|||
except Exception:
|
||||
logger.info("No Body in this message part", exc_info=True)
|
||||
exit(0)
|
||||
body = {
|
||||
body = {
|
||||
'text': text,
|
||||
'to': mail['To'].lower(),
|
||||
'author': mail['From'].lower(),
|
||||
'secret': Email.secret
|
||||
}
|
||||
}
|
||||
|
||||
# POST request mit API-key und JSON-body an /api/email/messages/:
|
||||
print("curl "
|
||||
# POST request mit API-key und JSON-body an /api/email/messages/:
|
||||
print("curl "
|
||||
"-X POST http://localhost/api/email/messages/ "
|
||||
"-H 'Content-Type: application/json' "
|
||||
"-d " + json.dumps(body))
|
||||
|
|
Loading…
Reference in a new issue