| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Convert::Addressbook::Mozilla2Blackberry; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20963
|
use 5.008004; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
821
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Convert::Addressbook::Mozilla2Blackberry ':all'; |
|
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
17
|
|
|
|
|
|
|
# will save memory. |
|
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#TODO a version of this module that checks state - Mozilla addr's LastModifiedDate |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my ($field_names); |
|
40
|
|
|
|
|
|
|
my (@data); |
|
41
|
|
|
|
|
|
|
my (@Blackberry_Fields); |
|
42
|
|
|
|
|
|
|
my (%field, %Conversion_Filter); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#Blackberry file format; |
|
45
|
|
|
|
|
|
|
@Blackberry_Fields = |
|
46
|
|
|
|
|
|
|
("First Name", |
|
47
|
|
|
|
|
|
|
"Middle Name", |
|
48
|
|
|
|
|
|
|
"Last Name", |
|
49
|
|
|
|
|
|
|
"Title", |
|
50
|
|
|
|
|
|
|
"Company Name", |
|
51
|
|
|
|
|
|
|
"Work Phone", |
|
52
|
|
|
|
|
|
|
"Home Phone", |
|
53
|
|
|
|
|
|
|
"Fax", |
|
54
|
|
|
|
|
|
|
"Mobile Phone", |
|
55
|
|
|
|
|
|
|
"PIN", |
|
56
|
|
|
|
|
|
|
"Pager", |
|
57
|
|
|
|
|
|
|
"Email Address 1", |
|
58
|
|
|
|
|
|
|
"Email Address 2", |
|
59
|
|
|
|
|
|
|
"Email Address 3", |
|
60
|
|
|
|
|
|
|
"Address1", |
|
61
|
|
|
|
|
|
|
"Address2", |
|
62
|
|
|
|
|
|
|
"City", |
|
63
|
|
|
|
|
|
|
"State/Prov", |
|
64
|
|
|
|
|
|
|
"Zip/Postal Code", |
|
65
|
|
|
|
|
|
|
"Country", |
|
66
|
|
|
|
|
|
|
"Notes", |
|
67
|
|
|
|
|
|
|
"Interactive Handheld", |
|
68
|
|
|
|
|
|
|
"1-way Pager", |
|
69
|
|
|
|
|
|
|
"User Defined 1", |
|
70
|
|
|
|
|
|
|
"User Defined 2", |
|
71
|
|
|
|
|
|
|
"User Defined 3", |
|
72
|
|
|
|
|
|
|
"User Defined 4");
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#the 'master' map of how to convert between Mozilla fields and the |
|
75
|
|
|
|
|
|
|
# Blackberry fields, above. The Blackberry field is the key, Mozilla the |
|
76
|
|
|
|
|
|
|
# value, so we can iterate through @Blackberry_Fields and work on each |
|
77
|
|
|
|
|
|
|
# element in turn, while preserving the correct order |
|
78
|
|
|
|
|
|
|
# also needs blank "filler" lines including to map fields that don't exist in Mozilla |
|
79
|
|
|
|
|
|
|
# to blackberry |
|
80
|
|
|
|
|
|
|
%Conversion_Filter = ( |
|
81
|
|
|
|
|
|
|
"First Name" => "FirstName", |
|
82
|
|
|
|
|
|
|
"Middle Name" => "", |
|
83
|
|
|
|
|
|
|
"Last Name" => "LastName", |
|
84
|
|
|
|
|
|
|
"Title" => "", |
|
85
|
|
|
|
|
|
|
"Company Name" => "Company", |
|
86
|
|
|
|
|
|
|
"Work Phone" => "WorkPhone", |
|
87
|
|
|
|
|
|
|
"Home Phone" => "HomePhone", |
|
88
|
|
|
|
|
|
|
"Fax" => "FaxNumber", |
|
89
|
|
|
|
|
|
|
"Mobile Phone" => "CellularNumber", |
|
90
|
|
|
|
|
|
|
"PIN" => "", |
|
91
|
|
|
|
|
|
|
"Pager" => "", |
|
92
|
|
|
|
|
|
|
"Email Address 1" => "PrimaryEmail", |
|
93
|
|
|
|
|
|
|
"Email Address 2" => "DefaultEmail", |
|
94
|
|
|
|
|
|
|
"Email Address 3" => "SecondEmail", |
|
95
|
|
|
|
|
|
|
"Address1" => "WorkAddress", |
|
96
|
|
|
|
|
|
|
"Address2" => "WorkAddress2", |
|
97
|
|
|
|
|
|
|
"Address3" => "", #no corresponding field |
|
98
|
|
|
|
|
|
|
"City" => "WorkCity", |
|
99
|
|
|
|
|
|
|
"State\/Prov" => "WorkState", |
|
100
|
|
|
|
|
|
|
"Zip\/Postal Code" => "WorkZipCode", |
|
101
|
|
|
|
|
|
|
"Country" => "WorkCountry", |
|
102
|
|
|
|
|
|
|
"Notes" => "", |
|
103
|
|
|
|
|
|
|
"Interactive Handheld" => "", |
|
104
|
|
|
|
|
|
|
"1-way Pager" => "", |
|
105
|
|
|
|
|
|
|
"User Defined 1" => "Custom1", |
|
106
|
|
|
|
|
|
|
"User Defined 2" => "Custom2", |
|
107
|
|
|
|
|
|
|
"User Defined 3" => "Custom3", |
|
108
|
|
|
|
|
|
|
"User Defined 4" => "", #no corresponding field |
|
109
|
|
|
|
|
|
|
); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
########################### |
|
112
|
|
|
|
|
|
|
# create the new() object for the instance |
|
113
|
|
|
|
|
|
|
########################### |
|
114
|
|
|
|
|
|
|
sub new { |
|
115
|
0
|
|
|
0
|
0
|
|
my $class = shift; # works on @_ by default |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $ConversionInfo = {}; #create a blank hash |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
#setup the OO Object. Don't mind the man behind the curtain.. |
|
120
|
0
|
|
|
|
|
|
bless $ConversionInfo, $class; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#give the blackberry header information to the object |
|
123
|
0
|
|
|
|
|
|
$ConversionInfo->{'BlackberryHeaders'} = \@Blackberry_Fields; |
|
124
|
|
|
|
|
|
|
#get the filename we were given, if any |
|
125
|
|
|
|
|
|
|
#if (defined ($file)) { $ConversionInfo->{'file'}; } |
|
126
|
|
|
|
|
|
|
#allow the object to reference the @FileData array |
|
127
|
|
|
|
|
|
|
#$ConversionInfo->{'FileData'} = \@FileData; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#allow the object to reference the converted data hash |
|
130
|
0
|
|
|
|
|
|
$ConversionInfo->{'field'} = \%field; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#give the calling routine access to our data and routines |
|
133
|
0
|
|
|
|
|
|
return $ConversionInfo; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
###########################
|
|
137
|
|
|
|
|
|
|
#print the blackberry field headers - |
|
138
|
|
|
|
|
|
|
# iterate over ever instance and print
|
|
139
|
|
|
|
|
|
|
# it, basically..
|
|
140
|
|
|
|
|
|
|
########################### |
|
141
|
|
|
|
|
|
|
sub PrintBlackberryHeaders |
|
142
|
|
|
|
|
|
|
{ |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
0
|
0
|
|
map({ print "$_,"; } @Blackberry_Fields);
|
|
|
0
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
print "\n";
|
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
############################ |
|
149
|
|
|
|
|
|
|
# return a list of the Header fields |
|
150
|
|
|
|
|
|
|
# that Blackberry uses in its .CSV import file |
|
151
|
|
|
|
|
|
|
# mostly just to be nice, but it might help if I CPAN this.. |
|
152
|
|
|
|
|
|
|
############################# |
|
153
|
|
|
|
|
|
|
sub ReturnBlackberryHeaders |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
|
|
|
|
|
|
#get the ojbect refernce to the instance thats calling us |
|
156
|
0
|
|
|
0
|
0
|
|
my ($obj) = shift; |
|
157
|
|
|
|
|
|
|
#return the details as requested above |
|
158
|
0
|
|
|
|
|
|
return $obj->{@Blackberry_Fields}; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
######################### |
|
162
|
|
|
|
|
|
|
# convert each record passed, from each line in an array |
|
163
|
|
|
|
|
|
|
# expects a hash reference which contains a set of data to convert |
|
164
|
|
|
|
|
|
|
# note: unlike the original script, this only converts one set of records |
|
165
|
|
|
|
|
|
|
# at a time, to convert the entire file, you must call it repeatedly. |
|
166
|
|
|
|
|
|
|
# returns a single scalar containing the CSV record set of the converted record |
|
167
|
|
|
|
|
|
|
#########################
|
|
168
|
|
|
|
|
|
|
sub StreamConvert |
|
169
|
|
|
|
|
|
|
{ |
|
170
|
|
|
|
|
|
|
#get the ojbect refernce to the instance thats calling us |
|
171
|
0
|
0
|
|
0
|
0
|
|
(my ($obj) = shift) || carp ("No object - did you call new() first?\n"); |
|
172
|
|
|
|
|
|
|
#setup a scalar to hold the processed record data |
|
173
|
0
|
|
|
|
|
|
my $converted_record; |
|
174
|
|
|
|
|
|
|
# get the reference to the hash from the calling routine, and dereference |
|
175
|
0
|
0
|
|
|
|
|
(my $hashref = shift) || carp("No hash passed to StreamConvert\n"); |
|
176
|
0
|
|
|
|
|
|
my %record_to_import = %$hashref; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# # fields on the left are the Blackberry fields, the right; Mozilla |
|
179
|
|
|
|
|
|
|
# #TODO prevent warning messages if the mozilla var is undef - eval block? |
|
180
|
|
|
|
|
|
|
# #this is rather painful, but I can't think of a way to iterate over |
|
181
|
|
|
|
|
|
|
# #these and keep the record match correct without using a hash |
|
182
|
0
|
|
|
|
|
|
my %blackberry_records; |
|
183
|
0
|
|
|
|
|
|
$blackberry_records{"First Name"} = $record_to_import{"FirstName"}; |
|
184
|
0
|
|
|
|
|
|
$blackberry_records{"Last Name"} = $record_to_import{"LastName"}; |
|
185
|
0
|
|
|
|
|
|
$blackberry_records{"Company Name"} = $record_to_import{"Company"}; |
|
186
|
0
|
|
|
|
|
|
$blackberry_records{"Work Phone"} = $record_to_import{"WorkPhone"}; |
|
187
|
0
|
|
|
|
|
|
$blackberry_records{"Home Phone"} = $record_to_import{"HomePhone"}; |
|
188
|
0
|
|
|
|
|
|
$blackberry_records{"Fax"} = $record_to_import{"FaxNumber"}; |
|
189
|
0
|
|
|
|
|
|
$blackberry_records{"Mobile Phone"} = $record_to_import{"CellularNumber"}; |
|
190
|
0
|
|
|
|
|
|
$blackberry_records{"Email Address 1"} = $record_to_import{"PrimaryEmail"}; |
|
191
|
0
|
|
|
|
|
|
$blackberry_records{"Email Address 2"} = $record_to_import{"DefaultEmail"}; |
|
192
|
0
|
|
|
|
|
|
$blackberry_records{"Email Address 3"} = $record_to_import{"SecondEmail"}; |
|
193
|
0
|
|
|
|
|
|
$blackberry_records{"Address1"} = $record_to_import{"WorkAddress"}; |
|
194
|
0
|
|
|
|
|
|
$blackberry_records{"Address2"} = $record_to_import{"WorkAddress2"}; |
|
195
|
0
|
|
|
|
|
|
$blackberry_records{"City"} = $record_to_import{"WorkCity"}; |
|
196
|
0
|
|
|
|
|
|
$blackberry_records{"State/Prov"} = $record_to_import{"WorkState"}; |
|
197
|
0
|
|
|
|
|
|
$blackberry_records{"Zip/Postal Code"} = $record_to_import{"WorkZipCode"}; |
|
198
|
0
|
|
|
|
|
|
$blackberry_records{"Country"} = $record_to_import{"WorkCountry"}; |
|
199
|
0
|
|
|
|
|
|
$blackberry_records{"User Defined 1"} = $record_to_import{"Custom1"}; |
|
200
|
0
|
|
|
|
|
|
$blackberry_records{"User Defined 2"} = $record_to_import{"Custom2"}; |
|
201
|
0
|
|
|
|
|
|
$blackberry_records{"User Defined 3"} = $record_to_import{"Custom3"}; |
|
202
|
|
|
|
|
|
|
#TODO try and create the firstName and LastName fields from other Mozilla fields e.g. DisplayName |
|
203
|
|
|
|
|
|
|
#create a default name if it doesn't exist |
|
204
|
|
|
|
|
|
|
#not perfect, but if theres sufficient need, I'll look into some regex to split the |
|
205
|
|
|
|
|
|
|
# DisplayName up, and seperate the email address |
|
206
|
0
|
0
|
0
|
|
|
|
if ( (!defined($record_to_import{"FirstName"})) && (!defined($record_to_import{"LastName"}))) |
|
207
|
|
|
|
|
|
|
{ |
|
208
|
0
|
|
|
|
|
|
$blackberry_records{"First Name"} = $record_to_import{"DisplayName"}; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
#TODO return the data to the calling program
as a scalar |
|
212
|
|
|
|
|
|
|
#TODO convert the print statements into additions to $converted_record |
|
213
|
|
|
|
|
|
|
#iterate through the blackberry field list to generate the correct |
|
214
|
|
|
|
|
|
|
#sequence of CSV fields
|
|
215
|
0
|
|
|
|
|
|
for $field_names (@Blackberry_Fields) |
|
216
|
|
|
|
|
|
|
{
|
|
217
|
|
|
|
|
|
|
#my $testvar = $record_to_import{$Conversion_Filter{$field_names}}; |
|
218
|
|
|
|
|
|
|
#if the field is already propulated, add it to the hash |
|
219
|
0
|
0
|
|
|
|
|
if ( defined($record_to_import{$Conversion_Filter{$field_names}}) ) |
|
220
|
|
|
|
|
|
|
{
|
|
221
|
0
|
|
|
|
|
|
print $record_to_import{$Conversion_Filter{$field_names}} . ","; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
#otherwise, just print the delimiter
|
|
224
|
|
|
|
|
|
|
else
|
|
225
|
|
|
|
|
|
|
{
|
|
226
|
0
|
|
|
|
|
|
print ",";
|
|
227
|
|
|
|
|
|
|
}
|
|
228
|
|
|
|
|
|
|
}
|
|
229
|
|
|
|
|
|
|
#once we're done, print the end of line to move to the next record
|
|
230
|
0
|
|
|
|
|
|
print "\n";
|
|
231
|
|
|
|
|
|
|
#}#end of
|
|
232
|
0
|
|
|
|
|
|
return $converted_record; |
|
233
|
|
|
|
|
|
|
}#end of StreamConvert() |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
#end of module |
|
236
|
|
|
|
|
|
|
1; |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |