3

I'm trying to open a specific email folder in Thunderbird (v102.7.1), using the command line arguments.

I already found out that using thunderbird.exe mid:<MESSAGE-ID> will open the email with <MESSAGE-ID>.

Is there a way to open an email folder with a similar method or the command line in general?

I already tried:

  • thunderbird.exe mid:<FOLDER-LOCATION>
  • thunderbird.exe mail:<FOLDER-LOCATION>
  • thunderbird.exe inbox:<FOLDER-LOCATION>
  • thunderbird.exe <FOLDER-LOCATION>
  • thunderbird.exe label:<LABEL>
  • thunderbird.exe -mail label:<LABEL>
  • thunderbird.exe -mail -folder "mailbox://imap.<PROVIDER>.de/Inbox
  • thunderbird.exe -mail <ACCOUNT NAME>/<NAMESPACE>/INBOX

and various other things I don't remember anymore.

3
  • Welcome to the community. I'm not certain but I think this depends on where exactly the mail is. For example GMail doesn't have folders, but labels. If you have GMail, you could try something like thunderbird.exe label:<LABEL>. No guarantees tho' :-) These two came right up with google search - maybe they help? support.mozilla.org/en-US/questions/1148495 support.cdn.mozilla.net/en-US/questions/1374787 Commented Feb 6, 2023 at 11:41
  • Sadly thunderbird.exe label:<LABEL> or any variation did not work. I'm affaid, the links did not provide any usefull information. Still a good idea tho.
    – username
    Commented Feb 6, 2023 at 12:39
  • Dang! I'd suggest you edit the question to add this. This is generally advisable so that the relevant info is directly available for the community members without digging it out from comments. As SE communities aren't discussion forums, I'd suggest checking the Help section to get a handle on how things work. Commented Feb 6, 2023 at 12:45

1 Answer 1

0

I used a combination of batch & AutoHotkey:

  1. Open Thunderbird session.json file at:
    %AppData%\Thunderbird\Profiles\[email protected]\session.json
    (REPLACE YOUR_MAIL).
  2. Exit Thunderbird.
  3. The folderURI is saved in session.json.
  4. Make the files below and copy "thunderbird.bat" & "Thunderbird Open Specific Folder.ahk" to "C:\Windows\System32\".

thunderbird.bat accepts 2 args, -mail & folderName

Thunderbird Open Specific Folder.ahk accepts 1 arg, folderName which is passed on from the thunderbird.bat

(REPLACE YOUR_MAIL). 5. Open cmd & type for ex: thunderbird -mail Inbox.

The only downside is you have to close Thunderbird (not minimize to tray, but File > Exit) in order for it to open specific folder.

thunderbird.bat

@echo off

rem Check if the first parameter is "-mail"
if "%1"=="-mail" (
    rem Check if the second parameter is "Inbox"
    if "%~2"=="Inbox" (
        rem Run the AutoHotkey script for Inbox
        start "" /b "Thunderbird Open Specific Folder.ahk" Inbox
        exit /b
    )

    rem Check if the second parameter is "Drafts"
    if "%~2"=="Drafts" (
        rem Run the AutoHotkey script for Drafts
        start "" /b "Thunderbird Open Specific Folder.ahk" Drafts
        exit /b
    )

    rem Check if the second parameter is "Templates"
    if "%~2"=="Templates" (
        rem Run the AutoHotkey script for Templates
        start "" /b "Thunderbird Open Specific Folder.ahk" Templates
        exit /b
    )

    rem Check if the second parameter is "Trash"
    if "%~2"=="Trash" (
        rem Run the AutoHotkey script for Trash
        start "" /b "Thunderbird Open Specific Folder.ahk" Trash
        exit /b
    )

    rem Check if the second parameter is "Gmail Drafts"
    if "%~2"=="Gmail Drafts" (
        rem Run the AutoHotkey script for Gmail Drafts
        start "" /b "Thunderbird Open Specific Folder.ahk" "Gmail Drafts"
        exit /b
    )

    rem Check if the second parameter is "Sent Mail"
    if "%~2"=="Sent Mail" (
        rem Run the AutoHotkey script for Sent Mail
        start "" /b "Thunderbird Open Specific Folder.ahk" "Sent Mail"
        exit /b
    )

    rem Check if the second parameter is "All Mail"
    if "%~2"=="All Mail" (
        rem Run the AutoHotkey script for All Mail
        start "" /b "Thunderbird Open Specific Folder.ahk" "All Mail"
        exit /b
    )

    rem Check if the second parameter is "Spam"
    if "%~2"=="Spam" (
        rem Run the AutoHotkey script for Spam
        start "" /b "Thunderbird Open Specific Folder.ahk" Spam
        exit /b
    )

    rem Check if the second parameter is "Gmail Trash"
    if "%~2"=="Gmail Trash" (
        rem Run the AutoHotkey script for Gmail Trash
        start "" /b "Thunderbird Open Specific Folder.ahk" Gmail Trash
        exit /b
    )
)

