Closed Bug 2018026 Opened 8 months ago Closed 8 months ago

Saved emails use filenames which are not cross-platform safe

Categories

(Thunderbird :: Mail Window Front End, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED
150 Branch

People

(Reporter: benc, Assigned: benc)

References

Details

Attachments

(1 external file)

When you save an email by dragging it out of the message list and into the OS file manager, the filename it uses is derived from the subject line, but the filename sanitisation varies by the OS you're using. So it's very easy to save emails on linux which cannot be copied over to Windows, say.
e.g. Re: Proposed new Feature: Substituting colons by under...linux).eml contains colons, which are not allowed in windows filenames (I think there may be some issues on Mac too...).

From a conversation on tb-developers:
https://thunderbird.topicbox.com/groups/developers/T41bd7318199ff1d5-M04d30ea13231e5db8ebb9a39

The function which attempts to sanitise filenames (at least for drag&drop) is validateFileName():
https://searchfox.org/comm-central/rev/11c492ff625cb853c3dbad64fd2a22629538608a/mail/base/content/utilityOverlay.js#111-130

It should probably just sanitise all potentially-problematic names, regardless of the host operating system.
There's a reasonably comprehensive set of rules in the C++ side, in EncodeFilename() which acts as a pretty good template:
https://searchfox.org/comm-central/source/mailnews/base/src/nsMsgUtils.cpp#1778
Although that function performs percent-encoding of unwanted characters (as it tries to be reversible) - that might not be desirable here, where the goal is a decent human-readable filename.

Patch there to address the immediate concerns.
Some less important odds and ends that'd be worth following up on:

  • validateFileName() is a silly name, because it doesn't validate. It munges :-) sanitiseFilename() might be a better name.
  • move the mail.save_msg_filename_underscores_for_space check out of the function and pass it in as a param? Or just let the calling function handle replacing spaces with underscores. Just seems wrong having preferences affecting such otherwise-simple functions.
  • all the places that call this function add the file extension (eg .eml) on afterwards. Would be much better to pass in the whole filename, and have a separate function which deals with inserting "-N" suffixes if the filename already exists.
See Also: → 259184
See Also: → 2019085
Target Milestone: --- → 150 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/f26745040f14
Tighten up filename rules when saving messages and make them safe across OSes. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Duplicate of this bug: 1917941
Duplicate of this bug: 2041949
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: