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

Content-Type: application/pdf; #66

Open
kalzon1 opened this issue May 3, 2017 · 2 comments
Open

Content-Type: application/pdf; #66

kalzon1 opened this issue May 3, 2017 · 2 comments

Comments

@kalzon1
Copy link

kalzon1 commented May 3, 2017

Hello,

Another type of attachment issue I've come across is where the Content-Type is an application not a boundary
example:
Content-Type: application/pdf;\r\n name="Payment Advice Note from 05/03/2017.pdf

This does not set a MimeBoundaryName in the MailMessage.MailMessage(...) so it does not process the attached PDF properly.

Instead the email looks something like

%PDF-1.3
%����
%RSTXPDF3 Parameters: DRSTXbdh
%Devtype PDF1 Font TIMES bold Lang EN Script: 0 ->/C001
2 0 obj
<<
/Type /FontDescriptor
/Ascent 683
/CapHeight 676
/Descent -217
/Flags 34
/FontBBox [-168 -218 1000 935]
/FontName /Times-Bold
/ItalicAngle 0
/StemV 105

endobj
3 0 obj
/WinAnsiEncoding
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Bold
/Name /C001
/Encoding 3 0 R
/Widths
[ 0250 0333 0554 0500 0500 1000 0833 0333 0333 0333 0500 0571 0250 0333 0250 0279 0500 0500 0500 0500 0500 0500 0500 0500 0500 0500 0333 0333 0571 0571 0571 0500 0929 0721 0667 0721 0721 0667 0613 0779 0779 0388 0500 0779 0667 0946 0721 0779 0613 0779
0721 0554 0667 0721 0721 1000 0721 0721 0667 0333 0279 0333 0579 0500 0333 0500 0554 0446 0554 0446 0333 0500 0554 0279 0333 0554 0279 0833 0554 0500 0554 0554 0446 0388 0333 0554 0500 0721 0500 0500 0446 0396 0221 0396 0521]
/FirstChar 32
/LastChar 126
/FontDescriptor 2 0 R

endobj
%Devtype PDF1 Font TIMES normal Lang EN Script: 0 ->/C002
5 0 obj
<<
/Type /FontDescriptor
/Ascent 683
/CapHeight 662
/Descent -217
/Flags 34
/FontBBox [-168 -218 1000 898]
/FontName /Times-Roman
/ItalicAngle 0
/StemV 105

endobj
6 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
/Name /C002
/Encoding 3 0 R
/Widths
[ 0250 0333 0408 0500 0500 0833 0779 0333 0333 0333 0500 0563 0250 0333 0250 0279 0500 0500 0500 0500 0500 0500 0500 0500 0500 0500 0279 0279 0563 0563 0563 0446 0921 0721 0667 0667 0721 0613 0554 0721 0721 0333 0388 0721 0613 0888 0721 0721 0554 0721
0667 0554 0613 0721 0721 0946 0721 0721 0613 0333 0279 0333 0471 0500 0333 0446 0500 0446 0500 0446 0333 0500 0500 0279 0279 0500 0279 0779 0500 0500 0500 0500 0333 0388 0279 0500 0500 0721 0500 0500 0446 0479 0200 0479 0542]
/FirstChar 32
/LastChar 126
/FontDescriptor 5 0 R

endobj
%Devtype PDF1 Font HELVE normal Lang EN Script: 0 ->/C003
7 0 obj
<<
/Type /FontDescriptor
/Ascent 718
/CapHeight 718
/Descent -207
/Flags 32
/FontBBox [-166 -225 1000 931]
/FontName /Helvetica
/ItalicAngle 0
/StemV 105