rem If the conditions are not met, display a message
echo Invalid parameters. Usage: %0 -mail "FolderName"

Thunderbird Open Specific Folder.ahk

#NoEnv
SetWorkingDir %A_ScriptDir%
#Warn
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
SetTitleMatchMode Fast
DetectHiddenWindows Off
DetectHiddenText On
#WinActivateForce
#NoTrayIcon
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
#Persistent
#MaxThreadsPerHotkey 2

ThunderbirdOpenSpecificFolder:
FileCopy, %A_AppData%\Thunderbird\Profiles\[email protected]\session.json, %A_AppData%\Thunderbird\Profiles\[email protected]\session.json.bak, 1  ; session.json > session.json.bak
RunWait, cmd /c cd /d "`%APPDATA`%\Thunderbird\Profiles\[email protected]\" && jq . session.json > sessionPretty.json, , Hide  ; sessionPretty.json
FileRead, session, %A_AppData%\Thunderbird\Profiles\[email protected]\sessionPretty.json  ; sessionPretty.json
folder := A_Args[1]  ; folder
/*
MsgBox, 262144, , "%folder%"  ; folder
*/
If (folder = "Inbox")  ; IF folder = Inbox
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/INBOX""")  ; folder = Inbox
}
Else If (folder = "Drafts")  ; IF folder = Drafts
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/Drafts""")  ; folder = Drafts
}
Else If (folder = "Templates")  ; IF folder = Templates
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/Templates""")  ; folder = Templates
}
Else If (folder = "Trash")  ; IF folder = Trash
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/Trash""")  ; folder = Trash
}
Else If (folder = "Gmail Drafts")  ; IF folder = Gmail Drafts
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/[Gmail]/Drafts""")  ; folder = Gmail Drafts
}
Else If (folder = "Sent Mail")  ; IF folder = Sent Mail
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/[Gmail]/Sent Mail""")  ; folder = Sent Mail
}
Else If (folder = "All Mail")  ; IF folder = All Mail
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/[Gmail]/All Mail""")  ; folder = All Mail
}
Else If (folder = "Spam")  ; IF folder = Spam
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/[Gmail]/Spam""")  ; folder = Spam
}
Else If (folder = "Gmail Trash")  ; IF folder = Gmail Trash
{
    session := RegExReplace(session, """folderURI.*""", """folderURI"": ""imap://YOUR_MAIL%[email protected]/[Gmail]/Trash""")  ; folder = Gmail Trash
}
FileDelete, %A_AppData%\Thunderbird\Profiles\[email protected]\sessionPretty.json  ; sessionPretty.json
FileDelete, %A_AppData%\Thunderbird\Profiles\[email protected]\session.json  ; session.json
FileAppend, %session%, %A_AppData%\Thunderbird\Profiles\[email protected]\session.json  ; session.json
Run, thunderbird  ; thunderbird
ExitApp  ; ExitApp
Return

URLS.txt

imap://YOUR_MAIL%[email protected]/INBOX
imap://YOUR_MAIL%[email protected]/Drafts
imap://YOUR_MAIL%[email protected]/Templates
imap://YOUR_MAIL%[email protected]/Trash

imap://YOUR_MAIL%[email protected]/[Gmail]/Drafts
imap://YOUR_MAIL%[email protected]/[Gmail]/Sent Mail
imap://YOUR_MAIL%[email protected]/[Gmail]/All Mail
imap://YOUR_MAIL%[email protected]/[Gmail]/Spam
imap://YOUR_MAIL%[email protected]/[Gmail]/Trash

(REPLACE YOUR_MAIL).

Cli Commands.txt

thunderbird -mail Inbox
thunderbird -mail Drafts
thunderbird -mail Templates
thunderbird -mail Trash
thunderbird -mail "Gmail Drafts"
thunderbird -mail "Sent Mail"
thunderbird -mail "All Mail"
thunderbird -mail Spam
thunderbird -mail "Gmail Trash"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .