Fixing mojibake for email

119 Views Asked by At

My application for macOS archives emails from email clients and IMAP accounts. One user got an email from a Windows user and archived the email from Mail. My app reads the data directly from the hard disk.

The user has an email with some a nice mojibake:

enter image description here

I can identify a few of the characters:

‰ → ä ¸ → ü

But I can't figure out whhat the original encoding is. I made myself an encoding table for the characters "ö ä ü ß" and my data is not in that table:

enter image description here

Code:

dim theLeft as string = "ö  ä  ü  ß"
for currentEncoding as integer = 0 to Encodings.Count - 1
  
  dim EncodingInternetName as String = Encodings.Item(currentEncoding).internetName
  
  if EncodingInternetName.IndexOf("iso") = -1 and EncodingInternetName.IndexOf("windows") = -1 then Continue
  dim newString as string = DefineEncoding(theLeft, Encodings.Item(currentEncoding))  '<---convert
  newString = ConvertEncoding(newString, Encodings.UTF8)
  Result.Add(EncodingInternetName + " " + newString)
  
next

Does anyone have an idea what encoding was used for the Mojibake?

1

There are 1 best solutions below

0
On
dim theString as String = "ˆ ‰ ¸ fl"
theString = theString.ConvertEncoding(Encodings.WindowsANSI)
theString = theString.DefineEncoding(Encodings.UTF8)
theString = theString.ConvertEncoding(Encodings.MacRoman)
theString = theString.DefineEncoding(Encodings.WindowsANSI)
theString = theString.ConvertEncoding(Encodings.UTF8)