Closed Bug 350825 Opened 18 years ago Closed 1 year ago

When detaching, comma in target file name or path will break link to local file because X-Mozilla-External-Attachment-URL is truncated at first comma

Categories

(MailNews Core :: Attachments, defect)

defect

Tracking

(thunderbird_esr102 wontfix)

RESOLVED FIXED
114 Branch
Tracking Status
thunderbird_esr102 --- wontfix

People

(Reporter: Joerg.Thoennes, Assigned: betterbird.project)

References

Details

(Whiteboard: [dataloss])

Attachments

(3 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

If the attachment file name contains a comma ",", the file can be detached
successfully, the reference to the local file system is incomplete. The URL
in the mail contains the complete path up to, but not including the first comma.


Reproducible: Always

Steps to Reproduce:
1. Create a mail with an attachment, eg. "Attach, attach.doc"
2. Save mail as draft, possibly move it to some temp. TEST folder
3. Open saved mail and attachment -- OK
4. Detach attachment
5. Open saved mail with detached file
6. Open the attachment

Actual Results:  
File Not Found

The file .../Attach cannot be found. Please check the location and try again.

Expected Results:  
The detached file ".../Attach, attach.doc" can be located on the filesystem and opened successfully.
Summary: detach of file names with commas stores imcomplete file name → detach of file names with commas stores incomplete file name
I'll look into this...
Assignee: mscott → bienvenu
Status: UNCONFIRMED → NEW
Ever confirmed: true
This applies to WinXP, not just Linux, and is still the case now.
Fixing it might just be a matter of encoding the ',' character before the uri is passed in as a parameter in startProcessing in nsMessenger (http://mxr.mozilla.org/mailnews/source/mailnews/base/src/nsMessenger.cpp#2979).  
In my add-on I've rewritten the detaching part of messenger in JavaScript and simply doing 'replace(/,/g,"%2C")' to the uri string before its used seems to fix it.  I'm not sure what this would be in C++ or where the best place to put it would be though or I'd make the patch file.
Assignee: bienvenu → nobody
Component: Mail Window Front End → Attachments
Product: Thunderbird → MailNews Core
QA Contact: front-end → attachments
--- Comment #1 from WADA <m-wada@japan.com>  2009-01-14 23:56:38 PST ---
(in response to my duplicate (oops) bug report 387639)
(Q1) Following header was generated after detach, wasn't it?
> > Content-Disposition: ...; filename="Dear, Keith - 13.04.09.doc"
> > X-Mozilla-External-Attachment-URL: file:///C:/.../Dear
> > ("," and string after "," is cut-off)
(Q2) Before detach, the attachment was opened successufully, wasn't it?

Q1: No, nothing was added to the headers after detach, even in View|Headers|All.
Q2: yes that is correct.
(In reply to comment #6)
> even in View|Headers|All.
Check mail source(View/Message Source) and check mail headers for the attachment part.
ok then, yes, after detaching the file the source includes this:

Content-Type: application/msword;
 name="Dear, Keith - 13.04.09.doc"
Content-Disposition: attachment; filename="Dear, Keith - 13.04.09.doc"
X-Mozilla-External-Attachment-URL: file:///C:/temp/Dear
X-Mozilla-Altered: AttachmentDetached; date="Fri Jan 16 08:26:30 2009"

The original MIME headers for this attachment are:
Content-Type: application/msword;
 name="Dear, Keith - 13.04.09.doc"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="Dear, Keith - 13.04.09.doc"
this bug still occurs, using seamonkey 2.13 on linux x86_64.
Also, I believe bug 580253 is a dupe of this bug.
Summary: detach of file names with commas stores incomplete file name → When detaching, link to file broken because X-Mozilla-External-Attachment-URL is truncated at first comma in target file name or path
Summary: When detaching, link to file broken because X-Mozilla-External-Attachment-URL is truncated at first comma in target file name or path → When detaching, comma in target file name or path will break link to local file because X-Mozilla-External-Attachment-URL is truncated at first comma
Jim, if comment 2 and comment 3 cited below are true, this looks like a one-line fix?

(In reply to Andrew Williamson [:eviljeff] from comment #2)
> Fixing it might just be a matter of encoding the ',' character before the
> uri is passed in as a parameter in startProcessing in nsMessenger
> (http://mxr.mozilla.org/mailnews/source/mailnews/base/src/nsMessenger.
> cpp#2979).

(In reply to Andrew Williamson [:eviljeff] from comment #3)
> In my add-on I've rewritten the detaching part of messenger in JavaScript
> and simply doing 'replace(/,/g,"%2C")' to the uri string before its used
> seems to fix it.
OS: Linux → All
Hardware: x86 → All
This bug is still open and it's really annoying! Why is it so difficult to fix it? Can someone fix this, please? 
The behaviour looks a little similiar to bug 900117.

BTW: I wonder what people without the possibility to edit the message source do in such cases. I use Header Tools Lite -> Edit Full Source to correct the broken path.
https://addons.mozilla.org/en-US/thunderbird/addon/header-tools-lite/
This bug is still alive and 12 years old. Fix this, please!
I have to use notepad to edit the message file with the help of URL-encoding tool. (My "Message Store Type" is "File per message (maildir)".)

This bug still exists. (Thunderbird 60.9.1, mbox file format).

I am using the attachment detach feature a lot. With this bug, I cannot trust it anymore.
Please please please fix this bug!
Thanks

Thunderbird 68.4.2 again truncates the link to a detached file at the first comma in the filename

See https://support.mozilla.org/en-US/questions/1278071#answer-1285865

Whiteboard: [dataloss]

Still exists in 68.6.0 (64-Bit) Linux.

Example of defective .eml with the errors highlighted.

Problem recurs under 68.12.1

Still defective in 78.3.1…  what a shame.

Fifteen years later, Thunderbird 78.11.0. The bug is still there. It looks like all that needs to be done is add the comma in mDetachedFileUris() to the list of characters that need to be URLencoded, just like it is done for the space characters.

Val, can you please clarify this suggestion. mDetachedFileUris is a list of URIs defined here:
https://searchfox.org/comm-central/rev/fa532a6d47183bed8d0a5016ff27e092f791c9e1/mailnews/base/src/nsMessenger.cpp#2319
So which "list of characters" are you referring to? You don't need to submit a patch, you could just copy the modified code into a comment here.

Flags: needinfo?(val.kulkov)

This is where the URI of the saved file is constructed:
https://searchfox.org/comm-central/rev/20577b15cbba0144791385497892348220fa3037/mailnews/base/src/nsMessenger.cpp#704-709
Apparently a comma is valid in a URI and not percent-encoded.

Later on, the damage happens here:
https://searchfox.org/comm-central/rev/20577b15cbba0144791385497892348220fa3037/mailnews/base/src/nsMessenger.cpp#2625
where URLs are strung together with a comma, and then later parsed here:
https://searchfox.org/comm-central/rev/20577b15cbba0144791385497892348220fa3037/mailnews/mime/src/mimeobj.cpp#172
The design issue lies in stringing file URLs together with a comma and later splitting at a comma, when a comma can be part of the file URLs.

A hacky one-line fix could be to percent-encode the comma before nsMessenger.cpp#2625. That's a bit like the suggestion in comment #22 which in itself is not a solution.

Flags: needinfo?(val.kulkov)

Great investigative work, Rachel! I think you pinned it. Your patch in comment #25 makes total sense to me. I looked for what I meant by saying the "list of characters" in comment #22 and I could not find it :-(

Severity: normal → S3
Attachment #9331104 - Flags: review?(mkmelin+mozilla)

Comment on attachment 9331104 [details] [diff] [review]
350825-commas-detached-attachment.patch

Looks good, r=mkmelin

Attachment #9331104 - Flags: review?(mkmelin+mozilla) → review+
Assignee: nobody → betterbird.project
Status: NEW → ASSIGNED
Target Milestone: --- → 114 Branch

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/ebd51aa99865
Percent-encode commas in URI of detached attachment. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: