summaryrefslogtreecommitdiff
path: root/user-profiles/feeds/imm-notmuch-insert.py
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2021-09-04 21:52:24 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2021-09-04 21:52:24 +0200
commit09d82350943286abc4a0b66c84287eb30a4b6f43 (patch)
tree9a823767b6fd5d073934a5627190755ff88b4c2c /user-profiles/feeds/imm-notmuch-insert.py
parent2a7280335e2d290ea96c795dbb5bbc12cdd8061b (diff)
downloadnixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.gz
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.bz2
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.xz
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.zip
feeds: imm-notmuch-insert
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())