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?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
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,042
    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:
    245
    Josh Orfanakis
    Apr 25, 2004
  3. j
    Replies:
    3
    Views:
    632
    Sue Mosher [MVP-Outlook]
    May 24, 2004
  4. Detecting signed/encrypted mail messages

    , Jan 29, 2006, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    543
    Dmitry Streblechenko
    Jan 29, 2006
  5. 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:
    807
    Ramazan
    Nov 24, 2010
Loading...

Share This Page