alexlance / signal-message-exporter

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

Add option to export only SMS/MMS #4

Closed timatinsipid closed 1 year ago

timatinsipid commented 2 years ago

I see in the script this

parser.add_argument('--mode', '-m', dest='mode', action='store', help="mode should be one sms-only, sms-mms-only, sms-mms-signal")

I would only want to export SMS/MMS but cannot see how to do it?

alexlance commented 2 years ago

Ah yep that line is commented out - the feature wasn't added (yet).

Check out the print_num_* functions at the top of the file - they use the type field to delineate between Signal messages and SMS/MMS messages. One could then use those type IDs around these lines:

https://github.com/alexlance/signal-message-exporter/blob/21d404be58fc270108e249b1aa9ac2482720df61/signal-message-exporter.py#L265

https://github.com/alexlance/signal-message-exporter/blob/21d404be58fc270108e249b1aa9ac2482720df61/signal-message-exporter.py#L280

to only pick out SMS/MMS messages.

timatinsipid commented 2 years ago

So I changed line 265 to this cursor.execute('select from sms where type in (20, 87, 23) order by date_sent') and 280 to this cursor.execute('select from mms where msg_box in (20, 87, 23) order by date')

and it produced something, but i seem to have a lot of errors 2022-10-18 02:49:09 - INFO - Finished media export. Messages exported: 1516 Errors: 1220 A lot of them say ERROR - Could not find contact in the recipient table with ID: 113,

not sure if that is normal or not

alexlance commented 2 years ago

It will have printed out the ... 1220 messages (that is a ton), if you scroll up and look through them, do they look like they maybe belong to a contact that you no longer have in your contacts list?

One approach might be to put a bit of stuff in the code like:

myoldcontacts = {
    113: {"phone": "0400000000", "name": "John Smith"},
    209: {"phone": "0400000000", "name": "Jane Smith"}
  (and so on)
}

and then add a thing in the code around line

 87     try:
 88         phone = ADDRESSES[row["address"]]['phone']
 89         name = ADDRESSES[row["address"]]['name']
 90     except KeyError:
 91         try:
 92             phone = GROUPS[row["address"]][0]['phone']
 93             name = GROUPS[row["address"]][0]['name']
 94         except (KeyError, IndexError):
 95             try:
 96                 phone = myoldcontacts[row["address"]]['phone']     <---- new stuff
 97                 name = myoldcontacts[row["address"]]['name']       <----- new stuff
 98             except:
 99                 logging.error(f'Could not find contact in the recipient table with ID: {row["address"]}, sms looks like: {row}')
timatinsipid commented 2 years ago

It all seems to be the same contact and they are a current contact. I made the changes with just contact 113 I added this around line 194 myoldcontacts = { 113: {"phone": "+12345678901", "name": "User Name"} } and added this to both the SMS and MMS sections around line 94 and line 134 except (KeyError, IndexError): try: phone = myoldcontacts[row["address"]]['phone'] name = myoldcontacts[row["address"]]['name'] except: logging.error(f'Could not find contact in the recipient table with ID: {row["address"]}, mms looks like: {row}')

This fixed the export issue and all the errors resolved so it looks like it was one bad contact that keeps using signal and stopping again

jgravois commented 2 years ago

I would only want to export SMS/MMS

this was my preference as well. i was also able to sort myself out using the instructions above too. 🙏