This file is indexed.

/usr/share/perl5/SyncBBDB/pilotBBDB.pm is in syncbbdb 2.6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#------------------------------------------------------------------------------
#   $Date: 2006/05/01 19:40:48 $
#   RCS: $Id: pilotBBDB.pm,v 1.4 2006/05/01 19:40:48 aaronkaplan Exp $
#------------------------------------------------------------------------------

package pilotBBDB;

use strict;
require SyncUtil::pilotHashDB;
@pilotBBDB::ISA = qw(pilotHashDB);

sub new {
    my $type = shift;
    my $self = pilotHashDB->new(shift, shift, shift, shift);

    bless ($self, $type);

    $self->{'translate'} = shift;

    my $db              = $self->{'dlp'}->open("AddressDB");
    $self->{'db'}       = $db;

    my $appInfo         = $db->getAppBlock();
    $self->{'appInfo'}  = $appInfo;

    $self->{'CategoryNames'} = $appInfo->{'categoryName'};
    my @CategoryNames        = @{$self->{'CategoryNames'}};
    my $i = 0;
    foreach my $cat (@CategoryNames) {
      $self->{'CategoryHash'}{$cat} = $i++;
    }

    $self->{'phoneLabels'} = $appInfo->{'phoneLabel'};
    my @phoneLabels        = @{$self->{'phoneLabels'}};
    $i=0;
    foreach my $label (@phoneLabels) {
      $self->{'phoneLabelsHash'}{$label} = $i++;
    }

    $self->{'labels'} = $appInfo->{'label'};
    my @labels        = @{$self->{'labels'}};
    $i=0;
    foreach my $label (@labels) {
      $self->{'labelsHash'}{$label} = $i++;
    }

    $self->{'Fields'} = [ 'Last', 'First', 'Company',
			  'Field1', 'Field2', 'Field3','Field4', 'Field5',
			  'Address', 'City', 'State', 'Zip', 'Country',
			  'Title',
			  'Custom1', 'Custom2', 'Custom3', 'Custom4',
			  'Note'
			  ];
    $i=0;
    foreach my $f (@{$self->{'Fields'}}) {
	## map of fields to indexes in entry...
	$self->{'FieldMap'}{$f} = $i++;
    }

    $self;
}

sub name {
  my $self = shift;
  return "Pilot Address Book";
}

sub syncRec {
  my $self = shift;
  my $lrec = shift;


  my $map = new pilotBBDBMap($lrec, $self->{'translate'});

  my %origIDS;
  foreach my $rec (@{$map->{'records'}}) {
      # break any existing references...
      $self->{'hashObj'}->setLocalHash($rec->{'id'}, undef);
      delete $self->{'localDB'}->{'hash'}{$rec->{'id'}};

      # remember we were associated with this id...
      $origIDS{$rec->{'id'}} = 1;
  }

  # Update the mapping..
  $map->updateMappingFromBBDB($self);

  # make sure all the pilot records we think exist actually do exist.
  # Even if this means we need to create them...
  foreach my $rec (@{$map->{'records'}}) {
      my $prec = $self->getRec($rec->{'id'});
      if (! defined $prec) {
	  $prec = $self->newRec();
	  $rec->{'id'} = $prec->{'id'};
      }
      # we continue to reference these ids..
      delete $origIDS{$rec->{'id'}};
  }

  # This is the list of ids we used to reference but don't anymore...
  foreach my $id (keys %origIDS) {
      $self->deleteRec($id);
      $self->{'localDB'}->deleteRec($id);
  }

  $lrec->{'notes'}{'pilot-id'} = $map->toString();
  my $lhash = $self->{'localDB'}->hashRecord($lrec);


  foreach my $rec (@{$map->{'records'}}) {
      # Restore the new references
      $self->{'hashObj'}->setLocalHash($rec->{'id'}, $lhash);
      $self->{'localDB'}->{'hash'}{$rec->{'id'}} = $lrec;
  }

  foreach my $rec (@{$map->{'records'}}) {
      my $prec = $self->getRec($rec->{'id'});
      
      ## Most categoryy setup code is in pilotBBDBMap.pm
      my $category = $rec->{'category'};

       ## fallback case..
      $category = "Unfiled" if (not $category);

      $prec->{'category'} = 0; # also 'Unfiled'
      if (defined $self->{'CategoryHash'}{$category}) {
	  $prec->{'category'} = $self->{'CategoryHash'}{$category};
      }

      # to set which phone is shown in the one line display...

      # Standard stuff
      $self->setField($prec, 'Last',    $lrec->{'lname'});
      $self->setField($prec, 'First',   $lrec->{'fname'});
      $self->setField($prec, 'Company', $lrec->{'org'});

      $self->setField($prec, 'Title',   
		      $lrec->{'notes'}{'title'} || "");

      $self->setField($prec, 'Note',
		      $lrec->{'notes'}{'notes'} || "");

      if (defined $rec->{'name'} && 
	  defined $lrec->{'addrH'}{$rec->{'name'}}) {
	  my $addr = $lrec->{'addrH'}{$rec->{'name'}};
	  
	  $self->setField($prec, 'Address', 
			  join("\xA", @{$addr->{'street'}}));
	  $self->setField($prec, 'City',  $addr->{'city'});
	  $self->setField($prec, 'State', $addr->{'state'});
	  if (defined $addr->{'zip'}) {
	      $self->setField($prec, 'Zip', join(' ',@{$addr->{'zip'}}));
	  } else {
	      $self->setField($prec, 'Zip', "");
	  }
	  $self->setField($prec, 'Country', $addr->{'country'});
      } else {
	  $self->setField($prec, 'Address', "");
	  $self->setField($prec, 'City',    "");
	  $self->setField($prec, 'State',   "");
	  $self->setField($prec, 'Zip',     "");
	  $self->setField($prec, 'Country', "");
      }

      # Empty everything out...
      $self->setField($prec, 'Field1', "");
      $self->setField($prec, 'Field2', "");
      $self->setField($prec, 'Field3', "");
      $self->setField($prec, 'Field4', "");
      $self->setField($prec, 'Field5', "");
      $prec->{'phoneLabel'}[0] = 0;
      $prec->{'phoneLabel'}[1] = 1;
      $prec->{'phoneLabel'}[2] = 2;
      $prec->{'phoneLabel'}[3] = 3;
      $prec->{'phoneLabel'}[4] = 4;

      $self->setField($prec, 'Custom1', "");
      $self->setField($prec, 'Custom2', "");
      $self->setField($prec, 'Custom3', "");
      $self->setField($prec, 'Custom4', "");

      my $first=1;
      foreach my $ent (@{$rec->{'mappings'}}) {
	  my $btype = $ent->{'bbdb-type'};
	  my $bname = $ent->{'bbdb-name'};
	  my $val = "";
	  if ($btype eq "phone") {
	      $val = $lrec->{'phoneH'}{$bname}->phoneString();
	  } elsif ($btype eq "note") {
	      if ($bname ne 'notes') {
	          $val = $lrec->{'notes'}{$bname};
	      }
	      # $lrec->{'notes'}{'notes'} was already handled above.
	  } elsif ($btype eq "net") {
	      my @email = @{$lrec->{'email'}};
	      #$val = join("\xA",@email);
	      $val = $email[0];
	  } elsif ($btype eq "aka") {
	      my @aka = @{$lrec->{'aka'}};
	      $val = join(", ",@aka);
	  } else {
	      print "Unknown bbdb-type\n";
	  }
	  
	  # Set the fields value...
	  $self->setField($prec, $ent->{'pilot'}, $val);

	  if (defined $ent->{'pilot-label'}) {
	      if ($ent->{'pilot'} =~ m/Field(.)/) {
		  my $idx = $1; $idx--;
		  # Set the label for the field....
		  $prec->{'phoneLabel'}[$idx] = $ent->{'pilot-label'};
		  if ($first) {
		    # Set the one-line phone to the first entry...
		    # This really needs better support so I can
		    # remember if it was changed on the pilot...
		    $prec->{'showPhone'} = $idx;
		    $first = 0;
		  }

	      }
	  }
      }

      # Send the modified record back to the Pilot...
      $self->setRec($prec); # Also updates Hash
  }
}

sub printRec {
    my $self = shift;
    my $prec  = shift;

    my @fields = ('Last', 'First', 'Title', 'Company', 
		  'Address', 'City', 'State', 'Zip', 'Country',
		  'Field1', 'Field2', 'Field3', 'Field4', 'Field5',
		  'Custom1', 'Custom2', 'Custom3', 'Custom4',
		  'Note');
    foreach my $f (@fields) {
	print $f. ": " . $self->getField($prec, $f) . "\n";
    }
    print "Lables: " . join(", ", @{$prec->{'phoneLabel'}}) . "\n";
}


sub newRec {
    my $self = shift;

    my $ret = PDA::Pilot::AddressDatabase->record;

    $ret->{'id'} = 0;
    $ret->{'category'} = 0;
    $ret->{'entry'} = ["", "", "", "", "", "", 
		       "", "", "", "", "", "", 
		       "", "", "", "", "", ""];

    $ret->{'phoneLabel'} = [0 .. 4];
    $ret->{'secret'} = 0;
    
    $self->setRec($ret);
    return $ret;
}


sub dupRec {
  my $self = shift;
  my $prec = shift;
  my $lrec = shift;
  my $lcpy = shift;

  my $ret = PDA::Pilot::AddressDatabase->record;

  $ret->{'id'} = 0;  ## disassociate from original record...

  $ret->{'category'} = $prec->{'category'};
  
  my @dup = ();
  push(@dup, @{$prec->{'entry'}});
  $ret->{'entry'} = [@dup];

  @dup = ();
  push(@dup, @{$prec->{'phoneLabel'}});
  $ret->{'phoneLabel'} = [@dup];

  $ret->{'secret'}     = $prec->{'secret'};

  $self->setRec($ret);  # Get a record ID...

  my $map    = new pilotBBDBMap($lrec, $self->{'translate'});
  my $mapRec = $map->getMapForID($prec->{'id'});

  # setup new mapping for local rec.
  $map = new pilotBBDBMap($lcpy, $self->{'translate'});
  push(@{$map->{'records'}}, $mapRec->copy($ret->{'id'}));
  $lcpy->{'notes'}{'pilot-id'} = $map->toString();

  return $ret;
}

sub categoryStr {
  my $self = shift;
  my $rec  = shift;
  return ${$self->{'CategoryNames'}}[$rec->{'category'}];
}

sub getPhoneLabel {
  my $self = shift;
  my $indx = shift;
  return $self->{'phoneLabels'}[$indx];
}

sub getCustLabel {
  my $self = shift;
  my $indx = shift;
  return $self->{'labels'}[$indx+$self->getFieldIndex('Custom1')];
}

sub getFieldIndex {
  my $self  = shift;
  my $field = shift;
  return $self->{'FieldMap'}{$field};
}

sub getField {
  my $self  = shift;
  my $rec   = shift;
  my $field = shift;
  my $i     = $self->getFieldIndex($field);

  if (!defined $i) {
      print "Unkown Pilot field: $field\n" ;

      my $x=0;
      my ($pack, $file, $line, $subname);
      while (($pack, $file, $line, $subname) = caller($x++)) {
	  print "\tfile:$file line:$line\n";
      }
  }

  return $rec->{'entry'}[$i];
}

sub setField {
  my $self  = shift;
  my $rec   = shift;
  my $field = shift;
  my $val   = shift;

  my $indx = $self->getFieldIndex($field);
  print "Field: $field\n" if (not defined $indx) ;
  $rec->{'entry'}[$indx] = $val;
}

sub output {
  my $self = shift;
  my $rec  = shift;
  my $fn   = $self->getField($rec, 'First');
  my $ln   = $self->getField($rec, 'Last');
  my $org  = $self->getField($rec, 'Company');
  my $str  = "";
  
  $fn  = "" if !defined($fn);
  $ln  = "" if !defined($ln);
  $org = "" if !defined($org);

  $str = $fn;
  $str .= " "  if ($str && $ln);
  $str .= $ln;
  $str .= ", " if ($str && $org);
  $str .= $org;
  $str ||= "<No Name> - " . $rec->{'id'};
    
  $self->{'host'}->output($str . "\n");
}
1;