Skip to content

Commit

Permalink
Better address book parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jun 22, 2016
1 parent 1332321 commit 3de7c3e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions archive_imessage.pl
Expand Up @@ -675,15 +675,17 @@ sub parse_addressbook_name {
$addressbookdb = DBI->connect("DBI:SQLite:dbname=$addressbookdbname", '', '', { RaiseError => 0 })
or fail("Couldn't open addressbook database at '$archivedir/$addressbookdbname': " . $DBI::errstr);

$lookupstmt = $addressbookdb->prepare('select c15Phone, c16Email, c11Nickname, c0First, c2Middle, c1Last from ABPersonFullTextSearch_content where ((c15Phone LIKE ?) or (c16Email LIKE ?)) limit 1;')
$lookupstmt = $addressbookdb->prepare('select c15Phone, c16Email, c11Nickname, c0First, c2Middle, c1Last from ABPersonFullTextSearch_content where ((c15Phone LIKE ?) or (c15Phone LIKE ?) or (c15Phone LIKE ?) or (c16Email LIKE ?) or (c16Email LIKE ?) or (c16Email LIKE ?)) limit 1;')
or fail("Couldn't prepare name lookup SELECT statement: " . $DBI::errstr);
}

sub lookup_ios_address {
my $address = shift;
my $like = "%$address%";
my $like1 = "$address %";
my $like2 = "% $address %";
my $like3 = "% $address";

$lookupstmt->execute($like, $like) or fail("Couldn't execute name lookup SELECT statement: " . $DBI::errstr);
$lookupstmt->execute($like1, $like2, $like3, $like1, $like2, $like3) or fail("Couldn't execute name lookup SELECT statement: " . $DBI::errstr);

my @lookuprow = $lookupstmt->fetchrow_array();
if (@lookuprow) {
Expand Down Expand Up @@ -736,6 +738,7 @@ sub lookup_ios_address {
my $x = shift @lines;
last if (not defined $x) || ($x eq '');
$x =~ s/[^0-9]//g; # flatten.
$x =~ s/\A1//; # take out US country code
$mac_addressbook{$x} = [ @person ];
dbgprint("Person phone: [$x]\n");
}
Expand All @@ -759,14 +762,13 @@ sub lookup_macos_address {

# !!! FIXME: this all sucks.
my $phone = $address;
$phone =~ s/\A\+1//;
$phone =~ s/[^0-9]//g; # flatten.
$phone =~ s/\A1//; # remove US country code
my $email = lc($address);

my @lookuprow = ();
foreach (keys(%mac_addressbook)) {
if ( (($email ne '') && (index($_, $email) != -1)) ||
(($phone ne '') && (index($_, $phone) != -1)) ) {
if ( ($_ eq $email) || ($_ eq $phone) ) {
my $person = $mac_addressbook{$_};
@lookuprow = @$person;
last;
Expand Down

0 comments on commit 3de7c3e

Please sign in to comment.