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.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/user-profiles/feeds/imm-notmuch-insert.py b/user-profiles/feeds/imm-notmuch-insert.py
new file mode 100644
index 00000000..855f3a83
--- /dev/null
+++ b/user-profiles/feeds/imm-notmuch-insert.py
@@ -0,0 +1,37 @@
1#!@python@/bin/python
2
3import json
4import sys
5import subprocess
6from io import StringIO
7from email.message import EmailMessage
8import configparser
9from os import environ
10from dateutil.parser import isoparse
11
12def main():
13 notmuchConfig = configparser.ConfigParser()
14 notmuchConfig.read(environ.get('NOTMUCH_CONFIG'))
15
16 callbackMessage = json.load(sys.stdin)
17
18 msg = EmailMessage()
19 authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors']))
20 msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) <imm@imm.invalid>"
21 msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>"
22 msg['Subject'] = callbackMessage['feed_item']['title']
23 msg['Message-ID'] = f"{callbackMessage['feed_item']['identifier']@imm.invalid}"
24 for link in callbackMessage['feed_item']['links']:
25 msg.add_header('Link', link)
26 if 'date' in callbackMessage['feed_item']:
27 date = isoparse(callbackMessage['feed_item']['date'])
28 msg['Date'] = date.strftime('%a, %e %b %Y %T %z')
29
30 subprocess.run(
31 args=['notmuch', 'insert'],
32 check=True,
33 stdin=StringIO(bytes(msg))
34 )
35
36if __name__ == '__main__':
37 sys.exit(main())