3 # mutt.vcard.filter - vcard filter for use with the mutt autoview facility
4 # Copyright (C) 1997,1998,1999 David A Pearson
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the license, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # This little perl script is a simple filter for text/x-vcard
21 # attachments. I'm pretty sure I've *not* included everything
22 # possible in here, but it "works for me". Feel free to improve
23 # in any way you see fit.
25 # Here is how I use it. In my ~/.mutt_mailcap (use your filename of
26 # choice) I have the following entry:
28 # text/x-vcard; mutt.vcard.filter; copiousoutput
30 # All you then need to do is add a line like:
32 # auto_view text/x-vcard
34 # to your ~/.muttrc (use your filename of choice).
36 # All comments/flames/feedback can be directed to:
38 # davep@hagbard.demon.co.uk
61 if ( /^fn:\s*(.*)$/i )
65 elsif ( /^n:\s*(.*);\s*(.*)$/i )
67 @additional = ( "", "Additional information:", "" ) if $#additional == -1;
69 @additional = ( @additional, "Last Name:\t$1", "First Name:\t$2" );
71 elsif ( /^title:\s*(.*)$/i )
75 elsif ( /^org:\s*(.*)$/i )
79 elsif ( /^adr:\s*(.*)$/i )
85 @address = split( /;/, $addr );
87 elsif ( /^email;\s*(.*?):\s*(.*)$/i || /^tel;\s*(.*?):\s*(.*)$/i )
92 @contacts = ( @contacts, uc( substr( $type, 0, 1 ) ) .
93 substr( $type, 1 ) . ": $value" );
95 elsif ( /^note:\s*(.*)$/i )
97 @notes = ( "" ) if $#notes == -1;
98 @notes = ( @notes, $1 );
102 elsif ( /^=.{2}=$/ && $found_note )
108 @notes = ( "" ) if $#notes == -1;
109 @notes = ( @notes, $line );
111 elsif ( /^end:\s*vcard$/i )
118 $in_card = /^begin:\s*vcard\s*$/i;
122 @address = ( $org, @address ) if $org;
123 @address = ( $title, @address ) if $title;
124 @address = ( $name, @address ) if $name;
127 @
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
128 $addr_line, $contact_line
131 $len = $#address > $#contacts ?
$#address : $#contacts;
133 print "" . ( "=" x
76 ) . "\n";
135 for ( $i = 0; $i <= $len; $i++ )
137 $addr_line = $i <= $#address ?
$address[ $i ] : "";
138 $contact_line = $i <= $#contacts ?
$contacts[ $i ] : "";
142 for ( $i = 0; $i <= $#notes; $i++ )
144 print "$notes[ $i ]\n";
147 for ( $i = 0; $i <= $#additional; $i++ )
149 print "$additional[ $i ]\n";
152 print "" . ( "=" x
76 ) . "\n";