Mapi.cs
author Thomas
Fri, 18 Jan 2019 11:33:47 +0100
changeset 2550 80e3f982663e
parent 2548 b03230188759
child 2555 6334e58eb55e
permissions -rw-r--r--
Add methods to get IMAPITable properties
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>
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    17
        internal enum HResult : uint
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    18
        {
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    19
            S_FALSE                             = 0x00000001,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    20
            S_OK                                = 0x00000000,
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    21
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    22
            E_NOTIMPL                           = 0x80004001,
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    23
2548
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
    24
            MAPI_E_INTERFACE_NOT_SUPPORTED	    = 0x80004002,
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
    25
            MAPI_E_INTERFACE_NOT_SUPPORTED_2    = 0x80000004,
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    26
            MAPI_E_CALL_FAILED                  = 0x80004005,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    27
            MAPI_E_NOT_ENOUGH_MEMORY            = 0x8007000E,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    28
            MAPI_E_INVALID_PARAMETER            = 0x80000003,
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
    29
            MAPI_E_NO_ACCESS                    = 0x80070005,
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
    30
            MAPI_E_NO_ACCESS_2                  = 0x80000009,
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    31
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    32
            E_INVALIDARG                        = 0x80070057,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    33
            E_OUTOFMEMORY                       = 0x80000002,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    34
            E_UNEXPECTED                        = 0x8000FFFF,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    35
            E_FAIL                              = 0x80000008,
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    36
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    37
            MAPI_E_NO_SUPPORT                   = 0x80040000 | 0x102,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    38
            MAPI_E_BAD_CHARWIDTH                = 0x80040000 | 0x103,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    39
            MAPI_E_STRING_TOO_LONG              = 0x80040000 | 0x105,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    40
            MAPI_E_UNKNOWN_FLAGS                = 0x80040000 | 0x106,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    41
            MAPI_E_INVALID_ENTRYID              = 0x80040000 | 0x107,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    42
            MAPI_E_INVALID_OBJECT               = 0x80040000 | 0x108,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    43
            MAPI_E_OBJECT_CHANGED               = 0x80040000 | 0x109,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    44
            MAPI_E_OBJECT_DELETED               = 0x80040000 | 0x10A,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    45
            MAPI_E_BUSY                         = 0x80040000 | 0x10B,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    46
            MAPI_E_NOT_ENOUGH_DISK              = 0x80040000 | 0x10D,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    47
            MAPI_E_NOT_ENOUGH_RESOURCES         = 0x80040000 | 0x10E,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    48
            MAPI_E_NOT_FOUND                    = 0x80040000 | 0x10F,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    49
            MAPI_E_VERSION                      = 0x80040000 | 0x110,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    50
            MAPI_E_LOGON_FAILED                 = 0x80040000 | 0x111,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    51
            MAPI_E_SESSION_LIMIT                = 0x80040000 | 0x112,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    52
            MAPI_E_USER_CANCEL                  = 0x80040000 | 0x113,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    53
            MAPI_E_UNABLE_TO_ABORT              = 0x80040000 | 0x114,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    54
            MAPI_E_NETWORK_ERROR                = 0x80040000 | 0x115,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    55
            MAPI_E_DISK_ERROR                   = 0x80040000 | 0x116,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    56
            MAPI_E_TOO_COMPLEX                  = 0x80040000 | 0x117,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    57
            MAPI_E_BAD_COLUMN                   = 0x80040000 | 0x118,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    58
            MAPI_E_EXTENDED_ERROR               = 0x80040000 | 0x119,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    59
            MAPI_E_COMPUTED                     = 0x80040000 | 0x11A,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    60
            MAPI_E_CORRUPT_DATA                 = 0x80040000 | 0x11B,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    61
            MAPI_E_UNCONFIGURED                 = 0x80040000 | 0x11C,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    62
            MAPI_E_FAILONEPROVIDER              = 0x80040000 | 0x11D,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    63
            MAPI_E_UNKNOWN_CPID                 = 0x80040000 | 0x11E,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    64
            MAPI_E_UNKNOWN_LCID                 = 0x80040000 | 0x11F,
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    65
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    66
            MAPI_E_CORRUPT_STORE                = 0x80040000 | 0x600,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    67
            MAPI_E_NOT_IN_QUEUE                 = 0x80040000 | 0x601,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    68
            MAPI_E_NO_SUPPRESS                  = 0x80040000 | 0x602,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    69
            MAPI_E_COLLISION                    = 0x80040000 | 0x604,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    70
            MAPI_E_NOT_INITIALIZED              = 0x80040000 | 0x605,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    71
            MAPI_E_NON_STANDARD                 = 0x80040000 | 0x606,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    72
            MAPI_E_NO_RECIPIENTS                = 0x80040000 | 0x607,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    73
            MAPI_E_SUBMITTED                    = 0x80040000 | 0x608,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    74
            MAPI_E_HAS_FOLDERS                  = 0x80040000 | 0x609,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    75
            MAPI_E_HAS_MESSAGES                 = 0x80040000 | 0x60A,
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    76
            MAPI_E_FOLDER_CYCLE                 = 0x80040000 | 0x60B
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
    77
        }
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    78
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
        /// 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
    81
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    82
        internal static class MAPIInterfaceIds
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    83
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    84
            public const string IMAPISession        = "00020300-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    85
            public const string IMAPIProp           = "00020303-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    86
            public const string IMAPITable          = "00020301-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    87
            public const string IMAPIMsgStore       = "00020306-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    88
            public const string IMAPIFolder         = "0002030C-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    89
            public const string IMAPISpoolerService = "0002031E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    90
            public const string IMAPIStatus         = "0002031E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    91
            public const string IMessage            = "00020307-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    92
            public const string IAddrBook           = "00020309-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    93
            public const string IProfSect           = "00020304-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    94
            public const string IMAPIContainer      = "0002030B-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    95
            public const string IABContainer        = "0002030D-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    96
            public const string IMsgServiceAdmin    = "0002031D-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    97
            public const string IProfAdmin          = "0002031C-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    98
            public const string IMailUser           = "0002030A-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
    99
            public const string IDistList           = "0002030E-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   100
            public const string IAttachment         = "00020308-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   101
            public const string IMAPIControl        = "0002031B-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   102
            public const string IMAPILogonRemote    = "00020346-0000-0000-C000-000000000046";
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   103
            public const string IMAPIForm           = "00020327-0000-0000-C000-000000000046";
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   104
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   105
            public const string IID_IStorage        = "0000000B-0000-0000-C000-000000000046";
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   106
            public const string IID_IStream         = "0000000C-0000-0000-C000-000000000046";
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   107
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   108
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   109
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   110
        /// Save options for the IMAPIProp.SaveChanges method.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   111
        /// </summary>
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   112
        internal enum SaveOption
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   113
        {
2505
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   114
            KEEP_OPEN_READONLY = 0x00000001,
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   115
            KEEP_OPEN_READWRITE = 0x00000002,
8a26c367dfe8 Only hide messages if not on IMAP
Thomas
parents: 2501
diff changeset
   116
            FORCE_SAVE = 0x00000004
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   117
        }
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   118
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   119
        /// <summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   120
        /// Flag to indicate that IMAPIProps::GetProps should return unicode values.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   121
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   122
        private const uint MAPI_UNICODE = 0x80000000;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   123
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   124
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   125
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   126
        #region Interfaces
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   127
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   128
        /// 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
   129
        /// support properties implement this interface.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   130
        /// </summary>
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
            ComImport,
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   133
            ComVisible(false),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   134
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   135
            Guid(Mapi.MAPIInterfaceIds.IMAPIProp)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   136
        ]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   137
        internal interface IMAPIProp
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   138
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   139
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   140
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   141
            int GetLastError();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   142
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   143
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   144
            int SaveChanges(uint uFlags);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   145
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   146
            [PreserveSig]
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   147
            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
   148
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   149
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   150
            int GetPropList();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   151
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   152
            [PreserveSig]
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   153
            int OpenProperty(uint ulPropTag, ref Guid lpiid, uint ulInterfaceOptions, uint ulFlags, out IntPtr lppUnk);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   154
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   155
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   156
            int SetProps(uint values, IntPtr propArray, IntPtr problems);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   157
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   158
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   159
            int DeleteProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   160
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   161
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   162
            int CopyTo();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   163
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   164
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   165
            int CopyProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   166
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   167
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   168
            int GetNamesFromIDs();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   169
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   170
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   171
            int GetIDsFromNames();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   172
        }
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   173
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   174
        /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   175
        /// Provides a read-only view of a table. IMAPITable is used by clients and service providers to manipulate the way a table appears. 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   176
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   177
        [Guid("00020301-0000-0000-c000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   178
        public interface IMAPITable
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   179
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   180
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   181
            /// Returns a MAPIERROR structure containing information about the previous error on the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   182
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   183
            /// <param name="hResult">HRESULT containing the error generated in the previous method call.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   184
            /// <param name="ulFlags">Bitmask of flags that controls the type of the returned strings. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   185
            /// <param name="lppMAPIError">Pointer to a pointer to the returned MAPIERROR structure containing version, component, and context information for the error.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   186
            /// <returns>S_OK, if the call succeeded and has returned the expected value or values; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   187
            int GetLastError(int hResult, uint ulFlags, out IntPtr lppMAPIError);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   188
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   189
            /// Registers an advise sink object to receive notification of specified events affecting the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   190
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   191
            /// <param name="ulEventMask">Value indicating the type of event that will generate the notification.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   192
            /// <param name="lpAdviseSink">Pointer to an advise sink object to receive the subsequent notifications. This advise sink object must have been already allocated.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   193
            /// <param name="lpulConnection">Pointer to a nonzero value that represents the successful notification registration.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   194
            /// <returns>S_OK, if the notification registration successfully completed; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   195
            int Advise(uint ulEventMask, IntPtr lpAdviseSink, IntPtr lpulConnection);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   196
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   197
            /// Cancels the sending of notifications previously set up with a call to the IMAPITable::Advise method.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   198
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   199
            /// <param name="ulConnection">The number of the registration connection returned by a call to IMAPITable::Advise.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   200
            /// <returns>S_OK, if the call succeeded; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   201
            int Unadvise(uint ulConnection);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   202
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   203
            /// Returns the table's status and type.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   204
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   205
            /// <param name="lpulTableStatus">Pointer to a value indicating the status of the table.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   206
            /// <param name="lpulTableType">Pointer to a value that indicates the table's type.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   207
            /// <returns>S_OK, if the table's status was successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   208
            int GetStatus(IntPtr lpulTableStatus, IntPtr lpulTableType);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   209
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   210
            /// Defines the particular properties and order of properties to appear as columns in the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   211
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   212
            /// <param name="lpPropTagArray">Pointer to an array of property tags identifying properties to be included as columns in the table. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   213
            /// <param name="ulFlags">Bitmask of flags that controls the return of an asynchronous call to SetColumns.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   214
            /// <returns>S_OK, if the column setting operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   215
            int SetColumns([MarshalAs(UnmanagedType.LPArray)] uint[] lpPropTagArray, uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   216
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   217
            /// Returns a list of columns for the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   218
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   219
            /// <param name="ulFlags">Bitmask of flags that indicates which column set should be returned.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   220
            /// <param name="lpPropTagArray">Pointer to an SPropTagArray structure containing the property tags for the column set.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   221
            /// <returns>S_OK, if the column set was successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   222
            int QueryColumns(uint ulFlags, IntPtr lpPropTagArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   223
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   224
            /// Returns the total number of rows in the table. 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   225
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   226
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   227
            /// <param name="lpulCount">Pointer to the number of rows in the table.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   228
            /// <returns>S_OK, if the row count was successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   229
            int GetRowCount(uint ulFlags, out uint lpulCount);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   230
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   231
            /// Moves the cursor to a specific position in the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   232
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   233
            /// <param name="bkOrigin">The bookmark identifying the starting position for the seek operation.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   234
            /// <param name="lRowCount">The signed count of the number of rows to move, starting from the bookmark identified by the bkOrigin parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   235
            /// <param name="lplRowsSought">If lRowCount is a valid pointer on input, lplRowsSought points to the number of rows that were processed in the seek operation, the sign of which indicates the direction of search, forward or backward. If lRowCount is negative, then lplRowsSought is negative.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   236
            /// <returns>S_OK, if the seek operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   237
            int SeekRow(int bkOrigin, int lRowCount, out IntPtr lplRowsSought);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   238
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   239
            /// Moves the cursor to an approximate fractional position in the table. 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   240
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   241
            /// <param name="ulNumerator">The numerator of the fraction representing the table position</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   242
            /// <param name="ulDenominator">The denominator of the fraction representing the table position</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   243
            /// <returns>S_OK, if the seek operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   244
            int SeekRowApprox(uint ulNumerator, uint ulDenominator);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   245
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   246
            /// Retrieves the current table row position of the cursor, based on a fractional value.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   247
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   248
            /// <param name="lpulRow">Pointer to the number of the current row.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   249
            /// <param name="lpulNumerator">Pointer to the numerator for the fraction identifying the table position.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   250
            /// <param name="lpulDenominator">Pointer to the denominator for the fraction identifying the table position.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   251
            /// <returns>S_OK, if the method returned valid values in lpulRow, lpulNumerator, and lpulDenominator; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   252
            int QueryPosition(IntPtr lpulRow, IntPtr lpulNumerator, IntPtr lpulDenominator);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   253
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   254
            /// Finds the next row in a table that matches specific search criteria and moves the cursor to that row.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   255
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   256
            /// <param name="lpRestriction">A pointer to an SRestriction structure that describes the search criteria.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   257
            /// <param name="BkOrigin">A bookmark identifying the row where FindRow should begin its search.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   258
            /// <param name="ulFlags">A bitmask of flags that controls the direction of the search.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   259
            /// <returns>S_OK, if the find operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   260
            int FindRow(out IntPtr lpRestriction, uint BkOrigin, uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   261
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   262
            /// Applies a filter to a table, reducing the row set to only those rows matching the specified criteria.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   263
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   264
            /// <param name="lpRestriction">Pointer to an SRestriction structure defining the conditions of the filter. Passing NULL in the lpRestriction parameter removes the current filter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   265
            /// <param name="ulFlags">Bitmask of flags that controls the timing of the restriction operation.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   266
            /// <returns>S_OK, if the filter was successfully applied; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   267
            int Restrict(out IntPtr lpRestriction, uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   268
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   269
            /// Creates a bookmark at the table's current position.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   270
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   271
            /// <param name="lpbkPosition">Pointer to the returned 32-bit bookmark value. This bookmark can later be passed in a call to the IMAPITable::SeekRow method</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   272
            /// <returns>S_OK, if the call succeeded and has returned the expected value or values; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   273
            int CreateBookmark(IntPtr lpbkPosition);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   274
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   275
            /// Releases the memory associated with a bookmark.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   276
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   277
            /// <param name="bkPosition">The bookmark to be freed, created by calling the IMAPITable::CreateBookmark method.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   278
            /// <returns>S_OK, if the bookmark was successfully freed; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   279
            int FreeBookmark(IntPtr bkPosition);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   280
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   281
            /// Orders the rows of the table, depending on sort criteria.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   282
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   283
            /// <param name="lpSortCriteria">Pointer to an SSortOrderSet structure that contains the sort criteria to apply.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   284
            /// <param name="ulFlags">Bitmask of flags that controls the timing of the IMAPITable::SortTable operation.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   285
            /// <returns>S_OK, if the sort operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   286
            int SortTable(IntPtr lpSortCriteria, int ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   287
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   288
            /// Retrieves the current sort order for a table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   289
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   290
            /// <param name="lppSortCriteria">Pointer to a pointer to the SSortOrderSet structure holding the current sort order.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   291
            /// <returns>S_OK, if the current sort order was successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   292
            int QuerySortOrder(IntPtr lppSortCriteria);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   293
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   294
            /// Returns one or more rows from a table, beginning at the current cursor position.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   295
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   296
            /// <param name="lRowCount">Maximum number of rows to be returned.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   297
            /// <param name="ulFlags">Bitmask of flags that control how rows are returned.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   298
            /// <param name="lppRows">Pointer to a pointer to an SRowSet structure holding the table rows.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   299
            /// <returns>S_OK, if the rows were successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   300
            int QueryRows(int lRowCount, uint ulFlags, out IntPtr lppRows);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   301
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   302
            /// Stops any asynchronous operations currently in progress for the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   303
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   304
            /// <returns>S_OK, if one or more asynchronous operations have been stopped; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   305
            int Abort();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   306
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   307
            /// Expands a collapsed table category, adding the leaf or lower-level heading rows belonging to the category to the table view.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   308
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   309
            /// <param name="cbInstanceKey">The count of bytes in the PR_INSTANCE_KEY property pointed to by the pbInstanceKey parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   310
            /// <param name="pbInstanceKey">A pointer to the PR_INSTANCE_KEY property that identifies the heading row for the category.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   311
            /// <param name="ulRowCount">The maximum number of rows to return in the lppRows parameter. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   312
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   313
            /// <param name="lppRows">A pointer to an SRowSet structure receiving the first (up to ulRowCount) rows that have been inserted into the table view as a result of the expansion.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   314
            /// <param name="lpulMoreRows">A pointer to the total number of rows that were added to the table view.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   315
            /// <returns>S_OK, if the category was expanded successfully; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   316
            int ExpandRow(uint cbInstanceKey, IntPtr pbInstanceKey, uint ulRowCount, uint ulFlags, IntPtr lppRows, IntPtr lpulMoreRows);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   317
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   318
            /// Collapses an expanded table category, removing any lower-level headings and leaf rows belonging to the category from the table view.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   319
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   320
            /// <param name="cbInstanceKey">The count of bytes in the PR_INSTANCE_KEY property pointed to by the pbInstanceKey parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   321
            /// <param name="pbInstanceKey">A pointer to the PR_INSTANCE_KEY property that identifies the heading row for the category. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   322
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   323
            /// <param name="lpulRowCount">A pointer to the total number of rows that are being removed from the table view.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   324
            /// <returns>S_OK, if the collapse operation has succeeded; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   325
            int CollapseRow(uint cbInstanceKey, IntPtr pbInstanceKey, uint ulFlags, IntPtr lpulRowCount);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   326
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   327
            /// Suspends processing until one or more asynchronous operations in progress on the table have completed.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   328
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   329
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   330
            /// <param name="ulTimeout">Maximum number of milliseconds to wait for the asynchronous operation or operations to complete.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   331
            /// <param name="lpulTableStatus">On input, either a valid pointer or NULL. On output, if lpulTableStatus is a valid pointer, it points to the most recent status of the table. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   332
            /// <returns>S_OK, if the wait operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   333
            int WaitForCompletion(uint ulFlags, uint ulTimeout, IntPtr lpulTableStatus);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   334
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   335
            /// Returns the data that is needed to rebuild the current collapsed or expanded state of a categorized table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   336
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   337
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   338
            /// <param name="cbInstanceKey">The count of bytes in the instance key pointed to by the lpbInstanceKey parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   339
            /// <param name="lpbInstanceKey">A pointer to the PR_INSTANCE_KEY property of the row at which the current collapsed or expanded state should be rebuilt. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   340
            /// <param name="lpcbCollapseState">A pointer to the count of structures pointed to by the lppbCollapseState parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   341
            /// <param name="lppbCollapseState">A pointer to a pointer to structures that contain data that describes the current table view.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   342
            /// <returns>S_OK, if the state for the categorized table was successfully saved; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   343
            int GetCollapseState(uint ulFlags, uint cbInstanceKey, IntPtr lpbInstanceKey, IntPtr lpcbCollapseState, IntPtr lppbCollapseState);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   344
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   345
            /// Rebuilds the current expanded or collapsed state of a categorized table using data that was saved by a prior call to the IMAPITable::GetCollapseState method.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   346
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   347
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   348
            /// <param name="cbCollapseState">Count of bytes in the structure pointed to by the pbCollapseState parameter.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   349
            /// <param name="pbCollapseState">Pointer to the structures containing the data needed to rebuild the table view.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   350
            /// <param name="lpbkLocation">Pointer to a bookmark identifying the row in the table at which the collapsed or expanded state should be rebuilt. </param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   351
            /// <returns>S_OK, if the state of the categorized table was successfully rebuilt; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   352
            int SetCollapseState(uint ulFlags, uint cbCollapseState, IntPtr pbCollapseState, IntPtr lpbkLocation);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   353
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   354
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   355
        /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   356
        /// The IMessage interface defines methods and properties used to manage messages.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   357
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   358
        [ComImport()]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   359
        [Guid("00020307-0000-0000-C000-000000000046")]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   360
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   361
        interface IMessage
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   362
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   363
            int GetLastError(int hResult, uint ulFlags, out IntPtr lppMAPIError);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   364
            int SaveChanges(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   365
            int GetProps(IntPtr lpPropTagArray, uint ulFlags, out uint lpcValues, out IntPtr lppPropArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   366
            int GetPropList(uint ulFlags, out IntPtr lppPropTagArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   367
            [return: MarshalAs(UnmanagedType.I4)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   368
            [PreserveSig]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   369
            int OpenProperty(uint ulPropTag, ref Guid lpiid, uint ulInterfaceOptions, uint ulFlags, out IntPtr lppUnk);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   370
            int SetProps(uint cValues, IntPtr lpPropArray, out IntPtr lppProblems);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   371
            int DeleteProps(IntPtr lpPropTagArray, out IntPtr lppProblems);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   372
            int CopyTo(uint ciidExclude, ref Guid rgiidExclude, IntPtr lpExcludeProps, uint ulUIParam,
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   373
            IntPtr lpProgress, ref Guid lpInterface, IntPtr lpDestObj, uint ulFlags, out IntPtr lppProblems);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   374
            int CopyProps(IntPtr lpIncludeProps, uint ulUIParam, IntPtr lpProgress, ref Guid lpInterface,
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   375
            IntPtr lpDestObj, uint ulFlags, out IntPtr lppProblems);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   376
            int GetNamesFromIDs(out IntPtr lppPropTags, ref Guid lpPropSetGuid, uint ulFlags,
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   377
            out uint lpcPropNames, out IntPtr lpppPropNames);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   378
            int GetIDsFromNames(uint cPropNames, ref IntPtr lppPropNames, uint ulFlags, out IntPtr lppPropTags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   379
            int GetAttachmentTable(uint ulFlags, out IMAPITable lppTable);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   380
            //int OpenAttach(uint ulAttachmentNum, ref Guid lpInterface, uint ulFlags, out IAttach lppAttach);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   381
            int CreateAttach();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   382
            int DeleteAttach();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   383
            int GetRecipientTable(uint ulFlags, out IMAPITable lppTable);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   384
            int ModifyRecipients();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   385
            int SubmitMessage(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   386
            int SetReadFlag(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   387
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   388
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   389
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   390
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   391
        #region Structures
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   392
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   393
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   394
        /// The SPropValue structure describes a MAPI property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   395
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   396
        public struct SPropValue
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   397
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   398
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   399
            /// 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
   400
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   401
            public uint PropTag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   402
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   403
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   404
            /// Reserved for MAPI; do not use.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   405
            /// </summary>
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   406
#pragma warning disable 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   407
            public uint DwAlignPad;
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   408
#pragma warning restore 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   409
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   410
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   411
            /// 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
   412
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   413
            public PV Value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   414
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   415
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   416
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   417
        /// Union of data values for the SPropValue.value property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   418
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   419
        [StructLayout(LayoutKind.Explicit, Size = 8)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   420
        public struct PV
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   421
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   422
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   423
            public short i;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   424
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   425
            public int l;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   426
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   427
            public uint ul;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   428
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   429
            public float flt;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   430
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   431
            public double dbl;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   432
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   433
            public ushort b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   434
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   435
            public double at;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   436
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   437
            public IntPtr lpszA;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   438
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   439
            public IntPtr lpszW;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   440
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   441
            public IntPtr lpguid;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   442
            /*[FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   443
            public IntPtr bin;*/
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   444
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   445
            public ulong li;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   446
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   447
            public SRowSet bin;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   448
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   449
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   450
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   451
        /// Describes a row from a table that contains selected properties for a specific object.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   452
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   453
        [StructLayout(LayoutKind.Sequential)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   454
        public struct SRow
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   455
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   456
            public uint ulAdrEntryPad;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   457
            public uint cValues;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   458
            public IntPtr lpProps;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   459
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   460
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   461
        /// <summary>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   462
        /// 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
   463
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   464
        [StructLayout(LayoutKind.Sequential)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   465
        public struct SRowSet
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   466
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   467
            public uint cRows;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   468
            public IntPtr aRow; // pSRow
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   469
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   470
            public byte[] AsBytes
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   471
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   472
                get
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   473
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   474
                    byte[] b = new byte[this.cRows];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   475
                    for (int i = 0; i < this.cRows; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   476
                        b[i] = Marshal.ReadByte(aRow, i);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   477
                    return b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   478
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   479
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   480
        }
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   481
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   482
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   483
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   484
        #region Methods
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   485
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   486
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   487
        /// Retrieves a managed object from the SPropValue structure that is returned by GetProps etc.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   488
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   489
        /// <param name="mapiProperty">The MAPI property the value was retrieved for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   490
        /// <param name="sPropValue">The value to convert.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   491
        /// <returns>The converted object or null if an error occured.</returns>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   492
        public static object ConvertSPropValueToObject(MapiProperty.MapiProp mapiProperty, SPropValue sPropValue)
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   493
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   494
            object propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   495
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   496
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   497
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   498
                switch (mapiProperty.DataType)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   499
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   500
                    case MapiProperty.MapiDataType.PtypBoolean:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   501
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   502
                            propertyValue = Convert.ToBoolean(sPropValue.Value.b);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   503
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   504
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   505
                    case MapiProperty.MapiDataType.PtypString:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   506
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   507
                            if ((((uint)sPropValue.Value.lpszW).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   508
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   509
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   510
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   511
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   512
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   513
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   514
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszW);
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
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   518
                    case MapiProperty.MapiDataType.PtypString8:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   519
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   520
                            if ((((uint)sPropValue.Value.lpszA).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   521
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   522
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   523
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string8: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   524
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   525
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   526
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   527
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszA);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   528
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   529
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   530
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   531
                    case MapiProperty.MapiDataType.PtypInteger16:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   532
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   533
                            propertyValue = sPropValue.Value.i;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   534
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   535
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   536
                    case MapiProperty.MapiDataType.PtypInteger32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   537
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   538
                            propertyValue = sPropValue.Value.l;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   539
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   540
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   541
                    case MapiProperty.MapiDataType.PtypFloating32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   542
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   543
                            propertyValue = sPropValue.Value.flt;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   544
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   545
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   546
                    case MapiProperty.MapiDataType.PtypFloating64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   547
                    case MapiProperty.MapiDataType.PtypFloatingTime:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   548
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   549
                            propertyValue = sPropValue.Value.at;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   550
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   551
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   552
                    case MapiProperty.MapiDataType.PtypInteger64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   553
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   554
                            propertyValue = sPropValue.Value.li;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   555
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   556
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   557
                    case MapiProperty.MapiDataType.PtypGuid:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   558
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   559
                            propertyValue = Marshal.PtrToStructure(sPropValue.Value.lpguid, typeof(Guid));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   560
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   561
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   562
                    case MapiProperty.MapiDataType.PtypBinary:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   563
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   564
                            propertyValue = sPropValue.Value.bin;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   565
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   566
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   567
                    default:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   568
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   569
                            propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   570
                            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
   571
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   572
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   573
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   574
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   575
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   576
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   577
                propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   578
                Log.Error("ConvertSPropValueToObject: Error converting MAPI property {0}. Exception: {1}.", mapiProperty.DaslName, ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   579
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   580
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   581
            return propertyValue;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   582
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   583
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   584
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   585
        /// Gets the attachment table of an Outlook mail item.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   586
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   587
        /// <param name="omi">The Outlook mail item to get its attachment table for.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   588
        /// <param name="attachmentTable">The attachment table.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   589
        /// <returns>The status of this method.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   590
        public static int GetAttachmentTable(Outlook.MailItem omi, out IMAPITable attachmentTable)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   591
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   592
            int result = (int)Mapi.HResult.S_FALSE;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   593
            attachmentTable = null;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   594
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   595
            // Get MAPI object from mail item
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   596
            object mapiObject = omi?.MAPIOBJECT;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   597
            if (mapiObject == null)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   598
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   599
                Log.Error("GetMAPIProperties: MAPI object is null. Property could not be set.");
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   600
                return result;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   601
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   602
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   603
            // Pointer to IUnknown interface
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   604
            IntPtr IUnknown = IntPtr.Zero;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   605
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   606
            // Pointer to IMessage interface
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   607
            IntPtr IMessage = IntPtr.Zero;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   608
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   609
            try
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   610
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   611
                // Initialize MAPI
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   612
                NativeMethods.MAPIInitialize(IntPtr.Zero);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   613
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   614
                // Get the IUnknown interface from the MAPI object
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   615
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   616
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   617
                // Get the attachment table
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   618
                IMessage message = (IMessage)mapiObject;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   619
                result = message.GetAttachmentTable(0, out attachmentTable);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   620
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   621
            catch (Exception ex)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   622
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   623
                Log.Error("OpenMAPIProperty: Error occured. " + ex.ToString());
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   624
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   625
            finally
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   626
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   627
                if (IUnknown != IntPtr.Zero)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   628
                {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   629
                    Marshal.Release(IUnknown);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   630
                }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   631
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   632
                if (IMessage != IntPtr.Zero)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   633
                {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   634
                    Marshal.FreeHGlobal(IMessage);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   635
                }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   636
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   637
                NativeMethods.MAPIUninitialize();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   638
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   639
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   640
            return result;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   641
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   642
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   643
        /// <summary>
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   644
        /// Converts an error code into a meaningful error message (if available).
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   645
        /// </summary>
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   646
        /// <param name="error">The error code to convert.</param>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   647
        /// <returns>A string with a meaningful error code or null if an error occurs.</returns>
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   648
        public static string GetHResultError(int error)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   649
        {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   650
            try
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   651
            {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   652
                foreach (var hResult in Enum.GetValues(typeof(Mapi.HResult)))
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   653
                {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   654
                    if (((int)(uint)hResult) == error)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   655
                    {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   656
                        return Enum.GetName(typeof(Mapi.HResult), hResult);
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   657
                    }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   658
                }
2548
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   659
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   660
                // As backup, return a hex value string
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   661
                return error.ToString("X2");
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   662
            }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   663
            catch (Exception ex)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   664
            {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   665
                Log.Error("GetHResultError: Error getting HResult error. " + ex.ToString());
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   666
            }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   667
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   668
            return null;
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   669
        }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   670
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   671
        /// <summary>
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   672
        /// Gets a MAPI property value from an Outlook mail item.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   673
        /// </summary>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   674
        /// <param name="omi">The Outlook mail item to get the property value for.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   675
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   676
        /// <returns>The value or null if it doesn't exist or an error occured.</returns>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   677
        public static object GetMAPIProperty(Outlook.MailItem omi, MapiProperty.MapiProp mapiProperty)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   678
        {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   679
            return Mapi.GetMAPIProperty(omi?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMessage, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   680
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   681
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   682
        /// <summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   683
        /// Gets a MAPI property value from an Outlook folder item.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   684
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   685
        /// <param name="omi">The Outlook folder item to get the property value for.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   686
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   687
        /// <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
   688
        public static object GetMAPIProperty(Outlook.Folder folder, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   689
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   690
            return Mapi.GetMAPIProperty(folder?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMAPIFolder, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   691
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   692
2544
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   693
        /// <summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   694
        /// Gets the specified MAPI property value for this store.
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   695
        /// </summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   696
        /// <param name="store">The Outlook store to process with.</param>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   697
        /// <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
   698
        /// <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
   699
        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
   700
        {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   701
            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
   702
        }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   703
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   704
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   705
        /// Gets a MAPI property value from an Outlook item.
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   706
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   707
        /// <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
   708
        /// <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
   709
        /// has to match the type of the mapiObject parameter.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   710
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   711
        /// <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
   712
        private static object GetMAPIProperty(object mapiObject, string mapiInterfaceId, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   713
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   714
            // Check passed parameters
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   715
            if ((mapiObject == null) ||
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   716
                (string.IsNullOrEmpty(mapiInterfaceId)))
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   717
            {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   718
                Log.Error("GetMAPIProperty: MAPI object oder interface id is null. Returning null.");
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   719
                return null;
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   720
            }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   721
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   722
            object propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   723
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   724
            // Pointer to IUnknown interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   725
            IntPtr IUnknown = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   726
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   727
            // Pointer to IMessage, IMAPIFolder etc. interface
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   728
            IntPtr IMAPIObject = IntPtr.Zero;
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   729
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   730
            // Pointer to IMAPIProp interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   731
            IntPtr IMAPIProp = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   732
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   733
            // Structure that will hold the property value
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   734
            Mapi.SPropValue sPropValue;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   735
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   736
            // A pointer that points to the SPropValue structure 
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   737
            IntPtr ptrPropValue = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   738
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   739
            try
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   740
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   741
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   742
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   743
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   744
                // Get the IUnknown interface from the MAPI object
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   745
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   746
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   747
                // Set the MAPI object interface GUID that we pass to retrieve the IMessage interface.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   748
                Guid guidIMessage = new Guid(mapiInterfaceId);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   749
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   750
                // Try to retrieve the MAPI object interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   751
                if (Marshal.QueryInterface(IUnknown, ref guidIMessage, out IMAPIObject) != (uint)Mapi.HResult.S_OK)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   752
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   753
                    Log.Error("GetMAPIProperty: Could not retrieve IMessage interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   754
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   755
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   756
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   757
                // Set the IMAPIProp interface GUID that we pass to retrieve the IMAPIProp Interface.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   758
                Guid guidIMAPIProp = new Guid(Mapi.MAPIInterfaceIds.IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   759
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   760
                // Try to retrieve the IMAPIProp interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   761
                if ((Marshal.QueryInterface(IMAPIObject, ref guidIMAPIProp, out IMAPIProp) != (uint)Mapi.HResult.S_OK) ||
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   762
                    (IMAPIProp == IntPtr.Zero))
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   763
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   764
                    Log.Error("GetMAPIProperty: Could not retrieve IMAPIProp interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   765
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   766
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   767
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   768
                // Try to get the property
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   769
                NativeMethods.HrGetOneProp(IMAPIProp, mapiProperty.Tag, out ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   770
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   771
                if (ptrPropValue == IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   772
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   773
                    Log.Error("GetMAPIProperty: Could not retrieve pointer to property value. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   774
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   775
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   776
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   777
                // Get the SPropValue structure
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   778
                sPropValue = (SPropValue)Marshal.PtrToStructure(ptrPropValue, typeof(SPropValue));
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   779
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   780
                // Convert the retrieved value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   781
                propertyValue = Mapi.ConvertSPropValueToObject(mapiProperty, sPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   782
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   783
            catch (Exception ex)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   784
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   785
                propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   786
                Log.Error("GetMAPIProperty: Error occured. " + ex.ToString());
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   787
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   788
            finally
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   789
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   790
                // Free used memory structures
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   791
                if (ptrPropValue != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   792
                {
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   793
                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   794
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   795
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   796
                // Clean up all references to COM Objects
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   797
                if (IMAPIProp != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   798
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   799
                    Marshal.Release(IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   800
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   801
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   802
                if (IMAPIObject != IntPtr.Zero)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   803
                {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   804
                    Marshal.Release(IMAPIObject);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   805
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   806
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   807
                if (IUnknown != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   808
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   809
                    Marshal.Release(IUnknown);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   810
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   811
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   812
                NativeMethods.MAPIUninitialize();
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   813
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   814
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   815
            return propertyValue;
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   816
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   817
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   818
        /// <summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   819
        /// Gets a set of MAPI property values from an Outlook item.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   820
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   821
        /// <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
   822
        /// <param name="mapiProperties">The MAPI properties to get their values for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   823
        /// <param name="propertyValues">The retrieved values.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   824
        /// <returns>The error code returned by IMAPIProp::GetProps or 0 if no error occured.</returns>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   825
        internal static int GetMAPIProperties(object mapiObject, List<MapiProperty.MapiProp> mapiProperties, out MapiPropertyValueDictionary propertyValues)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   826
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   827
            int result = (int)Mapi.HResult.S_FALSE;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   828
            propertyValues = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   829
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   830
            // Get MAPI object from mail item
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   831
            if (mapiObject == null)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   832
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   833
                Log.Error("GetMAPIProperties: MAPI object is null. Property could not be set.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   834
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   835
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   836
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   837
            // Check if we actually have some properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   838
            int propertiesCount = mapiProperties.Count;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   839
            if (propertiesCount < 1)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   840
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   841
                Log.Error("GetMAPIProperties: No properties found.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   842
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   843
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   844
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   845
            // Pointer to IUnknown interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   846
            IntPtr IUnknown = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   847
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   848
            // Pointer to the MAPI properties array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   849
            IntPtr propTagArray = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   850
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   851
            // Pointer to the value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   852
            IntPtr valuePtr = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   853
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   854
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   855
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   856
                // Initialize MAPI
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   857
                NativeMethods.MAPIInitialize(IntPtr.Zero);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   858
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   859
                // Get the IUnknown interface from the MAPI object
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   860
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   861
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   862
                // Get the IMAPIProp interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   863
                Mapi.IMAPIProp IMAPIProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   864
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   865
                // Create the SPropValue structure
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   866
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   867
                int propValueSize = Marshal.SizeOf(sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   868
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   869
                // Allocate memory for the array of SPropValues to set
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   870
                propTagArray = Marshal.AllocHGlobal(propValueSize * propertiesCount);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   871
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   872
                // Create the property values array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   873
                uint[] propertyTags = new uint[propertiesCount + 1];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   874
                propertyTags[0] = (uint)propertiesCount;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   875
                for (int i = 0; i < propertiesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   876
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   877
                    propertyTags[i + 1] = (uint)mapiProperties[i].Tag;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   878
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   879
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   880
                // Get properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   881
                result = IMAPIProp.GetProps(propertyTags, Mapi.MAPI_UNICODE, out uint valuesCount, out IntPtr propArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   882
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   883
                // Convert the retrieved values
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   884
                object[] values = new object[valuesCount];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   885
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   886
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   887
                    sPropValue = (SPropValue)Marshal.PtrToStructure((propArray + (i * propValueSize)), typeof(SPropValue));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   888
                    values[i] = Mapi.ConvertSPropValueToObject(mapiProperties[i], sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   889
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   890
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   891
                // Check if returned values match properties count
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   892
                if (propertiesCount != valuesCount)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   893
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   894
                    Log.Error("GetMAPIProperties: Properties count doesn't match values count.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   895
                    return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   896
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   897
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   898
                // Create return dictionary
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   899
                propertyValues = new MapiPropertyValueDictionary();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   900
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   901
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   902
                    propertyValues.Add(mapiProperties[i], values[i]);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   903
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   904
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   905
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   906
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   907
                Log.Error("SetMAPIProperties: Error occured. " + ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   908
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   909
            finally
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   910
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   911
                if (IUnknown != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   912
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   913
                    Marshal.Release(IUnknown);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   914
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   915
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   916
                if (propTagArray != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   917
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   918
                    Marshal.FreeHGlobal(propTagArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   919
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   920
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   921
                if (valuePtr != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   922
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   923
                    Marshal.FreeHGlobal(valuePtr);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   924
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   925
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   926
                NativeMethods.MAPIUninitialize();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   927
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   928
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   929
            return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   930
        }
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   931
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   932
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   933
        /// Gets a list of all table rows and their MAPI properties using the IMAPITable.QueryRows method.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   934
        /// Each list entry in the return value corresponds to a table row, while each list entry's dictionary
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   935
        /// is a set of property value pairs returned for the table row.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   936
        /// This code is based on Fred Song's Managed MAPI: 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   937
        /// https://www.codeproject.com/Articles/455823/Managed-MAPI-Part-1-Logon-MAPI-Session-and-Retriev
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   938
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   939
        /// <param name="mapiTable">The table to query its rows.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   940
        /// <param name="rowCount">The maximum count of rows to query.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   941
        /// <param name="values">The returned values.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   942
        /// <returns>The status code of the IMAPITable.QueryRows method.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   943
        public static int GetTableProperties(Mapi.IMAPITable mapiTable, int rowCount, out List<Dictionary<uint, object>> properties)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   944
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   945
            IntPtr pRowSet = IntPtr.Zero;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   946
            properties = null;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   947
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   948
            int status = mapiTable.QueryRows(rowCount, 0, out pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   949
            if (status != (uint)Mapi.HResult.S_OK)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   950
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   951
                NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   952
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   953
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   954
            uint cRows = (uint)Marshal.ReadInt32(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   955
            if (cRows < 1)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   956
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   957
                NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   958
                return status;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   959
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   960
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   961
            int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   962
            int sizeOfSRow = 2 * intSize + pIntSize;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   963
            IntPtr rows = pRowSet + intSize;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   964
            properties = new List<Dictionary<uint, object>>();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   965
            for (int i = 0; i < cRows; i++)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   966
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   967
                IntPtr pRowOffset = rows + i * sizeOfSRow;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   968
                uint cValues = (uint)Marshal.ReadInt32(pRowOffset + pIntSize);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   969
                IntPtr pProps = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   970
                
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   971
                int size =  Marshal.SizeOf(typeof(SPropValue));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   972
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   973
                Dictionary<uint, object> propValues = new Dictionary<uint, object>();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   974
                for (int j = 0; j < cValues; j++) // each column
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   975
                {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   976
                    SPropValue lpProp = (SPropValue)Marshal.PtrToStructure((pProps + (j * size)), typeof(SPropValue));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   977
                    propValues.Add(lpProp.PropTag, lpProp.Value);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   978
                }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   979
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   980
                properties.Add(propValues);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   981
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   982
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   983
            NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   984
            return status;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   985
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   986
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   987
        /// <summary>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   988
        /// Sets the given MAPI properties on the Outlook mail item.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   989
        /// 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
   990
        /// 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
   991
        /// required data type for each MAPI property.
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
   992
        /// Do not call this method from a background thread!
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   993
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   994
        /// <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
   995
        /// <param name="mapiProperties">The MAPI properties to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   996
        /// <param name="values">The values to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   997
        /// <returns>True if the method succeeds, otherwise false.</returns>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   998
        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
   999
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1000
            // The return status of this method
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1001
            bool success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1002
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1003
            // Pointer to IUnknown interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1004
            IntPtr IUnknown = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1005
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1006
            // Pointer to the MAPI properties array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1007
            IntPtr propArray = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1008
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1009
            // Pointer to the value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1010
            IntPtr valuePtr = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1011
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1012
            // Get MAPI object from mail item
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1013
            object mapiObject = omi?.MAPIOBJECT;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1014
            if (mapiObject == null)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1015
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1016
                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
  1017
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1018
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1019
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1020
            // Make sure the properties count matches the values count
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1021
            int propCount = mapiProperties.Length;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1022
            if (propCount != values.Length)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1023
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1024
                Log.Error("SetMAPIProperties: Mismatch between tag count and value count.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1025
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1026
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1027
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1028
            try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1029
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1030
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1031
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1032
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1033
                // Get the IUnknown interface from the MAPI object
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1034
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1035
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1036
                // Get the IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1037
                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
  1038
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1039
                // Create the SPropValue structure
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1040
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1041
                var propValueSize = Marshal.SizeOf(sPropValue);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1042
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1043
                // Allocate memory for the array of SPropValues to set
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1044
                propArray = Marshal.AllocHGlobal(propValueSize * propCount);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1045
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1046
                // Create the property values array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1047
                for (int i = 0; i < propCount; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1048
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1049
                    // Get the current property/value pair
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1050
                    MapiProperty.MapiProp mapiProperty = mapiProperties[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1051
                    uint tag = mapiProperty.Tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1052
                    object value = values[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1053
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1054
                    // Set the property value's property tag
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1055
                    sPropValue.PropTag = (uint)tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1056
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1057
                    // Set the property value's value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1058
                    switch (mapiProperty.DataType)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1059
                    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1060
                        case MapiProperty.MapiDataType.PtypBoolean:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1061
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1062
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1063
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1064
                                    sPropValue.Value.b = (ushort)Convert.ToInt16((bool)value);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1065
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1066
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1067
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1068
                                    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
  1069
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1070
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1071
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1072
                        case MapiProperty.MapiDataType.PtypString:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1073
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1074
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1075
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1076
                                    valuePtr = Marshal.StringToHGlobalUni(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1077
                                    sPropValue.Value.lpszW = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1078
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1079
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1080
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1081
                                    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
  1082
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1083
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1084
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1085
                        case MapiProperty.MapiDataType.PtypString8:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1086
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1087
                                try
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
                                    valuePtr = Marshal.StringToHGlobalAnsi(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1090
                                    sPropValue.Value.lpszA = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1091
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1092
                                catch (Exception ex)
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
                                    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
  1095
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1096
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1097
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1098
                        case MapiProperty.MapiDataType.PtypInteger16:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1099
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1100
                                try
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
                                    sPropValue.Value.i = (short)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1103
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1104
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1105
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1106
                                    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
  1107
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1108
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1109
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1110
                        case MapiProperty.MapiDataType.PtypInteger32:
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
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1113
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1114
                                    sPropValue.Value.l = (int)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1115
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1116
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1117
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1118
                                    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
  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
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1122
                        case MapiProperty.MapiDataType.PtypFloating32:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1123
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1124
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1125
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1126
                                    sPropValue.Value.flt = (float)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1127
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1128
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1129
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1130
                                    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
  1131
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1132
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1133
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1134
                        case MapiProperty.MapiDataType.PtypFloating64:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1135
                        case MapiProperty.MapiDataType.PtypFloatingTime:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1136
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1137
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1138
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1139
                                    sPropValue.Value.at = (double)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1140
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1141
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1142
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1143
                                    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
  1144
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1145
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1146
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1147
                        case MapiProperty.MapiDataType.PtypInteger64:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1148
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1149
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1150
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1151
                                    sPropValue.Value.li = (ulong)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1152
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1153
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1154
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1155
                                    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
  1156
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1157
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1158
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1159
                        case MapiProperty.MapiDataType.PtypGuid:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1160
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1161
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1162
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1163
                                    IntPtr guidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(value));
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1164
                                    Marshal.StructureToPtr((Guid)value, guidPtr, false);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1165
                                    sPropValue.Value.lpguid = guidPtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1166
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1167
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1168
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1169
                                    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
  1170
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1171
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1172
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1173
                        case MapiProperty.MapiDataType.PtypBinary:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1174
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1175
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1176
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1177
                                    sPropValue.Value.bin = (Mapi.SRowSet)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1178
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1179
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1180
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1181
                                    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
  1182
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1183
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1184
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1185
                        default:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1186
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1187
                                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
  1188
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1189
                    }
2370
38dc1da79cf5 Set sender for mirror items
Thomas
parents: 2368
diff changeset
  1190
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1191
                    Marshal.StructureToPtr(sPropValue, (IntPtr)((uint)propArray + (propValueSize * i)), false);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1192
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1193
                    if (valuePtr != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1194
                    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1195
                        Marshal.FreeHGlobal(valuePtr);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1196
                    }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1197
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1198
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1199
                // Set properties and save
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1200
                IntPtr problems = IntPtr.Zero;
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
  1201
                if (IMAPIProp.SetProps((uint)propCount, propArray, problems) == (uint)Mapi.HResult.S_OK)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1202
                {
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
  1203
                    success = (IMAPIProp.SaveChanges((uint)Mapi.SaveOption.KEEP_OPEN_READWRITE) == (uint)Mapi.HResult.S_OK);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1204
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1205
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1206
            catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1207
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1208
                Log.Error("SetMAPIProperties: Error occured. " + ex.ToString());
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1209
                success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1210
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1211
            finally
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1212
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1213
                if (IUnknown != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1214
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1215
                    Marshal.Release(IUnknown);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1216
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1217
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1218
                if (propArray != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1219
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1220
                    Marshal.FreeHGlobal(propArray);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1221
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1222
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1223
                if (valuePtr != IntPtr.Zero)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1224
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1225
                    Marshal.FreeHGlobal(valuePtr);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1226
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1227
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1228
                NativeMethods.MAPIUninitialize();
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1229
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1230
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1231
            return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1232
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1233
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1234
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1235
        /// Sets the given MAPI property on the Outlook mail item.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1236
        /// 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
  1237
        /// required data type for the MAPI property.
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1238
        /// Do not call this method from a background thread!
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1239
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1240
        /// <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
  1241
        /// <param name="mapiProperties">The MAPI property to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1242
        /// <param name="values">The value to set.</param>
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1243
        /// <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
  1244
        /// <returns>True if the method succeeds, otherwise false.</returns>
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1245
        public static bool SetMAPIProperty(Outlook.MailItem omi,
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1246
                                           MapiProperty.MapiProp mapiProperty,
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1247
                                           object value,
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1248
                                           bool useSetProps = false)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1249
        {
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1250
            if (useSetProps)
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1251
            {
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1252
                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
  1253
            }
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1254
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1255
            // The return status of this method
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1256
            bool success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1257
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1258
            // Pointer to IUnknown interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1259
            IntPtr IUnknown = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1260
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1261
            // Pointer to IMessage interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1262
            IntPtr IMessage = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1263
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1264
            // Pointer to IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1265
            IntPtr IMAPIProp = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1266
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1267
            // 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
  1268
            Mapi.SPropValue sPropValue;
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1269
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1270
            // A pointer that points to the SPropValue structure 
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1271
            IntPtr ptrPropValue = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1272
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1273
            // Pointer to the value
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1274
            IntPtr valuePtr = IntPtr.Zero;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1275
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1276
            // Get MAPI object from mail item
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1277
            object mapiObject = omi?.MAPIOBJECT;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1278
            if (mapiObject == null)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1279
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1280
                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
  1281
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1282
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1283
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1284
            try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1285
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1286
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1287
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1288
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1289
                // Get the IUnknown interface from the MAPI object
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1290
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1291
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1292
                // 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
  1293
                Guid guidIMessage = new Guid(Mapi.MAPIInterfaceIds.IMessage);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1294
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1295
                // Try to retrieve the IMessage interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
  1296
                if (Marshal.QueryInterface(IUnknown, ref guidIMessage, out IMessage) != (uint)Mapi.HResult.S_OK)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1297
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1298
                    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
  1299
                    return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1300
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1301
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1302
                // 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
  1303
                Guid guidIMAPIProp = new Guid(Mapi.MAPIInterfaceIds.IMAPIProp);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1304
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1305
                // Try to retrieve the IMAPIProp interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
  1306
                if ((Marshal.QueryInterface(IMessage, ref guidIMAPIProp, out IMAPIProp) != (uint)Mapi.HResult.S_OK) ||
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1307
                    (IMAPIProp == IntPtr.Zero))
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1308
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1309
                    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
  1310
                    return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1311
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1312
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1313
                // Create the SPropValue structure
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1314
                sPropValue = new Mapi.SPropValue
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1315
                {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1316
                    PropTag = (uint)mapiProperty.Tag
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1317
                };
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1318
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1319
                // Set the property value's value
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1320
                switch (mapiProperty.DataType)
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1321
                {
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1322
                    case MapiProperty.MapiDataType.PtypBoolean:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1323
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1324
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1325
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1326
                                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
  1327
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1328
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1329
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1330
                                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
  1331
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1332
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1333
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1334
                    case MapiProperty.MapiDataType.PtypString:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1335
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1336
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1337
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1338
                                valuePtr = Marshal.StringToHGlobalUni(value as string);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1339
                                sPropValue.Value.lpszW = valuePtr;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1340
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1341
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1342
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1343
                                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
  1344
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1345
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1346
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1347
                    case MapiProperty.MapiDataType.PtypString8:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1348
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1349
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1350
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1351
                                valuePtr = Marshal.StringToHGlobalAnsi(value as string);
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1352
                                sPropValue.Value.lpszA = valuePtr;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1353
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1354
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1355
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1356
                                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
  1357
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1358
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1359
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1360
                    case MapiProperty.MapiDataType.PtypInteger16:
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1361
                        {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1362
                            try
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1363
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1364
                                sPropValue.Value.i = (short)value;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1365
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1366
                            catch (Exception ex)
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1367
                            {
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1368
                                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
  1369
                            }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1370
                        }
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff changeset
  1371
                        break;
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2482
diff