private void InsertUnsubscribeLinkToBody(IGroupEscalateItemPerformanceTracker performanceTracker, IExtensibleLogger logger, IExchangePrincipal groupExchangePrincipal, IMessageItem originalItem, IMessageItem escalatedMessage) { performanceTracker.UnsubscribeUrlInserted = false; if (!this.groupEscalationFlightInfo.IsGroupEscalationFooterEnabled()) { GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.InsertUnsubscribeLinkToBody: Skipping inserting link as the GroupsDeepLink flight isn't enabled"); return; } GroupEscalationFooter groupEscalationFooter = new GroupEscalationFooter(groupExchangePrincipal.MailboxInfo.DisplayName, this.GetPreferredCulture(groupExchangePrincipal), new EscalationLinkBuilder(groupExchangePrincipal, this.mailboxUrls)); try { bool unsubscribeUrlInserted = groupEscalationFooter.InsertFooterToTheBody(originalItem, escalatedMessage); performanceTracker.UnsubscribeUrlInserted = unsubscribeUrlInserted; } catch (Exception ex) { this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.InsertUnsubscribeLinkToBody: Escalation footer not inserted because of exception:{0}", ex.ToString())); } performanceTracker.BuildUnsubscribeUrlMilliseconds = groupEscalationFooter.LastLinkBuildTimeMs; performanceTracker.LinkBodySize = groupEscalationFooter.LastBodySizeBytes; performanceTracker.LinkOnBodyDetectionMilliseconds = groupEscalationFooter.LastLinkOnBodyDetectionTimeMs; performanceTracker.LinkInsertOnBodyMilliseconds = groupEscalationFooter.LastLinkInsertOnBodyTimeMs; }
public bool EscalateItem(IMessageItem item, IMailboxSession mailboxSession, out bool isTransientError, bool isFromYammer = false) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(mailboxSession, "mailboxSession"); isTransientError = false; string yammerEscalateAddress; List <string> escalatedUsersList = this.GetEscalatedUsersList(mailboxSession, out yammerEscalateAddress); bool flag = GroupEscalation.ShouldEscalateToYammer(isFromYammer, yammerEscalateAddress, item.ClassName); if (escalatedUsersList.Count < 1 && !flag) { GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.EscalateItem: Skipping Escalation as there are no users in need to escalate"); return(true); } bool result = false; IExtensibleLogger logger = GroupEscalateItemDiagnosticsFrameFactory.Default.CreateLogger(mailboxSession.MailboxGuid, mailboxSession.OrganizationId); IGroupEscalateItemPerformanceTracker groupEscalateItemPerformanceTracker = GroupEscalateItemDiagnosticsFrameFactory.Default.CreatePerformanceTracker(mailboxSession); using (GroupEscalateItemDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "EscalateItem", logger, groupEscalateItemPerformanceTracker)) { try { if (item.From != null) { groupEscalateItemPerformanceTracker.OriginalMessageSender = (item.From.EmailAddress ?? string.Empty); groupEscalateItemPerformanceTracker.OriginalMessageSenderRecipientType = ((item.From.Origin != null) ? item.From.Origin.ToString() : string.Empty); groupEscalateItemPerformanceTracker.OriginalMessageClass = (item.ClassName ?? string.Empty); groupEscalateItemPerformanceTracker.OriginalMessageId = ((item.Id != null) ? item.Id.ToBase64String() : string.Empty); groupEscalateItemPerformanceTracker.OriginalInternetMessageId = (item.InternetMessageId ?? string.Empty); } StoreObjectId escalationFolderId = GroupEscalation.GetEscalationFolderId(mailboxSession); using (IMessageItem messageItem = this.CreateEscalationMessage(mailboxSession, escalationFolderId, item)) { ExDateTime?valueOrDefault = item.PropertyBag.GetValueOrDefault <ExDateTime?>(ItemSchema.SentTime); if (valueOrDefault != null) { messageItem[InternalSchema.OriginalSentTimeForEscalation] = valueOrDefault; } else { this.TraceAndLogError(logger, "EscalateItem", "GroupEscalation.EscalateItem: Couldn't find client submit time."); } IExchangePrincipal mailboxOwner = mailboxSession.MailboxOwner; Participant participant = new Participant(mailboxOwner); if (!ObjectClass.IsMeetingMessage(messageItem.ClassName)) { messageItem.Sender = participant; } messageItem.SuppressAllAutoResponses(); messageItem.IsGroupEscalationMessage = true; Participant[] array = new Participant[messageItem.Recipients.Count]; int num = 0; foreach (Recipient recipient in messageItem.Recipients) { recipient[ItemSchema.Responsibility] = false; array[num] = recipient.Participant; num++; } groupEscalateItemPerformanceTracker.ParticipantsInOriginalMessage = array.Length; List <Participant> list = new List <Participant>(array); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (!participant.ExistIn(array)) { Recipient recipient2 = messageItem.Recipients.Add(participant, RecipientItemType.To); list.Add(participant); recipient2[ItemSchema.Responsibility] = false; groupEscalateItemPerformanceTracker.IsGroupParticipantAddedToParticipants = true; } stopwatch.Stop(); groupEscalateItemPerformanceTracker.EnsureGroupParticipantAddedMilliseconds = stopwatch.ElapsedMilliseconds; stopwatch.Reset(); stopwatch.Start(); bool flag2 = false; foreach (string emailAddress in escalatedUsersList) { Participant participant2 = new Participant.Builder { EmailAddress = emailAddress, RoutingType = "EX" }.ToParticipant(); if (!participant2.ExistIn(array)) { Recipient recipient3 = messageItem.Recipients.Add(participant2, RecipientItemType.Bcc); recipient3[ItemSchema.Responsibility] = true; flag2 = true; groupEscalateItemPerformanceTracker.IncrementParticipantsAddedToEscalatedMessage(); } else { groupEscalateItemPerformanceTracker.IncrementParticipantsSkippedInEscalatedMessage(); } } stopwatch.Stop(); groupEscalateItemPerformanceTracker.DedupeParticipantsMilliseconds = stopwatch.ElapsedMilliseconds; groupEscalateItemPerformanceTracker.HasEscalatedUser = flag2; if (!flag2 && !flag) { GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.EscalateItem: Skipping Escalation as there are no additional users in need to escalate"); return(true); } messageItem.MarkRecipientAsSubmitted(list.ToArray()); if (flag) { this.EscalateMessageToYammer(mailboxSession, logger, groupEscalateItemPerformanceTracker, yammerEscalateAddress, flag2, escalationFolderId, messageItem); } if (flag2) { this.InsertUnsubscribeLinkToBody(groupEscalateItemPerformanceTracker, logger, mailboxOwner, item, messageItem); this.SendEscalateMessage(messageItem); } result = true; } } catch (StoragePermanentException arg) { this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got store permanent exception: {0}", arg)); } catch (StorageTransientException arg2) { this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got store transient exception: {0}", arg2)); isTransientError = true; } catch (Exception arg3) { this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got exception: {0}", arg3)); throw; } } return(result); }
private void EscalateMessageToYammer(IMailboxSession mailboxSession, IExtensibleLogger logger, IGroupEscalateItemPerformanceTracker performanceTracker, string yammerEscalateAddress, bool hasEscalatedUser, StoreObjectId draftsFolderId, IMessageItem escalatedMessage) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); performanceTracker.EscalateToYammer = true; GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.EscalateItem: Escalating message to yammer group: " + yammerEscalateAddress); if (hasEscalatedUser) { try { using (IMessageItem messageItem = this.CreateEscalationMessage(mailboxSession, draftsFolderId, escalatedMessage)) { this.SendEscalateMessageToYammer(messageItem, yammerEscalateAddress, mailboxSession); } goto IL_7D; } catch (Exception arg) { this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation to yammer failed. Got exception: {0}", arg)); goto IL_7D; } } this.SendEscalateMessageToYammer(escalatedMessage, yammerEscalateAddress, mailboxSession); IL_7D: stopwatch.Stop(); performanceTracker.SendToYammerMilliseconds = stopwatch.ElapsedMilliseconds; }