File Coverage

blib/lib/Mail/Addressbook/Convert/Ccmail.pm
Criterion Covered Total %
statement 56 65 86.1
branch 13 16 81.2
condition 5 6 83.3
subroutine 7 8 87.5
pod 2 2 100.0
total 83 97 85.5


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Mail::Addressbook::Convert::Spry - from ccmail Addressbook
4              
5             =head1 SYNOPSIS
6              
7             use strict;
8              
9             use Mail::Addressbook::Convert::Ccmail;
10              
11             my $Ccmail = new Mail::Addressbook::Convert::Ccmail();
12              
13             my $ccMailInFile ="ccmailSample.txt"; # name of the file containing the ccmail data
14              
15              
16             # Convert ccmail to Standard Intermediate format
17              
18             # see documentation for details on format.
19              
20             my $raIntermediate = $Ccmail->scan(\$ccMailInFile);
21              
22             # This will also work
23              
24             #my @ccmailInArray = @arrayContainingTheccmailData;
25              
26             #my $raIntermediate = $Ccmail->scan(\@ccmailInArray);
27              
28              
29              
30              
31             print join "", @$raIntermediate;
32              
33              
34              
35             =head1 REQUIRES
36              
37             Perl, version 5.001 or higher
38              
39             Carp
40              
41             =head1 DESCRIPTION
42              
43             This module is meant to be used as part of the Mail::Addressbook::Convert distribution.
44              
45             It can convert a ccMail addressbook to a Standard Intermediate format(STF)
46             As part of the larger distribution, it will allow conversion between ccMail and many other
47             formats.
48              
49             To use to convert between ccMial and Eudora as an example, you would do the following
50              
51             use Mail::Addressbook::Convert::Ccmail;
52              
53             use Mail::Addressbook::Convert::Eudora;
54              
55             my $Ccmail = new Mail::Addressbook::Convert::Ccmail();
56              
57             my $Eudora = new Mail::Addressbook::Convert::Eudora();
58              
59             my $ccMailInFile ="ccmailSample.txt"; # name of the file containing the ccmail data
60              
61             my $raIntermediate = $Ccmail->scan(\$ccMailInFile);
62              
63             my $raEudora = $Eudora->output($raIntermediate); # reference to an array containing a Eudora addressbook
64              
65              
66             =head1 DEFINITIONS
67            
68             Standard Intermediate Format(STF) :
69              
70             The addressbook format that is used as an intermediate
71             between conversions. It is rfc822 compliant and can
72             be used directly as a Eudora addressbook. Do not use
73             a Eudora addressbook as an STF. Some versions of
74             Eudora use a format, that while RFC822 compliant, will
75             not work as an STF. Run the Eudora addressbook
76             through $Eudora->scan()
77            
78             ccMail addressbook:
79              
80             * There are two possible input files, you can use either one.
81            
82             1. Export your address list to a file, "ccmail.txt".If you have several files you can export them all,
83             and combine them with a word processor.
84             2. Use your private address book directly, you just pick up the file "privdir.ini".
85             It is in the ccmail sub-directory of your windows directory.
86            
87             * If you want to export from both files, you can combine both types of files and use them together.
88              
89              
90              
91             =head1 METHODS
92              
93             =head2 new
94              
95             no arguments needed.
96              
97             =head2 scan
98              
99             Input : a reference to an array containing a tsv file or a reference to a scalar containing
100             the file name with the tsv data.
101             Returns: a reference to a STF ( see above).
102              
103             =head2 output
104              
105             There is no output method. That is you cannot convert to a ccmail format.
106              
107              
108             =head1 LIMITATIONS
109              
110             This only converts email address, aliases, and mailing lists. Phone numbers,
111             postal addresses and other such data are not converted.
112              
113              
114              
115             =head1 REFERENCES
116              
117              
118              
119            
120              
121             =head1 HISTORY
122              
123             This code is derived from the code used on www.interguru.com/mailconv.htm . The site
124             has been up since 1996 ( but ldif was only included on 1997, when Netscape 3 started
125             using it.) The site gets about 8000 unique visitors a month, many of whom make addressbook
126             conversions. The code has been well tested.
127              
128             =head1 FUTURE DIRECTIONS
129              
130              
131              
132              
133             =head1 SEE ALSO
134              
135              
136              
137             =head1 BUGS
138              
139             =head1 CHANGES
140              
141             Original Version 2001-Sept-09
142            
143             =head1 COPYRIGHT
144              
145             Copyright (c) 2001 Joe Davidson. All rights reserved.
146             This program is free software; you can redistribute it
147             and/or modify it under the terms of the Perl Artistic License
148             (see http://www.perl.com/perl/misc/Artistic.html). or the
149             GPL copyleft license ( http://www.gnu.org/copyleft/gpl.html)
150              
151              
152             =head1 AUTHOR
153              
154             Mail::Addressbook::Convert was written by Joe Davidson in 2001.
155              
156             =cut
157              
158             #------------------------------------------------------------------------------
159              
160 1     1   1059 use strict;
  1         2  
  1         53  
161              
162             package Mail::Addressbook::Convert::Ccmail;
163              
164 1     1   5 use Mail::Addressbook::Convert::Genr;
  1         2  
  1         22  
165 1     1   5 use Mail::Addressbook::Convert::Utilities;
  1         2  
  1         67  
166 1     1   6 use Carp;
  1         10  
  1         68  
167              
168 1     1   22 use 5.001;
  1         4  
  1         47  
169              
170 1     1   6 use vars qw(@ISA );
  1         2  
  1         644  
171             @ISA = qw { Mail::Addressbook::Convert::Genr };
172              
173             ############# Constructor ##########################################
174              
175             # new is inherited
176              
177            
178             ######################################################################
179              
180             sub scan
181             {
182 1     1 1 9 my $Ccmail = shift;
183            
184 1         2 my $inputParm = shift; # reference to input ccMail data as an array or reference to a
185             # scalar containing the name of a file containing the ccMail data.
186            
187 1         8 $Ccmail->setfileFormat("tsv");
188              
189 1         4 my $raCcMailArray= getInput($inputParm);
190            
191 1         3 my $haveName = 0;
192 1         2 my $haveAddress = 0;
193 1         1 my $endOfAddress = 0;
194 1         3 my ($name, $address, $part, @hold, @outputFile , $comment, $h1, $h2);
195              
196 1         5 while (my $line = shift @$raCcMailArray)
197             {
198 59         60 chomp $line;
199 59         69 $line =~ s/\r//g;
200 59 100       190 if ($line =~ /^Name/)
    100          
    100          
    50          
201             {
202 13         29 $line =~ s/Name: //;
203 13 100       31 if ($line =~ /.+\@.+\..+/)
204             {
205 2         4 $haveName = 1;
206 2         3 $haveAddress = 1;
207 2         3 $name = "";
208 2         3 $address = $line;
209             }
210             else
211             {
212 11         14 $haveName = 1;
213 11         12 $name = $line;
214             }
215             }
216             elsif ($line =~ /^Addr/)
217             {
218 13         38 $line =~ s/^Addr: //g;
219 13         37 @hold = split(" ",$line);
220 13         30 while ($part = shift @hold)
221             {
222 31 100       72 if (isValidInternetAddress($part))
223             {
224 9         10 $haveAddress = 1;
225 9         25 $address = $part;
226             }
227            
228             }
229             }
230             elsif ($line =~ /^Cmts/)
231             {
232 13         20 $line = substr($line,5);
233 13         15 $comment = $line;
234 13         15 $endOfAddress = 1;
235             }
236             elsif ($line =~ /^Entry\d=/)
237             {
238 0         0 ($h1,$h2) = split("=", $line);
239 0 0       0 if (&::isValidInternetAddress($h2))
240             {
241 0         0 $haveName = 1;
242 0         0 $haveAddress = 1;
243 0         0 $endOfAddress = 1;
244 0         0 $name = "";
245 0         0 $address = $h2;
246 0         0 undef $comment;
247             }
248             }
249 59 100 66     279 if ($haveAddress and $haveName and $endOfAddress)
      100        
250             {
251 11         12 $haveName = 0;
252 11         12 $endOfAddress = 0;
253 11         9 $haveAddress = 0;
254 11         15 $address =~ s/
255 11         14 $address =~ s/>//g;
256 11         30 push (@outputFile, $address."\t".$name.
257             "\t\t\t".$comment."\n");
258            
259 11         31 undef $comment;
260             }
261             }
262             # Now we have a tab separated ascii file,
263            
264 1         10 $Ccmail->SUPER::scan(\@outputFile);
265              
266              
267             }
268              
269              
270             sub output
271             {
272 0     0 1   confess "\nCcmail.pm does not have an output method. \n You cannot convert to ccMail";
273              
274              
275             }
276              
277             1;