diff options
Diffstat (limited to 'user-profiles/feeds/imm-notmuch-insert.py')
-rw-r--r-- | user-profiles/feeds/imm-notmuch-insert.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/user-profiles/feeds/imm-notmuch-insert.py b/user-profiles/feeds/imm-notmuch-insert.py deleted file mode 100644 index b7eed292..00000000 --- a/user-profiles/feeds/imm-notmuch-insert.py +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | #!@python@/bin/python | ||
2 | |||
3 | import json | ||
4 | import sys | ||
5 | import subprocess | ||
6 | from io import BytesIO | ||
7 | from email.message import EmailMessage | ||
8 | import configparser | ||
9 | from os import environ | ||
10 | from datetime import * | ||
11 | from dateutil.tz import * | ||
12 | from dateutil.parser import isoparse | ||
13 | from html2text import html2text | ||
14 | |||
15 | def main(): | ||
16 | notmuchConfig = configparser.ConfigParser() | ||
17 | notmuchConfig.read(environ.get('NOTMUCH_CONFIG')) | ||
18 | |||
19 | callbackMessage = json.load(sys.stdin) | ||
20 | |||
21 | msg = EmailMessage() | ||
22 | authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors'])) | ||
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>" | ||
27 | msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>" | ||
28 | if 'title' in callbackMessage['feed_item'] and callbackMessage['feed_item']['title']: | ||
29 | msg['Subject'] = callbackMessage['feed_item']['title'] | ||
30 | msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}" | ||
31 | for link in callbackMessage['feed_item']['links']: | ||
32 | msg.add_header('Link', link['uri']) | ||
33 | date = None | ||
34 | if 'date' in callbackMessage['feed_item']: | ||
35 | date = isoparse(callbackMessage['feed_item']['date']) | ||
36 | else: | ||
37 | date = datetime.now(tzlocal()) | ||
38 | msg['Date'] = date.strftime('%a, %e %b %Y %T %z') | ||
39 | |||
40 | if 'content' in callbackMessage['feed_item'] and callbackMessage['feed_item']['content']: | ||
41 | msg.set_content(html2text(callbackMessage['feed_item']['content'])) | ||
42 | msg.add_alternative(callbackMessage['feed_item']['content'], subtype='html') | ||
43 | |||
44 | |||
45 | subprocess.run( | ||
46 | args=['notmuch', 'insert'], | ||
47 | check=True, | ||
48 | input=bytes(msg) | ||
49 | ) | ||
50 | |||
51 | if __name__ == '__main__': | ||
52 | sys.exit(main()) | ||