From: martin f. krafft Date: Wed, 19 Feb 2025 09:04:12 +0000 (+0100) Subject: clean ical attachments of teams crap X-Git-Url: https://git.madduck.net/etc/neomutt.git/commitdiff_plain/04c2c9cc518da9a557a5295050922f1cbb496c6f?hp=0a4f99bfc0fbd1a3408686dbba8ce4c55c8446f3 clean ical attachments of teams crap --- diff --git a/.config/neomutt/icalcleaner b/.config/neomutt/icalcleaner new file mode 100755 index 0000000..ec07fc8 --- /dev/null +++ b/.config/neomutt/icalcleaner @@ -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)) diff --git a/.config/neomutt/mailcap.icalendar b/.config/neomutt/mailcap.icalendar index c6816fc..e681ffa 100644 --- a/.config/neomutt/mailcap.icalendar +++ b/.config/neomutt/mailcap.icalendar @@ -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'";