Пример #1
0
 public static void SBinaryRelease(ref SBinary b)
 {
     if (b.lpb != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(b.lpb);
         b.lpb = IntPtr.Zero;
         b.cb  = 0;
     }
 }
 public static void SBinaryRelease(ref SBinary b)
 {
     if (b.lpb != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(b.lpb);
         b.lpb = IntPtr.Zero;
         b.cb = 0;
     }
 }
Пример #3
0
        public bool CompareEntryIDs(EntryID entryid1, EntryID entryid2)
        {
            SBinary sb1 = SBinary.SBinaryCreate(entryid1.AsByteArray);
            SBinary sb2 = SBinary.SBinaryCreate(entryid2.AsByteArray);
            bool    result;

            session_.CompareEntryIDs(sb1.cb, sb1.lpb, sb2.cb, sb2.lpb, 0, out result);
            SBinary.SBinaryRelease(ref sb1);
            SBinary.SBinaryRelease(ref sb2);
            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the MsgStoreNewMailEventArgs class. 
 /// </summary>
 /// <param name="storeID">The entry identification of message store.</param>
 /// <param name="notification">The new mail notification structure.</param>
 public MsgStoreNewMailEventArgs(EntryID storeID, NEWMAIL_NOTIFICATION notification)
 {
     StoreID = storeID;
     SBinary sbEntry = new SBinary() { cb = notification.cbEntryID, lpb = notification.pEntryID };
     SBinary sbParent = new SBinary() { cb = notification.cbParentID, lpb = notification.pParentID };
     EntryID = sbEntry.cb > 0 ? new EntryID(sbEntry.AsBytes) : null;
     ParentID = sbParent.cb > 0 ? new EntryID(sbParent.AsBytes) : null;
     MessageFlags = (int)notification.MessageFlags;
     if ((notification.Flags & (uint)CharacterSet.UNICODE) == (uint)CharacterSet.UNICODE)
         MessageClass = Marshal.PtrToStringUni(notification.MessageClass);
     else
         MessageClass = Marshal.PtrToStringAnsi(notification.MessageClass);
 }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the MsgStoreNewMailEventArgs class.
        /// </summary>
        /// <param name="storeID">The entry identification of message store.</param>
        /// <param name="notification">The new mail notification structure.</param>
        public MsgStoreNewMailEventArgs(EntryID storeID, NEWMAIL_NOTIFICATION notification)
        {
            StoreID = storeID;
            SBinary sbEntry = new SBinary()
            {
                cb = notification.cbEntryID, lpb = notification.pEntryID
            };
            SBinary sbParent = new SBinary()
            {
                cb = notification.cbParentID, lpb = notification.pParentID
            };

            EntryID      = sbEntry.cb > 0 ? new EntryID(sbEntry.AsBytes) : null;
            ParentID     = sbParent.cb > 0 ? new EntryID(sbParent.AsBytes) : null;
            MessageFlags = (int)notification.MessageFlags;
            if ((notification.Flags & (uint)CharacterSet.UNICODE) == (uint)CharacterSet.UNICODE)
            {
                MessageClass = Marshal.PtrToStringUni(notification.MessageClass);
            }
            else
            {
                MessageClass = Marshal.PtrToStringAnsi(notification.MessageClass);
            }
        }
Пример #6
0
        /// <summary>
        /// Opens a message store.
        /// </summary>
        /// <param name="storeName">store name</param>
        /// <returns>true, if the message store was successfully opened; otherwise, failed.</returns>
        public bool OpenMessageStore(string storeName)
        {
            bool bResult = false;

            try
            {
                if (Content != null)
                {
                    Content.SeekRow(BookMark.BEGINNING, 0);
                    if (Content.SetColumns(new PropTags[] { PropTags.PR_DISPLAY_NAME, PropTags.PR_ENTRYID, PropTags.PR_DEFAULT_STORE }))
                    {
                        SRow[] sRows;
                        while (Content.QueryRows(1, out sRows))
                        {
                            if (sRows.Length != 1)
                            {
                                break;
                            }
                            if (string.IsNullOrEmpty(storeName))
                            {
                                if (sRows[0].propVals[2].AsBool)
                                {
                                    bResult = true;
                                }
                            }
                            else if (sRows[0].propVals[0].AsString.IndexOf(storeName) > -1)
                            {
                                bResult = true;
                            }
                            if (bResult)
                            {
                                break;
                            }
                        }
                        if (bResult)
                        {
                            if (CurrentStore != null)
                            {
                                CurrentStore.Dispose();
                                CurrentStore = null;
                            }
                            SBinary entryId = SBinary.SBinaryCreate(sRows[0].propVals[1].AsBinary);
                            storeName = sRows[0].propVals[0].AsString;
                            IntPtr pStore = IntPtr.Zero;
                            if (session_.OpenMsgStore(0, entryId.cb, entryId.lpb, IntPtr.Zero, (uint)MAPIFlag.BEST_ACCESS, out pStore) == HRESULT.S_OK)
                            {
                                if (pStore != IntPtr.Zero)
                                {
                                    IMsgStore msgStore = Marshal.GetObjectForIUnknown(pStore) as IMsgStore;
                                    CurrentStore = new MessageStore(this, msgStore, new EntryID(entryId.AsBytes), storeName);
                                }
                            }
                            SBinary.SBinaryRelease(ref entryId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            return(bResult);
        }