Пример #1
0
        internal void ProcessSentItemWrapperMessage(EmailMessage message, string mdbGuid, MessageItem replayItem, IStoreOperations storeOperations, IAgentInfoWriter agentInfo)
        {
            if (!this.IsSharedMailboxSentItemMessage(message, agentInfo))
            {
                return;
            }
            IPerformanceCounters counterInstance = this.perfCountersFactory.GetCounterInstance(mdbGuid);
            bool flag = true;

            try
            {
                MessageItem attachedMessageItem = this.GetAttachedMessageItem(replayItem, agentInfo);
                if (attachedMessageItem == null)
                {
                    this.logger.TraceDebug(new string[]
                    {
                        "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Message has the correct header tags but does not contain the original email attachment"
                    });
                }
                else
                {
                    string text = attachedMessageItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                    if (text != null && storeOperations.MessageExistsInSentItems(text))
                    {
                        this.logger.TraceDebug(new string[]
                        {
                            "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: message already exits in the sent items folder. Don't have to copy."
                        });
                    }
                    else
                    {
                        this.logger.TraceDebug(new string[]
                        {
                            "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Get the sent items folder Id."
                        });
                        storeOperations.CopyAttachmentToSentItemsFolder(attachedMessageItem);
                        this.UpdateAverageSentItemCopyTimePerfCounter(attachedMessageItem, counterInstance);
                        counterInstance.IncrementSentItemsMessages();
                    }
                }
            }
            catch (StorageTransientException ex)
            {
                flag = false;
                counterInstance.IncrementErrors();
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler encountered an exception: ",
                    ex.ToString()
                });
                this.logger.LogEvent(MailboxTransportEventLogConstants.Tuple_SharedMailboxSentItemsAgentException, ex);
                throw new SmtpResponseException(SharedMailboxSentItemsAgent.CopyFailedTransientError);
            }
            catch (Exception ex2)
            {
                flag = false;
                counterInstance.IncrementErrors();
                if (ex2 is OutOfMemoryException || ex2 is StackOverflowException || ex2 is ThreadAbortException)
                {
                    throw;
                }
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler encountered an exception:",
                    ex2.ToString()
                });
                this.logger.LogEvent(MailboxTransportEventLogConstants.Tuple_SharedMailboxSentItemsAgentException, ex2);
                throw new SmtpResponseException(SharedMailboxSentItemsAgent.CopyFailedPermanentError);
            }
            finally
            {
                if (flag)
                {
                    this.logger.TraceDebug(new string[]
                    {
                        "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Copy operation complete. Going to raise success exception to inform delivery service to drop this message."
                    });
                    throw new SmtpResponseException(SharedMailboxSentItemsAgent.SharedMailboxSentItemCopySuccess, "SharedMailboxSentItemsAgent");
                }
            }
        }