Archived Forum Post

Index of archived forum posts

Question:

CkEmail->addFileAttachment wrong encoding

Sep 16 '13 at 11:51

I have downloaded the last library and I noticed that when attaching a file in ANSI format arrives to the recipient in other (UTF-8) character set. I have tried changing character code via put_UTF8(false) and put_Charset but no change. If I compile in an older version of the library everything is ok.....


Answer

The "Utf8" property is very different than the "Charset" property. The Utf8 property is common to all Chilkat C++ classes and informs the object instance how to interpret strings passed to the object (and also whether to return ANSI or utf-8 strings). Remember: A "string" in C/C++ is a "const char *", which is a pointer to a sequence of bytes terminated by a null char. We implicitly assume 1-byte per char (meaning ANSI), but it doesn't have to be. If your program is passing utf-8 strings (meaning that characters are represented by bytes using the utf-8 encoding), then the Utf8 property must be set to true.

Note that the Utf8 property has nothing to do with the actual Charset of the email. You COULD pass strings using utf-8, but then send the email using "iso-8859-1" by setting the Charset property. What happens is that the utf-8 string is provided to the Email object correctly, and then when the MIME of the email is rendered, the string is converted from it's internal utf-8 storage to iso-8859-1 for the MIME.


Answer

Yes I know that. I just wanted to say that there could be a bug in library, because when attaching a file in an e-mail message via CkEmail object, the library changes the character encoding of that file. And when opening attached file wrong characters are displayed....


Answer

I wasn't able to reproduce the problem.

The AddFileAttachment method shouldn't modify the contents of the file. It should attach the content of the file exactly as-is byte-for-byte.

An email client will display the text in an attached text file according to the charset specified within the MIME sub-header for that particular attachment. By default, no charset is specified. Therefore, an email client would be expecting the bytes of the attachment to be the ANSI representation of the chars. If they are not, then the text will not be rendered correctly. You would need to add the charset for a particular attachment by calling the SetAttachmentCharset method (after adding the attachment).


Answer

I have tried and added SetAttachmentCharset but it doesn't work. You dnl the file I am trying to attach here: https://www.dropbox.com/s/38556i03152zmjq/zaposto_ok2013916.csv The file is saved in windows-1250. All special characters disappear after sending (ŠČĆščć).

BUT, if I compile the same code with older chilkat library, everything is ok....