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

Got it working!

parent f217540e
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ from email import message_from_bytes
import email.policy
from dateutil.parser import parse
import subprocess
import re
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
......@@ -11,16 +12,25 @@ class CustomSMTPServer(smtpd.SMTPServer):
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>')
if not title:
print("Title missing")
return
title = re.sub('^\[.*\] *', '', title)
subprocess.run(['wp', 'post', 'create',
'--post_author=2'
f'--post_date={d:%Y-%m-%d}',
f"--post_title={title}",
'--post_status=publish',
'--post_category=Veckomail',
f"--post_content=<pre>{body}</pre>"],
cwd='/usr/share/wordpress',
shell=False)
return
server = CustomSMTPServer(('localhost', 1025), None,
server = CustomSMTPServer(('0.0.0.0', 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