Example #1
0
        public static PropValue[][] QueryAllRows(MapiTable msgTable, Restriction restriction, ICollection <PropTag> propTags, int pageSize)
        {
            MapiUtils.InitQueryAllRows(msgTable, restriction, propTags);
            List <PropValue[]> list = new List <PropValue[]>();

            for (;;)
            {
                PropValue[][] array = msgTable.QueryRows(pageSize);
                if (array.GetLength(0) == 0)
                {
                    break;
                }
                list.AddRange(array);
            }
            return(list.ToArray());
        }
Example #2
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);
        }