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 ...@@ -4,6 +4,7 @@ from email import message_from_bytes
import email.policy import email.policy
from dateutil.parser import parse from dateutil.parser import parse
import subprocess import subprocess
import re
class CustomSMTPServer(smtpd.SMTPServer): class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data, **kwargs): def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
...@@ -11,16 +12,25 @@ class CustomSMTPServer(smtpd.SMTPServer): ...@@ -11,16 +12,25 @@ class CustomSMTPServer(smtpd.SMTPServer):
body = msg.get_content() body = msg.get_content()
d = parse(msg.get('Date')) d = parse(msg.get('Date'))
title = msg.get('Subject') title = msg.get('Subject')
subprocess.run('wp', 'post', 'create',
'--post_author', 1, if not title:
'--post_date', f'{d:%Y-%m-%d}', print("Title missing")
'--post_title', title, return
'--post_publish', 'publish',
'--post_category', 'Veckomail', title = re.sub('^\[.*\] *', '', title)
'--post_content', f'<pre>{body}</pre>')
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 return
server = CustomSMTPServer(('localhost', 1025), None, server = CustomSMTPServer(('0.0.0.0', 1025), None,
decode_data=False) decode_data=False)
asyncore.loop() asyncore.loop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment