Bug 1140323 Comment 2 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Consolidate sanitizeFileName into MailUtils.sys.mjs so that all code paths
for generating filenames when saving .eml files use the same logic. Replaces
duplicate local implementations in SearchDialog.js, about3Pane.js,
mailCommands.js, utilityOverlay.js, and ComposerCommands.js with imports
from the shared module.
Move sanitisation, shortening and uniqueness of message filenames into a new
nsIMsgFilenameUtils service that accounts for the actual destination path, and
drive batch saving of messages from the front end, so filenames are resolved
against the folder the user picks. The protocols which write the file
themselves (IMAP, EWS and NNTP) now write into the existing file instead of
replacing it, so that the file the front end creates to reserve a name stays
reserved until the save has finished.

The sanitising rules are portable, but the amount of room a name has is not:
the budget is PATH_MAX bytes of the native path on POSIX and MAX_PATH UTF-16
units on Windows, and neither the limits nor the native path (nsIFile's
nativePath() is [notxpcom]) are reachable from JS. Keeping the logic in C++
behind an XPCOM interface leaves one implementation shared by the front end and
by C++ callers, instead of having each of them approximate the platform's
limits.

Further code which turns untrusted text into an on-disk name can be
consolidated here later. NS_MsgHashIfNecessary() in nsMsgUtils.cpp, used for
folder, mbox and offline store names, truncates and hashes above a fixed 55
characters, without checking for reserved device names or counting bytes.

Back to Bug 1140323 Comment 2