예제 #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);
        }
예제 #2
0
        List <MessageRec> IFolder.EnumerateMessages(EnumerateMessagesFlags emFlags, PropTag[] additionalPtagsToLoad)
        {
            MrsTracer.Provider.Function("StorageFolder.EnumerateMessages: {0}", new object[]
            {
                this.DisplayNameForTracing
            });
            List <MessageRec> result = new List <MessageRec>();

            ItemQueryType[] array = new ItemQueryType[]
            {
                ItemQueryType.None,
                ItemQueryType.Associated
            };
            for (int i = 0; i < array.Length; i++)
            {
                ItemQueryType flags        = array[i];
                bool          doingFAI     = (flags & ItemQueryType.Associated) != ItemQueryType.None;
                bool          doingDeletes = (flags & ItemQueryType.SoftDeleted) != ItemQueryType.None;
                if ((emFlags & ((!doingDeletes || 2 != 0) ? EnumerateMessagesFlags.RegularMessages : ((EnumerateMessagesFlags)0))) != (EnumerateMessagesFlags)0)
                {
                    List <NativeStorePropertyDefinition> dataColumns = new List <NativeStorePropertyDefinition>(5);
                    int idxEntryId        = -1;
                    int idxCreationTime   = -1;
                    int idxMessageClass   = -1;
                    int idxRuleMsgVersion = -1;
                    int idxMessageSize    = -1;
                    idxEntryId = dataColumns.Count;
                    dataColumns.Add(this.Mailbox.ConvertPropTagsToDefinitions(new PropTag[]
                    {
                        PropTag.EntryId
                    })[0]);
                    if ((emFlags & EnumerateMessagesFlags.IncludeExtendedData) != (EnumerateMessagesFlags)0)
                    {
                        idxMessageSize = dataColumns.Count;
                        dataColumns.Add(this.Mailbox.ConvertPropTagsToDefinitions(new PropTag[]
                        {
                            PropTag.MessageSize
                        })[0]);
                        idxCreationTime = dataColumns.Count;
                        dataColumns.Add(this.Mailbox.ConvertPropTagsToDefinitions(new PropTag[]
                        {
                            PropTag.CreationTime
                        })[0]);
                    }
                    if (doingFAI)
                    {
                        idxMessageClass = dataColumns.Count;
                        dataColumns.Add(this.Mailbox.ConvertPropTagsToDefinitions(new PropTag[]
                        {
                            PropTag.MessageClass
                        })[0]);
                        idxRuleMsgVersion = dataColumns.Count;
                        dataColumns.Add(this.Mailbox.ConvertPropTagsToDefinitions(new PropTag[]
                        {
                            PropTag.RuleMsgVersion
                        })[0]);
                    }
                    int idxExtraPtags = dataColumns.Count;
                    if (additionalPtagsToLoad != null)
                    {
                        dataColumns.AddRange(this.Mailbox.ConvertPropTagsToDefinitions(additionalPtagsToLoad));
                    }
                    MrsTracer.Provider.Debug("StorageFolder.GetContentsTable({0})", new object[]
                    {
                        flags
                    });
                    ExecutionContext.Create(new DataContext[]
                    {
                        new OperationDataContext("StorageFolder.EnumerateMessages", OperationType.None),
                        new SimpleValueDataContext("Flags", flags)
                    }).Execute(delegate
                    {
                        QueryFilter queryFilter = null;
                        if (this.contentsRestriction != null)
                        {
                            queryFilter = this.contentsRestriction.GetQueryFilter(this.Mailbox.StoreSession);
                        }
                        using (QueryResult queryResult = this.CoreFolder.QueryExecutor.ItemQuery(flags, queryFilter, null, dataColumns.ToArray()))
                        {
                            MrsTracer.Provider.Debug("StorageFolder.EnumerateMessages: ItemQuery returned {0} items.", new object[]
                            {
                                queryResult.EstimatedRowCount
                            });
                            object[][] rows;
                            do
                            {
                                using (this.Mailbox.RHTracker.Start())
                                {
                                    rows = queryResult.GetRows(1000);
                                }
                                object[][] array2 = rows;
                                int j             = 0;
                                while (j < array2.Length)
                                {
                                    object[] array3 = array2[j];
                                    if (!doingFAI)
                                    {
                                        goto IL_197;
                                    }
                                    string x = (string)array3[idxMessageClass];
                                    if ((this.Mailbox.Options & MailboxOptions.IgnoreExtendedRuleFAIs) != MailboxOptions.None)
                                    {
                                        if (!StringComparer.OrdinalIgnoreCase.Equals(x, "IPM.Rule.Message") && !StringComparer.OrdinalIgnoreCase.Equals(x, "IPM.Rule.Version2.Message"))
                                        {
                                            if (!StringComparer.OrdinalIgnoreCase.Equals(x, "IPM.ExtendedRule.Message"))
                                            {
                                                goto IL_197;
                                            }
                                        }
                                    }
                                    else if (!StringComparer.OrdinalIgnoreCase.Equals(x, "IPM.Rule.Message") || !(array3[idxRuleMsgVersion] as short? == 1))
                                    {
                                        goto IL_197;
                                    }
                                    IL_3E6:
                                    j++;
                                    continue;
                                    IL_197:
                                    DateTime dateTime = DateTime.MinValue;
                                    if (idxCreationTime != -1)
                                    {
                                        object obj = array3[idxCreationTime];
                                        if (obj is ExDateTime)
                                        {
                                            dateTime = (DateTime)((ExDateTime)obj);
                                        }
                                    }
                                    byte[] entryId = (byte[])array3[idxEntryId];
                                    if (emFlags.HasFlag(EnumerateMessagesFlags.SkipICSMidSetMissing) && this.Mailbox.SupportsSavingSyncState)
                                    {
                                        SyncContentsManifestState syncContentsManifestState = this.Mailbox.SyncState[this.FolderId];
                                        if (syncContentsManifestState != null && !syncContentsManifestState.IdSetGivenContainsEntryId(entryId))
                                        {
                                            MrsTracer.Provider.Debug("entry id {0} with creation time {1} not found in given items.", new object[]
                                            {
                                                TraceUtils.DumpEntryId(entryId),
                                                dateTime
                                            });
                                            goto IL_3E6;
                                        }
                                    }
                                    List <PropValueData> list = null;
                                    if (additionalPtagsToLoad != null && additionalPtagsToLoad.Length > 0)
                                    {
                                        list = new List <PropValueData>();
                                        for (int k = idxExtraPtags; k < array3.Length; k++)
                                        {
                                            list.Add(new PropValueData(additionalPtagsToLoad[k - idxExtraPtags], array3[k]));
                                        }
                                    }
                                    int messageSize = 1000;
                                    if (idxMessageSize != -1)
                                    {
                                        object obj2 = array3[idxMessageSize];
                                        if (obj2 is int)
                                        {
                                            messageSize = (int)obj2;
                                        }
                                    }
                                    if (emFlags.HasFlag(EnumerateMessagesFlags.ReturnLongTermIDs))
                                    {
                                        if (list == null)
                                        {
                                            list = new List <PropValueData>();
                                        }
                                        list.Add(new PropValueData(PropTag.LTID, this.Mailbox.StoreSession.IdConverter.GetLongTermIdFromId(this.Mailbox.StoreSession.IdConverter.GetMidFromMessageId(StoreObjectId.FromProviderSpecificId(entryId)))));
                                    }
                                    MsgRecFlags msgRecFlags = doingFAI ? MsgRecFlags.Associated : MsgRecFlags.None;
                                    if (doingDeletes)
                                    {
                                        msgRecFlags |= MsgRecFlags.Deleted;
                                    }
                                    MessageRec item = new MessageRec(entryId, this.FolderId, dateTime, messageSize, msgRecFlags, (list == null) ? null : list.ToArray());
                                    result.Add(item);
                                    goto IL_3E6;
                                }
                            }while (rows.Length > 0);
                        }
                    });
                }
            }
            MrsTracer.Provider.Debug("StorageFolder.EnumerateMessages returns {0} items.", new object[]
            {
                result.Count
            });
            return(result);
        }