Got this exception :formatException

Mar 23, 2010 at 11:50 AM

 

formatException was caught
base-64 Invalid characters in the string
 public static String DecodeFromMailBody(String text, TransferEncoding encodeType, Encoding encoding)
        {
            Byte[] b = null;
            if (encodeType == TransferEncoding.Base64)
            {
                b = Convert.FromBase64String(text);
            }
            else if (encodeType == TransferEncoding.QuotedPrintable)
            {
                b = MailParser.FromQuotedPrintableText(text);
            }
            else
            {
                b = encoding.GetBytes(text);
            }
            return encoding.GetString(b);
        }

exception:

formatException was caught

base-64 Invalid characters in the string

 

-----------------------------------------------

 

namespace Higuchi.Net.Mail:

 public static String DecodeFromMailBody(String text, TransferEncoding encodeType, Encoding encoding)

        {

            Byte[] b = null;

 

            if (encodeType == TransferEncoding.Base64)

            {

                b = Convert.FromBase64String(text);     //     throw exception;

            }

            else if (encodeType == TransferEncoding.QuotedPrintable)

            {

                b = MailParser.FromQuotedPrintableText(text);

            }

            else

            {

                b = encoding.GetBytes(text);

            }

            return encoding.GetString(b);

        }

 

 

 

email backup file:

http://21.dc.ftn.qq.com/ftn_handler/ea62bc278f5cbb6abebd3b382acbfa4ebdf46b9c12effa5a69f2c47654818b37442df794c789b44f2280225e505ae5c53d6060564aabc91695d809977338c99e/md50000003982.msg?k=22393866433aceca0540ee754938051a5416005e565e070c570c155658595318510b5e574c01070104140b50045c0251515b0807550e302465545c535108000555090b5f590a1e58165e38&&txf_fid=8f2d9573c3167972c1d2c027971f23c3141b6dba

Coordinator
Mar 24, 2010 at 2:38 PM
Edited Apr 6, 2010 at 2:44 PM

The format of this mail is invalid.
line 631 must be line break your mail
dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdBc3NvY2--=_alternative 0042F6DE852576EE_=
must be
dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_=
You can read this mail by triming invalid char at line 631 and line 1203 as below.
dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_=
remove last "c3NvY2" at both two line and save it as text file as C:\Mail.txt. And read with C#Mail library.
----------------------------------------------------------------------------------
String text = File.ReadAllText("C:\Mail.txt");
Pop3Message mg = new Pop3Message(text);
String bodyText = mg.BodyText;

----------------------------------------------------------------------------------
One advise,spam mail is frequently invalid format.C#Mail library can't read invalid format mail. regard.

Mar 25, 2010 at 4:53 AM
Think you very much!


 

2010/3/24 higty <notifications@codeplex.com>

From: higty

The format of this mail is invalid. line 631 must be line break your mail dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdBc3NvY2--=_alternative 0042F6DE852576EE_= must be dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_= You can read this mail by triming invalid char at line 631 and line 1203 as below. dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_= remove last "c3NvY2" at both two line Save it as text file as C:\Mail.txt. And read with C#Mail library. ---------------------------------------------------------------------------------- String text = File.ReadAllText("C:\Mail.txt"); Pop3Message mg = new Pop3Message(text); String bodyText = mg.BodyText; ---------------------------------------------------------------------------------- One advise,spam mail is frequently invalid format.C#Mail library can't read invalid format mail. regard.

Read the full discussion online.

To add a post to this discussion, reply to this email (csharpmail@discussions.codeplex.com)

To start a new discussion for this project, email csharpmail@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Mar 25, 2010 at 10:04 AM
Think you very much!

I modified the code:
//--------------------------
namespace Higuchi.Net
public class MimeContent  
 public static List<String> ParseToContentTextList(String text, String multiPartBoundary) 

Line:80
/*
if(CurrentLine==StartOfBoundary || CurrentLine== EndOfBoundary)
 {
                        
                        if (sb.Length > 0)
                        {
                            l.Add(sb.ToString());
                        }
*/

-----------------------------------------
if (CurrentLine.IndexOf( StartOfBoundary)!=-1 ||
     CurrentLine.IndexOf( EndOfBoundary)!=-1)
  {
                        if (CurrentLine.Length > EndOfBoundary.Length)
                        {
                            string tempLine = CurrentLine.Replace(EndOfBoundary, string.Empty).Replace(StartOfBoundary, string.Empty).Trim();

                            if (tempLine.Length > 0)
                            {
                                sb.Append(tempLine.Substring(0, tempLine.Length - 2));
                            }
                        }

                        if (sb.Length > 0)
                        {
                            l.Add(sb.ToString());
                        }

..........

can solve my problem

---------------------------------------------------------------------------------------------------------------------------
2010/3/24 higty <notifications@codeplex.com>

From: higty

The format of this mail is invalid. line 631 must be line break your mail dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdBc3NvY2--=_alternative 0042F6DE852576EE_= must be dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_= You can read this mail by triming invalid char at line 631 and line 1203 as below. dGlvbnMNCnN0YW5kYXJkIGQnqKZjaGFuZ2UgZGUgbCdB --=_alternative 0042F6DE852576EE_= remove last "c3NvY2" at both two line Save it as text file as C:\Mail.txt. And read with C#Mail library. ---------------------------------------------------------------------------------- String text = File.ReadAllText("C:\Mail.txt"); Pop3Message mg = new Pop3Message(text); String bodyText = mg.BodyText; ---------------------------------------------------------------------------------- One advise,spam mail is frequently invalid format.C#Mail library can't read invalid format mail. regard.

Read the full discussion online.

To add a post to this discussion, reply to this email (csharpmail@discussions.codeplex.com)

To start a new discussion for this project, email csharpmail@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Mar 25, 2010 at 10:10 AM

-----------------------------------------
if (CurrentLine.IndexOf( StartOfBoundary)!=-1 ||
     CurrentLine.IndexOf( EndOfBoundary)!=-1)
  {
                        if (CurrentLine.Length > EndOfBoundary.Length)
                        {
                            string tempLine = CurrentLine.Replace(EndOfBoundary, string.Empty).Replace(StartOfBoundary, string.Empty).Trim();

                            if (tempLine.Length > 0)
                            {
                                // "\r\n".length=2  
                                sb.Append(tempLine.Substring(0, tempLine.Length - 2));
                            }
                        }

Coordinator
Mar 26, 2010 at 8:18 AM

I'll check mime rfc spec and determine whether this modification apply or not.

Thank you for your contdibution!