Open Bug 1140323 Opened 11 years ago Updated 1 day ago

threadPane._onDragStart/ThreadPaneOnDragStart() should use same logic or code as SaveAsFile() for ".eml" file name generation

Categories

(MailNews Core :: Backend, defect)

defect

Tracking

(Not tracked)

ASSIGNED
160 Branch

People

(Reporter: World, Assigned: welpy-cw)

References

Details

(Keywords: leave-open)

Attachments

(3 files, 2 obsolete files)

ThreadPaneOnDragStart() should use same logic or code as SaveAsFile() for ".eml" file name generation. http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCommands.js#342 342 function SaveAsFile(uris) 349 if (msgHdr.flags & Components.interfaces.nsMsgMessageFlags.HasRe) 350 name = (name) ? "Re: " + name : "Re: "; 352 let filename = GenerateValidFilename(name, ".eml"); http://mxr.mozilla.org/comm-central/source/mail/base/content/msgMail3PaneWindow.js#1379 1379 function ThreadPaneOnDragStart(aEvent) { 1421 if (!subject) { 1422 uniqueFileName = noSubjectString; 1423 } else { 1424 uniqueFileName = (subject.length <= maxUncutNameLength) ? 1425 subject : subject.substr(0, maxCutNameLength) + longSubjectTruncator; 1426 } 1427 uniqueFileName = suggestUniqueFileName(uniqueFileName, ".eml", fileNames); Due to above difference, when Subject has Re:, SaveAs generates "Re subject_text.eml", but Drag&Drop generares "subject_text.eml". Is it intentional or by design?
Severity: normal → S3
Summary: ThreadPaneOnDragStart() should use same logic or code as SaveAsFile() for ".eml" file name generation → threadPane._onDragStart/ThreadPaneOnDragStart() should use same logic or code as SaveAsFile() for ".eml" file name generation

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.

This removes the frontend workaround in mailCommands.js that used top.saveURL
for standalone .eml files, properly routing the operation through messenger.saveAs
and the C++ backend.

Key backend changes in nsMailboxService.cpp:

  • Moved the file: to mailbox: URI conversion logic from FetchMessage down
    into PrepareMessageUrl. This allows file: URIs to be properly processed
    by all mailbox actions, most notably SaveMessageToDisk.
  • Fixed a URI construction bug where number=0 was appended with an &
    without checking if a ? query string already existed.
  • Forced addDummyEnvelope to true for file: URIs in SaveMessageToDisk
    to prevent the mailbox protocol from swallowing the first header line
    (since .eml files lack the mbox "From " separator).
Attachment #9603060 - Attachment description: WIP: Bug 1140323 - Improve EML save tests to verify actual file content. r=#thunderbird-reviewers → WIP: Bug 1140323 - Improve tests for saving EML messages. r=#thunderbird-reviewers
Attachment #9603061 - Attachment description: WIP: Bug 1140323 - Refactor saving .eml files to use standard backend pipeline. r=#thunderbird-reviewers → WIP: Bug 1140323 - Route standalone EML saves through the mailbox backend. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: WIP: Bug 1140323 - Unify EML filename sanitization across all save paths. r=#thunderbird-reviewers → WIP: Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers
Assignee: nobody → h.w.forms
Attachment #9603061 - Attachment description: WIP: Bug 1140323 - Route standalone EML saves through the mailbox backend. r=#thunderbird-reviewers → Bug 1140323 - Route standalone EML saves through the mailbox backend. r=#thunderbird-reviewers
Status: NEW → ASSIGNED
Attachment #9602376 - Attachment description: WIP: Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers → Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers
Attachment #9603060 - Attachment is obsolete: true
Target Milestone: --- → 157 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/72f24353e83a
Route standalone EML saves through the mailbox backend. r=mkmelin

Attachment #9602376 - Attachment description: Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers → WIP: Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers

Migrate nsMessenger prompts and file picker strings, message drag fallback
filenames, and the open-message file picker from messenger.properties.
Reuse existing attachment messages and format C++ strings with
LocalizeMessage.

Add the locale migration recipe and focused filename and picker tests.
The path length strings are not yet in the localization source, so their
existing English values are seeded by the recipe.

Attachment #9646713 - Attachment description: WIP: Bug 1140323 - Migrate message file strings to Fluent. r?#thunderbird-reviewers → WIP: Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: WIP: Bug 1140323 - Centralize EML filename generation and sanitization. r=#thunderbird-reviewers → WIP: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers
Attachment #9646712 - Attachment is obsolete: true
See Also: → 2076477
Attachment #9646713 - Attachment description: WIP: Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers → Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: WIP: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers → Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers
Attachment #9646713 - Attachment description: Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers → WIP: Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers → WIP: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers
Attachment #9646713 - Attachment description: WIP: Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers → Bug 1140323 - Migrate message file strings to Fluent. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: WIP: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers → Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers
Attachment #9602376 - Attachment description: Bug 1140323 - Unify message filename generation in a path-aware service. r=#thunderbird-reviewers → Bug 1140323 - Unify message filename generation in MailUtils. r=#thunderbird-reviewers
Target Milestone: 157 Branch → 160 Branch

Pushed by brendan@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/1277e5088c80
Migrate message file strings to Fluent. r=mkmelin,tobyp,dandarnell

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: