Bug: Unable to open .eml from file:// uri
Status: REOPENED
Priority: P5
Created: 2022-02-15 11:36:55+00:00
Resolved: 2023-11-16 10:46:11+00:00

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0

Steps to reproduce:

I can not open a mail message fetched using browser namely as mail message, instead new message is created with the specified file as an attachment.

Consider the following use case: reply to particular comment to a bug from https://debbugs.gnu.org This bug tracker uses mail interface to accept new reports or comments. For convenience of other participants it is better to compose a message with proper `In-Reply-To` header.

- Choose any bug and any comment to it from https://debbugs.gnu.org
- A random one: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40959#50
- There is "mbox" link. Try to compose real reply to this message: click on the link and choose thunderbird to open the downloaded file


Actual results:

Thunderbird opens compose window with the file containing mail message as attachment.

The download has proper MIME type:
```
curl -I 'https://debbugs.gnu.org/cgi/bugreport.cgi?msg=50;bug=40959;mbox=yes'
HTTP/1.1 200 OK
Date: Mon, 14 Feb 2022 10:53:37 GMT
Server: Apache
Content-disposition: attachment; filename="bug_40959_message_50.mbox"
Strict-Transport-Security: max-age=63072000
Last-Modified: Fri, 05 Jun 2020 11:24:05 GMT
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
X-XSS-Protection: 1; mode=block
Content-Type: message/rfc822
```

However it becomes an ordinary text file as soon as it is downloaded to disk:
```
file bug_40959_message_50.mbox 
bug_40959_message_50.mbox: UTF-8 Unicode text
```

I have tried various options to open file. Error messages are given for daily build 99a1

Variants: silent failure, a message in the console:
```
thunderbird bug_40959_message_50.mbox
thunderbird file://`pwd`/bug_40959_message_50.mbox
thunderbird --file bug_40959_message_50.mbox
```
```
NS_ERROR_FAILURE: MessengerContentHandler.jsm:80
    openURI resource:///modules/MessengerContentHandler.jsm:80
    handle resource:///modules/MessengerContentHandler.jsm:553
```

With absolute path but **without** explicit `file://` scheme compose window appears with the file attached:
```
thunderbird `pwd`/bug_40959_message_50.mbox
thunderbird --file `pwd`/bug_40959_message_50.mbox
```

Main window with folder is raised and activated and an error is reported to the console if `--mail` option is used:
```
thunderbird --mail bug_40959_message_50.mbox
 Unrecognized URL: bug_40959_message_50.mbox

thunderbird --mail `pwd`/bug_40959_message_50.mbox
 Unrecognized URL: /home/ubuntu/bug_40959_message_50.mbox

thunderbird --mail file://`pwd`/bug_40959_message_50.mbox
 Unrecognized URL: file:///home/ubuntu/bug_40959_message_50.mbox
```


Expected results:

- There should be a command line option that forces opening a file as mail message bypassing heuristics.
- Some error message should be shown to user if thunderbird can not handle specified option and argument.
- `file://` scheme should not cause an error, the URI should be considered as a local file.

Workaround: rename file to give it `.eml` extension instead of `.mbox` and open it as a relative or absolute path. Warning: do not add explicit `file://` scheme otherwise it fails with the following message:
```
thunderbird file://`pwd`/bug_40959_message_50.eml
 NS_ERROR_FILE_TARGET_DOES_NOT_EXIST: Component returned failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) [nsICommandLine.resolveFile]
```