Results 1 to 3 of 3

Thread: [.NET 3.5+] RtfDecompressor - Decompress RTF From Outlook And Exchange Server

  1. #1

    Thread Starter
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    [.NET 3.5+] RtfDecompressor - Decompress RTF From Outlook And Exchange Server

    The following class is an implementation of the decompressing algorithm specified by [MS-OXRTFCP]: Rich Text Format (RTF) Compression Algorithm. Why is this useful? Well, let me explain:

    I recently ran into a situation where I wanted to parse the content out of a .MSG file. As you may or may not know, a .MSG file is a compound file. As such, it contains a bunch of streams mostly in either ASCII or Binary format. Anyhow, there is a property that is called PR_RTF_COMPRESSED that usually contains a compressed (very rarely it will be uncompressed, never seen it though) version of the RTF that comprises a .MSG file. If you wanted to create a .MSG viewer of some sort you would need something to pull out the nicely formatted RTF.

    When you create a email in Outlook (using 2003 for this), there is a ComboBox that specifies what type of format the email will be:

    Name:  Outlook_Message_Format.png
Views: 2490
Size:  54.2 KB

    This will be set to a default of HTML. Let's set this to Rich Text for now. If I send this message to someone and then drag out the email from Outlook into Windows Explorer and then run the RtfDecompressor on it I will the RTF for it. I can then bind then RTF to a RichTextBox for a preview of what the formatted and colorized email content looked like (sample application):

    Name:  Outlook_Message_Viewer.png
Views: 2751
Size:  44.6 KB

    Unfortunately, due to the .NET implementation of the RichTextBox, links are not displayed all that well and have some problems keeping the line breaks that separate them. Not much you can do about this (it works perfect in Microsoft Word and Word Pad).

    To use this class, you must have a basic understanding of how compound files work. I will be eventually be posting another thread that shows how you can access the different streams of a compound file. Specifically the .MSG file. Anyway, the use is simple:

    Code:
    Dim compressedRtf = Me.GetCompressedRtf()
    
    '//accepts either a System.Byte() or a
    '//                 System.IO.Stream
    Dim decompressedRtf = RtfDecompressor.Decompress(compressedRtf)
    Dim text = Encoding.ASCII.GetString(decompressedRtf)
    
    MessageBox.Show(text)
    In the algorithm there is a section on CRC checking. You can call Decompress and specify whether it should enforce a CRC check. The default implementation does not force a CRC check.

    Keep in mind this will work for all message formats, however, depending on your selection you will get very different decompressed RTF. If you select HTML, the decompressed RTF will basically contain pure HTML embedded in RTF. The Rich Text option will be the closest to what you see in Outlook.

    Applications
    • Microsoft Exchange Server 2003
    • Microsoft Exchange Server 2007
    • Microsoft Exchange Server 2010
    • Microsoft Office Outlook 2003
    • Microsoft Office Outlook 2007
    • Microsoft Office Outlook 2010


    Plans for this thread
    Attached Files Attached Files

  2. #2

    Thread Starter
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: [.NET 3.5+] RtfDecompressor - Decompress RTF From Outlook And Exchange Server

    Reserved.

  3. #3
    New Member
    Join Date
    Oct 2017
    Posts
    1

    Re: [.NET 3.5+] RtfDecompressor - Decompress RTF From Outlook And Exchange Server

    Great post! Do you have any ideas of how I can compress RTF to send to Outlook? IE To create an Outlook item and set the PR_RTF_COMPRESSED property?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width