From 8536028d0c4a6906ab03f27bae4b038780697bc6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 4 Sep 2021 22:51:12 +0200 Subject: feeds: ... --- user-profiles/feeds/imm-notmuch-insert.py | 19 ++++++++++++++++--- user-profiles/feeds/module.nix | 2 +- 2 files changed, 17 insertions(+), 4 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 from email.message import EmailMessage import configparser from os import environ +from datetime import * +from dateutil.tz import * from dateutil.parser import isoparse +from html2text import html2text def main(): notmuchConfig = configparser.ConfigParser() @@ -17,15 +20,25 @@ def main(): msg = EmailMessage() authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors'])) - msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) " + if authors: + msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) " + else: + msg['From'] = f"{callbackMessage['feed_definition']['title']} " msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>" msg['Subject'] = callbackMessage['feed_item']['title'] - msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}@imm.invalid" + msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}" for link in callbackMessage['feed_item']['links']: msg.add_header('Link', link['uri']) + date = None if 'date' in callbackMessage['feed_item']: date = isoparse(callbackMessage['feed_item']['date']) - msg['Date'] = date.strftime('%a, %e %b %Y %T %z') + else: + date = datetime.now(tzlocal()) + msg['Date'] = date.strftime('%a, %e %b %Y %T %z') + + msg.set_content(html2text(callbackMessage['feed_item']['content'])) + msg.add_alternative(callbackMessage['feed_item']['content'], subtype='html') + subprocess.run( args=['notmuch', 'insert'], diff --git a/user-profiles/feeds/module.nix b/user-profiles/feeds/module.nix index cf8ee99c..9116fa91 100644 --- a/user-profiles/feeds/module.nix +++ b/user-profiles/feeds/module.nix @@ -30,7 +30,7 @@ let phases = [ "buildPhase" "checkPhase" "installPhase" "fixupPhase" ]; - python = pkgs.python39.withPackages (ps: with ps; [ configparser dateutil ]); + python = pkgs.python39.withPackages (ps: with ps; [ configparser dateutil html2text ]); nativeBuildInputs = with pkgs; [ makeWrapper ]; -- cgit v1.2.3