diff --git a/bin/.bin/emails/dump-ical b/bin/.bin/emails/dump-ical new file mode 100755 index 00000000..63f987d2 --- /dev/null +++ b/bin/.bin/emails/dump-ical @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import sys +import warnings +import vobject +import datetime + + +def get_invitation_from_path(path): + with open(path) as f: + try: + # vobject uses deprecated Exceptions + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + return vobject.readOne(f, ignoreUnreadable=True) + except AttributeError: + return vobject.readOne(f, ignoreUnreadable=True) + + +def person_string(c): + return "{} {}".format(c.params['CN'][0], "<%s>" % c.value.split(':')[1]) + + +def when_str_of_start_end(s, e): + datetime_format = "%a, %d %b %Y at %H:%M" + + # sometimes, s and e can be dates only, so convert them to datetimes + if type(s) == datetime.date: + s = datetime.datetime.combine(s, datetime.time.min) + if type(e) == datetime.date: + e = datetime.datetime.combine(e, datetime.time.min) + + until_format = "%H:%M %Z" if s.date() == e.date() else datetime_format + return "{} -- {}".format(s.strftime(datetime_format), e.strftime(until_format)) + + +def pretty_print_invitation(invitation): + event = invitation.vevent.contents + title = event['summary'][0].value + org = event['organizer'][0] if 'organizer' in event else None + invitees = event['attendee'] if 'attendee' in event else None + start = event['dtstart'][0].value + end = event['dtend'][0].value + location = event['location'][0].value if 'location' in event else None + description = event['description'][0].value if 'description' in event else None + sequence = event['sequence'][0].value if 'sequence' in event else None + rrule = event['rrule'][0].value if 'rrule' in event else None + print("="*70) + if sequence is not None and int(sequence) > 0: + print("MEETING UPDATE".center(70)) + else: + print("MEETING INVITATION".center(70)) + print("="*70) + print("Event:\n\t{}".format(title)) + if org: + print("Organiser:\n\t{}".format(person_string(org))) + if invitees: + print("Invitees:") + for i in invitees: + print("\t{}".format(person_string(i))) + print("When:\n\t{}".format(when_str_of_start_end(start, end))) + if rrule: + print("Rrule:\n\t{}".format(rrule)) + if location: + print("Location:\n\t{}".format(location)) + if description: + print("---\n{}\n---".format(description)) + + +if __name__ == "__main__": + if len(sys.argv) != 2 or sys.argv[1].startswith('-'): + sys.stderr.write("Usage: %s \n".format(sys.argv[0])) + sys.exit(2) + inv = get_invitation_from_path(sys.argv[1]) + pretty_print_invitation(inv) diff --git a/mutt/.config/mutt/mailcap b/mutt/.config/mutt/mailcap index 321d32d1..85a4e09d 100644 --- a/mutt/.config/mutt/mailcap +++ b/mutt/.config/mutt/mailcap @@ -1,5 +1,6 @@ text/html; $BROWSER %s text/html; w3m -I %{charset} -T text/html -dump; copiousoutput; +text/calendar; dump-ical %s; copiousoutput; image/*; sxiv -a -b %s & video/*; setsid mpv --quiet %s & application/pdf; zathura %s & diff --git a/mutt/.config/mutt/muttrc b/mutt/.config/mutt/muttrc index 41c2abce..c20db0e0 100644 --- a/mutt/.config/mutt/muttrc +++ b/mutt/.config/mutt/muttrc @@ -137,12 +137,13 @@ set mailcap_path = "~/.config/mutt/mailcap" # https://neomutt.org/guide/mimesupp # Tells Mutt to automatically view files with these mime types auto_view text/html # https://neomutt.org/guide/reference#auto_view auto_view application/pgp-encrypted # https://neomutt.org/guide/reference#auto_view +auto_view text/calendar # https://neomutt.org/guide/reference#auto_view # Order to try and show multipart emails -alternative_order text/plain text/enriched text/html +alternative_order text/plain text/calendar text/enriched text/html # Macro to toggle alternates (plain <-> html), based on: # https://groups.google.com/d/msg/comp.mail.mutt/9I702oMwQQE/JqdLnp3j9WAJ -macro pager ,@aoh= "unalternative_order *; alternative_order text/html text/plain text/enriched; macro pager A ,@aot= 'toggle alternative order'" -macro pager ,@aot= "unalternative_order *; alternative_order text/plain text/enriched text/html; macro pager A ,@aoh= 'toggle alternative order'" +macro pager ,@aoh= "unalternative_order *; alternative_order text/calendar text/html text/plain text/enriched; macro pager A ,@aot= 'toggle alternative order'" +macro pager ,@aot= "unalternative_order *; alternative_order text/plain text/calendar text/enriched text/html; macro pager A ,@aoh= 'toggle alternative order'" macro pager A ,@aoh= "toggle alternative order" # Use urlscan to handle links in messages macro pager U "set pipe_decode = yesurlscan -dc -r 'linkhandler {}'set pipe_decode = no" "view URLs"