Skip to content
Snippets Groups Projects
Commit f217540e authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Initial commit.

parents
Branches
No related tags found
No related merge requests found
main.py 0 → 100644
import smtpd
import asyncore
from email import message_from_bytes
import email.policy
from dateutil.parser import parse
import subprocess
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
msg = message_from_bytes(data, policy=email.policy.default)
body = msg.get_content()
d = parse(msg.get('Date'))
title = msg.get('Subject')
subprocess.run('wp', 'post', 'create',
'--post_author', 1,
'--post_date', f'{d:%Y-%m-%d}',
'--post_title', title,
'--post_publish', 'publish',
'--post_category', 'Veckomail',
'--post_content', f'<pre>{body}</pre>')
return
server = CustomSMTPServer(('localhost', 1025), None,
decode_data=False)
asyncore.loop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment