line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Mail::Addressbook::Convert::Pine - convert to and from Pine formatted addressbooks |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use strict; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Pine; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $pine = new Mail::Addressbook::Convert::Pine(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $PineInFile ="pineSample.txt"; # name of the file containing the Ldif data |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Convert Pine to Standard Intermediate format |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# see documentation for details on format. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $raIntermediate = $pine->scan(\$PineInFile); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# This will also work |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#my @PineInArray = @arrayContainingThePineData; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#my $raIntermediate = $pine->scan(\@PineInArray); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Convert back to Pine |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $raPineOut = $pine->output($raIntermediate); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
print join "", @$raIntermediate; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
print "\n\n\n\n"; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
print join "", @$raPineOut; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 REQUIRES |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Perl, version 5.001 or higher |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Carp |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module is meant to be used as part of the Mail::Addressbook::Convert distribution. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
It can convert a Pine addressbook to a Standard Intermediate format(STF) and a STF to Pine |
49
|
|
|
|
|
|
|
As part of the larger distribution, it will allow conversion between Pine and many other |
50
|
|
|
|
|
|
|
formats. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
To use to convert between Pine and Eudora as an example, you would do the following |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Pine; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Mail::Addressbook::Convert::Eudora; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $Pine = new Mail::Addressbook::Convert::Pine(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $Eudora = new Mail::Addressbook::Convert::Eudora(); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $PineInFile ="pineSample.txt"; # name of the file containing the Pine data |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $raIntermediate = $Pine->scan(\$PineInFile); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $raEudora = $Eudora->output($raIntermediate); # reference to an array containing a Eudora addressbook |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DEFINITIONS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Standard Intermediate Format(STF) : |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The addressbook format that is used as an intermediate |
74
|
|
|
|
|
|
|
between conversions. It is rfc822 compliant and can |
75
|
|
|
|
|
|
|
be used directly as a Eudora addressbook. Do not use |
76
|
|
|
|
|
|
|
a Eudora addressbook as an STF. Some versions of |
77
|
|
|
|
|
|
|
Eudora use a format, that while RFC822 compliant, will |
78
|
|
|
|
|
|
|
not work as an STF. Run the Eudora addressbook |
79
|
|
|
|
|
|
|
through $Eudora->scan() |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Pine addressbook: |
82
|
|
|
|
|
|
|
A Pine addressbook. |
83
|
|
|
|
|
|
|
This module works on pine |
84
|
|
|
|
|
|
|
. |
85
|
|
|
|
|
|
|
You can find information on pine by searching |
86
|
|
|
|
|
|
|
for B on google.com or going to http://www.washington.edu/pine/. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 new |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
no arguments needed. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 scan |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Input : a reference to an array containing a pine file or a reference to a scalar containing |
98
|
|
|
|
|
|
|
the file name with the pine data. |
99
|
|
|
|
|
|
|
Returns: a reference to a STF ( see above). |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 output |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Input: a reference to a STF ( see above). |
104
|
|
|
|
|
|
|
Returns : a reference to an array containing a pine file. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 LIMITATIONS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This only converts email address, aliases, and mailing lists. Phone numbers, |
110
|
|
|
|
|
|
|
postal addresses and other such data are not converted. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 REFERENCES |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can find information on Pine at http://www.washington.edu/pine/ |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 HISTORY |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This code is derived from the code used on www.interguru.com/mailconv.htm . The site |
122
|
|
|
|
|
|
|
has been up since 1996 The site gets about 8000 unique visitors a month, many of whom make addressbook |
123
|
|
|
|
|
|
|
conversions. The code has been well tested. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 FUTURE DIRECTIONS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SEE ALSO |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
http://www.washington.edu/pine/ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 BUGS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 CHANGES |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Original Version 2001-Sept-09 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Copyright (c) 2001 Joe Davidson. All rights reserved. |
143
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
144
|
|
|
|
|
|
|
and/or modify it under the terms of the Perl Artistic License |
145
|
|
|
|
|
|
|
(see http://www.perl.com/perl/misc/Artistic.html). or the |
146
|
|
|
|
|
|
|
GPL copyleft license ( http://www.gnu.org/copyleft/gpl.html) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Mail::Addressbook::Convert was written by Joe Davidson in 2001. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
1
|
|
962
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
package Mail::Addressbook::Convert::Pine; |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
1
|
|
5
|
use Mail::Addressbook::Convert::Utilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
163
|
1
|
|
|
1
|
|
19
|
use 5.001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1365
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub new { |
166
|
3
|
|
|
3
|
1
|
282
|
bless {},shift; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
###################################################################### |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub scan { |
173
|
|
|
|
|
|
|
|
174
|
1
|
|
|
1
|
1
|
8
|
local $^W; #turn off warnings. This code was written without the -w flag, and is too difficult to patch it in. |
175
|
|
|
|
|
|
|
# |
176
|
1
|
|
|
|
|
2
|
my $Pine = shift; |
177
|
1
|
|
|
|
|
2
|
my $inputParm = shift; # reference to input ldif data as an array or reference to a |
178
|
|
|
|
|
|
|
# scalar containing the name of a file containing the Pine addresses. |
179
|
|
|
|
|
|
|
|
180
|
1
|
|
|
|
|
3
|
my $raPineArray= getInput($inputParm); |
181
|
1
|
|
|
|
|
3
|
my ($alias,$name,$address,$fcc,$comment); |
182
|
0
|
|
|
|
|
0
|
my ($lastname , @names, @outputFile); |
183
|
|
|
|
|
|
|
|
184
|
1
|
|
|
|
|
4
|
my @pineArray = @$raPineArray; |
185
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
2
|
foreach my $k (0..$#pineArray) |
187
|
|
|
|
|
|
|
{ |
188
|
8
|
50
|
|
|
|
18
|
next if $pineArray[$k] =~/^#/; |
189
|
8
|
|
|
|
|
4
|
undef $comment; |
190
|
8
|
|
|
|
|
20
|
($alias,$name,$address,$fcc,$comment) = split(/\t/, $pineArray[$k]); |
191
|
8
|
50
|
|
|
|
18
|
if ($address =~ /) |
192
|
|
|
|
|
|
|
{ |
193
|
0
|
|
|
|
|
0
|
(my $junk,$address) = split("<",$address); |
194
|
0
|
|
|
|
|
0
|
$address =~ s/>//; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
# Thanks to Erich Schraer |
197
|
|
|
|
|
|
|
# for suggestions to improve processing of names |
198
|
8
|
100
|
|
|
|
15
|
if ($name =~ /,/) |
199
|
|
|
|
|
|
|
{ # If name doesn't have a comma, leave alone |
200
|
5
|
|
|
|
|
11
|
@names = split(/,/, $name); # Split on the comma |
201
|
5
|
|
|
|
|
6
|
$lastname = shift(@names); |
202
|
5
|
|
|
|
|
8
|
$name = join(" ",@names,$lastname); |
203
|
5
|
|
|
|
|
12
|
$name =~ s/^ //; # get rid of space at beginning. |
204
|
|
|
|
|
|
|
} |
205
|
8
|
100
|
|
|
|
16
|
if ($address !~ /\,/) |
206
|
|
|
|
|
|
|
{ |
207
|
6
|
100
|
|
|
|
9
|
if ($name) |
208
|
|
|
|
|
|
|
{ |
209
|
5
|
|
|
|
|
12
|
push (@outputFile, "alias ".$alias. |
210
|
|
|
|
|
|
|
" \"".$name."\"<".$address. "\>\n") ; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else |
213
|
|
|
|
|
|
|
{ |
214
|
1
|
|
|
|
|
2
|
push (@outputFile, "alias ".$alias. |
215
|
|
|
|
|
|
|
" ".$address. "\n") ; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
else |
219
|
|
|
|
|
|
|
{ |
220
|
2
|
|
|
|
|
11
|
$address =~s/\(|\)//g; |
221
|
2
|
|
|
|
|
5
|
push (@outputFile, "alias ".$alias." ".$address. "\n") ; |
222
|
|
|
|
|
|
|
} |
223
|
8
|
50
|
|
|
|
17
|
if ($comment) |
224
|
|
|
|
|
|
|
{ |
225
|
0
|
|
|
|
|
0
|
push (@outputFile, "note ".$alias." ".$comment."\n"); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
} |
229
|
1
|
|
|
|
|
3
|
foreach (@outputFile) |
230
|
|
|
|
|
|
|
{ |
231
|
8
|
|
|
|
|
13
|
s/\r|\015|\013//; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
1
|
|
|
|
|
7
|
return \@outputFile; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
########################### sub output ####################### |
239
|
|
|
|
|
|
|
sub output |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
{ |
242
|
|
|
|
|
|
|
|
243
|
3
|
|
|
3
|
1
|
15
|
local $^W; #turn off warnings. This code was written without the -w flag, and is too difficult to patch it in. |
244
|
3
|
|
|
|
|
5
|
my $Pine = shift; |
245
|
3
|
|
|
|
|
4
|
my $raInputArray = shift; # reference to input Input data as an array |
246
|
|
|
|
|
|
|
|
247
|
3
|
|
|
|
|
73
|
my @inputArray = @$raInputArray; |
248
|
|
|
|
|
|
|
|
249
|
3
|
|
|
|
|
4
|
my (@outputFile, @indivalias, @middle,@indivaddr, %note, $i, $j, $k ); |
250
|
0
|
|
|
|
|
0
|
my ( @hold1, @lines, $alias, $rest, $commas, $name, @groupalias ); |
251
|
0
|
|
|
|
|
0
|
my (@groupaddr, $address); |
252
|
|
|
|
|
|
|
|
253
|
3
|
|
|
|
|
5
|
my $kk = 0; |
254
|
3
|
|
|
|
|
10
|
foreach $i (0..$#inputArray ) |
255
|
|
|
|
|
|
|
{ |
256
|
38
|
|
|
|
|
46
|
$inputArray[$i] =~ s/\r//g; |
257
|
38
|
100
|
|
|
|
78
|
if ($inputArray[$i] =~/^note/) |
258
|
|
|
|
|
|
|
{ |
259
|
6
|
|
|
|
|
18
|
@hold1 = split (" ",$inputArray[$i],3); |
260
|
6
|
|
|
|
|
15
|
$note{"$hold1[1]"} = $hold1[2]; |
261
|
6
|
|
|
|
|
31
|
$note{"$hold1[1]"} =~ s/\n|\r//g; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
else |
264
|
|
|
|
|
|
|
{ |
265
|
32
|
|
|
|
|
41
|
$lines[$kk] = $inputArray[$i]; |
266
|
32
|
|
|
|
|
71
|
$lines[$kk] =~ s/alias //g; |
267
|
32
|
|
|
|
|
45
|
$kk++; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
3
|
|
|
|
|
9
|
foreach $i (0..$#lines ) |
272
|
|
|
|
|
|
|
{ |
273
|
32
|
50
|
|
|
|
71
|
if ($lines[$i] =~/^\"/) #alais starts with quote. |
274
|
|
|
|
|
|
|
{ |
275
|
0
|
|
|
|
|
0
|
$lines[$i]=substr($lines[$i],1) ; # get rid of first quote. |
276
|
0
|
|
|
|
|
0
|
$lines[$i] =~ /(.+[^\"])\"(.*)/; |
277
|
0
|
|
|
|
|
0
|
$alias = $1; |
278
|
0
|
|
|
|
|
0
|
$rest = $2; |
279
|
0
|
|
|
|
|
0
|
$alias =~ s/\s//g; # get rid of spaces |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
else |
282
|
|
|
|
|
|
|
{ |
283
|
32
|
|
|
|
|
82
|
$lines[$i] =~ /(\S+)(.+)/;# match the alias and the rest |
284
|
32
|
|
|
|
|
52
|
$alias = $1; |
285
|
32
|
|
|
|
|
51
|
$rest = $2; |
286
|
|
|
|
|
|
|
} |
287
|
32
|
|
|
|
|
79
|
my $commas_outside_quotes = &commas_outside_quotes($rest); |
288
|
32
|
100
|
|
|
|
65
|
if ($commas_outside_quotes) |
289
|
|
|
|
|
|
|
# There are commas not enclosed in quotes |
290
|
|
|
|
|
|
|
{ #we have a group list. |
291
|
10
|
|
|
|
|
22
|
$groupalias[$j] = $alias; |
292
|
10
|
|
|
|
|
16
|
$groupaddr[$j] = $rest; |
293
|
10
|
|
|
|
|
219
|
$groupaddr[$j] =~ s/\s*//g; # get rid of all spaces |
294
|
10
|
|
|
|
|
21
|
$j++ |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
else # an individual address |
297
|
|
|
|
|
|
|
{ |
298
|
22
|
|
|
|
|
42
|
$indivalias[$k] = $alias; |
299
|
22
|
|
|
|
|
30
|
$middle[$k] = "\t\t"; |
300
|
22
|
100
|
|
|
|
56
|
if ( $rest =~ /) # compound address |
301
|
|
|
|
|
|
|
{ |
302
|
19
|
|
|
|
|
50
|
($name,$address) = split(/,$rest); |
303
|
19
|
|
|
|
|
40
|
$address =~s/>//; |
304
|
19
|
|
|
|
|
49
|
$name =~ s/\"//g; |
305
|
19
|
|
|
|
|
26
|
$name =~ s/\'//g; |
306
|
19
|
|
|
|
|
22
|
$name .= ","; |
307
|
19
|
100
|
|
|
|
73
|
if ($name =~/(\S+)\s+(\S+)/)# name in form of |
308
|
|
|
|
|
|
|
# two words (I assume firstname, lastname ) |
309
|
|
|
|
|
|
|
{ |
310
|
15
|
|
|
|
|
37
|
$name = $2.",".$1; |
311
|
|
|
|
|
|
|
} |
312
|
19
|
|
|
|
|
41
|
$middle[$k] = "\t".$name."\t"; |
313
|
19
|
|
|
|
|
43
|
$middle[$k] =~ s/,,/,/; |
314
|
19
|
|
|
|
|
29
|
$rest = $address; |
315
|
|
|
|
|
|
|
} |
316
|
22
|
|
|
|
|
30
|
$indivaddr[$k] = $rest; |
317
|
22
|
|
|
|
|
41
|
$k++ |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
3
|
|
|
|
|
11
|
foreach $i (0..$k-1) |
322
|
|
|
|
|
|
|
{ |
323
|
22
|
|
|
|
|
83
|
push (@outputFile, $indivalias[$i]."$middle[$i]".$indivaddr[$i] |
324
|
|
|
|
|
|
|
."\t\t".$note{"$indivalias[$i]"}."\n"); |
325
|
|
|
|
|
|
|
} |
326
|
3
|
|
|
|
|
10
|
foreach $i (0..$j -1) |
327
|
|
|
|
|
|
|
{ |
328
|
10
|
|
|
|
|
49
|
push( @outputFile, $groupalias[$i]."\t".$groupalias[$i] |
329
|
|
|
|
|
|
|
."\t(".$groupaddr[$i].")\t\t".$note{"$groupalias[$i]"}."\n"); |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
|
334
|
3
|
|
|
|
|
37
|
return \@outputFile; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
########################### end sub output ####################### |
340
|
|
|
|
|
|
|
1; |