Add filter script for ics files.
This is a python script for python 3 using the vobject library to show details about an ics file (text/calendar attachment). Signed-off-by: Jens Grassel <jens@wegtam.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
ae83373fa6
commit
374d3a0d01
2 changed files with 90 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -105,6 +105,7 @@ install: $(DOCS) aerc
|
||||||
install -m755 filters/hldiff $(DESTDIR)$(SHAREDIR)/filters/hldiff
|
install -m755 filters/hldiff $(DESTDIR)$(SHAREDIR)/filters/hldiff
|
||||||
install -m755 filters/html $(DESTDIR)$(SHAREDIR)/filters/html
|
install -m755 filters/html $(DESTDIR)$(SHAREDIR)/filters/html
|
||||||
install -m755 filters/plaintext $(DESTDIR)$(SHAREDIR)/filters/plaintext
|
install -m755 filters/plaintext $(DESTDIR)$(SHAREDIR)/filters/plaintext
|
||||||
|
install -m755 filters/show-ics-details.py $(DESTDIR)$(SHAREDIR)/filters/show-ics-details.py
|
||||||
install -m644 templates/new_message $(DESTDIR)$(SHAREDIR)/templates/new_message
|
install -m644 templates/new_message $(DESTDIR)$(SHAREDIR)/templates/new_message
|
||||||
install -m644 templates/quoted_reply $(DESTDIR)$(SHAREDIR)/templates/quoted_reply
|
install -m644 templates/quoted_reply $(DESTDIR)$(SHAREDIR)/templates/quoted_reply
|
||||||
install -m644 templates/forward_as_body $(DESTDIR)$(SHAREDIR)/templates/forward_as_body
|
install -m644 templates/forward_as_body $(DESTDIR)$(SHAREDIR)/templates/forward_as_body
|
||||||
|
|
89
filters/show-ics-details.py
Executable file
89
filters/show-ics-details.py
Executable file
|
@ -0,0 +1,89 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""Parse a vcard file given via stdin and output some details.
|
||||||
|
Currently the following details are displayed if present:
|
||||||
|
|
||||||
|
- start date and time
|
||||||
|
- the summary information of the event
|
||||||
|
- a list of attendees
|
||||||
|
- the description of the event
|
||||||
|
|
||||||
|
Please note: if multiple events are included in the data then only the
|
||||||
|
first one will be parsed and displayed!
|
||||||
|
|
||||||
|
REQUIREMENTS:
|
||||||
|
- Python 3
|
||||||
|
- Python 3 - vobject library
|
||||||
|
|
||||||
|
To use as a filter in aerc, add the following line to your aerc.config:
|
||||||
|
text/calendar=show-ics-details.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import vobject
|
||||||
|
|
||||||
|
|
||||||
|
def remove_mailto(message: str) -> str:
|
||||||
|
"""Remove a possible existing 'mailto:' from the given message.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
message -- A message string.
|
||||||
|
"""
|
||||||
|
return re.sub(r'^mailto:', '', message, flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
def extract_field(cal: vobject.icalendar.VCalendar2_0, name: str) -> str:
|
||||||
|
"""Extract the desired field from the given calendar object.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
cal -- A VCalendar 2.0 object.
|
||||||
|
name -- The field name.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
match name.strip():
|
||||||
|
case 'attendees':
|
||||||
|
attendees = []
|
||||||
|
for attendee in cal.vevent.attendee_list:
|
||||||
|
attendees.append(remove_mailto(attendee.valueRepr()).strip())
|
||||||
|
return ', '.join(attendees)
|
||||||
|
case 'description':
|
||||||
|
return cal.vevent.description.valueRepr().strip()
|
||||||
|
case 'dtstart':
|
||||||
|
return str(cal.vevent.dtstart.valueRepr()).strip()
|
||||||
|
case 'organizer':
|
||||||
|
return remove_mailto(cal.vevent.organizer.valueRepr()).strip()
|
||||||
|
case 'summary':
|
||||||
|
return cal.vevent.summary.valueRepr().strip()
|
||||||
|
case _:
|
||||||
|
return ''
|
||||||
|
except AttributeError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
attendees = ''
|
||||||
|
description = ''
|
||||||
|
dtstart = ''
|
||||||
|
error = ''
|
||||||
|
organizer = ''
|
||||||
|
summary = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
cal = vobject.readOne(sys.stdin)
|
||||||
|
attendees = extract_field(cal, 'attendees')
|
||||||
|
description = extract_field(cal, 'description')
|
||||||
|
dtstart = extract_field(cal, 'dtstart')
|
||||||
|
organizer = extract_field(cal, 'organizer')
|
||||||
|
summary = extract_field(cal, 'summary')
|
||||||
|
except vobject.base.ParseError:
|
||||||
|
error = '**Sorry, but we could not parse the calendar!**'
|
||||||
|
|
||||||
|
if error:
|
||||||
|
print(error)
|
||||||
|
print("")
|
||||||
|
|
||||||
|
print(f"Date/Time : {dtstart}")
|
||||||
|
print(f"Summary : {summary}")
|
||||||
|
print(f"Organizer : {organizer}")
|
||||||
|
print(f"Attendees : {attendees}")
|
||||||
|
print("")
|
||||||
|
print(description)
|
Loading…
Reference in a new issue