summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartyn Smith <martyn@catalyst.net.nz>2008-04-05 16:39:44 +1300
committerMartyn Smith <martyn@dollyfish.net.nz>2008-04-05 16:39:44 +1300
commit70dce9b16ec223090749cca28c5056472eba6b42 (patch)
tree228b4c46e53077be7ba562eacf21741f86589d28
downloadmutt-filters-70dce9b16ec223090749cca28c5056472eba6b42.zip
Initial revision
-rw-r--r--README22
-rwxr-xr-xvcalendar-filter58
2 files changed, 80 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..a138aba
--- /dev/null
+++ b/README
@@ -0,0 +1,22 @@
+This is a collection (okay, currently one) of scripts that can be used to
+filter non-text/plain messages in mutt so they're readable in the internal
+pager (in a simple text/plain representation)
+
+You need something like this in your muttrc ...
+
+autoview text/calendar
+alternative_order text/plain text/html text/*
+
+which instructs mutt that the text/calendar MIME type can be automatically
+viewed, but you prefer to see text/plain and text/html first.
+
+Lastly, in your mailcap (either /etc/mailcap or ~/.mailcap) you need something
+like ...
+
+text/calendar; /path/to/vcalendar-filter; copiousoutput
+
+Any problems/bugs/improvements or feedback of any type is welcome.
+
+martyn@dollyfish.net.nz
+
+http://dollyfish.net.nz/projects/mutt-filters
diff --git a/vcalendar-filter b/vcalendar-filter
new file mode 100755
index 0000000..9d97b95
--- /dev/null
+++ b/vcalendar-filter
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+# This script takes a simple VCALENDAR file as input on STDIN and produces a
+# human readable text/plain representation of it on STDOUT
+#
+# It has been designed for use with mutt's auto_view config option, see the
+# README file for more details
+
+use strict;
+use warnings;
+use Data::ICal;
+use Text::Autoformat;
+
+my $body = eval { local $/ = undef; <> };
+my $calendar = Data::ICal->new(data => $body);
+
+foreach my $entry ( @{$calendar->{entries}} ) {
+ my $properties;
+
+ foreach my $property ( keys %{$entry->properties} ) {
+ next unless defined $entry->property($property);
+ $properties->{$property} = join(', ', map { $_->decoded_value } @{$entry->property($property)});
+ if ( $property eq 'description' ) {
+ $properties->{$property} = eval qq{"$properties->{$property}"};
+
+ $properties->{$property} = autoformat $properties->{$property}, {
+ all => 1,
+ left => 15,
+ };
+ $properties->{$property} =~ s/^\s*// if defined $properties->{$property};
+ }
+ elsif ( $property =~ m{ \A dt (?: start | end ) \z }xms ) {
+ if ( $properties->{$property} =~ m{ (\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d) }xms ) {
+ $properties->{$property} = "$1-$2-$3 $4:$5";
+ }
+ }
+ }
+
+ if ( $entry->ical_entry_type eq 'VTIMEZONE' ) {
+ unless ( defined $properties->{tzid} and $properties->{tzid} =~ m{Pacific/Auckland} ) {
+ print "Timezone : ", $properties->{tzid}, "\n";
+ print "\n";
+ }
+ }
+ elsif ( $entry->ical_entry_type eq 'VEVENT' ) {
+ foreach my $key ( qw(summary BR description BR location organizer dtstart dtend) ) {
+ if ( $key eq 'BR' ) {
+ print "\n";
+ next;
+ }
+ next unless defined $properties->{$key};
+ printf "%-12s: %s\n", ucfirst $key, $properties->{$key};
+ }
+ }
+ else {
+ print "WARNING: Unknown entry type: ", $entry->ical_entry_type, "\n";
+ }
+}