Display Subject field of an eml file

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.
MyName1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zahabyCommented:
try to use
ContentTransferEncoding
0
zahabyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

MyName1Author Commented:
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
MyName1Author Commented:
the eml file has subject as "test ąćęłńóśźż ĄĆĘŁŃÓŚŹŻ test"
0
MyName1Author Commented:
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
zahabyCommented:
:) great
thanks for informations
0
MyName1Author Commented:
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
MyName1Author Commented:
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
MyName1Author Commented:
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
zahabyCommented:
thanks very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.