Skip to content

Commit

Permalink
Fixed case where we trash an ongoing conversation and then write an e…
Browse files Browse the repository at this point in the history
…mpty one.

Bunch of debug logging added, too.
  • Loading branch information
icculus committed Jun 23, 2016
1 parent 8d8ab97 commit 7a2bf06
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions archive_imessage.pl
Expand Up @@ -103,6 +103,8 @@ sub usage {
fail("--attachments-shrink-percent must be between 1 and 100.");
}

dbgprint("\$now is $now.\n");

sub archive_fname {
my $domain = shift;
my $name = shift;
Expand Down Expand Up @@ -267,6 +269,7 @@ sub flush_conversation {
dbgprint("Flushing conversation! trash=$trash\n");

if ($trash) {
$outmsgid = undef;
$output_text = '';
$output_html = '';
@output_attachments = ();
Expand Down Expand Up @@ -910,7 +913,7 @@ sub talk_gap {
if (($now - $date) < $gaptime) {
dbgprint("timestamp '$date' is less than $gaptime seconds old.\n");
if ($msgid < $ending_startid) {
$ending_startid = ($startmsgid-1);
$ending_startid = $startmsgid - 1;
dbgprint("forcing global startid to $ending_startid\n");
}
# trash this conversation, it might still be ongoing.
Expand All @@ -931,7 +934,9 @@ sub talk_gap {

# Try to merge collections that appear to be the same conversation...
if (($handle_id != $lasthandle_id) or (talk_gap($lastdate, $date))) {
flush_conversation(0);
dbgprint("This appears to be a new conversation.\n");

flush_conversation(0); # dump whatever might be pending.

$account = $default_account if (not defined $account); # happens on old SMS messages.
$account = $default_account if $account =~ /\A[ep]\:\Z/i;
Expand Down Expand Up @@ -1178,6 +1183,7 @@ sub talk_gap {
$outmsgid = $msgid;
}

dbgprint("Done running through all the messages in the database.\n");
$db->disconnect();

# Flush the final conversation if it's older than the talk gap.
Expand All @@ -1189,6 +1195,7 @@ sub talk_gap {

# Update the global startid.
if ($ending_startid != $startid) {
dbgprint("Flushing global startid: new=$ending_startid old=$startid\n");
$startid = $ending_startid;
flush_startid(undef, undef);
}
Expand All @@ -1197,6 +1204,8 @@ sub talk_gap {
print("All completed conversations archived.\n");
}

dbgprint("bye bye!\n");

exit(0);

# end of archive_imessage.pl ...

0 comments on commit 7a2bf06

Please sign in to comment.