This file is indexed.

/usr/share/perl5/Text/vCard/Addressbook.pm is in libtext-vcard-perl 2.13-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package Text::vCard::Addressbook;
{
  $Text::vCard::Addressbook::VERSION = '2.13';
}

use Carp;
use strict;
use warnings;
use File::Slurp;
use Text::vFile::asData;
use Text::vCard;

# See this module for your basic parser functions
use base qw(Text::vFile::asData);

=head1 NAME

Text::vCard::Addressbook - a package to parse, edit and create multiple vCards (RFC 2426) 

=head1 SYNOPSIS

To read an existing file:

  use Text::vCard::Addressbook;

  my $address_book = Text::vCard::Addressbook->new(
      { 'source_file' => '/path/to/address.vcf', } );

  foreach my $vcard ( $address_book->vcards() ) {
      print "Got card for " . $vcard->fullname() . "\n";
  }


To create a new file:

  use Text::vCard::Addressbook;

  my $address_book = Text::vCard::Addressbook->new();
  my $vcard        = $ab->add_vcard;
  $vcard->fullname('Foo Bar');
  $vcard->EMAIL('foo@bar.com');

  open my $out, '>', 'address.vcf' or die;
  print $out $address_book->export;

=head1 DESCRIPTION

This package provides an API to reading / editing and creating
multiple vCards. A vCard is an electronic business card. This package has
been developed based on rfc2426.

You will find that many applications (Apple Address book, MS Outlook,
Evolution etc) can export and import vCards. 

=head1 READING IN VCARDS


=head2 load()

  use Text::vCard::Addressbook;

  # Read in from a list of files
  my $address_book
      = Text::vCard::Addressbook->load( [ 'foo.vCard', 'Addresses.vcf' ] );

This method will croak if it is unable to read in any of the files.

=cut

sub load {
    my ( $proto, $files ) = @_;

    my $self = __PACKAGE__->new();

    foreach my $file ( @{$files} ) {
        croak "Unable to read file $file" unless -r $file;
        $self->import_data( scalar read_file($file) );
    }

    return $self;

}

=head2 import_data()

  $address_book->import_data($value);

This method imports data directly from a string.

=cut

sub import_data {
    my ( $self, $value ) = @_;

    $self->_process_text($value);
}

=head2 new()
  
  # Read in from just one file
  my $address_book = Text::vCard::Addressbook->new(
      { 'source_file' => '/path/to/address.vcf', } );


This method will croak if it is unable to read in the source_file.

  # File already in a string
  my $address_book
      = Text::vCard::Addressbook->new( { 'source_text' => $source_text, } );


  # Create a new address book
  my $address_book = Text::vCard::Addressbook->new();

Looping through all vcards in an address book.
  
  foreach my $vcard ( $address_book->vcards() ) {
      $vcard->...;
  }

  
=cut

sub new {
    my ( $proto, $conf ) = @_;
    my $class = ref($proto) || $proto;
    my $self = {};

    if ( defined $conf->{'source_file'} ) {

        # Need to read in source file
        croak "Unable to read file $conf->{'source_file'}\n"
            unless -r $conf->{'source_file'};
        $conf->{'source_text'} = read_file( $conf->{'source_file'} );
    }

    # create some where to store out individual vCard objects
    my @cards;
    $self->{'cards'} = \@cards;

    bless( $self, $class );

    # Process the text if we have it.
    $self->_process_text( $conf->{'source_text'} )
        if defined $conf->{'source_text'};

    return $self;
}

=head1 METHODS

=head2 add_vcard()

  my $vcard = $address_book->add_vcard();

This method creates a new empty L<Text::vCard> object, stores it in the
address book and return it so you can add data to it.

=cut

sub add_vcard {
    my $self  = shift;
    my $vcard = Text::vCard->new();
    push( @{ $self->{cards} }, $vcard );
    return $vcard;
}

=head2 vcards()

  my $vcards = $address_book->vcards();
  my @vcards = $address_book->vcards();

This method returns a reference to an array or an array of
vcards in this address book. This could be an empty list
if there are no entries in the address book.

=cut

