summaryrefslogtreecommitdiff
path: root/user-profiles/feeds/imm-notmuch-insert.py
diff options
context:
space:
mode:
Diffstat (limited to 'user-profiles/feeds/imm-notmuch-insert.py')
-rw-r--r--user-profiles/feeds/imm-notmuch-insert.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/user-profiles/feeds/imm-notmuch-insert.py b/user-profiles/feeds/imm-notmuch-insert.py
index a2dd3cb0..ba29ce5b 100644
--- a/user-profiles/feeds/imm-notmuch-insert.py
+++ b/user-profiles/feeds/imm-notmuch-insert.py
@@ -7,7 +7,10 @@ from io import BytesIO
7from email.message import EmailMessage 7from email.message import EmailMessage
8import configparser 8import configparser
9from os import environ 9from os import environ
10from datetime import *
11from dateutil.tz import *
10from dateutil.parser import isoparse 12from dateutil.parser import isoparse
13from html2text import html2text
11 14
12def main(): 15def main():
13 notmuchConfig = configparser.ConfigParser() 16 notmuchConfig = configparser.ConfigParser()
@@ -17,15 +20,25 @@ def main():
17 20
18 msg = EmailMessage() 21 msg = EmailMessage()
19 authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors'])) 22 authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors']))
20 msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) <imm@imm.invalid>" 23 if authors:
24 msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) <imm@imm.invalid>"
25 else:
26 msg['From'] = f"{callbackMessage['feed_definition']['title']} <imm@imm.invalid>"
21 msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>" 27 msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>"
22 msg['Subject'] = callbackMessage['feed_item']['title'] 28 msg['Subject'] = callbackMessage['feed_item']['title']
23 msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}@imm.invalid" 29 msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}"
24 for link in callbackMessage['feed_item']['links']: 30 for link in callbackMessage['feed_item']['links']:
25 msg.add_header('Link', link['uri']) 31 msg.add_header('Link', link['uri'])
32 date = None
26 if 'date' in callbackMessage['feed_item']: 33 if 'date' in callbackMessage['feed_item']:
27 date = isoparse(callbackMessage['feed_item']['date']) 34 date = isoparse(callbackMessage['feed_item']['date'])
28 msg['Date'] = date.strftime('%a, %e %b %Y %T %z') 35 else:
36 date = datetime.now(tzlocal())
37 msg['Date'] = date.strftime('%a, %e %b %Y %T %z')
38
39 msg.set_content(html2text(callbackMessage['feed_item']['content']))
40 msg.add_alternative(callbackMessage['feed_item']['content'], subtype='html')
41
29 42
30 subprocess.run( 43 subprocess.run(
31 args=['notmuch', 'insert'], 44 args=['notmuch', 'insert'],