1

How can I customize the date/time format in Thunderbird's message header section (see screenshot) ?

I would like the format to be: Thu, 13 Jun 2024 22:34 UTC+1

The answer should work for the current Thunderbird version 115.
I would prefer a solution without addons if possible.

screenshot

Thank you.

1 Answers1

1

Can confirm that the displayed value derives from a localized date string. Specifically, in mozilla-central/comm-central/mailnews/mime/emitters/nsMimeHtmlEmitter.cpp, there is the following, which injects what you might call a "virtual" header, X-Mozilla-LocalizedDate, into a list of headers for the UI to consume:

      // Add a localized version of the date header if we encounter it.                                                    
      if (!PL_strcasecmp("Date", headerInfo->name)) {                                                                      
        GenerateDateString(headerValue, convertedDateString, false);                                                       
        mailChannel->AddHeaderFromMIME("X-Mozilla-LocalizedDate"_ns,                                                       
                                       convertedDateString);                                                               
      }   

GenerateDateString is found in mozilla-central/comm-central/mailnews/mime/emitters/nsMimeBaseEmitter.cpp, and ultimately relies upon code from mozilla-central/intl/locale/AppDateTimeFormat.cpp to format the string that gets displayed. Eventually, we ultimately arrive at:

      nsAutoCString str;                                                                                                   
      rv = OSPreferences::GetInstance()->GetDateTimePattern(                                                               
          dateFormatStyle, timeFormatStyle, nsDependentCString(sLocale->get()),                                            
          str);                                                                                                            
      NS_ENSURE_SUCCESS(rv, rv);                                                                                           
      nsAutoString pattern = NS_ConvertUTF8toUTF16(str);                        

Where the operating system preferences are obtained, ultimately by code specific for each operating system (sidenote: who knew that setting a datetime string could get so... unwieldy):

$ grep -i -r 'readregionalprefslocales' intl/
intl/locale/android/OSPreferences_android.cpp:bool OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList) {
intl/locale/windows/OSPreferences_win.cpp:bool OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList) {
intl/locale/OSPreferences.cpp:  if (ReadRegionalPrefsLocales(aRetVal)) {
intl/locale/OSPreferences.h:  bool ReadRegionalPrefsLocales(nsTArray<nsCString>& aRetVal);
intl/locale/gtk/OSPreferences_gtk.cpp:bool OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList) {
intl/locale/mac/OSPreferences_mac.cpp:bool OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList) {
$

The formatted string gets sent back up the chain...

...and the UI then uses the string (in that virtual X-Mozilla-LocalizedDate MIME header) in mozilla-central/comm-central/mail/base/content/msgHdrView.js:

    let dateLabel = document.getElementById("dateLabel");                                                                  
    dateLabel.hidden = true;                                                                                               
    if (                                                                                                                   
      "x-mozilla-localizeddate" in currentHeaderData &&                                                                    
      currentHeaderData["x-mozilla-localizeddate"].headerValue                                                             
    ) {                                                                                                                    
      dateLabel.textContent =                                                                                              
        currentHeaderData["x-mozilla-localizeddate"].headerValue;                                                          
      let date = new Date(currentHeaderData.date.headerValue);                                                             
      if (!isNaN(date)) {                                                                                                  
        dateLabel.setAttribute("datetime", date.toISOString());                                                            
        dateLabel.hidden = false;                                                                                          
      }                                                                                                                    
    }