Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plaintext backup support? #227

Open
sequc82 opened this issue Aug 4, 2024 · 10 comments
Open

Plaintext backup support? #227

sequc82 opened this issue Aug 4, 2024 · 10 comments
Labels
awaiting response Further information is requested enhancement New feature or request

Comments

@sequc82
Copy link

sequc82 commented Aug 4, 2024

Hi @bepaald

First, thank you for your work in creating this tool!

Second, is it possible to use this tool on older plaintext backups, from back when Signal still exported them as XML?

@bepaald
Copy link
Owner

bepaald commented Aug 4, 2024

Hi! This tool currently does not work with the old XML backups (at least not as input, it does output them).

The XML format was quite simple if I remember correctly, it should not be too hard to maybe import such a file into an existing backup, after which any other function of this program should work on that backup file. Was there any specific functionality you were looking for?

Do note that the XML backups were (very) lossy. If I'm not mistaken (it's been a long time, I'd have to investigate to be sure) not only did they leave out messages (all outgoing group messages, and all messages with a media attachment (including the text part)), it also permanently altered the context of conversations as incoming group messages are indiscernible from the 1-on-1 messages of that specific contact.

Any work on this will take a little while though, I'm quite busy at the moment and the time I do have I'm spending on fixing existing functionality first (changes in Signal Desktop have broken some functions).

@bepaald
Copy link
Owner

bepaald commented Aug 18, 2024

Any chance #230 has made this feature request obsolete?

@bepaald bepaald added the enhancement New feature or request label Aug 18, 2024
@sequc82
Copy link
Author

sequc82 commented Sep 2, 2024

Hi @bepaald,

It may be obsolete for me, if I can get the DB version 23 backup mentioned in #230 to work, but I'm not sure if those two backups overlap yet.

Thanks!

@sequc82
Copy link
Author

sequc82 commented Sep 6, 2024

Hi @bepaald,

To follow up here, it looks like the DB version 23 backup I referenced in #230 did not overlap the old plaintext backups, so I would still find value in this enhancement, though I acknowledge it would be a rather low impact value add to your project overall, and with the breaking changes from Signal Desktop, I completely understand it to be a low priority change.

I know it can be time consuming to provide the background to get a new dev up to speed on an existing project, but I'd be happy to offer support where possible, when I have time!

@bepaald
Copy link
Owner

bepaald commented Sep 6, 2024

Ok, no problem. I will get on this when I have some time. I don't think it'll take too long (famous last words).

I think your support will be most useful by testing what I come up with, I'm sure I won't get it completely right immediately.

Still, an important question:
Is the goal here to just have a nicely formatted version of the XML contents (like --exporthtml), or to actually get a valid backup-file that can be restored by Signal Android?

In case of the latter, this tool will not be able to create any contacts, they need to already exist in the input-backup file into which the XML will be imported. In case of the former, this is not necessary, I can just insert (incomplete) contacts into the database, but the backup will not be valid.

@bepaald
Copy link
Owner

bepaald commented Sep 13, 2024

I've been making steady progress on this. Nothing in the repo yet, but locally I've actually written an XML parser, and a class that imports data from SignalPlaintextBackup.xml into an sqlite database. I'd say I'm making good progress.

Just another quick question. I know the backup file format has changed quite a bit over time, but I don't know if that has also happened with the plaintext backups. I only have one single plaintext backup from around april 2018, but I don't know if it looks the same as yours. Could you confirm the general structure of the XML file is this:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!-- File Created By Signal -->
<smses count="20659">
 <sms protocol="0" address="+[phone-number]" contact_name="[name]" date="1472921043299" readable_date="Sat, 03 Sep 2016 18:44:03 GMT+02:00" type="2" subject="null" body="[message body goes here]" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" />
 [...more sms tags...]
</smses>

Do you have the same two element types (smses (once) and sms (repeated))? Do you see any extra or missing attributes in your file?

Thanks!

bepaald added a commit that referenced this issue Sep 18, 2024
@bepaald
Copy link
Owner

bepaald commented Sep 24, 2024

An update:

I think this function is more or less complete (at least until it is tested).


  • To import a plaintext backup into an existing Android backup:
./signalbackup-tools [android backup] [passphrase] --importplaintextbackup [SignalPlaintextBackup.xml] -o [output]

The import attempts to automatically match the contacts in the XML file to those in the Android backup, first by name, then by phone number.

Note, due to the age of the plaintext backup, it is not unlikely the matching fails. In my testing, I had contacts in the plaintext backup that are no longer on Signal. For these, it's possible the contact has split into two in the Android backup, one with only a phone number and one with a UUID. It is important the contacts are matched correctly (the one with the UUID), or Signal will likely crash when attempting to restore.

The matching can be done manually as well. To list the contacts in the xml file, use ./signalbackup-tools --listxmlcontacts [SignalPlaintextBackup.xml]. To list the contacts in the Android backup, use --listrecipients (note the _id column). Then the matches can be specified manually by adding --mapxmlcontacts "+1234567890=3,+[more_phone_numbers]=[more_ids],..." to the --importplaintextbackup command, where the phone number is from the XML file, and the id is from the Android backup.

If contacts can not be matched, but importing is desired anyway, add --addincompletedataforhtmlexport. As the name implies this will not yield a valid Android backup, but the resulting backup can be passed to --exporthtml (or --exporthtml can be used in the same command, without even using -o [ouput]).


  • To export a plaintext backup to html (without an Android backup):

Obviously, the output backup from the above procedure can be passed to --exporthtml as desired, but if you want to do this without an existing Android backup, use

./signalbackup-tools --exportplaintextbackuphtml [SignalPlaintextBackup.xml] [HTMLOUTPUTDIR]

This command also supports most of the options that --exporthtml does (see here).

Additionally, both the above options support the options --(no-)xmlmarkdelivered and --(no-)xmlmarkread to mark the imported messages as read (default=false) or delivered (default=true), as this information is not available in the XML backup.


Note, in addition to the limitations of the plaintext backup I mentioned in an earlier message, I also noticed Signal-calls are in the backup and not distinguishable from other messages (except the message body "Called Bob", may be rare for real messages).


That was a lot to type, I hop it is somewhat clear. Let me know if anything needs clarification. Otherwise test it whenever you find the time.

Thanks!

@bepaald bepaald added the awaiting response Further information is requested label Oct 7, 2024
@bepaald
Copy link
Owner

bepaald commented Oct 25, 2024

ping

@sequc82
Copy link
Author

sequc82 commented Nov 14, 2024

@bepaald

I am so sorry I hadn't gotten back to you sooner. Unfortunately, life caught me by surprise, and now I'm finally able to check back in. Looks like you've been busy while I've been gone! Looking at what I have, it looks like the XML structure is the same as you describe, at least back to 2017.

To answer your earlier question, my original goal was just to format the old XML the same as --exporttohtml but it looks like you've gone above and beyond! I will give it a test as soon as I can.

@bepaald
Copy link
Owner

bepaald commented Nov 14, 2024

No problem, that's the way things go sometimes. Even if I had closed this issue as stale, it could always be re-opened.

Take your time, and let me know whether things work as you would want or if it needs more work. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Further information is requested enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants