alexlance / signal-message-exporter

Export SMS, MMS, and Signal messages out of Signal
39 stars 5 forks source link

Could not find contact in the recipient table #3

Closed jgravois closed 2 years ago

jgravois commented 2 years ago

Hi there! 👋 thanks for sharing (and maintaining) this Python script!

after processing ~15k sms messages successfully, I hit a (caught) error that prevents an .xml file from being generated.

ERROR - Could not find contact in the recipient table with ID: 624, sms looks like:
{
  '_id': 15106, 
  'thread_id': 448, 
  'address': 624, 
  'address_device_id': 1, 
  'person': None, 
  'date': 1567095496427, 
  'date_sent': 1567095492000, 
  'date_server': -1, 
  'protocol': 0, 
  'read': 1, 
  'status': -1, y
  'type': 20, 
  'reply_path_present': 0, 
  'delivery_receipt_count': 0, 
  'subject': None, 
  'body': ' no subject / JOHN, reply YES to confirm your appt at 9:30 AM on Tuesday, September 3, 2019. Call to cancel.\r\nBMG-Advantage\r\n9097943682\r\nText STOP to opt-out',
  'mismatched_identities': None, 
  'service_center': '+12063130055', 
  'subscription_id': 1, 
  'expires_in': 0, 
  'expire_started': 0, 
  'notified': 0, 
  'read_receipt_count': 0, 
  'unidentified': 0, 
  'reactions': None, 
  'reactions_unread': 0, 
  'reactions_last_seen': -1, 
  'remote_deleted': 0, 
  'notified_timestamp': 0, 
  'server_guid': None, 
  'receipt_timestamp': -1, 
  'export_state': b'0\x02', 
  'exported': 1
}

the message itself looks like a pretty benign robo-confirmation message to me so my instinct is to just try papering over the error and continue on:

    except (KeyError, IndexError):
        logging.error(f'Could not find contact in the recipient table with ID: {row["address"]}, sms looks like: {row}')

        phone = 'dummy phone number'
        name = 'dummy name'
        # sys.exit(1)

sms.setAttribute('address', phone)
sms.setAttribute('contact_name ', name)

that said, the only reason i'm using this tool is because the option built into Signal recently to export SMS is resulting in lots and lots of missing messages.

so any suggestions to help me get to the root of the 'real' problem would be a godsend.

https://community.signalusers.org/t/exported-sms-and-mms-but-cannot-delete-them-from-signal/48194/10?u=jgravois

alexlance commented 2 years ago

Hi there, I changed the behaviour of the script slightly, to skip past the errors, rather than halting in its tracks. There'll be a note about the errors at the bottom of the output now, and you can scroll back up and look for the word error to see which messages were skipped.

alexlance commented 2 years ago

I can't really tell you what the root cause of the problem is - it doesn't make sense that there'd be a contact in your address book if it's a robo-text.

Anyway if you run git pull to get the latest code and try it again you should get most of your messages exported.

jgravois commented 2 years ago

thanks for the quick reply @alexlance!

your tweaks allowed me to generate a sms-backup-restore.xml file, but sadly it was empty/0kb.

i've attached the complete log. the gist of it is:

2022-10-18 00:00:01 - INFO - Finished signalbackup-tools
2022-10-18 00:00:01 - INFO - Parsing the sqlite database bits/database.sqlite
2022-10-18 00:00:01 - INFO - Total num SMS messages: 38725
2022-10-18 00:00:01 - INFO - Total number Signal messages: 29105
2022-10-18 00:00:01 - INFO - Total num MMS messages: 13518
2022-10-18 00:00:01 - INFO - Total number Signal media messages: 2964
2022-10-18 00:00:01 - INFO - Starting SMS and Signal text message export
# ... 
2022-10-18 00:04:53 - INFO - Finished media export. Messages exported: 16536 Errors: 12
make: *** [run] Error 137

i should admit at this point that i'm running your script on OSX.

alexlance commented 2 years ago

Okay I'll just do some testing. Are you running it in docker?

alexlance commented 2 years ago

Just a heads up you've attached the log and it likely has the content of the "broken" messages in it, I've delete the attachment from the comment.

alexlance commented 2 years ago

Looks like that final error message "Error 137" means that docker ran out of memory. I had to increase both my memory and swap to get it to work on mac, eg:

Screen Shot 2022-10-18 at 12 16 07 pm
jgravois commented 2 years ago

you're a lifesaver. absolutely maxxing out my trusty old 2015 mbp allowed me to generate an .xml file successfully.

Screen Shot 2022-10-17 at 7 41 41 PM

the log and it likely has the content of the "broken" messages in it

thanks for that.

i snooped the 'body': of all the broken messages in the file to confirm there was nothing sensitive in them and redacted my passphrase from the corresponding CLI command before i uploaded it too just to be safe.

thanks again for sharing this work and helping me debug my own issue.