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

Using BodyBuilder setting TextBody to Subject: Re: BabyBjörn Meeting cause Translate error #137

Closed
LeeBear35 opened this issue May 6, 2015 · 4 comments
Labels
bug Something isn't working

Comments

@LeeBear35
Copy link

When the BodyBuilder is used to convert a MSG file to EML, and the text contains something like "Subject: Re: BabyBjörn Meeting" the calling ToString() on the resulting MimeMessage throws
{"Unable to translate bytes [F6] at index 1205 from specified code page to Unicode."}

Here is a redacted snip of the MimeMessage.Body:
{Content-Type: text/plain; charset=utf-8

I could meet at 12pm for 30 minutes so we'll need to work through the assortment quick.

Jeff

-----Original Message-----
Subject: Re: BabyBjörn Meeting

Sorry - Im booked until noon. Can you do 12:00, 12:30 or 1:00.

Here is the trace information:
? mkMessage.ToString()
{"Unable to translate bytes [F6] at index 1205 from specified code page to Unicode."}
_className: Nothing
_COMPlusExceptionCode: -532462766
_data: {System.Collections.ListDictionaryInternal}
_dynamicMethods: Nothing
_exceptionMethod: Nothing
_exceptionMethodString: Nothing
_helpURL: Nothing
_HResult: -2147024809
_innerException: Nothing
_ipForWatsonBuckets: 8791554014329
_message: "Unable to translate bytes [F6] at index 1205 from specified code page to Unicode."
_remoteStackIndex: 0
_remoteStackTraceString: Nothing
_safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager}
_source: Nothing
_stackTrace: {SByte()}
_stackTraceString: Nothing
_watsonBuckets: Nothing
_xcode: -532462766
_xptrs: 0
BytesUnknown: {Length=1}
bytesUnknown: {Length=1}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: Nothing
HResult: -2147024809
index: 1205
Index: 1205
InnerException: Nothing
IPForWatsonBuckets: 8791554014329
IsTransient: False
m_paramName: Nothing
Message: "Unable to translate bytes [F6] at index 1205 from specified code page to Unicode."
ParamName: Nothing
RemoteStackTrace: Nothing
s_EDILock: {Object}
Source: "mscorlib"
StackTrace: " at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index) at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index) at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes) at System.Text.UTF8Encoding.FallbackInvalidByteSequence(Byte* pSrc, Int32 ch, DecoderFallbackBuffer fallback) at System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder) at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count) at MimeKit.MimeMessage.ToString()"
TargetSite: {Void Throw(Byte[], Int32)}
WatsonBuckets: Nothing

jstedfast added a commit that referenced this issue May 6, 2015
@jstedfast
Copy link
Owner

It's important to note that you SHOULD NOT be using message.ToString () in order to serialize the message. It's meant more for the purpose of debugging. You really need to use WriteTo(Stream) (which can be a MemoryStream if you want to store it in a db or something)

That said, this exception is now caught allowing the code to fallback to using iso-889-1.

@jstedfast jstedfast added the bug Something isn't working label May 6, 2015
@LeeBear35
Copy link
Author

Thank you for the tip in using WriteTo(stream) instead of ToString()

@jstedfast
Copy link
Owner

Sure, no problem. FWIW, the reason that ToString() can never really be guaranteed to be accurate is that it assumes that the entire message stream is a single charset (which is not guaranteed to be the case). For example, you might have multiple attachments with different charsets or headers with different charsets, etc.

@LeeBear35
Copy link
Author

Makes perfect sense, and the WriteTo should actually provide better performance.

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