4 # @brief Extract text from a vCard file
6 # Copyright (C) 2016,2017 Olly Betts
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to
10 # deal in the Software without restriction, including without limitation the
11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 # sell copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 require Text::vCard::Addressbook;
33 # Exit with code 127 which omindex interprets as "filter not installed"
34 # and won't try further .msg files.
39 foreach my $file (@ARGV) {
43 dump_vcf('/dev/stdin');
48 my $address_book = Text::vCard::Addressbook->new({
49 'source_file' => $file
51 foreach my $vcard ($address_book->vcards()) {
60 print $sep if defined $sep;
63 foreach my $field (qw(
64 FN BDAY MAILER TZ TITLE ROLE NOTE PRODID REV SORT-STRING UID URL CLASS
65 EMAIL TEL NICKNAME)) {
66 # Ignore PHOTO for now.
67 # LABEL is in the sample in the EDRM set, but isn't handled properly
69 foreach my $node ($vcard->get($field)) {
70 defined $node or next;
72 my @types = grep {defined $_} $node->types();
74 print "(", join(", ", @types), ")";
76 print ": ", $node->value(), "\n";
80 foreach my $field (qw(ADR N GEO ORG)) {
81 foreach my $node ($vcard->get($field)) {
82 defined $node or next;
83 foreach my $method (@{ $Text::vCard::lookup{$field} }) {
84 my $res = $node->$method();
85 next unless defined $res;
86 if (ref($res) eq 'ARRAY') {
87 my @a = grep {$_ ne ''} @$res;
88 print "$field.$method: ", join("; ", @a) unless @a == 0;
90 print "$field.$method: ", $res, "\n" unless $res eq '';