Saving a single message with the date info

User Help for Mozilla Thunderbird
Post Reply
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Saving a single message with the date info

Post by user2018 »

When you select several email messages in Thunderbird and use the "Save as file" option, the filename format includes date info. However, if you select a single message and do the same then the date info is not included. So the filename format does not seem to be consistent (it changes depending on whether a single or multiple messages are selected); e.g., if I save the files selecting messages A and B and then I save only A and then I save only B then I get 4 files (instead, I think that only 2 files should be obtained and a confirmation dialog regarding the overwriting should be shown).

Summing up, I would like the filename format to be the same whether a single or several messages are selected and this filename format should include the timestamp information. Any advice about how this can be done? (I know about the extension ImportExport Tools, but it does not work in the recent versions of Thunderbird; besides, this seems to be a simple functionality to get, as it already works when several messages are selected; maybe some preference is available for this?).

Any advice or idea is welcome.
morat
Posts: 6425
Joined: February 3rd, 2009, 6:29 pm

Re: Saving a single message with the date info

Post by morat »

You can't change the format with a preference.

Reference
http://searchfox.org/comm-esr78/search? ... ommands.js
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Re: Saving a single message with the date info

Post by user2018 »

Thank you very much for the link. The modification needed for this to work seems pretty simple. Is there any easy way of overriding the definition of the function without modifying the original code?
morat
Posts: 6425
Joined: February 3rd, 2009, 6:29 pm

Re: Saving a single message with the date info

Post by morat »

You can reassign the SaveAsFile function with another function or use eval. I guess...

Find:

Code: Select all

let name = msgHdr.mime2DecodedSubject;
Replace with:

Code: Select all

let name = GenerateFilenameFromMsgHdr(msgHdr);
Examples
http://forums.mozillazine.org/viewtopic ... #p14802871
http://forums.mozillazine.org/viewtopic ... #p14875202
http://forums.mozillazine.org/viewtopic ... #p14869120
sfhowes
Posts: 754
Joined: April 1st, 2012, 10:21 am

Re: Saving a single message with the date info

Post by sfhowes »

ImportExportTools NG for TB 68 & 78:

https://addons.thunderbird.net/en-US/th ... ttools-ng/

File naming settings in the add-on's Options.
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Re: Saving a single message with the date info

Post by user2018 »

Thanks a lot! Both options seem to work perfectly.
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Re: Saving a single message with the date info

Post by user2018 »

I noticed a problem with the solution based on reassigning the SaveAsFile function. I use this code:

Code: Select all

      
      var a = "let name = msgHdr.mime2DecodedSubject;";
      var b = "let name = GenerateFilenameFromMsgHdr(msgHdr);";
      eval("SaveAsFile = " + SaveAsFile.toString().
        replace(a, b));
But when I store a message with subject "RE: Fwd: Re: My message", the message is stored as "Re_ Re_ Fwd_ Re_ My message....eml", that is, an extra "Re" is added, which is confusing and not appropritate. Any idea about the reason and how to solve it?

Thank you.
morat
Posts: 6425
Joined: February 3rd, 2009, 6:29 pm

Re: Saving a single message with the date info

Post by morat »

Try this:

Code: Select all

/* Thunderbird userChrome.js */

(function () {

if (location == "chrome://messenger/content/messenger.xul" ||
    location == "chrome://messenger/content/messenger.xhtml") {

  var a = "    let name = msgHdr.mime2DecodedSubject;"           + "\n";
  a = a + "    if (msgHdr.flags & Ci.nsMsgMessageFlags.HasRe) {" + "\n";
  a = a + '      name = name ? "Re: " + name : "Re: ";'          + "\n";
  a = a + "    }"                                                + "\n";
  var b = "    let name = GenerateFilenameFromMsgHdr(msgHdr);"   + "\n";
  eval("SaveAsFile = " + SaveAsFile.toString().
    replace(a, b));

}

})();
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Re: Saving a single message with the date info

Post by user2018 »

Thank you very much for the proposal!

Is the solution proposed a "hack" to fix a bug in mime2DecodedSubject? I ask this because it seems to me that the string returned by mime2DecodedSubject should be the one I was expecting, although I may be mistaken.

I tried it and this solves the problem mentioned. However, if the subject is actually something like "Re: Re: ..." (I'm not sure if receiving messages with such a subject makes sense or not -?-, but I do sometimes) then when I try to save the file only one of the "Re" is kept (however, in this case, the double "Re" is legitimate).

Another related strange behavior that I'm not sure if it is correct. If I forward a message such as "Re: ..." then the subject considered by Thunderbird for the new message to be forwarded is "Fwd: ..." (the "Re:" is lost): shouldn't it be "Fwd: Re: ..."? With further testing, I realize that something similar also happens if the subject is "Re: Fwd:": it gets transformed to "Fwd: Fwd:" when forwarded. Maybe all this is intended behavior, but I find it a bit strange.

Thank you for any suggestion.
Post Reply