diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-30 23:17:15 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-30 23:17:15 +0900 |
| commit | e05b1e51921016a8a83afa4bff06f97ab830033d (patch) | |
| tree | 70c0be7909023c703b9dc0d932c8e0d96d58d08d /bin | |
| parent | 696ce7215119801a3420f01b99e1db41984741c5 (diff) | |
updates
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/mutt.vcard.filter | 152 | ||||
| -rwxr-xr-x | bin/mw | 2 | ||||
| -rwxr-xr-x | bin/vcalendar-filter | 86 |
3 files changed, 239 insertions, 1 deletions
diff --git a/bin/mutt.vcard.filter b/bin/mutt.vcard.filter new file mode 100755 index 0000000..3a65a2d --- /dev/null +++ b/bin/mutt.vcard.filter @@ -0,0 +1,152 @@ +#!/usr/bin/perl -Tw + +# mutt.vcard.filter - vcard filter for use with the mutt autoview facility +# Copyright (C) 1997,1998,1999 David A Pearson +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the license, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# This little perl script is a simple filter for text/x-vcard +# attachments. I'm pretty sure I've *not* included everything +# possible in here, but it "works for me". Feel free to improve +# in any way you see fit. +# +# Here is how I use it. In my ~/.mutt_mailcap (use your filename of +# choice) I have the following entry: +# +# text/x-vcard; mutt.vcard.filter; copiousoutput +# +# All you then need to do is add a line like: +# +# auto_view text/x-vcard +# +# to your ~/.muttrc (use your filename of choice). +# +# All comments/flames/feedback can be directed to: +# +# davep@hagbard.demon.co.uk +# + +use strict; + +my $in_card = 0; +my @address = (); +my @contacts = (); +my @additional = (); +my @notes = (); +my $name = ""; +my $title = ""; +my $org = ""; +my $found_note = 0; +my $len; +my $i; +my $addr_line; +my $contact_line; + +while ( <> ) +{ + if ( $in_card ) + { + if ( /^fn:\s*(.*)$/i ) + { + $name = $1; + } + elsif ( /^n:\s*(.*);\s*(.*)$/i ) + { + @additional = ( "", "Additional information:", "" ) if $#additional == -1; + + @additional = ( @additional, "Last Name:\t$1", "First Name:\t$2" ); + } + elsif ( /^title:\s*(.*)$/i ) + { + $title = $1; + } + elsif ( /^org:\s*(.*)$/i ) + { + $org = $1; + } + elsif ( /^adr:\s*(.*)$/i ) + { + my $addr = $1; + + $addr =~ s/;+/;/g; + + @address = split( /;/, $addr ); + } + elsif ( /^email;\s*(.*?):\s*(.*)$/i || /^tel;\s*(.*?):\s*(.*)$/i ) + { + my $type = $1; + my $value = $2; + + @contacts = ( @contacts, uc( substr( $type, 0, 1 ) ) . + substr( $type, 1 ) . ": $value" ); + } + elsif ( /^note:\s*(.*)$/i ) + { + @notes = ( "" ) if $#notes == -1; + @notes = ( @notes, $1 ); + + $found_note = 1; + } + elsif ( /^=.{2}=$/ && $found_note ) + { + my $line = <>; + + chomp( $line ); + + @notes = ( "" ) if $#notes == -1; + @notes = ( @notes, $line ); + } + elsif ( /^end:\s*vcard$/i ) + { + $in_card = 0; + } + } + else + { + $in_card = /^begin:\s*vcard\s*$/i; + } +} + +@address = ( $org, @address ) if $org; +@address = ( $title, @address ) if $title; +@address = ( $name, @address ) if $name; + +format STDOUT = +@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +$addr_line, $contact_line +. + +$len = $#address > $#contacts ? $#address : $#contacts; + +print "" . ( "=" x 76 ) . "\n"; + +for ( $i = 0; $i <= $len; $i++ ) +{ + $addr_line = $i <= $#address ? $address[ $i ] : ""; + $contact_line = $i <= $#contacts ? $contacts[ $i ] : ""; + write; +} + +for ( $i = 0; $i <= $#notes; $i++ ) +{ + print "$notes[ $i ]\n"; +} + +for ( $i = 0; $i <= $#additional; $i++ ) +{ + print "$additional[ $i ]\n"; +} + +print "" . ( "=" x 76 ) . "\n"; @@ -339,7 +339,7 @@ Options allowed with -a: -x Password for account (recommended to be in double quotes) Options allowed with -d/-D: - -X Delete an account's local email too when deleting + -X Delete an account's local email too when deleting NOTE: Once at least one account is added, you can run \`mbsync -a\` to begin downloading mail. diff --git a/bin/vcalendar-filter b/bin/vcalendar-filter new file mode 100755 index 0000000..ffdf27a --- /dev/null +++ b/bin/vcalendar-filter @@ -0,0 +1,86 @@ +#!/usr/bin/perl + +# vcalendar-filter is a simple filter to give plain text representations of vcards +# Copyright (C) 2008 Martyn Smith +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# 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); + +# If parsing failed, try parsing as version 1.0 +$calendar = Data::ICal->new(data => $body, vcal10 => 1) unless $calendar; + +# If parsing failed, give up :-( +unless ( $calendar ) { + print "Unable to parse vcalendar: ", $calendar->error_message, "\n"; + print $body; + exit 1; +} + +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} = "$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' ) { + print '-' x 72, "\n"; + 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"; + } +} |
