chronicle-app / chronicle-imessage

chronicle-etl plugin for accessing your iMessage messages and attachments using the command line
4 stars 0 forks source link

Don't crash if icloud account/phone can't be inferred #3

Open hyfen opened 2 years ago

hyfen commented 2 years ago

The extractor uses the LocalContacts module to try and infer information about a user's icloud account and phone number (via local Address Book sqlite dbs). If these details can't be found and no options are passed in manually (via my_phone_number setting, etc), the extractor should raise an exception instead of crashing.

This was encountered by @wongjustin99 in #chronicle-etl/33:

Beginning job
/Users/goose/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/chronicle-imessage-0.2.3/lib/chronicle/imessage/imessage_extractor.rb:61:in `load_my_phone_contact': undefined method `fetch' for nil:NilClass (NoMethodError)

          phone_number: @config.my_phone_number || local_contacts.my_phone_contact.fetch(:phone_number),
                                                                                  ^^^^^^
        from /Users/goose/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/chronicle-imessage-0.2.3/lib/chronicle/imessage/imessage_extractor.rb:51:in `prepare_data'
hyfen commented 2 years ago

@wongjustin99, I'm using the local address book directory (~/Library/Application Support/AddressBook) to try and guess a user's phone number (so that a message's actor can be set properly) and it's hard to know what's typical in accounts that aren't mine.

If you open Contacts.app, do you have an entry at the top for yourself? Does it have a phone number associated with it?

This is what mine looks like:

image
wongjustin99 commented 2 years ago

I had an empty one for myself - probably since I use contacts synced to an external service. I clicked "Make this my Card" and now I have some phone numbers there.

however, I still see the same error and stacktrace.

I have 10+ numbers, but it appears you have just one. Could that be contributing?

image
hyfen commented 2 years ago

I pushed updates for chronicle-imessage and chronicle-etl that at least prevent the full crash. You can try again with:

gem install chronicle-etl -v 0.4.4
gem install chronicle-imessage -v 0.2.5
chronicle-etl -e imessage -t imessage --limit 10

I suspect it won't work because #4 isn't handled yet. But you can always pass in the missing information manually: chronicle-etl -e imessage -t imessage --limit 10 --extractor-opts my_phone_number:123-1234-1234 my_name:foo

The general problem is that the local iMessage sqlite database only contains the identifiers of participants, not your own number. Your iCloud account (for setting the sender of iMessages) is easy to figure out but not your phone number (for setting the sender of SMS). I might consider adding an option for users who don't care about sending the sender field.

Regarding your 10+ numbers, that's another thing I'll have to figure out with some sqlite reverse engineering but I have a feeling it might not be possible to correctly guess which is the sender because I don't see a concept of a default phone number in iCloud contacts.

wongjustin99 commented 2 years ago

I didn't need to manually pass that option in. Actually seems to be working now! Thanks so much for the help.

Now that I have this set up, this might be a conversation for somewhere else besides this issue - but how are you using these plugins? Are they piped into something else for viewing/analysis? Or do you have any ideas you were planning to flesh out?