Solved

Display Subject field of an eml file

Posted on 2004-10-26
850 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
Question by:MyName1
    11 Comments
     
    LVL 3

    Expert Comment

    by:zahaby
    try to use
    ContentTransferEncoding
    0
     
    LVL 3

    Expert Comment

    by:zahaby
    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:
    0
     

    Author Comment

    by:MyName1
    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
    the eml file has subject as "test ąćęłńóśźż ĄĆĘŁŃÓŚŹŻ test"
    0
     

    Author Comment

    by:MyName1
    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
    :) great
    thanks for informations
    0
     

    Author Comment

    by:MyName1
    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
    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
    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
    thanks very much
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    934 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now