Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display Subject field of an eml file

Posted on 2004-10-26
14
Medium Priority
?
941 Views
Last Modified: 2012-05-05
I have eml files which are QP encoded and charset is ISO 8859-2. I want to display the Subject and Body of the message as message box on a Polish desktop. How can acheive this using CDO ?
If I use GetDecodedContentStream().ReadText. The text that is displayed is not proper and some of the characters look like control characters.
Basically my application is a POP3 application which downloads messages as .eml and then displays only the subject and Body of message as a text box.

Any help is appreciated.
0
Comment
Question by:MyName1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
14 Comments
 
LVL 3

Expert Comment

by:zahaby
ID: 12415874
try to use
ContentTransferEncoding
0
 
LVL 3

Expert Comment

by:zahaby
ID: 12415893
A message body that contains content other than plain US-ASCII text is subdivided into parts. Examples of body parts include text, attachments, inline Hypertext Markup Language (HTML) pages, alternative representations of HTML pages, and so on. The IBodyPart interface defines a set of abstract methods and properties that you can use to manipulate message body parts.

Body parts are arranged hierarchically in a message that is formatted in MIME; for example, a message that contains only text and attachments has a two-level hierarchy—the first level includes the message content and the second level contains each attachment. The IBodyPart interface supports such hierarchies by exposing the BodyParts property. Navigating down one level from an implementing object returns a collection of objects, each of which exposes the IBodyPart interface.

Each object that exposes the IBodyPart interface provides access to content in serialized format using the GetDecodedContentStream or GetEncodedContentStream methods. Both methods return an ADO Stream object (exposing a _Stream interface) that contains the content in decoded or encoded format, respectively. Content encoding depends on whether the message body is formatted using MIME or Uuencode. This operation is controlled at the Message object level using the IMessage.MIMEFormatted property.

You can also use the GetStream method to return the entire body part and all sub-parts in serialized, encoded format. For messages formatted in MIME, this stream contains the mail headers (such as Content-Type) and the content encoded using the mechanism specified by the IBodyPart.ContentTransferEncoding property.
0
 
LVL 3

Accepted Solution

by:
zahaby earned 800 total points
ID: 12415932
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MyName1
ID: 12420470
This is what im doing in a sample vbs file

    Set Stm = CreateObject("ADODB.Stream")
    Stm.Open
    Stm.LoadFromFile "C:\\test.eml"
    Set iMsg = CreateObject("CDO.Message")
      
    Set iDsrc = iMsg.DataSource
    iDsrc.OpenObject Stm, "_Stream"
'MsgBox "Subject : " + iMsg.Subject
'MsgBox "Body : " + iMsg.BodyPart.GetDecodedContentStream().ReadText()
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True, True)
f1.WriteLine("Subject :" + iMsg.Subject)
llngLength = LenB(iMsg.Subject)
     For llngIndex = 1 To llngLength
          llngAscii = AscB(MidB(iMsg.Subject, llngIndex, 1))
          lstrUnicode = lstrUnicode + Chr(lLngAscii)
     Next
f1.WriteLine(lstrUnicode )
f1.Close()




The eml file has this as the subject
test ąćęłńóśźż ĄĆĘŁŃÓŚŹŻ test

and in my output i get it as
test ¹æê³ñ󜟿 ¥ÆÊ£ÑÓŒ¯ test

and unicode output as
t e s t   ¹ æ ê ³ ñ ó Sx¿   ¥ Æ Ê £ Ñ Ó R ¯   t e s t



What is going on ?

0
 

Author Comment

by:MyName1
ID: 12420491
the eml file has subject as "test ąćęłńóśźż ĄĆĘŁŃÓŚŹŻ test"
0
 

Author Comment

by:MyName1
ID: 12427032
Ok I got the vbscript to work. I had to use the fields property and then urn:schemas:httpmail:normalizedSubject. I dont like it.

Now I tried to use the same in C++. Im trying to display the From field which should be in unicode because im using
"urn:schemas:httpmail:From" field. Do you know if there is any bug in CDO ? As per documentation all these fields should be in unicode. Only the normalizedSubject and TextDescription fields are in Unicode the rest of it in ASCII.

I dont get it why and this is the code im using..

CoInitialize(NULL);
  _StreamPtr  pStm(__uuidof(Stream));

      _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);

      try {

            pStm->Open(

                            varOptional,

                            adModeUnknown,

                            adOpenStreamUnspecified,

                            _bstr_t(""),

                            _bstr_t(""));

                                    pStm->Charset = "UTF-8";

                                   

            pStm->LoadFromFile("C:\\test.eml");

      }

      catch(_com_error e)

      {

                          AfxMessageBox(e.ErrorMessage());

      }

 

      IMessagePtr iMsg(__uuidof(Message));

      IDataSourcePtr iDsrc;

      iDsrc = iMsg;

 

      try {

            iDsrc->OpenObject(pStm,_bstr_t("_Stream"));

      }

      catch(_com_error e)

      {

                          AfxMessageBox(e.ErrorMessage());

      }

 
                                    Field* p;

                                    iMsg->Fields->get_Item(_variant_t("urn:schemas:httpmail:From"), &p);

                         _variant_t t;

                         p->get_Value(&t);


                         ::MessageBoxW(NULL,t.bstrVal, t.bstrVal, MB_OK);

0
 
LVL 3

Expert Comment

by:zahaby
ID: 12427050
:) great
thanks for informations
0
 

Author Comment

by:MyName1
ID: 12427524
No man. you got it wrong. it only works in VBScript but in C++ never gives unicode although MSDN documentation says if you use
urn:schemas:httpmail
it should always return unicode..

any ideas ?
0
 

Author Comment

by:MyName1
ID: 12534393
Ok. The problem was with the CDOSys.dll I had on that machine. I installed SP4 and everything works fine now.
zahaby , just for being the only one who was interested in answering I want to give you 200 points. But i dont know how to do it. Moderator ??

Thanks...
0
 

Author Comment

by:MyName1
ID: 12741096
I already added this comment
"Ok. The problem was with the CDOSys.dll I had on that machine. I installed SP4 and everything works fine now.
zahaby , just for being the only one who was interested in answering I want to give you 200 points. But i dont know how to do it. Moderator ??
"
0
 
LVL 3

Expert Comment

by:zahaby
ID: 12752488
thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question