Example #1
0
        private bool IsSharedMailboxSentItemMessage(EmailMessage message, IAgentInfoWriter agentInfo)
        {
            Header header = message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-SharedMailbox-SentItem-Message");

            if (header == null || string.IsNullOrWhiteSpace(header.Value))
            {
                this.logger.TraceDebug(new string[]
                {
                    "Could not find the expected message header."
                });
                return(false);
            }
            bool flag;

            if (!bool.TryParse(header.Value, out flag) || !flag)
            {
                this.logger.TraceDebug(new string[]
                {
                    "Found the header but the value does not match the expected value. Expected: True, Actual ",
                    header.Value
                });
                return(false);
            }
            string text = "Found the message header with key X-MS-Exchange-SharedMailbox-SentItem-Message value " + header.Value + ". This message will be droped.";

            this.logger.TraceDebug(new string[]
            {
                text
            });
            agentInfo.AddAgentInfo("MessageFlagCheck", text);
            return(true);
        }
Example #2
0
 private MessageItem GetAttachedMessageItem(MessageItem message, IAgentInfoWriter agentInfo)
 {
     foreach (AttachmentHandle handle in message.AttachmentCollection.GetHandles())
     {
         using (Attachment attachment = message.AttachmentCollection.Open(handle))
         {
             ItemAttachment itemAttachment = attachment as ItemAttachment;
             if (itemAttachment != null)
             {
                 return(itemAttachment.GetItemAsMessage());
             }
             string text = "Warning: Message does not contain the expected attachment.";
             this.logger.TraceDebug(new string[]
             {
                 text
             });
             agentInfo.AddAgentInfo("AttachmentCheck", text);
         }
     }
     return(null);
 }
Example #3
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");
                }
            }
        }