Changing the InternetCodepage of messages

G

Guest

I have a large number of mail messages which have been written in Finnish,
but have been marked with a US-ASCII code page. The result is that some of
the characters are displayed incorrectly, e.g. "ä" is shown as a "d".

It is possible to correct this error in Outlook by opening the message,
setting the code page manually from the View>>Encoding menu and then saving
the message. Instead of doing this to about 500 messages by hand, I tried to
write a short program to do it.

The result of running the code below is that the code page of all messages
in my "Macro" folder is set to iso_8859_1 (as I want to happen).
Unfortunately, when I open the messages they are still displayed incorrectly.
However, if I open the View menu and look at the code page settings, they
are correctly set to "Western European (ISO)" as I want them to be. I.e. the
property change is successful, but the view of the message doesn't change.

What is it that I am missing ? Changing the code page manually from the
menu affects the message view immediately, while doing it programatically
does not cause the view to change. Is there something in the mail message
view (Inspector object) that persists ? Or should I be changing some other
property than the InternetCodepage ?

Thanks for all answers,
Juha


Sub SetMessageCodePages()
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myMessages As Outlook.Items
Dim myMessage As Object
Const USASCII As Long = 20127
Const iso_8859_1 As Long = 28591

Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myInboxFolder = _
myNamespace.GetDefaultFolder(olFolderInbox)
Set myRootFolder = myInboxFolder.Parent
Set myMacroFolder = myRootFolder.Folders("Macro")
Set myMessages = myMacroFolder.Items
For Each myMessage In myMessages
myMessage.InternetCodepage = iso_8859_1
Debug.Print "Code page has been set to:" &
myMessage.InternetCodepage
myMessage.Close olSave
Next
End Sub
 
D

Dmitry Streblechenko

AFAIK setting the InternetCodepage property changes the PR_INTERNET_CPID
MAPI property and that works fine for the Subject, Sender, etc. But when you
modify the code page from the inspector, besides resetting the
PR_INTERNET_CPID property, it sets the code page used by the RTF stream in
PR_RTF_COMPRESSED property, which is used to display the body of the
message. The code page specified in the RTF stream
({\rtf1\ansi\ansicpg1252...) takes precedence over PR_INTERNET_CPID for the
message body. I don't think there is an easy way to reset the RTF codepage.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top