This is not only ugly, it does not even work properly. If no errors remember the encoding that produced the fewest bytes.Built a list of suitable encodings (only iso-codepages and unicode).My first attempt was a simple brute-force attack: I wondered if it is possible to detect the best encoding from the given text. But it is definitely not a good solution if you have an end-user GUI application (most users do not even know what an "encoding" is). This is fine as long as you know the target character set or always assume Unicode. The user had to provide the charset to use for the Transfer-Encoding by hand. The body of the email is passed as String. I started this along with another component that constructs MIME conformant emails. The EncodingTools class offers some easy-to-use functions to determine the best encoding for different scenarios. This is very handy for codepage detection of text stored in files or for text that needs to be sent over the internet. Similarly, the IMultiLang2 interface has a function to detect the encoding of an incoming byte array. But luckily, Microsoft provides the MLang API, in which the IMultiLang3 interface is used for outbound encoding detection. One could argue that Unicode always does the trick but I needed the most efficient (byte saving) way to transfer data.ĭetecting a code page from text is a very tricky task. In some cases, you need to know what the best codepage (encoding) is to either transfer text over the internet or store it in a text file.
0 Comments
Leave a Reply. |