Convert/Juno.pm untested

filter: Statementstmt 0.0% 0 / 97 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 177 CC 28 SCAR 64.5
CC
28
Cov
0%
scan
812.0
output
2.0
BEGIN
2.0
CRAP 632.0
1 =head1 NAME
2  
3 Mail::Addressbook::Convert::Juno -- convert from Juno addressbooks.
4  
5 =head1 SYNOPSIS
6  
7 use strict;
8  
9 use Mail::Addressbook::Convert::Juno;
10  
11 my $Juno = new Mail::Addressbook::Convert::Juno();
12  
13 my $JunoInFile ="junoSample.nv"; # name of the file containing the Juno data
14 # it is found in the Spry folder
15  
16 # Convert Juno to Standard Intermediate format
17  
18 # see documentation for details on format.
19  
20 my $raIntermediate = $Juno->scan(\$JunoInFile.nv);
21  
22 # This will also work
23  
24 #my @JunoInArray = @arrayContainingTheJunoData;
25  
26 #my $raIntermediate = $Juno->scan(\@JunoInArray);
27  
28 print join "", @$raIntermediate;
29  
30  
31  
32 =head1 REQUIRES
33  
34 Perl, version 5.001 or higher
35  
36 Carp
37  
38 =head1 DESCRIPTION
39  
40 This module is meant to be used as part of the Mail::Addressbook::Convert distribution.
41  
42 It can convert a Tsv addressbook to a Standard Intermediate format(STF) and a STF to TSV
43 As part of the larger distribution, it will allow conversion between Spry and many other
44 formats.
45  
46 To use to convert between Juno and Eudora as an example, you would do the following
47  
48 use Mail::Addressbook::Convert::Juno;
49  
50 use Mail::Addressbook::Convert::Eudora;
51  
52 my $Juno = new Mail::Addressbook::Convert::Juno();
53  
54 my $Eudora = new Mail::Addressbook::Convert::Eudora();
55  
56 my $junoInFile ="junoSampleFile.nv"; # name of the file containing the juno data
57  
58 my $raIntermediate = $Juno->scan(\$junoInFile);
59  
60 my $raEudora = $Eudora->output($raIntermediate); # reference to an array containing a Eudora addressbook
61  
62  
63 =head1 DEFINITIONS
64
65 Standard Intermediate Format(STF) :
66  
67 The addressbook format that is used as an intermediate
68 between conversions. It is rfc822 compliant and can
69 be used directly as a Eudora addressbook. Do not use
70 a Eudora addressbook as an STF. Some versions of
71 Eudora use a format, that while RFC822 compliant, will
72 not work as an STF. Run the Eudora addressbook
73 through $Eudora->scan()
74
75 Juno addressbook:
76  
77 use the file with a .nv extension as the input
78
79
80 ------------------------------------------------------
81 =head1 METHODS
82  
83 =head2 new
84  
85 no arguments needed.
86  
87 =head2 scan
88  
89 Input : a reference to an array containing a Juno file or a reference to a scalar containing
90 the file name with the Juno data. The file exists in the Juno folder with an ".nv"
91 extension.
92
93 Returns: a reference to a STF ( see above).
94  
95 =head2 output
96  
97 There is no output method. That is you cannot convert to a Juno format.
98  
99  
100 =head1 LIMITATIONS
101  
102 This only converts email address, aliases, and mailing lists. Phone numbers,
103 postal addresses and other such data are not converted.
104  
105  
106  
107 =head1 REFERENCES
108  
109  
110  
111
112  
113 =head1 HISTORY
114  
115 This code is derived from the code used on www.interguru.com/mailconv.htm . The site
116 has been up since 1996 ( but ldif was only included on 1997, when Netscape 3 started
117 using it.) The site gets about 8000 unique visitors a month, many of whom make addressbook
118 conversions. The code has been well tested.
119  
120 =head1 FUTURE DIRECTIONS
121  
122  
123  
124  
125 =head1 SEE ALSO
126  
127  
128  
129 =head1 BUGS
130  
131 =head1 CHANGES
132  
133 Original Version 2001-Sept-09
134
135 =head1 COPYRIGHT
136  
137 Copyright (c) 2001 Joe Davidson. All rights reserved.
138 This program is free software; you can redistribute it
139 and/or modify it under the terms of the Perl Artistic License
140 (see http://www.perl.com/perl/misc/Artistic.html). or the
141 GPL copyleft license ( http://www.gnu.org/copyleft/gpl.html)
142  
143  
144 =head1 AUTHOR
145  
146 Mail::Addressbook::Convert was written by Joe Davidson <jdavidson@interguru.com> in 2001.
147  
148 =cut
149  
150 #------------------------------------------------------------------------------
151  
152 use strict;
153  
154  
155  
156 package Mail::Addressbook::Convert::Juno;
157  
158 use Mail::Addressbook::Convert::Eudora;
159 use Mail::Addressbook::Convert::Utilities;
160 use Mail::Addressbook::Convert::PersistentUtilities;
161 use Carp;
162  
163  
164 use 5.001;
165  
166 use vars qw(@ISA );
167 @ISA = qw { Mail::Addressbook::Convert::Eudora };
168  
169 ############# Constructor ##########################################
170  
171 # new is inherited
172  
173
174 ######################################################################
175  
176 sub scan
177 {
178
179 my $Juno = shift;
180 my $inputParm=shift;
181
182 my $raJunoArray= getInput($inputParm);
183
184 my $perUtil = new Mail::Addressbook::Convert::PersistentUtilities();
185 my @outputFile;
186  
187 my $insideRecord = 0;
188
189 my (@hold,$type,$name, @hold1, @hold2,$email,$alias1,@list, %aliasOf, %isAlias);
190 my (@members, $n1, $hold2, $holdLine, %nameOf);
191
192
193 # First Loop
194 foreach (@$raJunoArray)
195 {
196 $insideRecord = 1 if /^Type/;
197 $insideRecord = 0 unless /\S/;
198 if ($insideRecord)
199 {
200 chomp;
201 @hold = split(':');
202 $type = $hold[1] if ($hold[0] =~ /Type/);
203 $name = $hold[1] if ($hold[0] =~ /Name/);
204 if ($name =~ /\,/)
205 {
206 @hold2 = split(/\,/,$name, 2);
207 $name = $hold2[1]." ".$hold2[0];
208 }
209
210 $name =~ s/^\s+|\s+$//g;
211 $email = $hold[1] if ($hold[0] =~ /Email/);
212 $alias1 = $hold[1] if ($hold[0] =~ /Alias/);
213 if ($hold[0] =~ /Member/)
214 {
215 push (@list , $hold[1])
216 }
217 }
218 else
219 {
220 if ($type =~ /Entry/ )
221 {
222 @hold1 = split('@',$email);
223 $alias1 = $hold1[0];
224 unless ($aliasOf{$email}
225 or $email !~ /\@/)
226 {
227 $aliasOf{$email} =
228 $perUtil->makeAliasUnique($alias1);
229 $isAlias{$aliasOf{$email}} = 1;
230 }
231 }
232 elsif ($type =~ /MList/ )
233 {
234 foreach (@list)
235 {
236 if (/@/ and not $aliasOf{$_})
237 {
238 my @holdB = split('@');
239 $aliasOf{$_} =
240 $perUtil->makeAliasUnique($holdB[0])
241 unless $aliasOf{$_};
242 }
243 }
244 }
245
246 $nameOf{$email} = $name;
247 undef $alias1;
248 undef $type;
249 undef $email;
250 undef $name;
251 }
252 }
253 # Second Loop
254 $insideRecord = 0;
255 foreach (@$raJunoArray)
256 {
257
258 $insideRecord = 1 if /^Type/;
259 $insideRecord = 0 unless /\S/;
260 if ($insideRecord)
261 {
262 chomp;
263 @hold = split(':');
264 $type = $hold[1] if ($hold[0] =~ /Type/);
265 $email = $hold[1] if ($hold[0] =~ /Email/);
266 $name = $hold[1] if ($hold[0] =~ /Name/);
267 push (@list , $hold[1])
268 if $hold[0] =~ /Member/;
269 push (@members , $hold[1])
270 if ( $hold[0] =~ /Member/);
271 }
272 else
273 {
274 if ($type =~ /Entry/ )
275 {
276 $n1 = qq("$nameOf{$email}")
277 if $nameOf{$email};
278 $hold2 =
279 qq(alias $aliasOf{$email} $n1<$email>\n);
280 $hold2 =~ s/\n|\r//g;
281 push (@outputFile, $hold2."\n")
282 if ($email =~ /\@/);
283 }
284 elsif ($type =~ /MList/ and $list[0])
285 {
286 $holdLine = qq(alias $name );
287 foreach (@members)
288 {
289 if ($isAlias{$_})
290 {
291 $holdLine .= $_.",";
292 }
293 else
294 {
295 $holdLine .= $aliasOf{$_}.",";
296 }
297 }
298 $holdLine =~ s/,$//;
299 $holdLine =~ s/ ,/ /;
300 $holdLine =~ s/,,/,/g;
301 $holdLine .="\n";
302 $holdLine =~ s/\n|\r//g;
303 push (@outputFile,$holdLine);
304 foreach (@members)
305 {
306 #print "JHD20 $_\n";
307 }
308 }
309
310 undef $type;
311 undef $email;
312 undef $name;
313 undef @members;
314 undef $n1;
315 }
316 }
317  
318
319 return $Juno->SUPER::scan(\@outputFile);
320  
321  
322 }
323  
324  
325 sub output
326 {
327 confess "\nJuno.pm does not have an output method. \n You cannot convert to Juno";
328  
329  
330 }
331  
332 1;