Mapi.cs
author Thomas
Wed, 16 Jan 2019 14:29:14 +0100
changeset 2546 19b771109681
parent 2544 62e8b0fc8e78
child 2547 0a81e858680c
permissions -rw-r--r--
Add GetMAPIProperties method
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     1
´╗┐using System;
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
     2
using System.Collections.Generic;
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     3
using System.Runtime.InteropServices;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     4
using Outlook = Microsoft.Office.Interop.Outlook;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     5
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     6
namespace pEp
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
     7
{
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
     8
    /// <summary>
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
     9
    /// Provides methods to interact with MAPI via native (p/invoke) calls.
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
    10
    /// </summary>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    11
    internal class Mapi
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    12
    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    13
        #region Definitions
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    14
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    15
        /// A collection of MAPI error or warning codes.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    16
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    17
        internal static class HResult
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    18
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    19
            public const uint S_FALSE                           = 0x00000001;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    20
            public const uint S_OK                              = 0x00000000;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    21
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    22
            public const uint E_NOTIMPL                         = 0x80004001;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    23
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    24
            public const uint MAPI_E_CALL_FAILED                = 0x80004005;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    25
            public const uint MAPI_E_NOT_ENOUGH_MEMORY          = 0x8007000E;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    26
            public const uint MAPI_E_INVALID_PARAMETER          = 0x80000003;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    27
            public const uint MAPI_E_INTERFACE_NOT_SUPPORTED    = 0x80000004;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    28
            public const uint MAPI_E_NO_ACCESS                  = 0x80000009;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    29
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    30
            public const uint E_INVALIDARG                      = 0x80070057;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    31
            public const uint E_OUTOFMEMORY                     = 0x80000002;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    32
            public const uint E_UNEXPECTED                      = 0x8000FFFF;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    33
            public const uint E_FAIL                            = 0x80000008;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    34
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    35
            public const uint MAPI_E_NO_SUPPORT                 = 0x80040000 | 0x102;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    36
            public const uint MAPI_E_BAD_CHARWIDTH              = 0x80040000 | 0x103;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    37
            public const uint MAPI_E_STRING_TOO_LONG            = 0x80040000 | 0x105;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    38
            public const uint MAPI_E_UNKNOWN_FLAGS              = 0x80040000 | 0x106;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    39
            public const uint MAPI_E_INVALID_ENTRYID            = 0x80040000 | 0x107;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    40
            public const uint MAPI_E_INVALID_OBJECT             = 0x80040000 | 0x108;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    41
            public const uint MAPI_E_OBJECT_CHANGED             = 0x80040000 | 0x109;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    42
            public const uint MAPI_E_OBJECT_DELETED             = 0x80040000 | 0x10A;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    43
            public const uint MAPI_E_BUSY                       = 0x80040000 | 0x10B;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    44
            public const uint MAPI_E_NOT_ENOUGH_DISK            = 0x80040000 | 0x10D;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    45
            public const uint MAPI_E_NOT_ENOUGH_RESOURCES       = 0x80040000 | 0x10E;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    46
            public const uint MAPI_E_NOT_FOUND                  = 0x80040000 | 0x10F;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    47
            public const uint MAPI_E_VERSION                    = 0x80040000 | 0x110;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    48
            public const uint MAPI_E_LOGON_FAILED               = 0x80040000 | 0x111;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    49
            public const uint MAPI_E_SESSION_LIMIT              = 0x80040000 | 0x112;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    50
            public const uint MAPI_E_USER_CANCEL                = 0x80040000 | 0x113;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    51
            public const uint MAPI_E_UNABLE_TO_ABORT            = 0x80040000 | 0x114;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    52
            public const uint MAPI_E_NETWORK_ERROR              = 0x80040000 | 0x115;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    53
            public const uint MAPI_E_DISK_ERROR                 = 0x80040000 | 0x116;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    54
            public const uint MAPI_E_TOO_COMPLEX                = 0x80040000 | 0x117;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    55
            public const uint MAPI_E_BAD_COLUMN                 = 0x80040000 | 0x118;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    56
            public const uint MAPI_E_EXTENDED_ERROR             = 0x80040000 | 0x119;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    57
            public const uint MAPI_E_COMPUTED                   = 0x80040000 | 0x11A;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    58
            public const uint MAPI_E_CORRUPT_DATA               = 0x80040000 | 0x11B;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    59
            public const uint MAPI_E_UNCONFIGURED               = 0x80040000 | 0x11C;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    60
            public const uint MAPI_E_FAILONEPROVIDER            = 0x80040000 | 0x11D;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    61
            public const uint MAPI_E_UNKNOWN_CPID               = 0x80040000 | 0x11E;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    62
            public const uint MAPI_E_UNKNOWN_LCID               = 0x80040000 | 0x11F;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    63
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    64
            public const uint MAPI_E_CORRUPT_STORE              = 0x80040000 | 0x600;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    65
            public const uint MAPI_E_NOT_IN_QUEUE               = 0x80040000 | 0x601;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    66
            public const uint MAPI_E_NO_SUPPRESS                = 0x80040000 | 0x602;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    67
            public const uint MAPI_E_COLLISION                  = 0x80040000 | 0x604;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    68
            public const uint MAPI_E_NOT_INITIALIZED            = 0x80040000 | 0x605;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    69
            public const uint MAPI_E_NON_STANDARD               = 0x80040000 | 0x606;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    70
            public const uint MAPI_E_NO_RECIPIENTS              = 0x80040000 | 0x607;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    71
            public const uint MAPI_E_SUBMITTED                  = 0x80040000 | 0x608;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    72
            public const uint MAPI_E_HAS_FOLDERS                = 0x80040000 | 0x609;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    73
            public const uint MAPI_E_HAS_MESSAGES               = 0x80040000 | 0x60A;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    74
            public const uint MAPI_E_FOLDER_CYCLE               = 0x80040000 | 0x60B;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    75
        };
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    76
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    77
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    78
        /// Interface IDs used to retrieve the specific MAPI Interfaces from the IUnknown object.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    79
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    80
        internal static class MAPIInterfaceIds
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    81
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    82
            public const string IMAPISession        = "00020300-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    83
            public const string IMAPIProp           = "00020303-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    84
            public const string IMAPITable          = "00020301-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    85
            public const string IMAPIMsgStore       = "00020306-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    86
            public const string IMAPIFolder         = "0002030C-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    87
            public const string IMAPISpoolerService = "0002031E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    88
            public const string IMAPIStatus         = "0002031E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    89
            public const string IMessage            = "00020307-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    90
            public const string IAddrBook           = "00020309-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    91
            public const string IProfSect           = "00020304-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    92
            public const string IMAPIContainer      = "0002030B-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    93
            public const string IABContainer        = "0002030D-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    94
            public const string IMsgServiceAdmin    = "0002031D-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    95
            public const string IProfAdmin          = "0002031C-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    96
            public const string IMailUser           = "0002030A-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    97
            public const string IDistList           = "0002030E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    98
            public const string IAttachment         = "00020308-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    99
            public const string IMAPIControl        = "0002031B-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   100
            public const string IMAPILogonRemote    = "00020346-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   101
            public const string IMAPIForm           = "00020327-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   102
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   103
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   104
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   105
        /// Save options for the IMAPIProp.SaveChanges method.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   106
        /// </summary>
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   107
        internal enum SaveOption
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   108
        {
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   109
            KEEP_OPEN_READONLY = 0x00000001,
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   110
            KEEP_OPEN_READWRITE = 0x00000002,
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   111
            FORCE_SAVE = 0x00000004
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   112
        }
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   113
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   114
        /// <summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   115
        /// Flag to indicate that IMAPIProps::GetProps should return unicode values.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   116
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   117
        private const uint MAPI_UNICODE = 0x80000000;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   118
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   119
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   120
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   121
        #region Interfaces
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   122
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   123
        /// Enables clients, service providers, and MAPI to work with properties. All objects that 
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   124
        /// support properties implement this interface.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   125
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   126
        [
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   127
            ComImport,
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   128
            ComVisible(false),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   129
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   130
            Guid(Mapi.MAPIInterfaceIds.IMAPIProp)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   131
        ]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   132
        internal interface IMAPIProp
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   133
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   134
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   135
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   136
            int GetLastError();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   137
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   138
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   139
            int SaveChanges(uint uFlags);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   140
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   141
            [PreserveSig]
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   142
            int GetProps([MarshalAs(UnmanagedType.LPArray)] uint[] lpPropTagArray, uint flags, out uint count, out IntPtr propArray);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   143
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   144
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   145
            int GetPropList();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   146
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   147
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   148
            int OpenProperty();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   149
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   150
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   151
            int SetProps(uint values, IntPtr propArray, IntPtr problems);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   152
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   153
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   154
            int DeleteProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   155
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   156
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   157
            int CopyTo();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   158
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   159
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   160
            int CopyProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   161
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   162
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   163
            int GetNamesFromIDs();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   164
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   165
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   166
            int GetIDsFromNames();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   167
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   168
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   169
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   170
        #region Structures
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   171
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   172
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   173
        /// The SPropValue structure describes a MAPI property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   174
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   175
        public struct SPropValue
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   176
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   177
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   178
            /// Property tag for the property. Property tags are 32-bit unsigned integers consisting of the property's unique identifier in the high-order 16 bits and the property's type in the low-order 16 bits.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   179
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   180
            public uint PropTag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   181
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   182
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   183
            /// Reserved for MAPI; do not use.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   184
            /// </summary>
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   185
#pragma warning disable 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   186
            public uint DwAlignPad;
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   187
#pragma warning restore 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   188
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   189
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   190
            /// Union of data values, the specific value dictated by the property type.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   191
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   192
            public PV Value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   193
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   194
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   195
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   196
        /// Union of data values for the SPropValue.value property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   197
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   198
        [StructLayout(LayoutKind.Explicit, Size = 8)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   199
        public struct PV
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   200
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   201
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   202
            public short i;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   203
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   204
            public int l;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   205
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   206
            public uint ul;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   207
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   208
            public float flt;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   209
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   210
            public double dbl;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   211
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   212
            public ushort b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   213
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   214
            public double at;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   215
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   216
            public IntPtr lpszA;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   217
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   218
            public IntPtr lpszW;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   219
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   220
            public IntPtr lpguid;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   221
            /*[FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   222
            public IntPtr bin;*/
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   223
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   224
            public ulong li;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   225
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   226
            public SRowSet bin;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   227
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   228
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   229
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   230
        /// Contains an array of SRow structures. Each SRow structure describes a row from a table.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   231
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   232
        [StructLayout(LayoutKind.Sequential)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   233
        public struct SRowSet
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   234
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   235
            public uint cRows;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   236
            public IntPtr aRow; // pSRow
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   237
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   238
            public byte[] AsBytes
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   239
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   240
                get
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   241
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   242
                    byte[] b = new byte[this.cRows];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   243
                    for (int i = 0; i < this.cRows; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   244
                        b[i] = Marshal.ReadByte(aRow, i);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   245
                    return b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   246
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   247
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   248
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   249
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   250
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   251
        #region Methods
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   252
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   253
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   254
        /// Retrieves a managed object from the SPropValue structure that is returned by GetProps etc.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   255
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   256
        /// <param name="mapiProperty">The MAPI property the value was retrieved for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   257
        /// <param name="sPropValue">The value to convert.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   258
        /// <returns>The converted object or null if an error occured.</returns>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   259
        private static object ConvertSPropValueToObject(MapiProperty.MapiProp mapiProperty, SPropValue sPropValue)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   260
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   261
            object propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   262
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   263
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   264
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   265
                switch (mapiProperty.DataType)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   266
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   267
                    case MapiProperty.MapiDataType.PtypBoolean:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   268
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   269
                            propertyValue = Convert.ToBoolean(sPropValue.Value.b);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   270
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   271
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   272
                    case MapiProperty.MapiDataType.PtypString:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   273
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   274
                            if ((((uint)sPropValue.Value.lpszW).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   275
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   276
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   277
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   278
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   279
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   280
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   281
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszW);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   282
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   283
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   284
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   285
                    case MapiProperty.MapiDataType.PtypString8:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   286
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   287
                            if ((((uint)sPropValue.Value.lpszA).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   288
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   289
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   290
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string8: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   291
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   292
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   293
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   294
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszA);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   295
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   296
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   297
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   298
                    case MapiProperty.MapiDataType.PtypInteger16:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   299
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   300
                            propertyValue = sPropValue.Value.i;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   301
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   302
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   303
                    case MapiProperty.MapiDataType.PtypInteger32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   304
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   305
                            propertyValue = sPropValue.Value.l;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   306
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   307
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   308
                    case MapiProperty.MapiDataType.PtypFloating32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   309
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   310
                            propertyValue = sPropValue.Value.flt;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   311
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   312
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   313
                    case MapiProperty.MapiDataType.PtypFloating64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   314
                    case MapiProperty.MapiDataType.PtypFloatingTime:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   315
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   316
                            propertyValue = sPropValue.Value.at;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   317
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   318
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   319
                    case MapiProperty.MapiDataType.PtypInteger64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   320
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   321
                            propertyValue = sPropValue.Value.li;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   322
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   323
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   324
                    case MapiProperty.MapiDataType.PtypGuid:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   325
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   326
                            propertyValue = Marshal.PtrToStructure(sPropValue.Value.lpguid, typeof(Guid));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   327
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   328
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   329
                    case MapiProperty.MapiDataType.PtypBinary:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   330
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   331
                            propertyValue = sPropValue.Value.bin;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   332
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   333
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   334
                    default:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   335
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   336
                            propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   337
                            Log.Error("ConvertSPropValueToObject: Error converting SPropValue. Data type {0} not supported.", Enum.GetName(typeof(MapiProperty.MapiDataType), mapiProperty.DataType));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   338
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   339
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   340
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   341
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   342
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   343
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   344
                propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   345
                Log.Error("ConvertSPropValueToObject: Error converting MAPI property {0}. Exception: {1}.", mapiProperty.DaslName, ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   346
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   347
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   348
            return propertyValue;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   349
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   350
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   351
        /// <summary>
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   352
        /// Gets a MAPI property value from an Outlook mail item.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   353
        /// </summary>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   354
        /// <param name="omi">The Outlook mail item to get the property value for.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   355
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   356
        /// <returns>The value or null if it doesn't exist or an error occured.</returns>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   357
        public static object GetMAPIProperty(Outlook.MailItem omi, MapiProperty.MapiProp mapiProperty)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   358
        {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   359
            return Mapi.GetMAPIProperty(omi?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMessage, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   360
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   361
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   362
        /// <summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   363
        /// Gets a MAPI property value from an Outlook folder item.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   364
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   365
        /// <param name="omi">The Outlook folder item to get the property value for.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   366
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   367
        /// <returns>The value or null if it doesn't exist or an error occured.</returns>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   368
        public static object GetMAPIProperty(Outlook.Folder folder, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   369
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   370
            return Mapi.GetMAPIProperty(folder?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMAPIFolder, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   371
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   372
2544
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   373
        /// <summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   374
        /// Gets the specified MAPI property value for this store.
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   375
        /// </summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   376
        /// <param name="store">The Outlook store to process with.</param>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   377
        /// <param name="mapiProperty">The MAPI property to get its value for.</param>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   378
        /// <returns>The property value or null if not found or an error occured.</returns>
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   379
        public static object GetMAPIProperty(Outlook.Store store, MapiProperty.MapiProp mapiProperty)
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   380
        {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   381
            return Mapi.GetMAPIProperty(store?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMAPIMsgStore, mapiProperty);
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   382
        }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   383
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   384
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   385
        /// Gets a MAPI property value from an Outlook item.
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   386
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   387
        /// <param name="mapiObject">The MAPIOBJECT property of the Outlook item to get the property value for.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   388
        /// <param name="mapiInterfaceId">The MAPI interface id. Has to be one of the ones defined in Mapi.MAPIInterfaceIds and
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   389
        /// has to match the type of the mapiObject parameter.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   390
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   391
        /// <returns>The value or null if it doesn't exist or an error occured.</returns>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   392
        private static object GetMAPIProperty(object mapiObject, string mapiInterfaceId, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   393
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   394
            // Check passed parameters
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   395
            if ((mapiObject == null) ||
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   396
                (string.IsNullOrEmpty(mapiInterfaceId)))
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   397
            {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   398
                Log.Error("GetMAPIProperty: MAPI object oder interface id is null. Returning null.");
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   399
                return null;
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   400
            }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   401
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   402
            object propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   403
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   404
            // Pointer to IUnknown interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   405
            IntPtr IUnknown = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   406
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   407
            // Pointer to IMessage, IMAPIFolder etc. interface
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   408
            IntPtr IMAPIObject = IntPtr.Zero;
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   409
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   410
            // Pointer to IMAPIProp interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   411
            IntPtr IMAPIProp = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   412
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   413
            // Structure that will hold the property value
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   414
            Mapi.SPropValue sPropValue;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   415
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   416
            // A pointer that points to the SPropValue structure 
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   417
            IntPtr ptrPropValue = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   418
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   419
            try
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   420
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   421
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   422
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   423
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   424
                // Get the IUnknown interface from the MAPI object
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   425
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   426
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   427
                // Set the MAPI object interface GUID that we pass to retrieve the IMessage interface.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   428
                Guid guidIMessage = new Guid(mapiInterfaceId);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   429
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   430
                // Try to retrieve the MAPI object interface
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   431
                if (Marshal.QueryInterface(IUnknown, ref guidIMessage, out IMAPIObject) != Mapi.HResult.S_OK)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   432
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   433
                    Log.Error("GetMAPIProperty: Could not retrieve IMessage interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   434
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   435
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   436
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   437
                // Set the IMAPIProp interface GUID that we pass to retrieve the IMAPIProp Interface.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   438
                Guid guidIMAPIProp = new Guid(Mapi.MAPIInterfaceIds.IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   439
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   440
                // Try to retrieve the IMAPIProp interface
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   441
                if ((Marshal.QueryInterface(IMAPIObject, ref guidIMAPIProp, out IMAPIProp) != Mapi.HResult.S_OK) ||
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   442
                    (IMAPIProp == IntPtr.Zero))
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   443
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   444
                    Log.Error("GetMAPIProperty: Could not retrieve IMAPIProp interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   445
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   446
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   447
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   448
                // Try to get the property
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   449
                NativeMethods.HrGetOneProp(IMAPIProp, mapiProperty.Tag, out ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   450
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   451
                if (ptrPropValue == IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   452
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   453
                    Log.Error("GetMAPIProperty: Could not retrieve pointer to property value. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   454
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   455
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   456
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   457
                // Get the SPropValue structure
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   458
                sPropValue = (SPropValue)Marshal.PtrToStructure(ptrPropValue, typeof(SPropValue));
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   459
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   460
                // Convert the retrieved value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   461
                propertyValue = Mapi.ConvertSPropValueToObject(mapiProperty, sPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   462
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   463
            catch (Exception ex)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   464
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   465
                propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   466
                Log.Error("GetMAPIProperty: Error occured. " + ex.ToString());
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   467
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   468
            finally
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   469
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   470
                // Free used memory structures
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   471
                if (ptrPropValue != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   472
                {
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   473
                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   474
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   475
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   476
                // Clean up all references to COM Objects
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   477
                if (IMAPIProp != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   478
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   479
                    Marshal.Release(IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   480
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   481
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   482
                if (IMAPIObject != IntPtr.Zero)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   483
                {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   484
                    Marshal.Release(IMAPIObject);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   485
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   486
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   487
                if (IUnknown != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   488
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   489
                    Marshal.Release(IUnknown);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   490
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   491
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   492
                NativeMethods.MAPIUninitialize();
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   493
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   494
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   495
            return propertyValue;
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   496
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   497
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   498
        /// <summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   499
        /// Gets a set of MAPI property values from an Outlook item.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   500
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   501
        /// <param name="mapiObject">The MAPIOBJECT property of the Outlook item to get the property values for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   502
        /// <param name="mapiProperties">The MAPI properties to get their values for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   503
        /// <param name="propertyValues">The retrieved values.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   504
        /// <returns>The error code returned by IMAPIProp::GetProps or 0 if no error occured.</returns>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   505
        internal static int GetMAPIProperties(object mapiObject, List<MapiProperty.MapiProp> mapiProperties, out MapiPropertyValueDictionary propertyValues)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   506
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   507
            int result = (int)Mapi.HResult.S_FALSE;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   508
            propertyValues = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   509
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   510
            // Get MAPI object from mail item
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   511
            if (mapiObject == null)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   512
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   513
                Log.Error("GetMAPIProperties: MAPI object is null. Property could not be set.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   514
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   515
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   516
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   517
            // Check if we actually have some properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   518
            int propertiesCount = mapiProperties.Count;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   519
            if (propertiesCount < 1)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   520
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   521
                Log.Error("GetMAPIProperties: No properties found.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   522
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   523
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   524
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   525
            // Pointer to IUnknown interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   526
            IntPtr IUnknown = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   527
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   528
            // Pointer to the MAPI properties array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   529
            IntPtr propTagArray = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   530
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   531
            // Pointer to the value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   532
            IntPtr valuePtr = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   533
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   534
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   535
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   536
                // Initialize MAPI
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   537
                NativeMethods.MAPIInitialize(IntPtr.Zero);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   538
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   539
                // Get the IUnknown interface from the MAPI object
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   540
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   541
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   542
                // Get the IMAPIProp interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   543
                Mapi.IMAPIProp IMAPIProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   544
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   545
                // Create the SPropValue structure
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   546
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   547
                int propValueSize = Marshal.SizeOf(sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   548
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   549
                // Allocate memory for the array of SPropValues to set
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   550
                propTagArray = Marshal.AllocHGlobal(propValueSize * propertiesCount);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   551
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   552
                // Create the property values array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   553
                uint[] propertyTags = new uint[propertiesCount + 1];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   554
                propertyTags[0] = (uint)propertiesCount;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   555
                for (int i = 0; i < propertiesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   556
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   557
                    propertyTags[i + 1] = (uint)mapiProperties[i].Tag;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   558
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   559
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   560
                // Get properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   561
                result = IMAPIProp.GetProps(propertyTags, Mapi.MAPI_UNICODE, out uint valuesCount, out IntPtr propArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   562
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   563
                // Convert the retrieved values
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   564
                object[] values = new object[valuesCount];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   565
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   566
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   567
                    sPropValue = (SPropValue)Marshal.PtrToStructure((propArray + (i * propValueSize)), typeof(SPropValue));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   568
                    values[i] = Mapi.ConvertSPropValueToObject(mapiProperties[i], sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   569
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   570
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   571
                // Check if returned values match properties count
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   572
                if (propertiesCount != valuesCount)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   573
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   574
                    Log.Error("GetMAPIProperties: Properties count doesn't match values count.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   575
                    return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   576
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   577
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   578
                // Create return dictionary
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   579
                propertyValues = new MapiPropertyValueDictionary();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   580
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   581
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   582
                    propertyValues.Add(mapiProperties[i], values[i]);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   583
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   584
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   585
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   586
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   587
                Log.Error("SetMAPIProperties: Error occured. " + ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   588
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   589
            finally
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   590
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   591
                if (IUnknown != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   592
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   593
                    Marshal.Release(IUnknown);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   594
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   595
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   596
                if (propTagArray != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   597
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   598
                    Marshal.FreeHGlobal(propTagArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   599
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   600
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   601
                if (valuePtr != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   602
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   603
                    Marshal.FreeHGlobal(valuePtr);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   604
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   605
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   606
                NativeMethods.MAPIUninitialize();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   607
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   608
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   609
            return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   610
        }
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   611
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   612
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   613
        /// Sets the given MAPI properties on the Outlook mail item.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   614
        /// Note: the caller has to make sure that the count of MAPI properties
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   615
        /// and respective values matches and that the given values match the
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   616
        /// required data type for each MAPI property.
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   617
        /// Do not call this method from a background thread!
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   618
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   619
        /// <param name="omi">The Outlook mail item to set its properties.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   620
        /// <param name="mapiProperties">The MAPI properties to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   621
        /// <param name="values">The values to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   622
        /// <returns>True if the method succeeds, otherwise false.</returns>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   623
        public static bool SetMAPIProperties(Outlook.MailItem omi, MapiProperty.MapiProp[] mapiProperties, object[] values)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   624
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   625
            // The return status of this method
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   626
            bool success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   627
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   628
            // Pointer to IUnknown interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   629
            IntPtr IUnknown = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   630
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   631
            // Pointer to the MAPI properties array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   632
            IntPtr propArray = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   633
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   634
            // Pointer to the value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   635
            IntPtr valuePtr = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   636
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   637
            // Get MAPI object from mail item
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   638
            object mapiObject = omi?.MAPIOBJECT;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   639
            if (mapiObject == null)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   640
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   641
                Log.Error("SetMAPIProperties: MAPI object is null. Property could not be set.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   642
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   643
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   644
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   645
            // Make sure the properties count matches the values count
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   646
            int propCount = mapiProperties.Length;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   647
            if (propCount != values.Length)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   648
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   649
                Log.Error("SetMAPIProperties: Mismatch between tag count and value count.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   650
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   651
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   652
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   653
            try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   654
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   655
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   656
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   657
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   658
                // Get the IUnknown interface from the MAPI object
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   659
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   660
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   661
                // Get the IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   662
                Mapi.IMAPIProp IMAPIProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   663
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   664
                // Create the SPropValue structure
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   665
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   666
                var propValueSize = Marshal.SizeOf(sPropValue);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   667
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   668
                // Allocate memory for the array of SPropValues to set
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   669
                propArray = Marshal.AllocHGlobal(propValueSize * propCount);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   670
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   671
                // Create the property values array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   672
                for (int i = 0; i < propCount; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   673
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   674
                    // Get the current property/value pair
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   675
                    MapiProperty.MapiProp mapiProperty = mapiProperties[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   676
                    uint tag = mapiProperty.Tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   677
                    object value = values[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   678
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   679
                    // Set the property value's property tag
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   680
                    sPropValue.PropTag = (uint)tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   681
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   682
                    // Set the property value's value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   683
                    switch (mapiProperty.DataType)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   684
                    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   685
                        case MapiProperty.MapiDataType.PtypBoolean:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   686
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   687
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   688
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   689
                                    sPropValue.Value.b = (ushort)Convert.ToInt16((bool)value);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   690
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   691
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   692
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   693
                                    throw new Exception(string.Format("Error converting to Boolean. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   694
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   695
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   696
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   697
                        case MapiProperty.MapiDataType.PtypString:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   698
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   699
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   700
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   701
                                    valuePtr = Marshal.StringToHGlobalUni(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   702
                                    sPropValue.Value.lpszW = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   703
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   704
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   705
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   706
                                    throw new Exception(string.Format("Error converting to String. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   707
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   708
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   709
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   710
                        case MapiProperty.MapiDataType.PtypString8:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   711
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   712
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   713
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   714
                                    valuePtr = Marshal.StringToHGlobalAnsi(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   715
                                    sPropValue.Value.lpszA = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   716
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   717
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   718
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   719
                                    throw new Exception(string.Format("Error converting to String8. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   720
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   721
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   722
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   723
                        case MapiProperty.MapiDataType.PtypInteger16:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   724
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   725
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   726
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   727
                                    sPropValue.Value.i = (short)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   728
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   729
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   730
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   731
                                    throw new Exception(string.Format("Error converting to Short. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   732
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   733
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   734
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   735
                        case MapiProperty.MapiDataType.PtypInteger32:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   736
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   737
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   738
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   739
                                    sPropValue.Value.l = (int)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   740
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   741
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   742
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   743
                                    throw new Exception(string.Format("Error converting to Integer. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   744
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   745
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   746
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   747
                        case MapiProperty.MapiDataType.PtypFloating32:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   748
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   749
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   750
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   751
                                    sPropValue.Value.flt = (float)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   752
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   753
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   754
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   755
                                    throw new Exception(string.Format("Error converting to Float. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   756
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   757
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   758
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   759
                        case MapiProperty.MapiDataType.PtypFloating64:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   760
                        case MapiProperty.MapiDataType.PtypFloatingTime:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   761
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   762
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   763
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   764
                                    sPropValue.Value.at = (double)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   765
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   766
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   767
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   768
                                    throw new Exception(string.Format("Error converting to Double. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   769
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   770
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   771
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   772
                        case MapiProperty.MapiDataType.PtypInteger64:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   773
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   774
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   775
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   776
                                    sPropValue.Value.li = (ulong)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   777
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   778
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   779
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   780
                                    throw new Exception(string.Format("Error converting to Ulong. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   781
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   782
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   783
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   784
                        case MapiProperty.MapiDataType.PtypGuid:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   785
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   786
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   787
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   788
                                    IntPtr guidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(value));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   789
                                    Marshal.StructureToPtr((Guid)value, guidPtr, false);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   790
                                    sPropValue.Value.lpguid = guidPtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   791
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   792
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   793
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   794
                                    throw new Exception(string.Format("Error converting to Guid. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   795
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   796
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   797
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   798
                        case MapiProperty.MapiDataType.PtypBinary:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   799
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   800
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   801
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   802
                                    sPropValue.Value.bin = (Mapi.SRowSet)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   803
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   804
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   805
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   806
                                    throw new Exception(string.Format("Error converting to Binary. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   807
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   808
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   809
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   810
                        default:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   811
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   812
                                throw new Exception(string.Format("Error creating SPropValue. Data type {0} not supported.", Enum.GetName(typeof(MapiProperty.MapiDataType), mapiProperty.DataType)));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   813
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   814
                    }
2370
38dc1da79cf5 Set sender for mirror items
Thomas
parents: 2368
diff changeset
   815
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   816
                    Marshal.StructureToPtr(sPropValue, (IntPtr)((uint)propArray + (propValueSize * i)), false);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   817
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   818
                    if (valuePtr != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   819
                    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   820
                        Marshal.FreeHGlobal(valuePtr);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   821
                    }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   822
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   823
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   824
                // Set properties and save
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   825
                IntPtr problems = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   826
                if (IMAPIProp.SetProps((uint)propCount, propArray, problems) == Mapi.HResult.S_OK)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   827
                {
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   828
                    success = (IMAPIProp.SaveChanges((uint)Mapi.SaveOption.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   829
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   830
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   831
            catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   832
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   833
                Log.Error("SetMAPIProperties: Error occured. " + ex.ToString());
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   834
                success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   835
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   836
            finally
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   837
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   838
                if (IUnknown != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   839
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   840
                    Marshal.Release(IUnknown);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   841
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   842
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   843
                if (propArray != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   844
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   845
                    Marshal.FreeHGlobal(propArray);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   846
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   847
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   848
                if (valuePtr != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   849
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   850
                    Marshal.FreeHGlobal(valuePtr);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   851
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   852
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   853
                NativeMethods.MAPIUninitialize();
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   854
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   855
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   856
            return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   857
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   858
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   859
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   860
        /// Sets the given MAPI property on the Outlook mail item.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   861
        /// Note: the caller has to make sure that the given value matches the
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   862
        /// required data type for the MAPI property.
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   863
        /// Do not call this method from a background thread!
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   864
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   865
        /// <param name="omi">The Outlook mail item to set the property for.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   866
        /// <param name="mapiProperties">The MAPI property to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   867
        /// <param name="values">The value to set.</param>
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   868
        /// <param name="useSetProps">Whether to use the IMAPIProp.SetProps method (instead of HrSetOneProp).</param>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   869
        /// <returns>True if the method succeeds, otherwise false.</returns>
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   870
        public static bool SetMAPIProperty(Outlook.MailItem omi,
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   871
                                           MapiProperty.MapiProp mapiProperty,
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   872
                                           object value,
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   873
                                           bool useSetProps = false)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   874
        {
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   875
            if (useSetProps)
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   876
            {
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   877
                return Mapi.SetMAPIProperties(omi, new MapiProperty.MapiProp[] { mapiProperty }, new object[] { value });
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   878
            }
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   879
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   880
            // The return status of this method
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   881
            bool success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   882
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   883
            // Pointer to IUnknown interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   884
            IntPtr IUnknown = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   885
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   886
            // Pointer to IMessage interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   887
            IntPtr IMessage = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   888
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   889
            // Pointer to IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   890
            IntPtr IMAPIProp = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   891
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   892
            // Structure that will hold the property value
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   893
            Mapi.SPropValue sPropValue;
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   894
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   895
            // A pointer that points to the SPropValue structure 
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   896
            IntPtr ptrPropValue = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   897
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   898
            // Pointer to the value
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   899
            IntPtr valuePtr = IntPtr.Zero;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   900
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   901
            // Get MAPI object from mail item
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   902
            object mapiObject = omi?.MAPIOBJECT;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   903
            if (mapiObject == null)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   904
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   905
                Log.Error("SetMAPIProperty: MAPI object is null. Property could not be set.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   906
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   907
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   908
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   909
            try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   910
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   911
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   912
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   913
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   914
                // Get the IUnknown interface from the MAPI object
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   915
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   916
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   917
                // Set the IMessage interface GUID that we pass to retrieve the IMessage interface.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   918
                Guid guidIMessage = new Guid(Mapi.MAPIInterfaceIds.IMessage);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   919
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   920
                // Try to retrieve the IMessage interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   921
                if (Marshal.QueryInterface(IUnknown, ref guidIMessage, out IMessage) != Mapi.HResult.S_OK)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   922
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   923
                    Log.Error("SetMAPIProperty: Could not retrieve IMessage interface. Property could not be set.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   924
                    return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   925
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   926
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   927
                // Set the IMAPIProp interface GUID that we pass to retrieve the IMAPIProp Interface.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   928
                Guid guidIMAPIProp = new Guid(Mapi.MAPIInterfaceIds.IMAPIProp);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   929
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   930
                // Try to retrieve the IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   931
                if ((Marshal.QueryInterface(IMessage, ref guidIMAPIProp, out IMAPIProp) != Mapi.HResult.S_OK) ||
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   932
                    (IMAPIProp == IntPtr.Zero))
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   933
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   934
                    Log.Error("SetMAPIProperty: Could not retrieve IMAPIProp interface. Property could not be set.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   935
                    return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   936
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   937
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   938
                // Create the SPropValue structure
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   939
                sPropValue = new Mapi.SPropValue
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   940
                {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   941
                    PropTag = (uint)mapiProperty.Tag
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   942
                };
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   943
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   944
                // Set the property value's value
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   945
                switch (mapiProperty.DataType)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   946
                {
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   947
                    case MapiProperty.MapiDataType.PtypBoolean:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   948
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   949
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   950
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   951
                                sPropValue.Value.b = (ushort)Convert.ToInt16((bool)value);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   952
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   953
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   954
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   955
                                throw new Exception(string.Format("Error converting to Boolean. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   956
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   957
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   958
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   959
                    case MapiProperty.MapiDataType.PtypString:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   960
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   961
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   962
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   963
                                valuePtr = Marshal.StringToHGlobalUni(value as string);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   964
                                sPropValue.Value.lpszW = valuePtr;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   965
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   966
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   967
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   968
                                throw new Exception(string.Format("Error converting to String. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   969
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   970
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   971
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   972
                    case MapiProperty.MapiDataType.PtypString8:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   973
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   974
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   975
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   976
                                valuePtr = Marshal.StringToHGlobalAnsi(value as string);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   977
                                sPropValue.Value.lpszA = valuePtr;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   978
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   979
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   980
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   981
                                throw new Exception(string.Format("Error converting to String8. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   982
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   983
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   984
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   985
                    case MapiProperty.MapiDataType.PtypInteger16:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   986
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   987
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   988
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   989
                                sPropValue.Value.i = (short)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   990
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   991
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   992
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   993
                                throw new Exception(string.Format("Error converting to Short. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   994
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   995
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   996
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   997
                    case MapiProperty.MapiDataType.PtypInteger32:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   998
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
   999
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1000
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1001
                                sPropValue.Value.l = (int)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1002
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1003
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1004
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1005
                                throw new Exception(string.Format("Error converting to Integer. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1006
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1007
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1008
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1009
                    case MapiProperty.MapiDataType.PtypFloating32:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1010
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1011
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1012
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1013
                                sPropValue.Value.flt = (float)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1014
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1015
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1016
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1017
                                throw new Exception(string.Format("Error converting to Float. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1018
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1019
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1020
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1021
                    case MapiProperty.MapiDataType.PtypFloating64:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1022
                    case MapiProperty.MapiDataType.PtypFloatingTime:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1023
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1024
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1025
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1026
                                sPropValue.Value.at = (double)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1027
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1028
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1029
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1030
                                throw new Exception(string.Format("Error converting to Double. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1031
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1032
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1033
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1034
                    case MapiProperty.MapiDataType.PtypInteger64:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1035
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1036
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1037
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1038
                                sPropValue.Value.li = (ulong)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1039
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1040
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1041
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1042
                                throw new Exception(string.Format("Error converting to Ulong. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1043
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1044
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1045
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1046
                    case MapiProperty.MapiDataType.PtypGuid:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1047
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1048
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1049
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1050
                                IntPtr guidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(value));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1051
                                Marshal.StructureToPtr((Guid)value, guidPtr, false);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1052
                                sPropValue.Value.lpguid = guidPtr;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1053
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1054
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1055
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1056
                                throw new Exception(string.Format("Error converting to Guid. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1057
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1058
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1059
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1060
                    case MapiProperty.MapiDataType.PtypBinary:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1061
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1062
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1063
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1064
                                sPropValue.Value.bin = (Mapi.SRowSet)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1065
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1066
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1067
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1068
                                throw new Exception(string.Format("Error converting to Binary. Property tag: {0}. Value: {1}. Exception: {2}.", mapiProperty.DaslName, value?.ToString(), ex.ToString()));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1069
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1070
                        }
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1071
                        break;
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1072
                    default:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1073
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1074
                            throw new Exception(string.Format("Error creating SPropValue. Data type {0} not supported.", Enum.GetName(typeof(MapiProperty.MapiDataType), mapiProperty.DataType)));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1075
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1076
                }
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1077
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1078
                // Get pointer to property value structure
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1079
                ptrPropValue = Marshal.AllocHGlobal(Marshal.SizeOf(sPropValue));
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1080
                Marshal.StructureToPtr(sPropValue, ptrPropValue, false);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1081
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1082
                // Try to set the property
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1083
                NativeMethods.HrSetOneProp(IMAPIProp, ptrPropValue);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1084
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1085
                // Save changes
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1086
                Mapi.IMAPIProp mapiProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
  1087
                success = (mapiProp.SaveChanges((uint)Mapi.SaveOption.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1088
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1089
            catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1090
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1091
                Log.Error("SetMAPIProperty: Error occured. " + ex.ToString());
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1092
                success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1093
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1094
            finally
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1095
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1096
                // Free used memory structures
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1097
                if (ptrPropValue != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1098
                {
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1099
                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1100
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1101
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1102
                // Clean up all references to COM Objects
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1103
                if (IMAPIProp != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1104
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1105
                    Marshal.Release(IMAPIProp);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1106
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1107
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1108
                if (IMessage != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1109
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1110
                    Marshal.Release(IMessage);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1111
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1112
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1113
                if (IUnknown != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1114
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1115
                    Marshal.Release(IUnknown);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1116
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1117
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1118
                NativeMethods.MAPIUninitialize();
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1119
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1120
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1121
            return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1122
        }
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1123
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1124
        /// <summary>
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
  1125
        /// Calls SaveChanges() with the given flag.
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1126
        /// </summary>
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1127
        /// <param name="omi">The Outlook mail item to save.</param>
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
  1128
        /// <param name="saveOption">The save flag to pass.</param>
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1129
        /// <returns>The status of this method.</returns>
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
  1130
        public static int Save(Outlook.MailItem omi, Mapi.SaveOption saveOption)
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1131
        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1132
            int status = (int)Mapi.HResult.S_FALSE;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1133
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1134
            // Pointer to IUnknown interface
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1135
            IntPtr IUnknown = IntPtr.Zero;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1136
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1137
            // A pointer that points to the SPropValue structure 
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1138
            IntPtr ptrPropValue = IntPtr.Zero;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1139
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1140
            // Get MAPI object from mail item
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1141
            object mapiObject = omi?.MAPIOBJECT;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1142
            if (mapiObject == null)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1143
            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1144
                Log.Error("SetMAPIProperty: MAPI object is null. Property could not be set.");
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1145
                return status;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1146
            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1147
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1148
            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1149
            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1150
                // Initialize MAPI
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1151
                NativeMethods.MAPIInitialize(IntPtr.Zero);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1152
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1153
                // Get the IUnknown interface from the MAPI object
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1154
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1155
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1156
                // Save changes
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1157
                Mapi.IMAPIProp mapiProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
  1158
                status = mapiProp.SaveChanges((uint)saveOption);
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1159
            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1160
            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1161
            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1162
                Log.Error("SetMAPIProperty: Error occured. " + ex.ToString());
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1163
                status = (int)Mapi.HResult.S_FALSE;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1164
            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1165
            finally
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1166
            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1167
                // Free used memory structures
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1168
                if (ptrPropValue != IntPtr.Zero)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1169
                {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1170
                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1171
                }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1172
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1173
                // Clean up all references to COM Objects
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1174
                if (IUnknown != IntPtr.Zero)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1175
                {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1176
                    Marshal.Release(IUnknown);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1177
                }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1178
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1179
                NativeMethods.MAPIUninitialize();
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1180
            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1181
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1182
            return status;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1183
        }
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1184
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1185
    }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1186
}