Esempio n. 1
0
        public static void ExportMessagesWithBadItemDetection(ISourceMailbox mailbox, List <MessageRec> messages, Func <IFxProxyPool> getProxyPool, ExportMessagesFlags flags, PropTag[] propsToCopyExplicitly, PropTag[] excludeProps, TestIntegration testIntegration, ref List <BadMessageRec> badMessages)
        {
            MrsTracer.Common.Debug("ExportMessagesWithBadItemDetection: Exporting {0} messages", new object[]
            {
                messages.Count
            });
            Exception ex;

            if (MapiUtils.ExportMessageBatch(mailbox, messages, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, out ex))
            {
                return;
            }
            MrsTracer.Common.Warning("ExportMessages failed with a bad item error. Current batch count {0}. Will retry copying messages in smaller batches. {1}", new object[]
            {
                messages.Count,
                CommonUtils.FullExceptionMessage(ex)
            });
            if (messages.Count != 1)
            {
                int num = messages.Count / 2;
                List <MessageRec> list  = new List <MessageRec>(num);
                List <MessageRec> list2 = new List <MessageRec>(messages.Count - num);
                for (int i = 0; i < messages.Count; i++)
                {
                    if (i < num)
                    {
                        list.Add(messages[i]);
                    }
                    else
                    {
                        list2.Add(messages[i]);
                    }
                }
                MapiUtils.ExportMessagesWithBadItemDetection(mailbox, list, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, ref badMessages);
                MapiUtils.ExportMessagesWithBadItemDetection(mailbox, list2, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, ref badMessages);
                return;
            }
            MessageRec messageRec = messages[0];

            MrsTracer.Common.Warning("Single message {0} copy failed. Error {1}", new object[]
            {
                TraceUtils.DumpEntryId(messageRec.EntryId),
                CommonUtils.FullExceptionMessage(ex)
            });
            EntryIdMap <MessageRec> entryIdMap;
            EntryIdMap <FolderRec>  entryIdMap2;

            MapiUtils.LookupBadMessagesInMailbox(mailbox, messages, out entryIdMap, out entryIdMap2);
            MessageRec msgData;

            if (!entryIdMap.TryGetValue(messageRec.EntryId, out msgData))
            {
                badMessages.Add(BadMessageRec.MissingItem(messageRec));
                return;
            }
            DownlevelBadItemsPermanentException ex2 = ex as DownlevelBadItemsPermanentException;

            if (ex2 != null)
            {
                badMessages.Add(ex2.BadItems[0]);
                return;
            }
            FolderRec folderRec = entryIdMap2[messageRec.FolderId];

            badMessages.Add(BadMessageRec.Item(msgData, folderRec, ex));
        }