Makes mutt view calender invites nicely
This commit is contained in:
parent
6414e1ce72
commit
cecdd951dd
3 changed files with 80 additions and 3 deletions
75
bin/.bin/emails/dump-ical
Executable file
75
bin/.bin/emails/dump-ical
Executable file
|
@ -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 <filename.ics>\n".format(sys.argv[0]))
|
||||
sys.exit(2)
|
||||
inv = get_invitation_from_path(sys.argv[1])
|
||||
pretty_print_invitation(inv)
|
|
@ -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 &
|
||||
|
|
|
@ -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= "<enter-command>unalternative_order *; alternative_order text/html text/plain text/enriched; macro pager A ,@aot= 'toggle alternative order'<enter><exit><display-message>"
|
||||
macro pager ,@aot= "<enter-command>unalternative_order *; alternative_order text/plain text/enriched text/html; macro pager A ,@aoh= 'toggle alternative order'<enter><exit><display-message>"
|
||||
macro pager ,@aoh= "<enter-command>unalternative_order *; alternative_order text/calendar text/html text/plain text/enriched; macro pager A ,@aot= 'toggle alternative order'<enter><exit><display-message>"
|
||||
macro pager ,@aot= "<enter-command>unalternative_order *; alternative_order text/plain text/calendar text/enriched text/html; macro pager A ,@aoh= 'toggle alternative order'<enter><exit><display-message>"
|
||||
macro pager A ,@aoh= "toggle alternative order"
|
||||
# Use urlscan to handle links in messages
|
||||
macro pager U "<enter-command>set pipe_decode = yes<enter><pipe-message>urlscan -dc -r 'linkhandler {}'<enter><enter-command>set pipe_decode = no<enter>" "view URLs"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue