Author |
|
Luca Newbie
Joined: 15 October 2006
Online Status: Offline Posts: 17
|
Posted: 03 November 2006 at 6:44am | IP Logged
|
|
|
Hello,
I have developed a desktop application which does the following:
- Loads an .eml file
- Allows end users to modify it and preview it
- Saves the edited message
This application must deal with international charsets, and preserve the same charset after editing (it must not switch to utf-8). As i said, it is running on end users' pc (not on a web server).
I would like to know how I should set Codepagemode property in this scenario.
Thanks
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 03 November 2006 at 12:50pm | IP Logged
|
|
|
You should use CharsetOriginal property and ConvertCharset method. The following code shows how to preserve the message body in its original encoding:
Code:
Set Msg = CreateObject("MailBee.Message")
Msg.ImportFromFile "C:\1.eml"
Msg.Charset = Msg.CharsetOriginal
Msg.BodyText = Msg.ConvertCharset(Msg.BodyText, "", Msg.CharsetOriginal)
Msg.SaveMessage "C:\2.eml" |
|
|
You can also use Msg.ConvertCharset(Msg.BodyText, "", Msg.CharsetOriginal) clause if you need to convert a string into original character encoding of the message.
Please note, ConvertCharset and CharsetOriginal are not available in MailBee Objects 5.4. To use it, you should download the latest update (installation instructions included).
These new members will be officially presented in MailBee Objects 5.5.
Best regards,
Andrew
|
Back to Top |
|
|
Luca Newbie
Joined: 15 October 2006
Online Status: Offline Posts: 17
|
Posted: 03 November 2006 at 10:43pm | IP Logged
|
|
|
Hello,
thank you for your prompt answer. Still, even with the newer code you provided, I did not succeed in loading and saving a particular message without destroying it.
Here is an example; it is a polish (iso-8859-2) e-mail:
1.zip
(you have to scroll down the page and wait a few seconds before you can download the file, I'm sorry about this)
If you look at the message saved by MailBee, some letters are different (look at the titles, where it is most evident).
I also tried setting Codepagemode = 1 before loading the message, results are different but not better.
Thank you
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 04 November 2006 at 10:57am | IP Logged
|
|
|
You're right, CodepageMode=1 was the right thing to do with this mail. However, sad thing came to surface - it appears Windows counterpart of Poland codepage (1250) is missing some characters from its Internet version (28592 AKA "iso-8859-2")!
Thus, you cannot work with Poland in Windows codepage. When CodepageMode=1, MailBee converts the data into Windows codepage which makes it possible to always display it in Windows controls, etc. But this won't work with Poland.
We added another mode for CodepageMode, 3. If CodepageMode=3, MailBee does not convert anything and simply returns what it found in the message. With Poland, it should work ok.
If your app is Poland-centric, you could also use:
Msg.Codepage = 28592
and leave CodepageMode defaut (i.e. 0).
However, if your app is widely distributed and you have to support Cyrillic users, CodepageMode=3 will not help because KOI-8R charset is very different from Windows-1251 charset and users will see garbage. For Cyrillic users, CodepageMode=1 should be used.
There is also a few other languages where Windows codepage and Internet codepage do not match.
I.e. in Cyrillic, both KOI-8R and Windows-1251 contain full character set but characters occupy different positions. In Poland, Windows codepage contains less characters than Internet version but the remaining characters occupy the same positions in both codepages.
Thus, for Poland, use CodepageMode=3, for everything else - CodepageMode=1.
The latest version of MailBee.dll is at:
http://www.afterlogic.com/updates/mailbee.zip
Regards,
Alex
|
Back to Top |
|
|
Luca Newbie
Joined: 15 October 2006
Online Status: Offline Posts: 17
|
Posted: 04 November 2006 at 9:19pm | IP Logged
|
|
|
Thanks for the excellent support Alex, that works! I felt there was something specific to iso-8859-2: application had been tested on the most unusual (to me) charsets, including Cyrillic and Hebrew, which is written right to left!, and had always worked well (MailBee Objects' excellent handling of international issues was a primary reson for buying it).
Since my app is not Poland-centric, here is how I plan to modify code (simplified), using one of the new properties:
Msg.CodepageMode = 1
Msg.ImportFromFile "C:\1.eml"
If Msg.CharsetOriginal = "iso-8859-2" Then
Msg.CodepageMode = 3
Msg.ImportFromFile "C:\1.eml"
End If
Since I have no way of knowing which charset is used in the message until I load it, I use CodepageMode = 1 as default and, if it is a Polish message, change CodepageMode and re-load it. Does it sound ok to you?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 05 November 2006 at 6:08am | IP Logged
|
|
|
Yes, your workaround looks good. However, I would replace:
Code:
Msg.CharsetOriginal = "iso-8859-2" |
|
|
with:
Code:
Msg.CodepageOriginal = 28592 |
|
|
(CodepageOriginal is another new property of v5.5). You already have it in your updated version.
Why is this change needed? "iso-8859-2" is not the only name for Poland Internet codepage (28592). It could also be "iso8859-2", "iso_8859-2", etc, all denoting 28592 codepage. Using codepage number instead of charset name will cover all the cases.
Regards,
Alex
|
Back to Top |
|
|