Mapi.cs
author Thomas
Mon, 25 Mar 2019 13:27:16 +0100
branchsync
changeset 2610 09fde2338362
parent 2597 a745e942a666
child 3288 3c10b308e3c3
permissions -rw-r--r--
Merge with default
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>
2563
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   120
        /// Deletion options for the IMAPIFolder.DeleteMessages method.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   121
        /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   122
        internal enum DeletionFlags : uint
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   123
        {
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   124
            DELETE_HARD_DELETE = 0x00000010,
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   125
            //MESSAGE_DIALOG = ?
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   126
        }
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   127
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   128
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   129
        /// Flag to indicate that IMAPIProps::GetProps should return unicode values.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   130
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   131
        private const uint MAPI_UNICODE = 0x80000000;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   132
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   133
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   134
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   135
        #region Interfaces
2563
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   136
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   137
        /// <summary>
2597
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   138
        /// Manages high-level operations on container objects such as address books, distribution lists, and folders.
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   139
        /// </summary>
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   140
        [
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   141
            ComImport,
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   142
            ComVisible(false),
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   143
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   144
            Guid(Mapi.MAPIInterfaceIds.IMAPIContainer)
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   145
        ]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   146
        internal interface IMAPIContainer : IMAPIProp
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   147
        {
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   148
            [return: MarshalAs(UnmanagedType.I4)]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   149
            [PreserveSig]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   150
            int GetContentsTable();
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   151
            [return: MarshalAs(UnmanagedType.I4)]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   152
            [PreserveSig]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   153
            int GetHierarchyTable();
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   154
            [return: MarshalAs(UnmanagedType.I4)]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   155
            [PreserveSig]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   156
            int OpenEntry(uint cbEntryId, IntPtr entryId, ref Guid iid, uint flags, out IntPtr type, out IntPtr iUnk);
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   157
            [return: MarshalAs(UnmanagedType.I4)]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   158
            [PreserveSig]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   159
            int SetSearchCriteria();
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   160
            [return: MarshalAs(UnmanagedType.I4)]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   161
            [PreserveSig]
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   162
            int GetSearchCriteria();
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   163
        }
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   164
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   165
        /// <summary>
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   166
        /// Performs operations on the messages and subfolders in a folder.
2563
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   167
        /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   168
        [
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   169
            ComImport,
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   170
            ComVisible(false),
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   171
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   172
            Guid(Mapi.MAPIInterfaceIds.IMAPIFolder)
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   173
        ]
2597
a745e942a666 Add IMAPIContainer interface
Thomas
parents: 2595
diff changeset
   174
        internal interface IMAPIFolder : IMAPIContainer
2563
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   175
        {
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   176
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   177
            /// Creates a new message.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   178
            /// <paramref name="_interface"/>A pointer to the interface identifier (IID) that represents the interface 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   179
            /// to be used to access the new message. Valid interface identifiers include IID_IUnknown, IID_IMAPIProp, 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   180
            /// IID_IMAPIContainer, and IID_IMAPIFolder. Passing NULL causes the message store provider to return the 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   181
            /// standard message interface, IMessage::IMAPIProp.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   182
            /// <param name="flags">A bitmask of flags that controls how the message is created.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   183
            /// <param name="message">A pointer to a pointer to the newly created message.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   184
            /// See: https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/imapifolder-createmessage
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   185
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   186
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   187
            [return: MarshalAs(UnmanagedType.I4)]
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   188
            [PreserveSig]
2595
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   189
            int CreateMessage(ref Guid lpiid, uint flags, [MarshalAs(UnmanagedType.Interface)] out IMessage message);
2563
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   190
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   191
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   192
            /// Copies or moves one or more messages. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   193
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   194
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   195
            int CopyMessages();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   196
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   197
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   198
            /// Deletes one or more messages. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   199
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   200
            /// <param name="msgList">A pointer to an ENTRYLIST structure that contains the 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   201
            /// number of messages to delete and an array of ENTRYID structures that identify the messages.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   202
            /// <param name="uiParam">A handle to the parent window of the progress indicator. The ulUIParam 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   203
            /// parameter is ignored unless the MESSAGE_DIALOG flag is set in the ulFlags parameter.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   204
            /// <param name="progress">A pointer to a progress object that displays a progress indicator. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   205
            /// If IntPtr.Zero is passed in lpProgress, the message store provider displays a progress indicator 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   206
            /// by using the MAPI progress object implementation. The lpProgress parameter is ignored unless the 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   207
            /// MESSAGE_DIALOG flag is set in the ulFlags parameter.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   208
            /// <param name="flags">A bitmask of flags that controls how the messages are deleted. The following flags can be set:
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   209
            /// DELETE_HARD_DELETE: Permanently removes all messages, including soft-deleted ones.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   210
            /// MESSAGE_DIALOG: Displays a progress indicator as the operation proceeds.</param>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   211
            /// See: https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/imapifolder-deletemessages
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   212
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   213
            [return: MarshalAs(UnmanagedType.I4)]
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   214
            [PreserveSig]
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   215
            int DeleteMessages(IntPtr msgList, uint uiParam, IntPtr progress, uint flags);
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   216
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   217
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   218
            /// Creates a new subfolder. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   219
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   220
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   221
            int CreateFolder();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   222
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   223
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   224
            /// Copies or moves a subfolder. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   225
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   226
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   227
            int CopyFolder();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   228
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   229
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   230
            /// Deletes a subfolder. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   231
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   232
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   233
            int DeleteFolder();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   234
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   235
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   236
            /// Sets or clears the MSGFLAG_READ flag in the PR_MESSAGE_FLAGS (PidTagMessageFlags) property 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   237
            /// of one or more of the folder's messages, and manages the sending of read reports.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   238
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   239
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   240
            int SetReadFlags();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   241
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   242
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   243
            /// Obtains the status associated with a message in a particular folder.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   244
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   245
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   246
            int GetMessageStatus();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   247
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   248
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   249
            ///  Sets the status associated with a message.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   250
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   251
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   252
            int SetMessageStatus();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   253
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   254
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   255
            /// Sets the default sort order for a folder's contents table.
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   256
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   257
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   258
            int SaveContentsSort();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   259
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   260
            /// <summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   261
            ///  Deletes all messages and subfolders from a folder without deleting the folder itself. 
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   262
            /// </summary>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   263
            /// <returns>The status of this method.</returns>
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   264
            int EmptyFolder();
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   265
        }
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   266
4d6d0d703449 Add IMAPIFolder interface
Thomas
parents: 2558
diff changeset
   267
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   268
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   269
        /// 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
   270
        /// support properties implement this interface.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   271
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   272
        [
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   273
            ComImport,
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   274
            ComVisible(false),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   275
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   276
            Guid(Mapi.MAPIInterfaceIds.IMAPIProp)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   277
        ]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   278
        internal interface IMAPIProp
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   279
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   280
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   281
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   282
            int GetLastError();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   283
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   284
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   285
            int SaveChanges(uint uFlags);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   286
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   287
            [PreserveSig]
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   288
            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
   289
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   290
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   291
            int GetPropList();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   292
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   293
            [PreserveSig]
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   294
            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
   295
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   296
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   297
            int SetProps(uint values, IntPtr propArray, IntPtr problems);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   298
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   299
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   300
            int DeleteProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   301
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   302
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   303
            int CopyTo();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   304
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   305
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   306
            int CopyProps();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   307
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   308
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   309
            int GetNamesFromIDs();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   310
            [return: MarshalAs(UnmanagedType.I4)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   311
            [PreserveSig]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   312
            int GetIDsFromNames();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   313
        }
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   314
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   315
        /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   316
        /// 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
   317
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   318
        [Guid("00020301-0000-0000-c000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   319
        public interface IMAPITable
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   320
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   321
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   322
            /// 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
   323
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   324
            /// <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
   325
            /// <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
   326
            /// <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
   327
            /// <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
   328
            int GetLastError(int hResult, uint ulFlags, out IntPtr lppMAPIError);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   329
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   330
            /// 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
   331
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   332
            /// <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
   333
            /// <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
   334
            /// <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
   335
            /// <returns>S_OK, if the notification registration successfully completed; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   336
            int Advise(uint ulEventMask, IntPtr lpAdviseSink, IntPtr lpulConnection);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   337
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   338
            /// 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
   339
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   340
            /// <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
   341
            /// <returns>S_OK, if the call succeeded; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   342
            int Unadvise(uint ulConnection);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   343
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   344
            /// Returns the table's status and type.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   345
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   346
            /// <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
   347
            /// <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
   348
            /// <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
   349
            int GetStatus(IntPtr lpulTableStatus, IntPtr lpulTableType);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   350
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   351
            /// 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
   352
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   353
            /// <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
   354
            /// <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
   355
            /// <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
   356
            int SetColumns([MarshalAs(UnmanagedType.LPArray)] uint[] lpPropTagArray, uint ulFlags);
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
            /// Returns a list of columns for the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   359
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   360
            /// <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
   361
            /// <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
   362
            /// <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
   363
            int QueryColumns(uint ulFlags, IntPtr lpPropTagArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   364
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   365
            /// Returns the total number of rows in the table. 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   366
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   367
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   368
            /// <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
   369
            /// <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
   370
            int GetRowCount(uint ulFlags, out uint lpulCount);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   371
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   372
            /// Moves the cursor to a specific position in the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   373
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   374
            /// <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
   375
            /// <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
   376
            /// <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
   377
            /// <returns>S_OK, if the seek operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   378
            int SeekRow(int bkOrigin, int lRowCount, out IntPtr lplRowsSought);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   379
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   380
            /// Moves the cursor to an approximate fractional position in the table. 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   381
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   382
            /// <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
   383
            /// <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
   384
            /// <returns>S_OK, if the seek operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   385
            int SeekRowApprox(uint ulNumerator, uint ulDenominator);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   386
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   387
            /// 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
   388
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   389
            /// <param name="lpulRow">Pointer to the number of the current row.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   390
            /// <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
   391
            /// <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
   392
            /// <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
   393
            int QueryPosition(IntPtr lpulRow, IntPtr lpulNumerator, IntPtr lpulDenominator);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   394
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   395
            /// 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
   396
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   397
            /// <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
   398
            /// <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
   399
            /// <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
   400
            /// <returns>S_OK, if the find operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   401
            int FindRow(out IntPtr lpRestriction, uint BkOrigin, uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   402
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   403
            /// 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
   404
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   405
            /// <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
   406
            /// <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
   407
            /// <returns>S_OK, if the filter was successfully applied; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   408
            int Restrict(out IntPtr lpRestriction, uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   409
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   410
            /// Creates a bookmark at the table's current position.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   411
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   412
            /// <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
   413
            /// <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
   414
            int CreateBookmark(IntPtr lpbkPosition);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   415
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   416
            /// Releases the memory associated with a bookmark.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   417
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   418
            /// <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
   419
            /// <returns>S_OK, if the bookmark was successfully freed; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   420
            int FreeBookmark(IntPtr bkPosition);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   421
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   422
            /// Orders the rows of the table, depending on sort criteria.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   423
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   424
            /// <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
   425
            /// <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
   426
            /// <returns>S_OK, if the sort operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   427
            int SortTable(IntPtr lpSortCriteria, int ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   428
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   429
            /// Retrieves the current sort order for a table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   430
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   431
            /// <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
   432
            /// <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
   433
            int QuerySortOrder(IntPtr lppSortCriteria);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   434
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   435
            /// 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
   436
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   437
            /// <param name="lRowCount">Maximum number of rows to be returned.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   438
            /// <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
   439
            /// <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
   440
            /// <returns>S_OK, if the rows were successfully returned; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   441
            int QueryRows(int lRowCount, uint ulFlags, out IntPtr lppRows);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   442
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   443
            /// Stops any asynchronous operations currently in progress for the table.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   444
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   445
            /// <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
   446
            int Abort();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   447
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   448
            /// 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
   449
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   450
            /// <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
   451
            /// <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
   452
            /// <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
   453
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   454
            /// <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
   455
            /// <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
   456
            /// <returns>S_OK, if the category was expanded successfully; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   457
            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
   458
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   459
            /// 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
   460
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   461
            /// <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
   462
            /// <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
   463
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   464
            /// <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
   465
            /// <returns>S_OK, if the collapse operation has succeeded; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   466
            int CollapseRow(uint cbInstanceKey, IntPtr pbInstanceKey, uint ulFlags, IntPtr lpulRowCount);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   467
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   468
            /// 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
   469
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   470
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   471
            /// <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
   472
            /// <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
   473
            /// <returns>S_OK, if the wait operation was successful; otherwise, failed.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   474
            int WaitForCompletion(uint ulFlags, uint ulTimeout, IntPtr lpulTableStatus);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   475
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   476
            /// 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
   477
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   478
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   479
            /// <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
   480
            /// <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
   481
            /// <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
   482
            /// <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
   483
            /// <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
   484
            int GetCollapseState(uint ulFlags, uint cbInstanceKey, IntPtr lpbInstanceKey, IntPtr lpcbCollapseState, IntPtr lppbCollapseState);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   485
            /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   486
            /// 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
   487
            /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   488
            /// <param name="ulFlags">Reserved; must be zero.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   489
            /// <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
   490
            /// <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
   491
            /// <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
   492
            /// <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
   493
            int SetCollapseState(uint ulFlags, uint cbCollapseState, IntPtr pbCollapseState, IntPtr lpbkLocation);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   494
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   495
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   496
        /// <summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   497
        /// The IMessage interface defines methods and properties used to manage messages.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   498
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   499
        [ComImport()]
2595
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   500
        [Guid(Mapi.MAPIInterfaceIds.IMessage)]        
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   501
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
2555
6334e58eb55e Formatting
Thomas
parents: 2550
diff changeset
   502
        public interface IMessage
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   503
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   504
            int GetLastError(int hResult, uint ulFlags, out IntPtr lppMAPIError);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   505
            int SaveChanges(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   506
            int GetProps(IntPtr lpPropTagArray, uint ulFlags, out uint lpcValues, out IntPtr lppPropArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   507
            int GetPropList(uint ulFlags, out IntPtr lppPropTagArray);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   508
            [return: MarshalAs(UnmanagedType.I4)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   509
            [PreserveSig]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   510
            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
   511
            int SetProps(uint cValues, IntPtr lpPropArray, out IntPtr lppProblems);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   512
            int DeleteProps(IntPtr lpPropTagArray, out IntPtr lppProblems);
2555
6334e58eb55e Formatting
Thomas
parents: 2550
diff changeset
   513
            int CopyTo(uint ciidExclude, ref Guid rgiidExclude, IntPtr lpExcludeProps, uint ulUIParam, IntPtr lpProgress, ref Guid lpInterface, IntPtr lpDestObj, uint ulFlags, out IntPtr lppProblems);
6334e58eb55e Formatting
Thomas
parents: 2550
diff changeset
   514
            int CopyProps(IntPtr lpIncludeProps, uint ulUIParam, IntPtr lpProgress, ref Guid lpInterface, IntPtr lpDestObj, uint ulFlags, out IntPtr lppProblems);
6334e58eb55e Formatting
Thomas
parents: 2550
diff changeset
   515
            int GetNamesFromIDs(out IntPtr lppPropTags, ref Guid lpPropSetGuid, uint ulFlags, out uint lpcPropNames, out IntPtr lpppPropNames);
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   516
            int GetIDsFromNames(uint cPropNames, ref IntPtr lppPropNames, uint ulFlags, out IntPtr lppPropTags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   517
            int GetAttachmentTable(uint ulFlags, out IMAPITable lppTable);
2595
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   518
            int OpenAttach(uint ulAttachmentNum, ref Guid lpInterface, uint ulFlags, out IAttach lppAttach);
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   519
            int CreateAttach();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   520
            int DeleteAttach();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   521
            int GetRecipientTable(uint ulFlags, out IMAPITable lppTable);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   522
            int ModifyRecipients();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   523
            int SubmitMessage(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   524
            int SetReadFlag(uint ulFlags);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   525
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   526
2595
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   527
        [ComImport()]
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   528
        [Guid(Mapi.MAPIInterfaceIds.IAttachment)]
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   529
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   530
        public interface IAttach : IMAPIProp
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   531
        { }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   532
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   533
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   534
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   535
        #region Structures
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   536
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   537
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   538
        /// The SPropValue structure describes a MAPI property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   539
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   540
        public struct SPropValue
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   541
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   542
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   543
            /// 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
   544
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   545
            public uint PropTag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   546
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   547
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   548
            /// Reserved for MAPI; do not use.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   549
            /// </summary>
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   550
#pragma warning disable 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   551
            public uint DwAlignPad;
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   552
#pragma warning restore 649
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   553
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   554
            /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   555
            /// 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
   556
            /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   557
            public PV Value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   558
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   559
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   560
        /// <summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   561
        /// Union of data values for the SPropValue.value property.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   562
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   563
        [StructLayout(LayoutKind.Explicit, Size = 8)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   564
        public struct PV
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   565
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   566
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   567
            public short i;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   568
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   569
            public int l;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   570
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   571
            public uint ul;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   572
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   573
            public float flt;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   574
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   575
            public double dbl;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   576
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   577
            public ushort b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   578
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   579
            public double at;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   580
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   581
            public IntPtr lpszA;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   582
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   583
            public IntPtr lpszW;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   584
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   585
            public IntPtr lpguid;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   586
            /*[FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   587
            public IntPtr bin;*/
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   588
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   589
            public ulong li;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   590
            [FieldOffset(0)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   591
            public SRowSet bin;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   592
        }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   593
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   594
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   595
        /// 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
   596
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   597
        [StructLayout(LayoutKind.Sequential)]
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   598
        public struct SRow
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   599
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   600
            public uint ulAdrEntryPad;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   601
            public uint cValues;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   602
            public IntPtr lpProps;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   603
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   604
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   605
        /// <summary>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   606
        /// 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
   607
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   608
        [StructLayout(LayoutKind.Sequential)]
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   609
        public struct SRowSet
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   610
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   611
            public uint cRows;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   612
            public IntPtr aRow; // pSRow
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   613
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   614
            public byte[] AsBytes
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   615
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   616
                get
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   617
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   618
                    byte[] b = new byte[this.cRows];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   619
                    for (int i = 0; i < this.cRows; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   620
                        b[i] = Marshal.ReadByte(aRow, i);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   621
                    return b;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   622
                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   623
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   624
        }
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   625
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   626
        #endregion
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   627
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
   628
        #region Methods
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   629
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   630
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   631
        /// Retrieves a managed object from the SPropValue structure that is returned by GetProps etc.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   632
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   633
        /// <param name="mapiProperty">The MAPI property the value was retrieved for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   634
        /// <param name="sPropValue">The value to convert.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   635
        /// <returns>The converted object or null if an error occured.</returns>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   636
        public static object ConvertSPropValueToObject(MapiProperty.MapiProp mapiProperty, SPropValue sPropValue)
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   637
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   638
            object propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   639
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   640
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   641
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   642
                switch (mapiProperty.DataType)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   643
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   644
                    case MapiProperty.MapiDataType.PtypBoolean:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   645
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   646
                            propertyValue = Convert.ToBoolean(sPropValue.Value.b);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   647
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   648
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   649
                    case MapiProperty.MapiDataType.PtypString:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   650
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   651
                            if ((((uint)sPropValue.Value.lpszW).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   652
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   653
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   654
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   655
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   656
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   657
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   658
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszW);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   659
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   660
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   661
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   662
                    case MapiProperty.MapiDataType.PtypString8:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   663
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   664
                            if ((((uint)sPropValue.Value.lpszA).ToString("X2") is string hexValue) &&
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   665
                                (hexValue.StartsWith("800")))
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   666
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   667
                                Log.Error("ConvertSPropValueToObject: Cannot convert MAPI property {0} to string8: {1}", mapiProperty.DaslName, hexValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   668
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   669
                            else
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   670
                            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   671
                                propertyValue = Marshal.PtrToStringUni(sPropValue.Value.lpszA);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   672
                            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   673
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   674
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   675
                    case MapiProperty.MapiDataType.PtypInteger16:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   676
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   677
                            propertyValue = sPropValue.Value.i;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   678
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   679
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   680
                    case MapiProperty.MapiDataType.PtypInteger32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   681
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   682
                            propertyValue = sPropValue.Value.l;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   683
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   684
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   685
                    case MapiProperty.MapiDataType.PtypFloating32:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   686
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   687
                            propertyValue = sPropValue.Value.flt;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   688
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   689
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   690
                    case MapiProperty.MapiDataType.PtypFloating64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   691
                    case MapiProperty.MapiDataType.PtypFloatingTime:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   692
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   693
                            propertyValue = sPropValue.Value.at;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   694
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   695
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   696
                    case MapiProperty.MapiDataType.PtypInteger64:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   697
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   698
                            propertyValue = sPropValue.Value.li;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   699
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   700
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   701
                    case MapiProperty.MapiDataType.PtypGuid:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   702
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   703
                            propertyValue = Marshal.PtrToStructure(sPropValue.Value.lpguid, typeof(Guid));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   704
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   705
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   706
                    case MapiProperty.MapiDataType.PtypBinary:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   707
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   708
                            propertyValue = sPropValue.Value.bin;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   709
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   710
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   711
                    default:
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   712
                        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   713
                            propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   714
                            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
   715
                        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   716
                        break;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   717
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   718
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   719
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   720
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   721
                propertyValue = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   722
                Log.Error("ConvertSPropValueToObject: Error converting MAPI property {0}. Exception: {1}.", mapiProperty.DaslName, ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   723
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   724
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   725
            return propertyValue;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   726
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   727
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   728
        /// <summary>
2595
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   729
        /// Gets an attachment's properties.
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   730
        /// </summary>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   731
        /// <param name="omi">The Outlook mail item that contains the attachment.</param>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   732
        /// <param name="index">The attachment's index. 0-based.</param>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   733
        /// <param name="mapiProperties">The MAPI properties to get its values for.</param>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   734
        /// <param name="propertyValues">The property values that have been returned.</param>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   735
        /// <returns>The status (Mapi.HResult) of this method.</returns>
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   736
        public static int GetAttachmentProperties(Outlook.MailItem omi,
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   737
                                                  int index,
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   738
                                                  List<MapiProperty.MapiProp> mapiProperties,
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   739
                                                  out MAPIProperties propertyValues)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   740
        {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   741
            int result = (int)Mapi.HResult.S_FALSE;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   742
            propertyValues = null;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   743
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   744
            try
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   745
            {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   746
                // Get the IMessage interface
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   747
                IMessage iMessage = (IMessage)omi?.MAPIOBJECT;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   748
                if (iMessage == null)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   749
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   750
                    throw new Exception("Could not get IMessage interface.");
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   751
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   752
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   753
                // Open the attachment
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   754
                Guid guid = (typeof(Mapi.IAttach)).GUID;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   755
                result = iMessage.OpenAttach((uint)index, ref guid, 0, out IAttach attachment);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   756
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   757
                // If we can't open the attachment, throw error
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   758
                if (result != 0)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   759
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   760
                    throw new Exception("Error opening attachment. " + Mapi.GetHResultError(result));
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   761
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   762
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   763
                // Create the SPropValue structure
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   764
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   765
                int propValueSize = Marshal.SizeOf(sPropValue);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   766
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   767
                // Allocate memory for the array of SPropValues to set
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   768
                int propertiesCount = mapiProperties.Count;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   769
                IntPtr propTagArray = Marshal.AllocHGlobal(propValueSize * propertiesCount);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   770
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   771
                // Create the property values array
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   772
                uint[] propertyTags = new uint[propertiesCount + 1];
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   773
                propertyTags[0] = (uint)propertiesCount;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   774
                for (int i = 0; i < propertiesCount; i++)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   775
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   776
                    propertyTags[i + 1] = (uint)mapiProperties[i].Tag;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   777
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   778
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   779
                // Get properties
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   780
                result = attachment.GetProps(propertyTags, Mapi.MAPI_UNICODE, out uint valuesCount, out IntPtr propArray);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   781
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   782
                // If an error occured, just log at this point.
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   783
                if (result != 0)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   784
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   785
                    Log.Error("OpenAttachment: Error getting attachment properties. " + Mapi.GetHResultError(result));
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   786
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   787
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   788
                // Convert the retrieved values
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   789
                object[] values = new object[valuesCount];
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   790
                for (int i = 0; i < valuesCount; i++)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   791
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   792
                    sPropValue = (SPropValue)Marshal.PtrToStructure((propArray + (i * propValueSize)), typeof(SPropValue));
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   793
                    values[i] = Mapi.ConvertSPropValueToObject(mapiProperties[i], sPropValue);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   794
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   795
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   796
                // Check if returned values match properties count
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   797
                if (propertiesCount != valuesCount)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   798
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   799
                    throw new Exception("Properties count doesn't match values count.");
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   800
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   801
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   802
                // Create return dictionary
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   803
                propertyValues = new MAPIProperties();
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   804
                for (int i = 0; i < valuesCount; i++)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   805
                {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   806
                    propertyValues.Add(mapiProperties[i], values[i]);
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   807
                }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   808
            }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   809
            catch (Exception ex)
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   810
            {
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   811
                Log.Error("OpenAttachment: Error getting attachment.  " + ex.ToString());
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   812
            }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   813
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   814
            return result;
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   815
        }
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   816
8b720212bbdf Add GetAttachmentProperties method
Thomas
parents: 2563
diff changeset
   817
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   818
        /// Gets the attachment table of an Outlook mail item.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   819
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   820
        /// <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
   821
        /// <param name="attachmentTable">The attachment table.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   822
        /// <returns>The status of this method.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   823
        public static int GetAttachmentTable(Outlook.MailItem omi, out IMAPITable attachmentTable)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   824
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   825
            int result = (int)Mapi.HResult.S_FALSE;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   826
            attachmentTable = null;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   827
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   828
            // Get MAPI object from mail item
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   829
            object mapiObject = omi?.MAPIOBJECT;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   830
            if (mapiObject == null)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   831
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   832
                Log.Error("GetMAPIProperties: MAPI object is null. Property could not be set.");
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   833
                return result;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   834
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   835
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   836
            // Pointer to IUnknown interface
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   837
            IntPtr IUnknown = IntPtr.Zero;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   838
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   839
            try
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   840
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   841
                // Initialize MAPI
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   842
                NativeMethods.MAPIInitialize(IntPtr.Zero);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   843
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   844
                // Get the IUnknown interface from the MAPI object
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   845
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   846
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   847
                // Get the attachment table
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   848
                IMessage message = (IMessage)mapiObject;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   849
                result = message.GetAttachmentTable(0, out attachmentTable);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   850
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   851
            catch (Exception ex)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   852
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   853
                Log.Error("OpenMAPIProperty: Error occured. " + ex.ToString());
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   854
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   855
            finally
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   856
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   857
                if (IUnknown != IntPtr.Zero)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   858
                {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   859
                    Marshal.Release(IUnknown);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   860
                }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   861
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   862
                NativeMethods.MAPIUninitialize();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   863
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   864
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   865
            return result;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   866
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   867
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   868
        /// <summary>
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   869
        /// Converts an error code into a meaningful error message (if available).
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   870
        /// </summary>
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   871
        /// <param name="error">The error code to convert.</param>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
   872
        /// <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
   873
        public static string GetHResultError(int error)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   874
        {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   875
            try
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   876
            {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   877
                foreach (var hResult in Enum.GetValues(typeof(Mapi.HResult)))
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   878
                {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   879
                    if (((int)(uint)hResult) == error)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   880
                    {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   881
                        return Enum.GetName(typeof(Mapi.HResult), hResult);
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   882
                    }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   883
                }
2548
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   884
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   885
                // As backup, return a hex value string
b03230188759 Return hex value if no error code found
Thomas
parents: 2547
diff changeset
   886
                return error.ToString("X2");
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   887
            }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   888
            catch (Exception ex)
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   889
            {
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   890
                Log.Error("GetHResultError: Error getting HResult error. " + ex.ToString());
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   891
            }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   892
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   893
            return null;
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   894
        }
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   895
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   896
        /// <summary>
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   897
        /// Gets a MAPI property value from an Outlook mail item.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   898
        /// </summary>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   899
        /// <param name="omi">The Outlook mail item to get the property value for.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   900
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   901
        /// <returns>The value or null if it doesn't exist or an error occured.</returns>
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   902
        public static object GetMAPIProperty(Outlook.MailItem omi, MapiProperty.MapiProp mapiProperty)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   903
        {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   904
            return Mapi.GetMAPIProperty(omi?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMessage, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   905
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   906
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   907
        /// <summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   908
        /// Gets a MAPI property value from an Outlook folder item.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   909
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   910
        /// <param name="omi">The Outlook folder item to get the property value for.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   911
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   912
        /// <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
   913
        public static object GetMAPIProperty(Outlook.Folder folder, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   914
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   915
            return Mapi.GetMAPIProperty(folder?.MAPIOBJECT, Mapi.MAPIInterfaceIds.IMAPIFolder, mapiProperty);
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   916
        }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   917
2544
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   918
        /// <summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   919
        /// Gets the specified MAPI property value for this store.
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   920
        /// </summary>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   921
        /// <param name="store">The Outlook store to process with.</param>
62e8b0fc8e78 Use property accessor to get store MAPI property
Thomas
parents: 2513
diff changeset
   922
        /// <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
   923
        /// <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
   924
        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
   925
        {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   926
            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
   927
        }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2505
diff changeset
   928
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   929
        /// <summary>
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
   930
        /// Gets a MAPI property value from an Outlook item.
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   931
        /// </summary>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   932
        /// <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
   933
        /// <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
   934
        /// has to match the type of the mapiObject parameter.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   935
        /// <param name="mapiProperty">The MAPI property to get its value.</param>
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   936
        /// <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
   937
        private static object GetMAPIProperty(object mapiObject, string mapiInterfaceId, MapiProperty.MapiProp mapiProperty)
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   938
        {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   939
            // Check passed parameters
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   940
            if ((mapiObject == null) ||
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   941
                (string.IsNullOrEmpty(mapiInterfaceId)))
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   942
            {
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   943
                Log.Error("GetMAPIProperty: MAPI object oder interface id is null. Returning null.");
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   944
                return null;
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   945
            }
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   946
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   947
            object propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   948
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   949
            // Pointer to IUnknown interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   950
            IntPtr IUnknown = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   951
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   952
            // Pointer to IMessage, IMAPIFolder etc. interface
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   953
            IntPtr IMAPIObject = IntPtr.Zero;
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   954
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   955
            // Pointer to IMAPIProp interface
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   956
            IntPtr IMAPIProp = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   957
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   958
            // Structure that will hold the property value
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   959
            Mapi.SPropValue sPropValue;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   960
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   961
            // A pointer that points to the SPropValue structure 
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   962
            IntPtr ptrPropValue = IntPtr.Zero;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   963
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   964
            try
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   965
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   966
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   967
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   968
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   969
                // Get the IUnknown interface from the MAPI object
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   970
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   971
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   972
                // Set the MAPI object interface GUID that we pass to retrieve the IMessage interface.
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   973
                Guid guidIMessage = new Guid(mapiInterfaceId);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   974
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
   975
                // Try to retrieve the MAPI object interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   976
                if (Marshal.QueryInterface(IUnknown, ref guidIMessage, out IMAPIObject) != (uint)Mapi.HResult.S_OK)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   977
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   978
                    Log.Error("GetMAPIProperty: Could not retrieve IMessage interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   979
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   980
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   981
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   982
                // Set the IMAPIProp interface GUID that we pass to retrieve the IMAPIProp Interface.
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   983
                Guid guidIMAPIProp = new Guid(Mapi.MAPIInterfaceIds.IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   984
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   985
                // Try to retrieve the IMAPIProp interface
2547
0a81e858680c Provide method to return meaningful MAPI errors
Thomas
parents: 2546
diff changeset
   986
                if ((Marshal.QueryInterface(IMAPIObject, ref guidIMAPIProp, out IMAPIProp) != (uint)Mapi.HResult.S_OK) ||
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   987
                    (IMAPIProp == IntPtr.Zero))
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   988
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   989
                    Log.Error("GetMAPIProperty: Could not retrieve IMAPIProp interface. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   990
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   991
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   992
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   993
                // Try to get the property
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
   994
                NativeMethods.HrGetOneProp(IMAPIProp, mapiProperty.Tag, out ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   995
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   996
                if (ptrPropValue == IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   997
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   998
                    Log.Error("GetMAPIProperty: Could not retrieve pointer to property value. Returning null.");
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
   999
                    return null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1000
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1001
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1002
                // Get the SPropValue structure
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1003
                sPropValue = (SPropValue)Marshal.PtrToStructure(ptrPropValue, typeof(SPropValue));
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1004
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1005
                // Convert the retrieved value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1006
                propertyValue = Mapi.ConvertSPropValueToObject(mapiProperty, sPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1007
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1008
            catch (Exception ex)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1009
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1010
                propertyValue = null;
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1011
                Log.Error("GetMAPIProperty: Error occured. " + ex.ToString());
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1012
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1013
            finally
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1014
            {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1015
                // Free used memory structures
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1016
                if (ptrPropValue != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1017
                {
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1018
                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1019
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1020
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1021
                // Clean up all references to COM Objects
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1022
                if (IMAPIProp != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1023
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1024
                    Marshal.Release(IMAPIProp);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1025
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1026
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
  1027
                if (IMAPIObject != IntPtr.Zero)
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1028
                {
2482
57c1ae205c92 Extend Mapi properties methods
Thomas
parents: 2401
diff changeset
  1029
                    Marshal.Release(IMAPIObject);
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1030
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1031
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1032
                if (IUnknown != IntPtr.Zero)
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1033
                {
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1034
                    Marshal.Release(IUnknown);
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1035
                }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1036
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1037
                NativeMethods.MAPIUninitialize();
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1038
            }
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1039
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1040
            return propertyValue;
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1041
        }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1042
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1043
        /// <summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1044
        /// Gets a set of MAPI property values from an Outlook item.
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1045
        /// </summary>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1046
        /// <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
  1047
        /// <param name="mapiProperties">The MAPI properties to get their values for.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1048
        /// <param name="propertyValues">The retrieved values.</param>
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1049
        /// <returns>The error code returned by IMAPIProp::GetProps or 0 if no error occured.</returns>
2558
ac168942503e Renaming
Thomas
parents: 2555
diff changeset
  1050
        internal static int GetMAPIProperties(object mapiObject, List<MapiProperty.MapiProp> mapiProperties, out MAPIProperties propertyValues)
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1051
        {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1052
            int result = (int)Mapi.HResult.S_FALSE;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1053
            propertyValues = null;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1054
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1055
            // Get MAPI object from mail item
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1056
            if (mapiObject == null)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1057
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1058
                Log.Error("GetMAPIProperties: MAPI object is null. Property could not be set.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1059
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1060
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1061
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1062
            // Check if we actually have some properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1063
            int propertiesCount = mapiProperties.Count;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1064
            if (propertiesCount < 1)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1065
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1066
                Log.Error("GetMAPIProperties: No properties found.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1067
                return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1068
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1069
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1070
            // Pointer to IUnknown interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1071
            IntPtr IUnknown = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1072
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1073
            // Pointer to the MAPI properties array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1074
            IntPtr propTagArray = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1075
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1076
            // Pointer to the value
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1077
            IntPtr valuePtr = IntPtr.Zero;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1078
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1079
            try
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1080
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1081
                // Initialize MAPI
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1082
                NativeMethods.MAPIInitialize(IntPtr.Zero);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1083
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1084
                // Get the IUnknown interface from the MAPI object
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1085
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1086
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1087
                // Get the IMAPIProp interface
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1088
                Mapi.IMAPIProp IMAPIProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1089
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1090
                // Create the SPropValue structure
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1091
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1092
                int propValueSize = Marshal.SizeOf(sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1093
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1094
                // Allocate memory for the array of SPropValues to set
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1095
                propTagArray = Marshal.AllocHGlobal(propValueSize * propertiesCount);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1096
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1097
                // Create the property values array
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1098
                uint[] propertyTags = new uint[propertiesCount + 1];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1099
                propertyTags[0] = (uint)propertiesCount;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1100
                for (int i = 0; i < propertiesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1101
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1102
                    propertyTags[i + 1] = (uint)mapiProperties[i].Tag;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1103
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1104
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1105
                // Get properties
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1106
                result = IMAPIProp.GetProps(propertyTags, Mapi.MAPI_UNICODE, out uint valuesCount, out IntPtr propArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1107
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1108
                // Convert the retrieved values
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1109
                object[] values = new object[valuesCount];
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1110
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1111
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1112
                    sPropValue = (SPropValue)Marshal.PtrToStructure((propArray + (i * propValueSize)), typeof(SPropValue));
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1113
                    values[i] = Mapi.ConvertSPropValueToObject(mapiProperties[i], sPropValue);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1114
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1115
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1116
                // Check if returned values match properties count
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1117
                if (propertiesCount != valuesCount)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1118
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1119
                    Log.Error("GetMAPIProperties: Properties count doesn't match values count.");
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1120
                    return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1121
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1122
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1123
                // Create return dictionary
2558
ac168942503e Renaming
Thomas
parents: 2555
diff changeset
  1124
                propertyValues = new MAPIProperties();
2546
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1125
                for (int i = 0; i < valuesCount; i++)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1126
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1127
                    propertyValues.Add(mapiProperties[i], values[i]);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1128
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1129
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1130
            catch (Exception ex)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1131
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1132
                Log.Error("SetMAPIProperties: Error occured. " + ex.ToString());
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1133
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1134
            finally
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1135
            {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1136
                if (IUnknown != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1137
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1138
                    Marshal.Release(IUnknown);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1139
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1140
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1141
                if (propTagArray != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1142
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1143
                    Marshal.FreeHGlobal(propTagArray);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1144
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1145
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1146
                if (valuePtr != IntPtr.Zero)
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1147
                {
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1148
                    Marshal.FreeHGlobal(valuePtr);
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1149
                }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1150
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1151
                NativeMethods.MAPIUninitialize();
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1152
            }
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1153
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1154
            return result;
19b771109681 Add GetMAPIProperties method
Thomas
parents: 2544
diff changeset
  1155
        }
2368
53cbaf41e57c Add GetMAPIProperty method
Thomas
parents: 2354
diff changeset
  1156
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1157
        /// <summary>
2550
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1158
        /// 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
  1159
        /// 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
  1160
        /// is a set of property value pairs returned for the table row.
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1161
        /// This code is based on Fred Song's Managed MAPI: 
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1162
        /// 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
  1163
        /// </summary>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1164
        /// <param name="mapiTable">The table to query its rows.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1165
        /// <param name="rowCount">The maximum count of rows to query.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1166
        /// <param name="values">The returned values.</param>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1167
        /// <returns>The status code of the IMAPITable.QueryRows method.</returns>
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1168
        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
  1169
        {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1170
            IntPtr pRowSet = IntPtr.Zero;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1171
            properties = null;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1172
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1173
            int status = mapiTable.QueryRows(rowCount, 0, out pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1174
            if (status != (uint)Mapi.HResult.S_OK)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1175
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1176
                NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1177
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1178
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1179
            uint cRows = (uint)Marshal.ReadInt32(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1180
            if (cRows < 1)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1181
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1182
                NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1183
                return status;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1184
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1185
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1186
            int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1187
            int sizeOfSRow = 2 * intSize + pIntSize;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1188
            IntPtr rows = pRowSet + intSize;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1189
            properties = new List<Dictionary<uint, object>>();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1190
            for (int i = 0; i < cRows; i++)
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1191
            {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1192
                IntPtr pRowOffset = rows + i * sizeOfSRow;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1193
                uint cValues = (uint)Marshal.ReadInt32(pRowOffset + pIntSize);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1194
                IntPtr pProps = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1195
                
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1196
                int size =  Marshal.SizeOf(typeof(SPropValue));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1197
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1198
                Dictionary<uint, object> propValues = new Dictionary<uint, object>();
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1199
                for (int j = 0; j < cValues; j++) // each column
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1200
                {
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1201
                    SPropValue lpProp = (SPropValue)Marshal.PtrToStructure((pProps + (j * size)), typeof(SPropValue));
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1202
                    propValues.Add(lpProp.PropTag, lpProp.Value);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1203
                }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1204
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1205
                properties.Add(propValues);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1206
            }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1207
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1208
            NativeMethods.MAPIFreeBuffer(pRowSet);
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1209
            return status;
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1210
        }
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1211
80e3f982663e Add methods to get IMAPITable properties
Thomas
parents: 2548
diff changeset
  1212
        /// <summary>
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1213
        /// Sets the given MAPI properties on the Outlook mail item.
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1214
        /// 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
  1215
        /// 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
  1216
        /// required data type for each MAPI property.
2354
e5b26ee3c384 Set SmartNoAttach MAPI property after decryption if needed
Thomas
parents: 2353
diff changeset
  1217
        /// Do not call this method from a background thread!
2353
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1218
        /// </summary>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1219
        /// <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
  1220
        /// <param name="mapiProperties">The MAPI properties to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1221
        /// <param name="values">The values to set.</param>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1222
        /// <returns>True if the method succeeds, otherwise false.</returns>
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1223
        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
  1224
        {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1225
            // The return status of this method
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1226
            bool success = false;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1227
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1228
            // Pointer to IUnknown interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1229
            IntPtr IUnknown = IntPtr.Zero;
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
            // Pointer to the MAPI properties array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1232
            IntPtr propArray = IntPtr.Zero;
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
            // Pointer to the value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1235
            IntPtr valuePtr = IntPtr.Zero;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1236
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1237
            // Get MAPI object from mail item
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1238
            object mapiObject = omi?.MAPIOBJECT;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1239
            if (mapiObject == null)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1240
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1241
                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
  1242
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1243
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1244
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1245
            // Make sure the properties count matches the values count
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1246
            int propCount = mapiProperties.Length;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1247
            if (propCount != values.Length)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1248
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1249
                Log.Error("SetMAPIProperties: Mismatch between tag count and value count.");
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1250
                return success;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1251
            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1252
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1253
            try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1254
            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1255
                // Initialize MAPI
2401
86384b7195bb Get rid of some warnings
Thomas
parents: 2370
diff changeset
  1256
                NativeMethods.MAPIInitialize(IntPtr.Zero);
2353
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
                // Get the IUnknown interface from the MAPI object
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1259
                IUnknown = Marshal.GetIUnknownForObject(mapiObject);
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
                // Get the IMAPIProp interface
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1262
                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
  1263
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1264
                // Create the SPropValue structure
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1265
                Mapi.SPropValue sPropValue = new Mapi.SPropValue();
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1266
                var propValueSize = Marshal.SizeOf(sPropValue);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1267
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1268
                // Allocate memory for the array of SPropValues to set
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1269
                propArray = Marshal.AllocHGlobal(propValueSize * propCount);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1270
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1271
                // Create the property values array
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1272
                for (int i = 0; i < propCount; i++)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1273
                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1274
                    // Get the current property/value pair
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1275
                    MapiProperty.MapiProp mapiProperty = mapiProperties[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1276
                    uint tag = mapiProperty.Tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1277
                    object value = values[i];
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1278
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1279
                    // Set the property value's property tag
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1280
                    sPropValue.PropTag = (uint)tag;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1281
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1282
                    // Set the property value's value
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1283
                    switch (mapiProperty.DataType)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1284
                    {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1285
                        case MapiProperty.MapiDataType.PtypBoolean:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1286
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1287
                                try
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
                                    sPropValue.Value.b = (ushort)Convert.ToInt16((bool)value);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1290
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1291
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1292
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1293
                                    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
  1294
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1295
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1296
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1297
                        case MapiProperty.MapiDataType.PtypString:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1298
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1299
                                try
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
                                    valuePtr = Marshal.StringToHGlobalUni(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1302
                                    sPropValue.Value.lpszW = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1303
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1304
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1305
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1306
                                    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
  1307
                                }
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
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1310
                        case MapiProperty.MapiDataType.PtypString8:
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
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1313
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1314
                                    valuePtr = Marshal.StringToHGlobalAnsi(value as string);
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1315
                                    sPropValue.Value.lpszA = valuePtr;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1316
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1317
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1318
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1319
                                    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
  1320
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1321
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1322
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1323
                        case MapiProperty.MapiDataType.PtypInteger16:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1324
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1325
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1326
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1327
                                    sPropValue.Value.i = (short)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1328
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1329
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1330
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1331
                                    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
  1332
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1333
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1334
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1335
                        case MapiProperty.MapiDataType.PtypInteger32:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1336
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1337
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1338
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1339
                                    sPropValue.Value.l = (int)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1340
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1341
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1342
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1343
                                    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
  1344
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1345
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1346
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1347
                        case MapiProperty.MapiDataType.PtypFloating32:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1348
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1349
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1350
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1351
                                    sPropValue.Value.flt = (float)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1352
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1353
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1354
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1355
                                    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
  1356
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1357
                            }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1358
                            break;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1359
                        case MapiProperty.MapiDataType.PtypFloating64:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1360
                        case MapiProperty.MapiDataType.PtypFloatingTime:
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1361
                            {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1362
                                try
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1363
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1364
                                    sPropValue.Value.at = (double)value;
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1365
                                }
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1366
                                catch (Exception ex)
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1367
                                {
81975e284b07 Add MAPI methods to set properties via p/invoke
Thomas
parents:
diff changeset
  1368
                                    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