sub vcards {
    my $self = shift;
    return wantarray ? @{ $self->{cards} } : $self->{cards};
}

=head2 set_encoding()

  $address_book->set_encoding('utf-8');

This method will add the string ';charset=utf-8' to each and 
every vCard entry. That does help in connection with e.g. an iPhone...

=cut

sub set_encoding {
    my ( $self, $coding ) = @_;
    $self->{'encoding'} |= '';
    $self->{'encoding'} = ";charset=$coding" if ( defined $coding );
    return $self->{'encoding'};
}

=head2 export()

  my $vcf_file = $address_book->export()

This method returns the vcard data in the vcf file format.

Please note there is no validation, you must ensure
that the correct nodes (FN,N,VERSION) are already added
to each vcard if you want to comply with RFC 2426.

This might not escape the results correctly
at the moment.

=cut

sub export {
    my $self = shift;
    my @lines;
    foreach my $vcard ( $self->vcards() ) {
        push @lines, 'BEGIN:VCARD';
        while ( my ( $node_type, $nodes ) = each %{ $vcard->{nodes} } ) {

            # Make sure all the nodes values are up to date
            my @export_nodes;
            foreach my $node ( @{$nodes} ) {
                my $name = $node_type;
                if ( $node->group() ) {

                    # Add the group in to the name
                    $name = $node->group() . '.' . $node_type;
                }

                my $param;
                $param = join( ',', ( $node->types() ) ) if $node->types();
                $name .= $self->set_encoding();
                $name .= ";TYPE=$param" if $param;
                push( @lines, "$name:" . $node->export_data );
            }
        }
        push @lines, 'END:VCARD';
    }
    my $vcf_file = join( "\r\n", @lines );
    $vcf_file .= "\r\n" if $vcf_file;
    return $vcf_file;
}

# PRIVATE METHODS

# Process a chunk of text, create Text::vCard objects and store in the address book
sub _process_text {
    my ( $self, $text ) = @_;

    # As data may handle \r - must ask richard
    $text =~ s/\r//g;

    if ( $text =~ /quoted-printable/i ) {

      # Edge case for 2.1 version
      #
      # http://tools.ietf.org/html/rfc2045#section-6.7 point (5),
      # lines containing quoted-printable encoded data can contain soft-line
      # breaks. These are indicated as single '=' sign at the end of the line.
      #
      # No longer needed in version 3.0:
      # http://tools.ietf.org/html/rfc2426 point (5)

        my $joinline = 0;

        my $out;
        foreach my $line ( split( "\n", $text ) ) {
            chomp($line);

            if ($joinline) {
                if ( $line =~ /=$/ ) {
                    $line =~ s/=$//;
                    $out .= $line;
                } else {
                    $joinline = 0;
                    $out .= $line . "\n";
                }
                next;
            }

            # find continued QP lines - could be done better
            if ( $line =~ /ENCODING=QUOTED-PRINTABLE/i && $line =~ /=$/ ) {

                $joinline = 1;    # join lines...

                $line =~ s/=$//;
                $out .= $line;
            } else {

                # add regular line;
                $out .= $line . "\n";
            }
        }
        $text = $out;

    }

    # Add error checking here ?
    my $asData = Text::vFile::asData->new;
    $asData->preserve_params(1);

    my $data = $asData->parse_lines( split( "\n", $text ) );
    foreach my $card ( @{ $data->{'objects'} } ) {

        # Run through each card in the data
        if ( $card->{'type'} =~ /VCARD/i ) {
            my $vcard = Text::vCard->new(
                { 'asData_node' => $card->{'properties'}, } );
            push( @{ $self->{'cards'} }, $vcard );
        } else {
            carp
                "This file contains $card->{'type'} data which was not parsed";
        }
    }

}

=head1 AUTHOR

Leo Lapworth, LLAP@cuckoo.org

=head1 COPYRIGHT

Copyright (c) 2003 Leo Lapworth. All rights reserved.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

=head1 ACKNOWLEDGEMENTS

The authors of L<Text::vFile::asData> for making my life so much easier.

=head1 SEE ALSO

L<Text::vCard>, L<Text::vCard::Node>

=cut

1;