Bug: [TB 102] All Imap folders and messages vanished from local client UI after provider canceled account.
Status: RESOLVED
Priority: --
Resolution: INVALID
Created: 2023-06-16 13:47:08+00:00
Resolved: 2023-06-19 08:19:12+00:00

Actually I use Betterbird 102, so tagging @Betterbird here, as I don't know if related code has been touched.

Background story: I had an old Imap e-mail account provided by a certain institution. Since I had left the institution, at one point the account was abolished and I had severe trouble recovering my mail. 

Keyword: Dataloss.

Details below:

### A) How to reproduce:

1. Have IMAP account. Let's call it `ImapThiloteE`
2. Have setting `Keep messages in all folders for this account on this computer` enabled
3. Have setting `Synchronize all messages locally regardless of age` enabled (Not sure if necessary) 
4. Have e-mail provider that cancels your account and deletes all your data from the Imap server
5. Start Thunderbird
6. Try to `Get new messages` for this e-mail account

### B) What happens:

1. Login fails, because account does not exist anymore
2. All Imap folders and messages vanished from local client UI. Only the `Inbox` symbol still shows, but when clicking on it will trigger an login attempt, which will fail, instead of showing messages or folders.

### C) Workaround and partial (not complete!) solution to recover mails in sub-folders:

1. Browse to the profile folder on your local computer, open `ImapMail>...` and manually copy and paste the e-mail account folder `ImapThiloteE` and the `ImapThiloteE.msf` file to `Mail > Local Folders > ...` 
2. All  following steps are done in `Mail > Local Folders > ...` 
3. There, rename `ImapThiloteE` to `ImapThiloteE.bsd` at the end of its name
4. For every folder within that mail account add a new "message container" file that is named similar to the folder name minus the `.sbd`. So if the folder is named `example.sbd`, then create a new file called `example`. In my case, this step was also necessary for my `Inbox`, as my inbox message container file was gone.
5. If you become aware of the existence of "lonely".msf files, which are not accompanied by message container files, for example in my case the Sent, Templates, Trash and Junk folder exhibited that characteristic, then you have to do TWO additional things: 1) create a .bsd folder with similar name. 2) Add a new empty file with similar name.

This process will allow you to recover all mails that were stored in sub-folders, but not mails that were stored in missing "message container files" (for lack of better words).

Luckily most of my messages (including the most important ones) were stored in sub-folders to the Inbox and their message container files were still intact, but other users may not that lucky.

### D) Bonus Problem:

1. Look into `ImapThiloteE`
2. Find lots and lots of Inbox-x.msf files (2kb large) with similar content.

I will add attachments.

Why is this? - Maybe left overs from failed login attempts?

I don't know exaclty when my account was deleted.
The first such file was created 2022-11-15 and there have been lots and lots since then.


### F) Two good questions, if answered might lead us to the root cause:

1. Why did all messages and folders vanish in the UI?
    
   **Rudimentary answer:** I don't know the code, but I suspect the login attempt triggered some kind of preparation for updating and downloading all the local messages and folders from the Imap Server. I suppose in future, this preparation should only start once the successful login has been confirmed and keep the locally stored messages "as is" and meanwhile keep them accessible to users in case the login fails.

2. Why were some of the "message container files" (e.g. for Inbox, Sent, Junk, etc.) missing in the profile folder?

   **Rudimentary answer:** I don't know. My other Imap accounts (from different providers) do **not** miss these files.