Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty attachment with wrong size #646

Closed
rqueizan opened this issue Jan 14, 2021 · 22 comments
Closed

Empty attachment with wrong size #646

rqueizan opened this issue Jan 14, 2021 · 22 comments
Labels
bug Something isn't working

Comments

@rqueizan
Copy link

Describe the bug
In previous versions of the library, when an empty attachment (without content) was read, it came with zero size.
Previous Version: MailKit: 2.8.0, MimeKit: 2.9.1
In the new versions it returns with the size between 1 and 2 bytes (octets).
New Version: MailKit: 2.10.0-2.10.1, MimeKit: 2.10.0-2.10.1

I detect the bug when run the test that cover that scenary.

Platform (please complete the following information):

  • OS: Windows 10 x64
  • .NET Runtime: net core app
  • .NET Framework: Net Core 2.0 (Target Framework)
  • MailKit Version: 2.10.0-2.10.1, MimeKit Version: 2.10.0-2.10.1

To Reproduce
Steps to reproduce the behavior:

  1. I sent an email with empty attachment.
  2. When read the email, the attachment report size greather than zero.
  3. When download de attachment, the size indicate that is greather than zero.

Expected behavior
The size of an empty attachment must be zero.

@jstedfast
Copy link
Owner

Can you provide a sample app? I'm not sure how you are determining size.

@rqueizan

This comment has been minimized.

1 similar comment
@rqueizan
Copy link
Author

rqueizan commented Jan 19, 2021 via email

@jstedfast
Copy link
Owner

That just gave me a file listing in a comment, but no actual source code that I can look at to see what you are doing so I can better understand the issue.

@jstedfast
Copy link
Owner

@rqueizan I don't see it. You can't reply to GitHub notifications with attachments, it will only post the message text as a comment.

@rqueizan
Copy link
Author

rqueizan commented Jan 19, 2021 via email

@jstedfast
Copy link
Owner

It's best not to reply to these comments using your email client because GitHub doesn't handle emails very well.

It's best to go to https://github.com/jstedfast/MailKit/issues/1136 and write your comment manually.

@rqueizan
Copy link
Author

Mial Kit Bug.docx

@rqueizan
Copy link
Author

Review the word document. I explain my way for fetch mails and how to build my own representations of the mail.

@rqueizan
Copy link
Author

I ran my tests with the old version, I send an empty attachment (an image, 0 bytes).
When I read the mail in the folder, it reports that it has a zero-byte attachment, the same thing happens when downloading.
If I read that same email from the folder with the new version of the library, it reports zero bytes, as with the old version.
However, when sending the mail with the new version of the library, the mail reports the empty attachment with 2 bytes of content (I suppose it is a lf, cr). When downloaded it comes blank.
The problem is that when estimating the size it fails, because in the previous versions it gave 0 bytes, in the new one it comes with 2 bytes.

@jstedfast
Copy link
Owner

jstedfast commented Jan 19, 2021

This is what the latest version of MimeKit generates with an empty attachment:

From: Sender Name <[email protected]>
Date: Tue, 19 Jan 2021 17:13:23 -0500
Subject: Test message with an empty attachment
Message-Id: <ZTBROVH3RCU4.6L5JRL70PLKC1@DESKTOP-FD9TH05>
To: Recipient Name <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-D2my5Z+Mr009Y3Ov908Jcw=="

--=-D2my5Z+Mr009Y3Ov908Jcw==
Content-Type: text/plain; charset=utf-8

This is the message text.
--=-D2my5Z+Mr009Y3Ov908Jcw==
Content-Type: image/png; name=empty.png
Content-Disposition: attachment; filename=empty.png

--=-D2my5Z+Mr009Y3Ov908Jcw==--

There's no way to remove the blank line w/o causing invalid MIME.

I also could not find any code changes to the way MIME is written out (lots of changes to the parser, though).

That said, I don't think it's related to the parser changes either because you seem to be using MailKit's BodyPart API which does not make use of MimeKit's parser (it uses the IMAP server's MIME parser instead).

So I'm kind of confused...

@jstedfast
Copy link
Owner

Can you verify that MimeKit 2.8.0 produces different output from 2.9.1? (or 2.10.x if you'd rather use 2.10 is fine).

@rqueizan
Copy link
Author

004-ReadCopy
001-Sending
002-CreatingCopy
003-ReadReceived

@rqueizan
Copy link
Author

The four picture represent de comparative use of new library and old library.
1st Sending mail
2nd Creating a copy in Sent folder.
3rd Reading a mail received.
4th Reading the copy in Sent folder.

@rqueizan
Copy link
Author

rqueizan commented Jan 20, 2021

This are the complete logs:
MKBnew.txt (2.10.X)
MKBold.txt (2.8.0)
With MailKit 2.9.0 I have the same problem.

@jstedfast
Copy link
Owner

in the 2.10.x version (I assume that's what the "MKBnew.txt" file represents), I can definitely see that there are too many blank lines for an empty MIME part:

C: --=-McaGg1eFrZRnn5DQ89W9+A==
C: Content-Type: text/plain; charset=utf-8
C:
C:
C: --=-McaGg1eFrZRnn5DQ89W9+A==
C: Content-Type: text/html; charset=utf-8
C:
C:
C: --=-McaGg1eFrZRnn5DQ89W9+A==--
C:
C: --=-0MJMUrUdjJcFsuJ+pHOTpQ==
C: Content-Type: IMAGE/png; name=emptyImage.png
C: Content-Transfer-Encoding: base64
C: Content-Disposition: attachment; filename=emptyImage.png
C:
C:
C:
C: --=-0MJMUrUdjJcFsuJ+pHOTpQ==--

The image/png, for example, has 3 blank lines. It should only have 1 like my example a few comments above has.

I'm not sure why you are getting 3. I can't seem to reproduce that here. How are you creating the image/png attachment?

@jstedfast jstedfast transferred this issue from jstedfast/MailKit Jan 20, 2021
@jstedfast
Copy link
Owner

Okay, so my local test case was broken and now that I fixed it, I'm getting 2 blank lines. But I think that's still ok. The issue you are having is that you are getting 3 blank lines and I still can't figure out how that is happening for you.

@jstedfast
Copy link
Owner

Does your empty.png have a newline in it? Or is it a 0-length file?

@jstedfast
Copy link
Owner

Ok, so when using the BodyBuilder, I can reproduce this...

@jstedfast
Copy link
Owner

Ah, ok, so in 2.9.0, I made the BodyBuilder.Attachments.Add() method always set the Content-Transfer-ENcoding to base64 for non-text content (based on mime-type), so the empty.png attachment went from not having an encoding to having an encoding.

The base64 encoder would always flush the content with a new-line sequence, even if the content that was base64 encoded was 0-length.

@jstedfast jstedfast added the bug Something isn't working label Jan 20, 2021
@rqueizan
Copy link
Author

See my code, how I build and send the email.
I send an empty Stream, 0-length.
I use the body builder.
008
007
006
005

@jstedfast
Copy link
Owner

Yep, my patch fixes that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants