Exemplo n.º 1
0
        List <MessageRec> IFolder.EnumerateMessages(EnumerateMessagesFlags emFlags, PropTag[] additionalPtagsToLoad)
        {
            List <MessageRec> result = new List <MessageRec>();

            if (!this.Folder.IsContentAvailable)
            {
                return(result);
            }
            ContentsTableFlags[] array = new ContentsTableFlags[]
            {
                ContentsTableFlags.None,
                ContentsTableFlags.Associated,
                ContentsTableFlags.ShowSoftDeletes,
                ContentsTableFlags.ShowSoftDeletes | ContentsTableFlags.Associated
            };
            ContentsTableFlags[] array2 = new ContentsTableFlags[]
            {
                ContentsTableFlags.None,
                ContentsTableFlags.Associated
            };
            ContentsTableFlags[] array3 = (this.Folder.MapiStore.VersionMajor < 15) ? array : array2;
            for (int i = 0; i < array3.Length; i++)
            {
                ContentsTableFlags flags = ContentsTableFlags.DeferredErrors | array3[i];
                bool doingFAI            = (flags & ContentsTableFlags.Associated) != ContentsTableFlags.None;
                bool doingDeletes        = (flags & ContentsTableFlags.ShowSoftDeletes) != ContentsTableFlags.None;
                if ((emFlags & ((!doingDeletes || 2 != 0) ? EnumerateMessagesFlags.RegularMessages : ((EnumerateMessagesFlags)0))) != (EnumerateMessagesFlags)0)
                {
                    List <PropTag> pta               = new List <PropTag>(5);
                    int            idxEntryId        = -1;
                    int            idxCreationTime   = -1;
                    int            idxMessageClass   = -1;
                    int            idxRuleMsgVersion = -1;
                    int            idxMessageSize    = -1;
                    idxEntryId = pta.Count;
                    pta.Add(PropTag.EntryId);
                    if ((emFlags & EnumerateMessagesFlags.IncludeExtendedData) != (EnumerateMessagesFlags)0)
                    {
                        idxMessageSize = pta.Count;
                        pta.Add(PropTag.MessageSize);
                        idxCreationTime = pta.Count;
                        pta.Add(PropTag.CreationTime);
                    }
                    if (doingFAI)
                    {
                        idxMessageClass = pta.Count;
                        pta.Add(PropTag.MessageClass);
                        idxRuleMsgVersion = pta.Count;
                        pta.Add(PropTag.RuleMsgVersion);
                    }
                    int idxExtraPtags = pta.Count;
                    if (additionalPtagsToLoad != null)
                    {
                        pta.AddRange(additionalPtagsToLoad);
                    }
                    MrsTracer.Provider.Debug("MapiFolder.GetContentsTable({0})", new object[]
                    {
                        flags
                    });
                    ExecutionContext.Create(new DataContext[]
                    {
                        new OperationDataContext("MapiFolder.GetContentsTable", OperationType.None),
                        new SimpleValueDataContext("Flags", flags)
                    }).Execute(delegate
                    {
                        int lcidValue = (!doingFAI && this.contentsRestriction != null) ? this.contentsRestriction.LCID : 0;
                        MapiTable contentsTable;
                        using (this.Mailbox.RHTracker.Start())
                        {
                            contentsTable = this.Folder.GetContentsTable(flags);
                        }
                        using (contentsTable)
                        {
                            using (new SortLCIDContext(this.Folder.MapiStore, lcidValue))
                            {
                                Restriction restriction = null;
                                if (!doingFAI && this.contentsRestriction != null)
                                {
                                    restriction = DataConverter <RestrictionConverter, Restriction, RestrictionData> .GetNative(this.contentsRestriction);
                                }
                                MapiUtils.InitQueryAllRows(contentsTable, restriction, pta);
                                for (;;)
                                {
                                    PropValue[][] array4;
                                    using (this.Mailbox.RHTracker.Start())
                                    {
                                        array4 = contentsTable.QueryRows(1000);
                                    }
                                    if (array4.GetLength(0) == 0)
                                    {
                                        break;
                                    }
                                    MrsTracer.Provider.Debug("QueryRows returned {0} items.", new object[]
                                    {
                                        array4.Length
                                    });
                                    PropValue[][] array5 = array4;
                                    int j = 0;
                                    while (j < array5.Length)
                                    {
                                        PropValue[] array6 = array5[j];
                                        if (!doingFAI)
                                        {
                                            goto IL_1F9;
                                        }
                                        string @string = array6[idxMessageClass].GetString();
                                        if ((this.Mailbox.Options & MailboxOptions.IgnoreExtendedRuleFAIs) != MailboxOptions.None)
                                        {
                                            if (!StringComparer.OrdinalIgnoreCase.Equals(@string, "IPM.Rule.Message") && !StringComparer.OrdinalIgnoreCase.Equals(@string, "IPM.Rule.Version2.Message"))
                                            {
                                                if (!StringComparer.OrdinalIgnoreCase.Equals(@string, "IPM.ExtendedRule.Message"))
                                                {
                                                    goto IL_1F9;
                                                }
                                            }
                                        }
                                        else if (!StringComparer.OrdinalIgnoreCase.Equals(@string, "IPM.Rule.Message") || array6[idxRuleMsgVersion].GetInt(0) != 1)
                                        {
                                            goto IL_1F9;
                                        }
                                        IL_423:
                                        j++;
                                        continue;
                                        IL_1F9:
                                        DateTime dateTime = (idxCreationTime != -1) ? MapiUtils.GetDateTimeOrDefault(array6[idxCreationTime]) : DateTime.MinValue;
                                        byte[] bytes      = array6[idxEntryId].GetBytes();
                                        if (emFlags.HasFlag(EnumerateMessagesFlags.SkipICSMidSetMissing) && bytes != null && this.Mailbox.SupportsSavingSyncState)
                                        {
                                            SyncContentsManifestState syncContentsManifestState = this.Mailbox.SyncState[this.FolderId];
                                            if (syncContentsManifestState != null && !syncContentsManifestState.IdSetGivenContainsEntryId(bytes))
                                            {
                                                MrsTracer.Provider.Debug("entry id {0} with creation time {1} not found in given items.", new object[]
                                                {
                                                    TraceUtils.DumpEntryId(bytes),
                                                    dateTime
                                                });
                                                goto IL_423;
                                            }
                                        }
                                        List <PropValueData> list = null;
                                        if (additionalPtagsToLoad != null && additionalPtagsToLoad.Length > 0)
                                        {
                                            list = new List <PropValueData>();
                                            for (int k = idxExtraPtags; k < array6.Length; k++)
                                            {
                                                list.Add(DataConverter <PropValueConverter, PropValue, PropValueData> .GetData(array6[k]));
                                            }
                                        }
                                        if ((emFlags & EnumerateMessagesFlags.ReturnLongTermIDs) == EnumerateMessagesFlags.ReturnLongTermIDs && bytes != null)
                                        {
                                            if (list == null)
                                            {
                                                list = new List <PropValueData>();
                                            }
                                            list.Add(new PropValueData(PropTag.LTID, this.Mailbox.MapiStore.GlobalIdFromId(this.Mailbox.MapiStore.GetMidFromMessageEntryId(bytes))));
                                        }
                                        MsgRecFlags msgRecFlags = doingFAI ? MsgRecFlags.Associated : MsgRecFlags.None;
                                        if (doingDeletes)
                                        {
                                            msgRecFlags |= MsgRecFlags.Deleted;
                                        }
                                        MessageRec item = new MessageRec(bytes, this.FolderId, dateTime, (idxMessageSize != -1) ? array6[idxMessageSize].GetInt(1000) : 1000, msgRecFlags, (list == null) ? null : list.ToArray());
                                        result.Add(item);
                                        goto IL_423;
                                    }
                                }
                            }
                        }
                    });
                }
            }
            MrsTracer.Provider.Debug("MapiFolder.EnumerateMessages returns {0} items.", new object[]
            {
                result.Count
            });
            return(result);
        }
Exemplo n.º 2
0
        List <MessageRec> IFolder.LookupMessages(PropTag ptagToLookup, List <byte[]> keysToLookup, PropTag[] additionalPtagsToLoad)
        {
            EntryIdMap <MessageRec> result = new EntryIdMap <MessageRec>();

            ContentsTableFlags[] array = new ContentsTableFlags[]
            {
                ContentsTableFlags.None,
                ContentsTableFlags.Associated
            };
            List <PropTag> pta        = new List <PropTag>(5);
            int            idxEntryId = pta.Count;

            pta.Add(PropTag.EntryId);
            int idxMessageSize = pta.Count;

            pta.Add(PropTag.MessageSize);
            int idxCreationTime = pta.Count;

            pta.Add(PropTag.CreationTime);
            int idxExtraPtags = pta.Count;

            if (additionalPtagsToLoad != null)
            {
                pta.AddRange(additionalPtagsToLoad);
            }
            for (int i = 0; i < array.Length; i++)
            {
                if (result.Count >= keysToLookup.Count)
                {
                    break;
                }
                ContentsTableFlags flags = ContentsTableFlags.DeferredErrors | array[i];
                bool doingFAI            = (flags & ContentsTableFlags.Associated) != ContentsTableFlags.None;
                ExecutionContext.Create(new DataContext[]
                {
                    new OperationDataContext("MapiFolder.GetContentsTable", OperationType.None),
                    new SimpleValueDataContext("Flags", flags)
                }).Execute(delegate
                {
                    MapiTable msgTable;
                    using (this.Mailbox.RHTracker.Start())
                    {
                        msgTable = this.Folder.GetContentsTable(flags);
                    }
                    using (msgTable)
                    {
                        if (ptagToLookup != PropTag.EntryId)
                        {
                            using (this.Mailbox.RHTracker.Start())
                            {
                                msgTable.SortTable(new SortOrder(ptagToLookup, SortFlags.Ascend), SortTableFlags.None);
                            }
                        }
                        msgTable.SetColumns(pta);
                        using (List <byte[]> .Enumerator enumerator = keysToLookup.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                byte[] key = enumerator.Current;
                                if (!result.ContainsKey(key))
                                {
                                    ExecutionContext.Create(new DataContext[]
                                    {
                                        new EntryIDsDataContext(key)
                                    }).Execute(delegate
                                    {
                                        try
                                        {
                                            using (this.Mailbox.RHTracker.Start())
                                            {
                                                if (!msgTable.FindRow(Restriction.EQ(ptagToLookup, key), BookMark.Beginning, FindRowFlag.None))
                                                {
                                                    return;
                                                }
                                            }
                                        }
                                        catch (MapiExceptionNotFound)
                                        {
                                            return;
                                        }
                                        PropValue[][] array2;
                                        using (this.Mailbox.RHTracker.Start())
                                        {
                                            array2 = msgTable.QueryRows(1);
                                        }
                                        if (array2.Length == 1)
                                        {
                                            PropValue[] array3 = array2[0];
                                            if (array3.Length != pta.Count)
                                            {
                                                return;
                                            }
                                            PropValueData[] array4 = null;
                                            if (additionalPtagsToLoad != null && additionalPtagsToLoad.Length > 0)
                                            {
                                                array4 = new PropValueData[additionalPtagsToLoad.Length];
                                                for (int j = idxExtraPtags; j < array3.Length; j++)
                                                {
                                                    array4[j - idxExtraPtags] = DataConverter <PropValueConverter, PropValue, PropValueData> .GetData(array3[j]);
                                                }
                                            }
                                            MessageRec value = new MessageRec(array3[idxEntryId].GetBytes(), this.FolderId, MapiUtils.GetDateTimeOrDefault(array3[idxCreationTime]), array3[idxMessageSize].GetInt(1000), doingFAI ? MsgRecFlags.Associated : MsgRecFlags.None, array4);
                                            result.Add(key, value);
                                            return;
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
            }
            MrsTracer.Provider.Debug("MapiFolder.LookupMessages returns {0} items.", new object[]
            {
                result.Count
            });
            return(new List <MessageRec>(result.Values));
        }