]> git.madduck.net Git - etc/neomutt.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

clean ical attachments of teams crap
authormartin f. krafft <madduck@madduck.net>
Wed, 19 Feb 2025 09:04:12 +0000 (10:04 +0100)
committermartin f. krafft <madduck@madduck.net>
Wed, 19 Feb 2025 09:04:12 +0000 (10:04 +0100)
.config/neomutt/icalcleaner [new file with mode: 0755]
.config/neomutt/mailcap.icalendar

diff --git a/.config/neomutt/icalcleaner b/.config/neomutt/icalcleaner
new file mode 100755 (executable)
index 0000000..ec07fc8
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+import sys
+import os
+from icalendar import Calendar, Event
+
+
+def parse_ics_file(fp):
+    cal = Calendar.from_ical(fp.read())
+
+    for event in cal.walk("VEVENT"):
+        event.subcomponents = list(
+            filter(lambda sc: sc.name != "VALARM", event.subcomponents)
+        )
+
+        if url := event.get("X-MICROSOFT-SKYPETEAMSMEETINGURL"):
+            event["location"] = url
+            desc = '\n'.join([
+                s.strip()
+                for s in event["description"].strip().split("_" * 8)
+                if s and not 'teams.microsoft.com' in s
+            ])
+            event["description"] = desc
+
+        for k in [k for k in event.keys() if k.startswith("X-MICROSOFT")]:
+            del event[k]
+
+    return cal.to_ical()
+
+if __name__ == "__main__":
+
+    if len(sys.argv) > 1 and sys.argv[1] != "-":
+        for f in sys.argv[1:]:
+            with open(f) as fp:
+                res = parse_ics_file(fp)
+
+            if res:
+                with open(f, 'w') as fp:
+                    fp.write(res.decode('utf-8'))
+
+    else:
+        print(parse_ics_file(sys.stdin))
index c6816fcbabfb6285e43dd17bc53190c63fa25a28..e681ffac0577c542f4c1883b4a4c790052d7a1cc 100644 (file)
@@ -2,6 +2,6 @@
 # Neomutt mailcap for iCalendar previewing/khal import
 
 text/calendar; ~/.config/neomutt/icalparser; description=iCal details; copiousoutput; \
-  print=sh -c "sensible-editor '%s' && khal import '%s'";
+  print=sh -c "~/.config/neomutt/icalcleaner '%s' && sensible-editor '%s' && khal import '%s'";
 application/ics; ~/.config/neomutt/icalparser; description=iCal details; copiousoutput; \
-  print=sh -c "sensible-editor '%s' && khal import '%s'";
+  print=sh -c "~/.config/neomutt/icalcleaner '%s' && sensible-editor '%s' && khal import '%s'";