foens / hpop

OpenPOP.NET code repository
http://hpop.sourceforge.net/
202 stars 115 forks source link

Base64: (FormatException) #18

Open mcjmcj opened 10 years ago

mcjmcj commented 10 years ago

22/08/2014 14:38:55 Base64: (FormatException) Comprimento inválido para uma matriz de caracteres Base-64. On string: UmVhZGluZXNzIEV2ZW50IHBhcmEgTWFy5286IENvbmhl52EgYSBtb2RlbG8gTWljcm9zb2Z0IGRl IEluZnJhc3RydWN0dXJlIE9wdGltaXphdGlvbg== 22/08/2014 14:39:01 TestForm: Message fetching failed: Comprimento inválido para uma matriz de caracteres Base-64. Stack trace: em System.Convert.FromBase64CharArray(Char[] inArray, Int32 offset, Int32 length) em System.Security.Cryptography.FromBase64Transform.TransformBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[] outputBuffer, Int32 outputOffset) em OpenPop.Mime.Decode.Base64.Decode(String base64Encoded) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Decode\Base64.cs:linha 61 em OpenPop.Mime.Decode.Base64.Decode(String base64Encoded, Encoding encoding) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Decode\Base64.cs:linha 79 em OpenPop.Mime.Decode.EncodedWord.Decode(String encodedWords) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Decode\EncodedWord.cs:linha 108 em OpenPop.Mime.Header.MessageHeader.ParseHeader(String headerName, String headerValue) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Header\MessageHeader.cs:linha 380 em OpenPop.Mime.Header.MessageHeader.ParseHeaders(NameValueCollection headers) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Header\MessageHeader.cs:linha 287 em OpenPop.Mime.Header.MessageHeader..ctor(NameValueCollection headers) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Header\MessageHeader.cs:linha 265 em OpenPop.Mime.Header.HeaderExtractor.ExtractHeadersAndBody(Byte[] fullRawMessage, MessageHeader& headers, Byte[]& body) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Header\HeaderExtractor.cs:linha 70 em OpenPop.Mime.Message..ctor(Byte[] rawMessageContent, Boolean parseBody) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Message.cs:linha 81 em OpenPop.Mime.Message..ctor(Byte[] rawMessageContent) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Mime\Message.cs:linha 59 em OpenPop.Pop3.Pop3Client.GetMessage(Int32 messageNumber) na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPop\Pop3\Pop3Client.cs:linha 659 em OpenPop.TestApplication.TestForm.ReceiveMails() na C:\Users\moacir.junior\Downloads\OpenPop.NET 2.0.5\source\OpenPOPTest\TestForm.cs:linha 501

foens commented 10 years ago

Currently I do not have a C# environment to test it. Is it possible you could fix this and provide a pull request?

IlyaGerasimets commented 10 years ago

Hi,

I believe I fixed (in 2.0.6) with this change: base64Encoded = base64Encoded.Replace(" ", "");

Thank you.

Best regards, Ilya Gerasimets

supershowwei commented 9 years ago

my base64 content:

PHNtaWw+PGhlYWQ+PGxheW91dD48cm9vdC1sYXlvdXQgd2lkdGg9IjMyMHB4IiBoZWlnaHQ9IjQ4MHB4Ii8+PHJlZ2lvbiBpZD0iSW1hZ2UiIGxlZnQ9IjAiIHRvcD0iMCIgd2lkdGg9IjMyMHB4IiBoZWlnaHQ9IjMyMHB4IiBmaXQ9Im1lZXQiLz48L2xheW91dD48L2hlYWQ+PGJvZHk+PHBhciBkdXI9IjUwMDBtcyI+PGltZyBzcmM9Im1tc19pbWctODM4Mjg0NTUwLmpwZyIgcmVnaW9uPSJJbWFnZSIvPjwvcGFyPjwvYm9keT48L3NtaWw+

It call Base64.Decode failed, occur FormatException. But it's success after i change "FromBase64TransformMode.DoNotIgnoreWhiteSpaces" to "FromBase64TransformMode.IgnoreWhiteSpaces" in Base64.cs.

But, the file saved is broken.

I don't know what differences between "FromBase64TransformMode.DoNotIgnoreWhiteSpaces" and "FromBase64TransformMode.IgnoreWhiteSpaces".

Then i chage to return Convert.FromBase64String(base64Encoded), it's work well.

Please refer to it.

enriuy commented 8 years ago

Hi.

I had the same problem, in my case I fixed it with a new replace in the code. The actual replace are

base64Encoded = base64Encoded.Replace("\r\n", ""); base64Encoded = base64Encoded.Replace("\t", ""); base64Encoded = base64Encoded.Replace(" ", "");

I added this and it work " base64Encoded = base64Encoded.Replace("!", "");"

the "!" is a valid char in the variant of base64 "Modified Base64 for Regular expressions (non standard)"

https://en.wikipedia.org/wiki/Base64

May be this is not your case but may be another variant of Base64

Sorry for any mistake or the broken english.