Bug 1939403 Comment 2 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

This is a twisted bug, and I do not think it is caused by my recent changes for the API. However, the API exposed an existing bug in core code.

The URI of tag folders with special chars could look like the following:

`prettyName`: "6: special"
`URI`: "mailbox://nobody@smart%20mailboxes/tags/67a2857d5" 

What happens is that [this code](https://searchfox.org/comm-esr128/rev/f2f1a47908f51d8137919aed10742e019e234ac8/mail/modules/SmartMailboxUtils.sys.mjs#215-224) tries to guess the URI of the tag folder based on its key (but the guessed URI is wrong), and then checks for the existence of the folder.

```
    let folder = this.#tagsFolder.getChildWithURI(
      this.getTagFolderUriForKey(tag.key),
      false,
      false
    );
    if (folder) {
      return folder;
    }
    folder = this.#tagsFolder.createLocalSubfolder(tag.key);
```
Since the folder was not found, it is created with the key. However, the folder with that name DOES exist and the create operation fails. Similar code is already used [in TB115](https://searchfox.org/comm-esr115/rev/da57de275e7ae5c089e6e55e57a25dcd182e3664/mail/base/content/about3Pane.js#1405-1414).

I think the conflict is due to different functions being used to create folders. We have
* `folder.createFolder()`
* `folder.createLocalSubfolder()`

The first one is sanitizing the name via a hash function:
https://searchfox.org/comm-central/rev/08aea30323820d7d612f849c932fd29d4d9ed972/mailnews/local/src/nsMsgMaildirStore.cpp#334

**How to fix this?**

1a. We could use `folder.getChildNamed()` to find the tag folder via its name
1b. We could call the used sanitize function from JS and reconstruct the hashed URI, but we might then not find folders which where created using `createLocalSubfolder()`

2. We probably no longer use `folder.createLocalSubfolder()` in SmartMailboxUtils.sys.mjs, but  `folder.createFolder()`
This is a twisted bug, and I do not think it is caused by my recent changes for the API. However, the API exposed an existing bug in core code.

The URI of tag folders with special chars could look like the following:

`prettyName`: "6: special"
`URI`: "mailbox://nobody@smart%20mailboxes/tags/67a2857d5" 

What happens is that [this code](https://searchfox.org/comm-esr128/rev/f2f1a47908f51d8137919aed10742e019e234ac8/mail/modules/SmartMailboxUtils.sys.mjs#215-224) tries to guess the URI of the tag folder based on its key (but the guessed URI is wrong), and then checks for the existence of the folder.

```
    let folder = this.#tagsFolder.getChildWithURI(
      this.getTagFolderUriForKey(tag.key),
      false,
      false
    );
    if (folder) {
      return folder;
    }
    folder = this.#tagsFolder.createLocalSubfolder(tag.key);
```
Since the folder was not found, it is created with the key. However, the folder with that name DOES exist and the create operation fails. Similar code is already used [in TB115](https://searchfox.org/comm-esr115/rev/da57de275e7ae5c089e6e55e57a25dcd182e3664/mail/base/content/about3Pane.js#1405-1414).

I think the conflict is due to different functions being used to create folders. We have
* `folder.createFolder()`
* `folder.createLocalSubfolder()`

The first one is sanitizing the name via a hash function:
https://searchfox.org/comm-central/rev/08aea30323820d7d612f849c932fd29d4d9ed972/mailnews/local/src/nsMsgMaildirStore.cpp#334

**How to fix this?**

* We could use `folder.getChildNamed()` to find the tag folder via its name
* We could try to call the used sanitize function from JS and reconstruct the hashed URI, but we might then not find folders which where created using `createLocalSubfolder()`

We probably no longer use `folder.createLocalSubfolder()` in SmartMailboxUtils.sys.mjs, but  `folder.createFolder()`
This is a twisted bug, and I do not think it is caused by my recent changes for the API. However, the API exposed an existing bug in core code.

The URI of tag folders with special chars could look like the following:

`prettyName`: "6: special"
`URI`: "mailbox://nobody@smart%20mailboxes/tags/67a2857d5" 

What happens is that [this code](https://searchfox.org/comm-esr128/rev/f2f1a47908f51d8137919aed10742e019e234ac8/mail/modules/SmartMailboxUtils.sys.mjs#215-224) tries to guess the URI of the tag folder based on its key (but the guessed URI is wrong), and then checks for the existence of the folder.

```
    let folder = this.#tagsFolder.getChildWithURI(
      this.getTagFolderUriForKey(tag.key),
      false,
      false
    );
    if (folder) {
      return folder;
    }
    folder = this.#tagsFolder.createLocalSubfolder(tag.key);
```
Since the folder was not found, it is created with the key. However, the folder with that name DOES exist and the create operation fails. Similar code is already used [in TB115](https://searchfox.org/comm-esr115/rev/da57de275e7ae5c089e6e55e57a25dcd182e3664/mail/base/content/about3Pane.js#1405-1414).

I think the conflict is due to different functions being used to create folders. We have
* `folder.createFolder()`
* `folder.createLocalSubfolder()`

The first one is sanitizing the name via a hash function:
https://searchfox.org/comm-central/rev/08aea30323820d7d612f849c932fd29d4d9ed972/mailnews/local/src/nsMsgMaildirStore.cpp#334

**How to fix this?**

* We could use `folder.getChildNamed()` to find the tag folder via its name
* We could try to call the used sanitize function from JS and reconstruct the hashed URI, but we might then not find folders which where created using `createLocalSubfolder()`

We probably should no longer use `folder.createLocalSubfolder()` in SmartMailboxUtils.sys.mjs, but  `folder.createFolder()`?
This is a twisted bug, and I do not think it is caused by my recent changes for the API. However, the API exposed an existing bug in core code.

The URI of tag folders with special chars could look like the following:

`prettyName`: "6: special"
`URI`: "mailbox://nobody@smart%20mailboxes/tags/67a2857d5" 

What happens is that [this code](https://searchfox.org/comm-esr128/rev/f2f1a47908f51d8137919aed10742e019e234ac8/mail/modules/SmartMailboxUtils.sys.mjs#215-224) tries to guess the URI of the tag folder based on its key (but the guessed URI is wrong), and then checks for the existence of the folder.

```
    let folder = this.#tagsFolder.getChildWithURI(
      this.getTagFolderUriForKey(tag.key),
      false,
      false
    );
    if (folder) {
      return folder;
    }
    folder = this.#tagsFolder.createLocalSubfolder(tag.key);
```
Since the folder was not found, it is created with the key. However, the folder with that name DOES exist and the create operation fails. Similar code is already used [in TB115](https://searchfox.org/comm-esr115/rev/da57de275e7ae5c089e6e55e57a25dcd182e3664/mail/base/content/about3Pane.js#1405-1414).

~~I think the conflict is due to different functions being used to create folders. We have~~
~~* `folder.createFolder()`~~
~~* `folder.createLocalSubfolder()`~~

The first one is sanitizing the name via a hash function:
https://searchfox.org/comm-central/rev/08aea30323820d7d612f849c932fd29d4d9ed972/mailnews/local/src/nsMsgMaildirStore.cpp#334

**How to fix this?**

* We could use `folder.getChildNamed()` to find the tag folder via its name
* We could try to call the used sanitize function from JS and reconstruct the hashed URI, but we might then not find folders which where created using `createLocalSubfolder()`

~~We probably should no longer use `folder.createLocalSubfolder()` in SmartMailboxUtils.sys.mjs, but  `folder.createFolder()`?~~

Edit: It seems both functions use the hash method in the end. That would mean special chars in tag folders are just broken?

Back to Bug 1939403 Comment 2