| 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<pine> 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 <jdavidson@interguru.com> in 2001. | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | #------------------------------------------------------------------------------ | ||||||||||
| 156 | |||||||||||
| 157 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 158 | |||||||||||
| 159 | |||||||||||
| 160 | package Mail::Addressbook::Convert::Pine; | ||||||||||
| 161 | |||||||||||
| 162 | 1 | ▶ | use Mail::Addressbook::Convert::Utilities; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 163 | 1 | ▶ | use 5.001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 164 | |||||||||||
| 165 | 3 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 166 | 3 | bless {},shift; | |||||||||
| 167 | } | ||||||||||
| 168 | |||||||||||
| 169 | ###################################################################### | ||||||||||
| 170 | |||||||||||
| 171 | |||||||||||
| 172 | 1 | ▶ | sub scan { | ||||||||
|
Subroutine
scan: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||
| 173 | |||||||||||
| 174 | 1 | local $^W; #turn off warnings. This code was written without the -w flag, and is too difficult to patch it in. | |||||||||
| 175 | # | ||||||||||
| 176 | 1 | my $Pine = shift; | |||||||||
| 177 | 1 | 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 | my $raPineArray= getInput($inputParm); | |||||||||
| 181 | 1 | my ($alias,$name,$address,$fcc,$comment); | |||||||||
| 182 | 1 | my ($lastname , @names, @outputFile); | |||||||||
| 183 | |||||||||||
| 184 | 1 | my @pineArray = @$raPineArray; | |||||||||
| 185 | |||||||||||
| 186 | 1 | foreach my $k (0..$#pineArray) | |||||||||
| 187 | { | ||||||||||
| 188 | 8 | ▶ | next if $pineArray[$k] =~/^#/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 189 | 8 | undef $comment; | |||||||||
| 190 | 8 | ($alias,$name,$address,$fcc,$comment) = split(/\t/, $pineArray[$k]); | |||||||||
| 191 | 8 | ▶ | if ($address =~ /</) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 192 | { | ||||||||||
| 193 | 0 | (my $junk,$address) = split("<",$address); | |||||||||
| 194 | 0 | $address =~ s/>//; | |||||||||
| 195 | } | ||||||||||
| 196 | # Thanks to Erich Schraer <erich@wubiosas.wustl.edu> | ||||||||||
| 197 | # for suggestions to improve processing of names | ||||||||||
| 198 | 8 | ▶ | if ($name =~ /,/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 199 | { # If name doesn't have a comma, leave alone | ||||||||||
| 200 | 5 | @names = split(/,/, $name); # Split on the comma | |||||||||
| 201 | 5 | $lastname = shift(@names); | |||||||||
| 202 | 5 | $name = join(" ",@names,$lastname); | |||||||||
| 203 | 5 | $name =~ s/^ //; # get rid of space at beginning. | |||||||||
| 204 | } | ||||||||||
| 205 | 8 | ▶ | if ($address !~ /\,/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 206 | { | ||||||||||
| 207 | 6 | ▶ | if ($name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 208 | { | ||||||||||
| 209 | 5 | push (@outputFile, "alias ".$alias. | |||||||||
| 210 | " \"".$name."\"<".$address. "\>\n") ; | ||||||||||
| 211 | } | ||||||||||
| 212 | else | ||||||||||
| 213 | { | ||||||||||
| 214 | 1 | push (@outputFile, "alias ".$alias. | |||||||||
| 215 | " ".$address. "\n") ; | ||||||||||
| 216 | } | ||||||||||
| 217 | } | ||||||||||
| 218 | else | ||||||||||
| 219 | { | ||||||||||
| 220 | 2 | $address =~s/\(|\)//g; | |||||||||
| 221 | 2 | push (@outputFile, "alias ".$alias." ".$address. "\n") ; | |||||||||
| 222 | } | ||||||||||
| 223 | 8 | ▶ | if ($comment) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 224 | { | ||||||||||
| 225 | 0 | push (@outputFile, "note ".$alias." ".$comment."\n"); | |||||||||
| 226 | } | ||||||||||
| 227 | |||||||||||
| 228 | } | ||||||||||
| 229 | 1 | foreach (@outputFile) | |||||||||
| 230 | { | ||||||||||
| 231 | 8 | s/\r|\015|\013//; | |||||||||
| 232 | } | ||||||||||
| 233 | |||||||||||
| 234 | 1 | return \@outputFile; | |||||||||
| 235 | } | ||||||||||
| 236 | |||||||||||
| 237 | |||||||||||
| 238 | ########################### sub output ####################### | ||||||||||
| 239 | sub output | ||||||||||
| 240 | |||||||||||
| 241 | 3 | ▶ | { | ||||||||
|
Subroutine
output: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||
| 242 | |||||||||||
| 243 | 3 | local $^W; #turn off warnings. This code was written without the -w flag, and is too difficult to patch it in. | |||||||||
| 244 | 3 | my $Pine = shift; | |||||||||
| 245 | 3 | my $raInputArray = shift; # reference to input Input data as an array | |||||||||
| 246 | |||||||||||
| 247 | 3 | my @inputArray = @$raInputArray; | |||||||||
| 248 | |||||||||||
| 249 | 3 | my (@outputFile, @indivalias, @middle,@indivaddr, %note, $i, $j, $k ); | |||||||||
| 250 | 3 | my ( @hold1, @lines, $alias, $rest, $commas, $name, @groupalias ); | |||||||||
| 251 | 3 | my (@groupaddr, $address); | |||||||||
| 252 | |||||||||||
| 253 | 3 | my $kk = 0; | |||||||||
| 254 | 3 | foreach $i (0..$#inputArray ) | |||||||||
| 255 | { | ||||||||||
| 256 | 38 | $inputArray[$i] =~ s/\r//g; | |||||||||
| 257 | 38 | ▶ | if ($inputArray[$i] =~/^note/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 258 | { | ||||||||||
| 259 | 6 | @hold1 = split (" ",$inputArray[$i],3); | |||||||||
| 260 | 6 | $note{"$hold1[1]"} = $hold1[2]; | |||||||||
| 261 | 6 | $note{"$hold1[1]"} =~ s/\n|\r//g; | |||||||||
| 262 | } | ||||||||||
| 263 | else | ||||||||||
| 264 | { | ||||||||||
| 265 | 32 | $lines[$kk] = $inputArray[$i]; | |||||||||
| 266 | 32 | $lines[$kk] =~ s/alias //g; | |||||||||
| 267 | 32 | $kk++; | |||||||||
| 268 | } | ||||||||||
| 269 | } | ||||||||||
| 270 | |||||||||||
| 271 | 3 | foreach $i (0..$#lines ) | |||||||||
| 272 | { | ||||||||||
| 273 | 32 | ▶ | if ($lines[$i] =~/^\"/) #alais starts with quote. | ||||||||
|
Branch: 1 branch
| |||||||||||
| 274 | { | ||||||||||
| 275 | 0 | $lines[$i]=substr($lines[$i],1) ; # get rid of first quote. | |||||||||
| 276 | 0 | $lines[$i] =~ /(.+[^\"])\"(.*)/; | |||||||||
| 277 | 0 | $alias = $1; | |||||||||
| 278 | 0 | $rest = $2; | |||||||||
| 279 | 0 | $alias =~ s/\s//g; # get rid of spaces | |||||||||
| 280 | } | ||||||||||
| 281 | else | ||||||||||
| 282 | { | ||||||||||
| 283 | 32 | $lines[$i] =~ /(\S+)(.+)/;# match the alias and the rest | |||||||||
| 284 | 32 | $alias = $1; | |||||||||
| 285 | 32 | $rest = $2; | |||||||||
| 286 | } | ||||||||||
| 287 | 32 | my $commas_outside_quotes = &commas_outside_quotes($rest); | |||||||||
| 288 | 32 | ▶ | if ($commas_outside_quotes) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 289 | # There are commas not enclosed in quotes | ||||||||||
| 290 | { #we have a group list. | ||||||||||
| 291 | 10 | $groupalias[$j] = $alias; | |||||||||
| 292 | 10 | $groupaddr[$j] = $rest; | |||||||||
| 293 | 10 | $groupaddr[$j] =~ s/\s*//g; # get rid of all spaces | |||||||||
| 294 | 10 | $j++ | |||||||||
| 295 | } | ||||||||||
| 296 | else # an individual address | ||||||||||
| 297 | { | ||||||||||
| 298 | 22 | $indivalias[$k] = $alias; | |||||||||
| 299 | 22 | $middle[$k] = "\t\t"; | |||||||||
| 300 | 22 | ▶ | if ( $rest =~ /</) # compound address | ||||||||
|
Branch: 1 branch
| |||||||||||
| 301 | { | ||||||||||
| 302 | 19 | ($name,$address) = split(/</,$rest); | |||||||||
| 303 | 19 | $address =~s/>//; | |||||||||
| 304 | 19 | $name =~ s/\"//g; | |||||||||
| 305 | 19 | $name =~ s/\'//g; | |||||||||
| 306 | 19 | $name .= ","; | |||||||||
| 307 | 19 | ▶ | if ($name =~/(\S+)\s+(\S+)/)# name in form of | ||||||||
|
Branch: 1 branch
| |||||||||||
| 308 | # two words (I assume firstname, lastname ) | ||||||||||
| 309 | { | ||||||||||
| 310 | 15 | $name = $2.",".$1; | |||||||||
| 311 | } | ||||||||||
| 312 | 19 | $middle[$k] = "\t".$name."\t"; | |||||||||
| 313 | 19 | $middle[$k] =~ s/,,/,/; | |||||||||
| 314 | 19 | $rest = $address; | |||||||||
| 315 | } | ||||||||||
| 316 | 22 | $indivaddr[$k] = $rest; | |||||||||
| 317 | 22 | $k++ | |||||||||
| 318 | } | ||||||||||
| 319 | } | ||||||||||
| 320 | |||||||||||
| 321 | 3 | foreach $i (0..$k-1) | |||||||||
| 322 | { | ||||||||||
| 323 | push (@outputFile, $indivalias[$i]."$middle[$i]".$indivaddr[$i] | ||||||||||
| 324 | 22 | ."\t\t".$note{"$indivalias[$i]"}."\n"); | |||||||||
| 325 | } | ||||||||||
| 326 | 3 | foreach $i (0..$j -1) | |||||||||
| 327 | { | ||||||||||
| 328 | push( @outputFile, $groupalias[$i]."\t".$groupalias[$i] | ||||||||||
| 329 | 10 | ."\t(".$groupaddr[$i].")\t\t".$note{"$groupalias[$i]"}."\n"); | |||||||||
| 330 | } | ||||||||||
| 331 | |||||||||||
| 332 | |||||||||||
| 333 | |||||||||||
| 334 | 3 | return \@outputFile; | |||||||||
| 335 | } | ||||||||||
| 336 | |||||||||||
| 337 | |||||||||||
| 338 | |||||||||||
| 339 | ########################### end sub output ####################### | ||||||||||
| 340 | 1 | 1; | |||||||||