Saving Message as text but trying to keeping unicode

C

chris

I am saving Outlook items using the SaveAs method to a Text file using
OlSaveAsType.olTXT as the Parameter however I am losing the Unicode
within the Item itself to the SaveAs method (it replaces the unicode
with garbage or ???).

Is there a way to preserve the unicode but still save it as a txt file?

I have tried RTF but this is not what I need because it keeps hold of
the Embedded attachments in the mime section and all I want it textual
representation of the message.


The other option available to me would be to save it to HTML but I know

that not all items save to HTML and if I convert an item that is
originally RTF it will lose its formatting on conversion.


i.e.
If oMailItem.BodyFormat = OlBodyFormat.olFormatHTML Then
oMailItem.BodyFormat = OlBodyFormat.olFormatRichText
End If
or vice-versa


Any help would be appreciated.


Thanks,


Chris


Below is the Save function I am using:


Public Function SaveOlItem(ByVal oItem As Object, ByVal sFile As
String, ByVal SaveFileFormat As OlSaveAsType) As Long


Dim oMailItem As Outlook.MailItem
Dim oMeetingItem As Outlook.MeetingItem
Dim oApptItem As Outlook.AppointmentItem
Dim oContactItem As Outlook.ContactItem
Dim oDistListItem As Outlook.DistListItem
Dim oDocItem As Outlook.DocumentItem
Dim oNoteItem As Outlook.NoteItem
Dim oPostItem As Outlook.PostItem
Dim oReportItem As Outlook.ReportItem
Dim oTaskItem As Outlook.TaskItem
Dim oTaskReqItem As Outlook.TaskRequestItem
Dim oTaskReqAccItem As Outlook.TaskRequestAcceptItem
Dim oTaskReqDecItem As Outlook.TaskRequestDeclineItem
Dim oTaskReqUpItem As Outlook.TaskRequestUpdateItem
On Error GoTo Error_Handler


Select Case oItem.Class
Case olMail
Set oMailItem = oItem.Copy
oMailItem.SaveAs sFile, SaveFileFormat
oMailItem.Copy
Set oMailItem = Nothing
Case olMeeting
Set oMeetingItem = oItem.Copy
oMeetingItem.SaveAs sFile, SaveFileFormat
Set oMeetingItem = Nothing
Case olMeetingRequest
Set oMeetingItem = oItem.Copy
oMeetingItem.SaveAs sFile, SaveFileFormat
Set oMeetingItem = Nothing
Case olAppointment
Set oApptItem = oItem.Copy
oApptItem.SaveAs sFile, SaveFileFormat
Set oApptItem = Nothing
Case olContact
Set oContactItem = oItem.Copy
oContactItem.SaveAs sFile, SaveFileFormat
Set oContactItem = Nothing
Case olDistributionList
Set oDistListItem = oItem.Copy
oDistListItem.SaveAs sFile, SaveFileFormat
Set oDistListItem = Nothing
Case olDocument
Set oDocItem = oItem.Copy
oDocItem.SaveAs sFile, SaveFileFormat
Set oDocItem = Nothing
Case olNote
Set oNoteItem = oItem.Copy
oNoteItem.SaveAs sFile, SaveFileFormat
Set oNoteItem = Nothing
Case olPost
Set oPostItem = oItem.Copy
oPostItem.SaveAs sFile, SaveFileFormat
Set oPostItem = Nothing
Case olReport
Set oReportItem = oItem.Copy
oReportItem.SaveAs sFile, SaveFileFormat
Set oReportItem = Nothing
Case olTask
Set oTaskItem = oItem.Copy
oTaskItem.SaveAs sFile, SaveFileFormat
Set oTaskItem = Nothing
Case olTaskRequest
Set oTaskReqItem = oItem.Copy
oTaskReqItem.SaveAs sFile, SaveFileFormat
Set oTaskReqItem = Nothing
Case olTaskRequestAccept
Set oTaskReqAccItem = oItem.Copy
oTaskReqAccItem.SaveAs sFile, SaveFileFormat
Set oTaskReqAccItem = Nothing
Case olTaskRequestDecline
Set oTaskReqDecItem = oItem.Copy
oTaskReqDecItem.SaveAs sFile, SaveFileFormat
Set oTaskReqDecItem = Nothing
Case olTaskRequestUpdate
Set oTaskReqUpItem = oItem.Copy
oTaskReqUpItem.SaveAs sFile, SaveFileFormat
Set oTaskReqUpItem = Nothing
Case Else
oItem.SaveAs sFile, SaveFileFormat
End Select


SaveOlItem = 0
Exit Function


Error_Handler:


SaveOlItem = Err.Number


'House Cleaning
Set oMailItem = Nothing
Set oPostItem = Nothing
Set oMeetingItem = Nothing
Set oApptItem = Nothing
Set oContactItem = Nothing
Set oDistListItem = Nothing
Set oDocItem = Nothing
Set oNoteItem = Nothing
Set oReportItem = Nothing
Set oTaskItem = Nothing
Set oTaskReqItem = Nothing
Set oTaskReqAccItem = Nothing
Set oTaskReqDecItem = Nothing
Set oTaskReqUpItem = Nothing


End Function
 
D

Dmitry Streblechenko

What is your version of Outlook? At least in Outlook 2003, a UTF-8 txt file
is created.

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

chris

Dimitry,

I'm using 2003 (11.6359.6408) SP1. I am surprised with this aswell.
I also thought Outlook would handle the Unicode but apparently not.

Is there a setting that may have been set that would change this?

In "Options/Other/Advanced Options" the Check box "Use Unicode Message
Format when saving message", is checked. and the only other place I see
Unicode is in "Options/Mail Format/International Options" and the
Preferred Encoding is set to "Unicode (UTF-8)". I'm lost at this
point.

Chris
 
C

chris

Dimitry,

I also notices that when I create a new mail item and insert
unicode..... It work when I saveAs to txt file but that is before I
send it and it prompts me for the encoding

On the receiving mail address or from my Sent Items folder, the message
behave as before when I save it. Lots of Garbage?????

Any idea why this is?

Regards,

Chris
 
C

chris

Another thing is that it is using Word as the editor when I create a
mail item which would explain why it is saving the unicode charactors.
 
C

chris

The Message format varies. Most are RTF though although I do believe I
have come across other formats. I know that changing between HTML and
RTF will result in losing the Format information.

Some of the items are Plain text that contain the Unicode do I need to
change the format to RTF or HTML before I save as type olTXT?
 
D

Dmitry Streblechenko

Save the message in question as an MSG file (File | Save As), zip it
(important!) and send to my private e-mail address - I'll take a look.

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