2022-05-24 07:36:05 +02:00
|
|
|
#!/usr/bin/awk -f
|
|
|
|
# ex: ft=awk
|
|
|
|
#
|
|
|
|
# awk filter for aerc to parse text/calendar mime-types
|
|
|
|
#
|
|
|
|
# Based on the ical2org.awk script by Eric S Fraga and updated by Guide Van
|
|
|
|
# Hoecke. Adapted to aerc by Koni Marti <koni.marti@gmail.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
UIDS[0];
|
|
|
|
people_attending[0];
|
|
|
|
people_partstat[0];
|
|
|
|
people_rsvp[0];
|
|
|
|
|
|
|
|
# use a colon to separate the type of data line from the actual contents
|
|
|
|
FS = ":";
|
2022-07-24 01:25:24 +02:00
|
|
|
}
|
2022-05-24 07:36:05 +02:00
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
{
|
|
|
|
# remove carriage return from every line
|
|
|
|
gsub(/\r/, "")
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/^[ ]/ {
|
2022-07-24 01:25:24 +02:00
|
|
|
# this block deals with the continuation lines that start with a whitespace
|
|
|
|
#
|
|
|
|
line = $0
|
|
|
|
# remove trailing whitespaces
|
|
|
|
gsub(/^[ ]/, "", line)
|
|
|
|
|
2022-05-24 07:36:05 +02:00
|
|
|
# assumes continuation lines start with a space
|
|
|
|
if (indescription) {
|
2022-07-24 01:25:24 +02:00
|
|
|
entry = entry line
|
2022-05-24 07:36:05 +02:00
|
|
|
} else if (insummary) {
|
2022-07-24 01:25:24 +02:00
|
|
|
summary = summary line
|
2022-05-24 07:36:05 +02:00
|
|
|
} else if (inattendee) {
|
2022-07-24 01:25:24 +02:00
|
|
|
attendee = attendee line
|
2022-05-24 07:36:05 +02:00
|
|
|
} else if (inorganizer) {
|
2022-07-24 01:25:24 +02:00
|
|
|
organizer = organizer line
|
2022-05-24 07:36:05 +02:00
|
|
|
} else if (inlocation) {
|
2022-07-24 01:25:24 +02:00
|
|
|
location = location unescape(line, 0)
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^BEGIN:VALARM/,/^END:VALARM/ {
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
2022-05-24 07:36:05 +02:00
|
|
|
/^BEGIN:VEVENT/ {
|
|
|
|
# start of an event: initialize global values used for each event
|
2022-07-24 01:25:24 +02:00
|
|
|
start_date = "";
|
|
|
|
end_date = "";
|
2022-05-24 07:36:05 +02:00
|
|
|
entry = ""
|
|
|
|
id = ""
|
|
|
|
|
|
|
|
indescription = 0;
|
|
|
|
insummary = 0
|
|
|
|
inattendee = 0
|
|
|
|
inorganizer = 0
|
|
|
|
inlocation = 0
|
|
|
|
|
|
|
|
location = ""
|
|
|
|
status = ""
|
|
|
|
summary = ""
|
|
|
|
attendee = ""
|
|
|
|
organizer = ""
|
|
|
|
|
|
|
|
rrend = ""
|
|
|
|
rcount = ""
|
|
|
|
intfreq = ""
|
2022-07-24 01:25:24 +02:00
|
|
|
idx = 0
|
2022-05-24 07:36:05 +02:00
|
|
|
|
|
|
|
delete people_attending;
|
|
|
|
delete people_partstat;
|
|
|
|
delete people_rsvp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/^[A-Z]/ {
|
|
|
|
if (attendee != "" && inattendee==1)
|
|
|
|
add_attendee(attendee)
|
|
|
|
|
|
|
|
if (organizer != "" && inorganizer==1)
|
|
|
|
organizer = find_full_name(organizer)
|
|
|
|
|
|
|
|
indescription = 0;
|
|
|
|
insummary = 0;
|
|
|
|
inattendee = 0;
|
|
|
|
inorganizer = 0;
|
|
|
|
inlocation = 0;
|
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^DTSTART[:;]/ {
|
|
|
|
tz = get_value($0, "TZID=[^:;]*", "=")
|
|
|
|
start_date = datetimestring($2, tz);
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^DTEND[:;]/ {
|
|
|
|
tz = get_value($0, "TZID=[^:;]*", "=")
|
2022-05-24 07:36:05 +02:00
|
|
|
end_date = datetimestring($2, tz);
|
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^RRULE[:]/ {
|
|
|
|
freq = get_value($0, "FREQ=[^:;]*", "=")
|
|
|
|
interval = get_value($0, "INTERVAL=[^:;]*", "=")
|
|
|
|
rrend = get_value($0, "UNTIL=[^:;]*", "=")
|
|
|
|
rcount = get_value($0, "COUNT=[^:;]*", "=")
|
|
|
|
intfreq = tolower(freq)
|
|
|
|
if (interval != "")
|
|
|
|
intfreq = " +" interval intfreq
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^METHOD/ {
|
|
|
|
method = $2
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^UID/ {
|
|
|
|
id = $2
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^STATUS/ {
|
|
|
|
status = $2
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^DESCRIPTION/ {
|
|
|
|
entry = entry $2
|
|
|
|
indescription = 1;
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
/^SUMMARY/ {
|
|
|
|
summary = $2
|
|
|
|
insummary = 1;
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/^ORGANIZER/ {
|
2022-07-24 01:25:24 +02:00
|
|
|
organizer = $0
|
2022-05-24 07:36:05 +02:00
|
|
|
inorganizer = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/^LOCATION/ {
|
2022-07-24 01:25:24 +02:00
|
|
|
location = unescape($2, 0);
|
2022-05-24 07:36:05 +02:00
|
|
|
inlocation = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/^ATTENDEE/ {
|
2022-07-24 01:25:24 +02:00
|
|
|
attendee = $0
|
2022-05-24 07:36:05 +02:00
|
|
|
inattendee = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/^END:VEVENT/ {
|
|
|
|
#output event
|
2022-07-24 01:25:24 +02:00
|
|
|
if (method != "") {
|
|
|
|
printf "\n This is a meeting %s\n\n", method
|
|
|
|
}
|
|
|
|
fmt = " %-14s%s\n"
|
2022-05-24 07:36:05 +02:00
|
|
|
is_duplicate = (id in UIDS);
|
|
|
|
if(is_duplicate == 0) {
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "SUMMARY", unescape(summary, 0)
|
|
|
|
if(location != "")
|
|
|
|
printf fmt, "LOCATION", location
|
2022-05-24 07:36:05 +02:00
|
|
|
if(organizer != "")
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "ORGANIZER", organizer
|
|
|
|
for (idx in people_attending) {
|
|
|
|
printf fmt, "ATTENDEE [" idx "]", people_attending[idx]
|
|
|
|
partstat = people_partstat[idx]
|
2022-05-24 07:36:05 +02:00
|
|
|
if (partstat != "") {
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "", "STATUS\t" partstat
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
2022-07-24 01:25:24 +02:00
|
|
|
rsvp = people_rsvp[idx]
|
2022-05-24 07:36:05 +02:00
|
|
|
if (rsvp != "") {
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "", "RSVP\t" rsvp
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "START", start_date
|
|
|
|
printf fmt, "END", end_date
|
2022-05-24 07:36:05 +02:00
|
|
|
if (intfreq != "") {
|
2022-07-24 01:25:24 +02:00
|
|
|
printf "\n"fmt, "RECURRENCE", intfreq
|
2022-05-24 07:36:05 +02:00
|
|
|
if (rcount != "")
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "COUNTS", rcount
|
2022-05-24 07:36:05 +02:00
|
|
|
if (rrend != "")
|
2022-07-24 01:25:24 +02:00
|
|
|
printf fmt, "END DATE", rrend
|
2022-05-24 07:36:05 +02:00
|
|
|
|
|
|
|
}
|
2022-07-24 01:25:24 +02:00
|
|
|
if(entry != "")
|
|
|
|
print "\n" unescape(entry, 1);
|
2022-05-24 07:36:05 +02:00
|
|
|
UIDS[id] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function unescape(input, preserve_newlines)
|
|
|
|
{
|
2022-07-24 01:25:24 +02:00
|
|
|
ret = input
|
|
|
|
gsub(/\\,/, ",", ret)
|
|
|
|
gsub(/\\;/, ";", ret)
|
2022-05-24 07:36:05 +02:00
|
|
|
if (preserve_newlines)
|
2022-07-24 01:25:24 +02:00
|
|
|
gsub(/\\n/, "\n", ret)
|
2022-05-24 07:36:05 +02:00
|
|
|
else
|
2022-07-24 01:25:24 +02:00
|
|
|
gsub(/\\n/, " ", ret)
|
2022-05-24 07:36:05 +02:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
function datetimestring(input, tzInput)
|
2022-05-24 07:36:05 +02:00
|
|
|
{
|
2022-07-24 01:25:24 +02:00
|
|
|
timestr = input
|
|
|
|
pos = index(timestr, "T")
|
|
|
|
if (pos < 0) {
|
|
|
|
return timestr
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
date = substr(timestr, 1, pos)
|
|
|
|
time = substr(timestr, pos+1, length(timestr))
|
2022-05-24 07:36:05 +02:00
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
year = substr(date, 1, 4)
|
|
|
|
month = substr(date, 5, 2)
|
|
|
|
day = substr(date, 7, 2)
|
2022-05-24 07:36:05 +02:00
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
hour = substr(time, 1, 2)
|
|
|
|
min = substr(time, 3, 2)
|
|
|
|
sec = substr(time, 5, 2)
|
2022-05-24 07:36:05 +02:00
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
return sprintf("%4d/%02d/%02d %02d:%02d:%02d %s", year, month, day, hour, min, sec, tzInput)
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_attendee(attendee)
|
|
|
|
{
|
|
|
|
CN = find_full_name(attendee)
|
|
|
|
if (CN != "") {
|
2022-07-24 01:25:24 +02:00
|
|
|
idx = idx + 1
|
|
|
|
people_attending[idx] = CN;
|
|
|
|
people_partstat[idx] = get_value(attendee, "PARTSTAT=[^;:]+", "=")
|
|
|
|
people_rsvp[idx] = get_value(attendee, "RSVP=[^;:]+", "=")
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
function find_full_name(line)
|
2022-05-24 07:36:05 +02:00
|
|
|
{
|
2022-07-24 01:25:24 +02:00
|
|
|
name = get_value(line, "CN=[^;:]+", "=")
|
|
|
|
email = get_value(line, "(mailto|MAILTO):[^;]+", ":")
|
2022-05-24 07:36:05 +02:00
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
if (name == "") {
|
|
|
|
return sprintf("<%s>", email)
|
|
|
|
} else {
|
|
|
|
return sprintf("%s <%s>", name, email)
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 01:25:24 +02:00
|
|
|
function get_value(line, regexp, sep) {
|
|
|
|
value = ""
|
|
|
|
match(line, regexp)
|
|
|
|
{
|
|
|
|
z = split(substr(line,RSTART,RLENGTH),data,sep)
|
|
|
|
if (z > 1) {
|
|
|
|
value = data[2]
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-24 01:25:24 +02:00
|
|
|
return value
|
2022-05-24 07:36:05 +02:00
|
|
|
}
|