endobj
8 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica
/Name /C003
/Encoding 3 0 R
/Widths
[ 0279 0279 0354 0554 0554 0888 0667 0221 0333 0333 0388 0583 0279 0333 0279 0279 0554 0554 0554 0554 0554 0554 0554 0554 0554 0554 0279 0279 0583 0583 0583 0554 1017 0667 0667 0721 0721 0667 0613 0779 0721 0279 0500 0667 0554 0833 0721 0779 0667 0779
0721 0667 0613 0721 0667 0946 0667 0667 0613 0279 0279 0279 0471 0554 0221 0554 0554 0500 0554 0554 0279 0554 0554 0221 0221 0500 0221 0833 0554 0554 0554 0554 0333 0500 0279 0554 0500 0721 0500 0500 0500 0333 0258 0333 0583]
/FirstChar 32
/LastChar 126
/FontDescriptor 7 0 R

endobj
9 0 obj
<<
/Length 10 0 R

stream
q 1 g 0 g 0.50 w 28.35 175.70 510.25 425.20 re S Q q 1 g 0 g 0.50 w 226.80 175.70 0.00 425.20 re S Q q 1 g 0 g 0.50 w 396.85 175.70 0.00 425.20 re S Q q 1 g 0 g 0.50 w 28.
....
startxref
8079
%%EOF

Any thoughts?

Thank you.

@kalzon1
Copy link
Author

kalzon1 commented May 8, 2017

Hello,

So I ran some tests on these types of emails using my old POP email code and they did come in fine. So I looked to see what the differences were. Now I realize this is probably not the best method, but it appears to be working for now. I explicitly added 3 new content types that do not use Boundary. image, application and message

I altered MailMessage.MailMessage() aprox line748

from
// if (!string.IsNullOrEmpty(MimeBoundaryName))

            if (!string.IsNullOrEmpty(MimeBoundaryName) ||
                    (this.BodyTransferEncoding == TransferEncoding.Base64 && 
                            (this.ContentType.ToLower().Contains("image") || this.ContentType.ToLower().Contains("application")
                            || this.ContentType.ToLower().Contains ("message"))                    
                    )
                )

I also had to change MimeParts.ExtractMIME(... ) approx. line 528

from

            else
            {
                // If the content type contains a character set, extract it.
                charSet = Functions.NormalizeCharSet(Functions.ExtractMimeParameter(contentType, "charset"));

                int semicolonPos = contentType.IndexOf(";");
                if (semicolonPos > -1)
                    contentType = contentType.Substring(0, semicolonPos);

TO

            else
            {
                // If the content type contains a character set, extract it.
                charSet = Functions.NormalizeCharSet(Functions.ExtractMimeParameter(contentType, "charset"));


                if (charSet == "")
                {
                    if (contentType.ToLower().Contains("application"))
                    {
                        charSet = Functions.NormalizeCharSet(Functions.ExtractMimeParameter(contentType, "application"));
                    }

                    if (charSet == "")
                    {
                        if (contentType.ToLower().Contains("image"))
                        {
                            charSet = Functions.NormalizeCharSet(Functions.ExtractMimeParameter(contentType, "image"));
                        }
                    }

                    if (charSet == "")
                    {
                        if (contentType.ToLower().Contains("message"))
                        {
                            charSet = Functions.NormalizeCharSet(Functions.ExtractMimeParameter(contentType, "message"));
                        }
                    }

                    int semicolonPos = contentType.IndexOf(";");
                    if (semicolonPos > -1)
                        contentType = contentType.Substring(0, semicolonPos);

                    // Add the message as-is.
                    mimeParts.Add(new MimePart(charSet, contentType, "", "", contentTransferEncoding, body));

                }
                else
                {
                    int semicolonPos = contentType.IndexOf(";");
                    if (semicolonPos > -1)
                        contentType = contentType.Substring(0, semicolonPos);

                    // Add the message as-is.
                    mimeParts.Add(new MimePart("", contentType, charSet, "", contentTransferEncoding, body));
                }

I hope this can help others and help get a better coded solution into the official version.

Thanks.

@bertjohnson
Copy link
Owner

Hi kalzon1, thanks for the report. I want to address this, but am not sure I fully understand the message structure that causes this issue. Would it be possible to forward one of these problematic messages to bert at opaquemail dot org? If so, I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants