| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Mail::Addressbook::Convert::Utilities | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This module is not designed to be used by the user. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | It provides utility methods with for Mail::Addressbook::Convert | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 REQUIRES | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Perl, version 5.001 or higher | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Carp | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 DEFINITIONS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 METHODS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 REFERENCES | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 HISTORY | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | This code is derived from the code used on www.interguru.com/mailconv.htm . The site | ||||||||||||||||||||||||||||
| 38 | has been up since 1996 ( but ldif was only included on 1997, when Netscape 3 started | ||||||||||||||||||||||||||||
| 39 | using it.) The site gets about 8000 unique visitors a month, many of whom make addressbook | ||||||||||||||||||||||||||||
| 40 | conversions. The code has been well tested. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 FUTURE DIRECTIONS | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 BUGS | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Original Version 2001-Sept-09 | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Copyright (c) 2001 Joe Davidson. All rights reserved. | ||||||||||||||||||||||||||||
| 56 | This program is free software; you can redistribute it | ||||||||||||||||||||||||||||
| 57 | and/or modify it under the terms of the Perl Artistic License | ||||||||||||||||||||||||||||
| 58 | (see http://www.perl.com/perl/misc/Artistic.html). or the | ||||||||||||||||||||||||||||
| 59 | GPL copyleft license ( http://www.gnu.org/copyleft/gpl.html) | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Mail::Addressbook::Convert was written by Joe Davidson <jdavidson@interguru.com> in 2001. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | package Mail::Addressbook::Convert::Utilities; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | use Exporter (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 74 | 1 | @EXPORT = qw( cleanalias commas_outside_quotes getInput isValidInternetAddress ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | use vars qw(%usedAlias ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | ##########################################################################3 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub cleanalias | ||||||||||||||||||||||||||||
| 86 | 99 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
cleanalias: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 99 | my($a2,$allowUnderscores)= @_; | |||||||||||||||||||||||||||
| 88 | 99 | $a2 =~ tr/A-Z0-9/a-z0-9/; #make sure alias is lowercase | |||||||||||||||||||||||||||
| 89 | 99 | ▶ | if ($allowUnderscores) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 5 | $a2 =~ tr/a-z0-9_//cd; # underscores, letters and numbers only | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else | ||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 94 | $a2 =~ tr/a-z0-9//cd; # letters and numbers only | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 99 | return($a2); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | ##########################################################################3 | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub commas_outside_quotes | ||||||||||||||||||||||||||||
| 102 | 47 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
commas_outside_quotes: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 47 | my($test_string) = $_[0]; | |||||||||||||||||||||||||||
| 104 | 47 | my($inside_quote,$num_chars,$s); | |||||||||||||||||||||||||||
| 105 | 47 | $inside_quote = 0; #false; | |||||||||||||||||||||||||||
| 106 | 47 | $num_chars = length($test_string); | |||||||||||||||||||||||||||
| 107 | 47 | foreach $s (0..$num_chars) | |||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 1166 | my($char) = substr($test_string,$s,1); | |||||||||||||||||||||||||||
| 110 | 1166 | ▶ | if ($char eq "\"") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 60 | {$inside_quote =!$inside_quote;} | |||||||||||||||||||||||||||
| 112 | 1166 | ▶ | if ($char eq "\," && !$inside_quote) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char eq "," and not $inside_quote
MC/DC50%1/2
$char eq "," and not $inside_quote
$char eq ","
not $inside_quote
Truth table66%2/3
A and not(B)
A= $char eq ","B= not $inside_quote
| |||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 14 | return 1; # we found a comma outside a quote | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 33 | return 0; # no commas outside quotes. | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | ########################################################################## | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 18 | ▶ | sub getInput { | ||||||||||||||||||||||||||
|
Subroutine
getInput: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 18 | my $parm = shift; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 18 | ▶ | if ((ref $parm) =~ /ARRAY/) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 5 | return $parm; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | elsif ( (ref $parm) =~ /SCALAR/) | ||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||
| 132 | 13 | local *FH; | |||||||||||||||||||||||||||
| 133 | 13 | my $fileName = $$parm; | |||||||||||||||||||||||||||
| 134 | 13 | ▶ | open (FH, "<$fileName") or confess "Utilities.pm getInput: could not open $fileName: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 13 | my @ary = <FH>; | |||||||||||||||||||||||||||
| 136 | 13 | close FH; | |||||||||||||||||||||||||||
| 137 | 13 | return \@ary; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | else | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 0 | croak " Utilities.pm getInput: Input parameter must be a reference to an array or scalar\n"; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | ######################## begin sub isValidInternetAddress ###################### | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | sub isValidInternetAddress | ||||||||||||||||||||||||||||
| 151 | 31 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isValidInternetAddress: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 31 | my $member = $_[0]; | |||||||||||||||||||||||||||
| 155 | 31 | return $member =~m/\s*^<?[^@<>]+@[^@.<>]+(\.[^@.<>]+)+>?\s*$/; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | if (0) | |||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | unless ($member =~ /([\w\-\+\.\_]+)@([\w\-\+\.]+)/) | ||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||
| 161 | return 0; | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | my $hst = $2; | ||||||||||||||||||||||||||||
| 164 | my @domains = split(/\./,$hst ); | ||||||||||||||||||||||||||||
| 165 | if ($#domains < 1) | ||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | return 0; | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | my $topLevelDomain = $domains[$#domains]; | ||||||||||||||||||||||||||||
| 170 | my $lengthTopLevelDomain = length($topLevelDomain ); | ||||||||||||||||||||||||||||
| 171 | if ($lengthTopLevelDomain > 3 or $lengthTopLevelDomain <2) | ||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | return 0; | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | return 1; | ||||||||||||||||||||||||||||
| 176 | 0 | } end of (0) | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | ######################## end sub isValidInternetAddress ###################### | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 1 | 1; | |||||||||||||||||||||||||||