How to save encrypted mail to disk (MSG) unencrypted

Discussion in 'Microsoft Outlook Program Addins' started by Damian Dekoszczak, Dec 29, 2011.

  1. Hi

    as in topic, i'm looking for a programmatic way to save encrypted
    email from inbox as unencrypted MSG file on disk. I want to do it from
    outlook add-in. Outlook Spy does it, so somehow it is possible. Of
    course saving by means on MailItem::SaveAs saves encrypted mail and so
    does code below:


    void SaveToMSG ( MailItem _item)

    {

    stringfilePath ="C:\\Users\\user\\Desktop\\"+ _item.Subject + ".msg";

    IntPtriSecMsg =IntPtr.Zero;

    IntPtriMsg;

    IntPtriProp;

    IntPtrptrGuid;

    variUnknown =ptrGuid =iMsg = iProp = IntPtr.Zero;

    IMapiPropprop = null;



    iUnknown= Marshal.GetIUnknownForObject(_item.MAPIOBJECT);

    var secMsg= (IMAPISecureMessage)_item.MAPIOBJECT;

    secMsg.GetBaseMessage(refiMsg);

    Marshal.QueryInterface(iMsg, ref _propGuid, out iProp);

    prop=
    (IMapiProp)Marshal.GetTypedObjectForIUnknown(iProp,typeof(IMapiProp));



    IStoragepStorage =null;

    IntPtrpMsgSession = IntPtr.Zero;

    IMessagepIMsg = null;

    varpMalloc =MAPIGetDefaultMalloc();



    StgCreateDocfile(filePath,

    STGM.READWRITE |

    STGM.TRANSACTED |

    STGM.CREATE, 0, out pStorage);



    OpenIMsgSession(pMalloc, 0, out pMsgSession);



    OpenIMsgOnIStg(pMsgSession,

    Marshal.GetFunctionPointerForDelegate(new
    MAPIAllocateBufferDelegate(MAPIAllocateBuffer)),

    Marshal.GetFunctionPointerForDelegate(new
    MAPIAllocateMoreDelegate(MAPIAllocateMore)),

    Marshal.GetFunctionPointerForDelegate(new
    MAPIFreeBufferDelegate(MAPIFreeBuffer)),

    pMalloc,

    IntPtr.Zero,

    pStorage,

    IntPtr.Zero, 0, 0x80000000, outpIMsg);



    r= WriteClassStg(pStorage, new Guid("{00020D0B-0000-0000-
    C000-000000000046}") );



    var guid = new Guid("00020307-0000-0000-C000-000000000046");

    r = prop.CopyTo(0, null,IntPtr.Zero,IntPtr.Zero, IntPtr.Zero,guid,
    pIMsg, 0,IntPtr.Zero);

    pIMsg.SaveChanges ( 2 );

    pStorage.Commit(0);



    Marshal.FinalReleaseComObject(pIMsg);

    Marshal.FinalReleaseComObject(pStorage);

    Marshal.ReleaseComObject(prop);

    CloseIMsgSession( pMsgSession );

    }



    Any hints how to do it? i tried passing IMAPISecureMessage IID as a
    second parameter of IMAPIProp::CopyTo (rgiidExclude) but to no avail.
     
    Damian Dekoszczak, Dec 29, 2011
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. zippy

    Save Message to MSG Compound File Doesn't Work With S/MIME Messages

    zippy, Jul 15, 2003, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    1,459
    Dmitry Streblechenko
    Jul 15, 2003
  2. Josh Orfanakis

    Cannot save MSG file

    Josh Orfanakis, Apr 25, 2004, in forum: Microsoft Outlook Program Addins
    Replies:
    0
    Views:
    369
    Josh Orfanakis
    Apr 25, 2004
  3. j
    Replies:
    3
    Views:
    804
    Sue Mosher [MVP-Outlook]
    May 24, 2004
  4. Sahil

    custom Outlook 2003 sorting and Encrypted emails

    Sahil, Jun 18, 2004, in forum: Microsoft Outlook Program Addins
    Replies:
    0
    Views:
    491
    Sahil
    Jun 18, 2004
  5. |{arl Shtoshek

    Determine if email is encrypted when using word as email editor

    |{arl Shtoshek, Aug 23, 2004, in forum: Microsoft Outlook Program Addins
    Replies:
    3
    Views:
    916
    Ken Slovak - [MVP - Outlook]
    Sep 20, 2004
  6. DarkJem

    Adding digital signature/encrypted body to a message (OL2002/2003 - C++)

    DarkJem, Mar 30, 2005, in forum: Microsoft Outlook Program Addins
    Replies:
    0
    Views:
    405
    DarkJem
    Mar 30, 2005
  7. Detecting signed/encrypted mail messages

    , Jan 29, 2006, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    712
    Dmitry Streblechenko
    Jan 29, 2006
  8. Ramazan

    Extended MAPI don't save encrypted mail in sent items folder

    Ramazan, Nov 23, 2010, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    1,188
    Ramazan
    Nov 24, 2010
Loading...