line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Mail::Addressbook::Convert::Csv - convert to and from CSV formatted addressbooks |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use strict; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Csv; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $csv = new Mail::Addressbook::ConvertCsv(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $CsvInFile ="csvSample.txt"; # name of the file containing the csv data |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Convert Csv to Standard Intermediate format |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# see documentation for details on format. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $raIntermediate = $csv->scan(\$CsvInFile); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# This will also work |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#my @CsvInArray = @arrayContainingTheCsvData; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#my $raIntermediate = $csv->scan(\@CsvInArray); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Convert back to Csv |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $raCsvOut = $csv->output($raIntermediate); |
31
|
|
|
|
|
|
|
# a reference to an array containing a csv file. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
print join "", @$raIntermediate; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print "\n\n\n\n"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
print join "", @$raCsvOut; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 REQUIRES |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Perl, version 5.001 or higher |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Carp |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This module is meant to be used as part of the Mail::Addressbook::Convert distribution. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
It can convert a Csv addressbook to a Standard Intermediate format(STF) and a STF to Csv |
50
|
|
|
|
|
|
|
As part of the larger distribution, it will allow conversion between Csv and many other |
51
|
|
|
|
|
|
|
formats. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
To use to convert between Csv and Eudora as an example, you would do the following |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Csv; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Eudora; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $Csv = new Mail::Addressbook::Convert::Csv(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $Eudora = new Mail::Addressbook::Convert::Eudora(); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $csvInFile ="csvSample.txt"; # name of the file containing the Csv data |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $raIntermediate = $Csv->scan(\$csvInFile); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $raEudora = $Eudora->output($raIntermediate); # reference to an array containing a Eudora addressbook |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DEFINITIONS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Standard Intermediate Format(STF) : |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The addressbook format that is used as an intermediate |
75
|
|
|
|
|
|
|
between conversions. It is rfc822 compliant and can |
76
|
|
|
|
|
|
|
be used directly as a Eudora addressbook. Do not use |
77
|
|
|
|
|
|
|
a Eudora addressbook as an STF. Some versions of |
78
|
|
|
|
|
|
|
Eudora use a format, that while RFC822 compliant, will |
79
|
|
|
|
|
|
|
not work as an STF. Run the Eudora addressbook |
80
|
|
|
|
|
|
|
through $Eudora->scan() |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Csv addressbook: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The comma separated columns are described below. Only the first one is mandatory. |
86
|
|
|
|
|
|
|
They may be enclosed in quotes. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
E-mail address. |
89
|
|
|
|
|
|
|
Name 1 Usually first name or full name. |
90
|
|
|
|
|
|
|
Name 2 Usually last name or leave blank |
91
|
|
|
|
|
|
|
Alias A unique alias, if it is not unique, it will be made unique. |
92
|
|
|
|
|
|
|
If it is left blank, a unique alias will be produced from |
93
|
|
|
|
|
|
|
the name portion of the e-mail address (the part to the left of the "@" sign). |
94
|
|
|
|
|
|
|
Comment |
95
|
|
|
|
|
|
|
In the following columns, as many as needed, put the names of any mailing lists |
96
|
|
|
|
|
|
|
(address list, distribution lists, etc.) that you want this address to be included in. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Two Examples: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Using only column 1 |
101
|
|
|
|
|
|
|
jdavidson@interguru.com |
102
|
|
|
|
|
|
|
Using Columns 1 and 4 |
103
|
|
|
|
|
|
|
jdavidson@interguru.com,,jhd |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A full Example ------------------------------------------------ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
jhd@radix.net,Joe,Davidson1,jhd,comment1,lista |
110
|
|
|
|
|
|
|
jdavidson@interguru.com,Joe,Davidson2,,,lista,listb |
111
|
|
|
|
|
|
|
jhd@radix.net,Joe,Davidson3,,comment3 |
112
|
|
|
|
|
|
|
jhd@radix.net,Joe,Davidson4,,comment4,listb,listc |
113
|
|
|
|
|
|
|
kingtut@noplace.edu,King Tut |
114
|
|
|
|
|
|
|
queeenofsheba@kush.com |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
------------------------------------------------------ |
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 new |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
no arguments needed. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 scan |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Input : a reference to an array containing a csv file or a reference to a scalar containing |
126
|
|
|
|
|
|
|
the file name with the csv data. |
127
|
|
|
|
|
|
|
Returns: a reference to a STF ( see above). |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 output |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Input: a reference to a STF ( see above). |
132
|
|
|
|
|
|
|
Returns : a reference to an array containing a csv file. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 LIMITATIONS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This only converts email address, aliases, and mailing lists. Phone numbers, |
138
|
|
|
|
|
|
|
postal addresses and other such data are not converted. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 REFERENCES |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 HISTORY |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This code is derived from the code used on www.interguru.com/mailconv.htm . The site |
148
|
|
|
|
|
|
|
has been up since 1996 ( but ldif was only included on 1997, when Netscape 3 started |
149
|
|
|
|
|
|
|
using it.) The site gets about 8000 unique visitors a month, many of whom make addressbook |
150
|
|
|
|
|
|
|
conversions. The code has been well tested. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 FUTURE DIRECTIONS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SEE ALSO |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 BUGS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 CHANGES |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Original Version 2001-Sept-09 |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright (c) 2001 Joe Davidson. All rights reserved. |
170
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
171
|
|
|
|
|
|
|
and/or modify it under the terms of the Perl Artistic License |
172
|
|
|
|
|
|
|
(see http://www.perl.com/perl/misc/Artistic.html). or the |
173
|
|
|
|
|
|
|
GPL copyleft license ( http://www.gnu.org/copyleft/gpl.html) |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 AUTHOR |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Mail::Addressbook::Convert was written by Joe Davidson in 2001. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
183
|
|
|
|
|
|
|
|
184
|
1
|
|
|
1
|
|
5906
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
185
|
|
|
|
|
|
|
|
186
|
1
|
|
|
1
|
|
727
|
use Mail::Addressbook::Convert::Genr; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
85
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
package Mail::Addressbook::Convert::Csv; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
1
|
|
|
1
|
|
27
|
use 5.001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
175
|
|
196
|
|
|
|
|
|
|
@ISA = qw { Mail::Addressbook::Convert::Genr }; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
############# Constructor ########################################## |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# new is inherited |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
###################################################################### |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub scan |
206
|
|
|
|
|
|
|
{ |
207
|
1
|
|
|
1
|
1
|
9
|
my $Csv = shift; |
208
|
1
|
|
|
|
|
2
|
my $inputParm=shift; |
209
|
1
|
|
|
|
|
11
|
$Csv->setfileFormat("csv"); |
210
|
1
|
|
|
|
|
8
|
$Csv->SUPER::scan($inputParm); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
# sub output is inherited from genr. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub output |
217
|
|
|
|
|
|
|
{ |
218
|
1
|
|
|
1
|
1
|
8
|
my $Csv = shift; |
219
|
1
|
|
|
|
|
3
|
my $inputParm=shift; |
220
|
1
|
|
|
|
|
5
|
$Csv->setfileFormat("csv"); |
221
|
1
|
|
|
|
|
16
|
$Csv->SUPER::output($inputParm); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |