Closed Bug 507137 Opened 15 years ago Closed 15 years ago

attachment of .eml file can't be read by stream because of wrong size information

Categories

(Thunderbird :: General, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 3.0b4

People

(Reporter: tokoe, Assigned: tokoe)

Details

Attachments

(1 file, 5 obsolete files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009020409 Iceweasel/3.0.11 (Debian-3.0.11-1)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2pre) Gecko/20090729 Shredder/3.0b4pre

When trying to access the attachment of an external .eml file by any stream class (e.g. from within java script), the size of the attachment is always 0 bytes.
The reason for that is, that nsDummyMsgHeader is used which has its messageSize property always initialized with 0.

This report provides a patch that fixes it by passing the url of the .eml file to the appropriated message header sink, which setup a nsDummyMsgHeader with the file size as messageSize.

Reproducible: Always

Steps to Reproduce:
1. Open an external .eml file that contains attachments
2. Try to open a stream on the attachment and read from it

Actual Results:  
The reported size of the attachment is 0 bytes, although the attachment is not empty.

Expected Results:  
If the attachment is not empty, the content should be readable.
Attachment #391339 - Flags: review?(roc)
Assignee: nobody → tokoe
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Comment on attachment 391339 [details] [diff] [review]
Patch that sets the correct attachment size

roc has not yet seen the light and come over to the glamorous world of Thunderbird development from layout and what not.  Bienvenu is probably a better reviewer for this ;)
Attachment #391339 - Flags: superreview?(bienvenu)
Attachment #391339 - Flags: review?(roc)
Attachment #391339 - Flags: review?(bienvenu)
Sid, how does this relate to your idea of making the dummy message header a separate component?
One step at a time ;) -- though as I mentioned on IRC, it would be nice to have tests for this, and that practically necessitates a separate component. Do you think tests are necessary here before the patch gets checked in?
No, whatever feature ends up needing this can have mozmill tests for now...
Attachment #391339 - Flags: superreview?(bienvenu)
Attachment #391339 - Flags: superreview-
Attachment #391339 - Flags: review?(bienvenu)
Attachment #391339 - Flags: review-
Comment on attachment 391339 [details] [diff] [review]
Patch that sets the correct attachment size

thx for the patch, this looks reasonable, but you should add doxygen style comments to the method you added to nsIMsgHeaderSink, and explain what the url parameter is (specifically that it should be a file url).

Also, can you use let instead of var here:

+      var msgHdr = new nsDummyMsgHeader();
+  
+      var io = Components.classes["@mozilla.org/network/io-service;1"]
+                         .getService(Components.interfaces.nsIIOService);
+
+      var url = io.newURI(pathUrl, null, null);
+      var fileUrl = url.QueryInterface(Components.interfaces.nsIFileURL);

Or, you could do this all in one statement, without the temp vars.
Changed the js code to use 'let' instead of 'var' and add documentation to the new method getDummyMsgHeader in the IDL file
Attachment #391339 - Attachment is obsolete: true
Attachment #392448 - Flags: review?(bienvenu)
Attached patch Do not overload the method name (obsolete) — Splinter Review
Renamed GetDummyMsgHeader to CreateDummyMsgHeaderFromURL to avoid conflicts during binding generation for the interface.
Attachment #392448 - Attachment is obsolete: true
Attachment #392515 - Flags: review?(bienvenu)
Attachment #392448 - Flags: review?(bienvenu)
Comment on attachment 392515 [details] [diff] [review]
Do not overload the method name

thx, this looks OK, with a few nits:

any reason not to use ACString in the idl instead of string?

Also, this comment should be of the 
/**
 * @param url ...
 *
 * @returns
 */

form, of which there are a lot of examples in the existing code...

+  // returns a dummy message header that has its messageSize property set to the size
+  // of the .eml file that the passed url points to
Attachment #392515 - Flags: review?(bienvenu) → review-
Attached patch Adapt to review comments (obsolete) — Splinter Review
Changed comments to doxygen style and make use of ACString instead of string as input parameter type.
Attachment #392515 - Attachment is obsolete: true
Attachment #393481 - Flags: review?(bienvenu)
Comment on attachment 393481 [details] [diff] [review]
Adapt to review comments

either this is the wrong patch, or I'm the wrong reviewer, since I'm not a toolkit peer.
Attachment #393481 - Flags: review?(bienvenu)
Attached patch Adapt to review comments (obsolete) — Splinter Review
Fixed documentation and passing ACString instead of string in IDL file.

(This time the correct patch ;))
Attachment #393481 - Attachment is obsolete: true
Attachment #395009 - Flags: review?(bienvenu)
Comment on attachment 395009 [details] [diff] [review]
Adapt to review comments

looks good, thanks.
Attachment #395009 - Flags: review?(bienvenu) → review+
David does this patch needs sr too ?
technically, yes. And it also needs the corresponding suite change to suite/mailnews/msgHdrViewOverlay.js, now that I think of it. For that, you'd probably want to ask for sr from neil@httl.net, or standard8, who can review the suite change and give you sr at the same time.l
Comment on attachment 395009 [details] [diff] [review]
Adapt to review comments

Choosing neil as standard8 is swamped in triagging
Attachment #395009 - Flags: superreview?(neil)
Do we really need to create a new message header each time?
This should only happen when opening a .eml file, which shouldn't be that common...
Comment on attachment 395009 [details] [diff] [review]
Adapt to review comments

>         if (headerSink)
>-          return headerSink->GetDummyMsgHeader(aMsgHdr);
>+        {
>+          nsCAutoString pathName;
>+          m_filePath->GetNativePath(pathName);
>+          pathName.Insert("file://", 0);
>+
>+          return headerSink->CreateDummyMsgHeaderFromURL(pathName, aMsgHdr);
In which case rather than this bogus URI creation code I would just get the dummy msg header, get the size of m_filePath and set the size on the header.
Attachment #395009 - Flags: superreview?(neil) → superreview-
(In reply to comment #19)
Hej Neil,

> In which case rather than this bogus URI creation code I would just get the
> dummy msg header, get the size of m_filePath and set the size on the header.

Well, sid0 suggested to have this encapsulated inside the dummy message header class... So what way to go?
Attached patch Simplified patchSplinter Review
The new version of the patch moves the code to set the message size of the dummy header from the callee site to the caller site as requested by the super review.
Attachment #395009 - Attachment is obsolete: true
Attachment #396186 - Flags: review?(bienvenu)
Comment on attachment 396186 [details] [diff] [review]
Simplified patch

>+
>+          return rv;
>+        }
>       }
>     }
>   }
>   else
>     rv = NS_ERROR_NULL_POINTER;
> 
>   return rv;
> }
[It's probably safe to fall through to the end of the function to return rv.]
Attachment #396186 - Flags: superreview+
Attachment #396186 - Flags: review?(bienvenu) → review+
Comment on attachment 396186 [details] [diff] [review]
Simplified patch

I fixed Neil's nit, and a couple formatting issues, and landed this. Thx very much for the patch!
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 3.0b4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: