private void ParseMapiProperties()
 {
     base.Clear();
     if (this.blob != null)
     {
         IList <ParticipantEntryId> list;
         try
         {
             list = ParticipantEntryId.FromFlatEntryList(this.blob);
         }
         catch (CorruptDataException)
         {
             this.isCorrectionNeeded = true;
             throw;
         }
         string[] array = null;
         if (this.names != null)
         {
             array = this.names.Split(new char[]
             {
                 ';'
             });
             if (array.Length != list.Count)
             {
                 array = null;
             }
         }
         int num = 0;
         foreach (ParticipantEntryId participantEntryId in list)
         {
             Participant.Builder builder = new Participant.Builder();
             string text = null;
             if (array != null)
             {
                 text = array[num].Trim();
             }
             num++;
             if (participantEntryId is OneOffParticipantEntryId || participantEntryId is ADParticipantEntryId)
             {
                 builder.SetPropertiesFrom(participantEntryId);
             }
             else
             {
                 this.isCorrectionNeeded = true;
                 if (text == null)
                 {
                     continue;
                 }
                 builder.EmailAddress = text;
                 builder.RoutingType  = "SMTP";
             }
             if (text != null)
             {
                 builder.DisplayName = text;
             }
             base.Items.Add(builder.ToParticipant());
         }
     }
     this.isListChanged = false;
 }
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            Participant.Builder builder = new Participant.Builder();
            bool flag = base.Get(propertyBag, builder);

            if (this.emailAddressForDisplayPropDef != null)
            {
                string valueOrDefault = propertyBag.GetValueOrDefault <string>(this.emailAddressForDisplayPropDef);
                if (!string.IsNullOrEmpty(valueOrDefault))
                {
                    builder[ParticipantSchema.EmailAddressForDisplay] = valueOrDefault;
                    if (Participant.RoutingTypeEquals(builder.RoutingType, "EX") && PropertyError.IsPropertyNotFound(builder.TryGetProperty(ParticipantSchema.SmtpAddress)) && SmtpAddress.IsValidSmtpAddress(valueOrDefault))
                    {
                        builder[ParticipantSchema.SmtpAddress] = valueOrDefault;
                    }
                }
            }
            if (!flag && PropertyError.IsPropertyNotFound(builder.TryGetProperty(ParticipantSchema.EmailAddressForDisplay)))
            {
                return(new PropertyError(this, PropertyErrorCode.NotFound));
            }
            byte[] valueOrDefault2 = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.EntryId);
            if (valueOrDefault2 != null)
            {
                builder.Origin = new StoreParticipantOrigin(StoreObjectId.FromProviderSpecificId(valueOrDefault2), this.emailAddressIndex);
            }
            return(builder.ToParticipant());
        }
        private List <string> GetTargetUsers(MessageItem item, Participant[] participantsOnOriginalMessage, IWorkingSetPublisherPerformanceTracker performanceTracker)
        {
            List <string> list      = new List <string>(this.groupsCache[item.Session.MailboxGuid].TargetUsers.Count);
            Stopwatch     stopwatch = new Stopwatch();

            stopwatch.Start();
            if (this.groupsCache[item.Session.MailboxGuid].TargetUsers.Count > 0)
            {
                foreach (string text in this.groupsCache[item.Session.MailboxGuid].TargetUsers)
                {
                    Participant participant = new Participant.Builder
                    {
                        EmailAddress = text,
                        RoutingType  = "EX"
                    }.ToParticipant();
                    if (participant.ExistIn(participantsOnOriginalMessage))
                    {
                        performanceTracker.IncrementParticipantsSkippedInPublishedMessage();
                    }
                    else
                    {
                        list.Add(text);
                        performanceTracker.IncrementParticipantsAddedToPublishedMessage();
                    }
                }
            }
            stopwatch.Stop();
            performanceTracker.DedupeParticipantsMilliseconds = stopwatch.ElapsedMilliseconds;
            return(list);
        }
Exemple #4
0
        private static ProxyAddress GetLegacyProxyAddress(IRuleEvaluationContext context, byte[] entryId)
        {
            if (entryId.Length == 0)
            {
                context.TraceDebug("GetLegacyProxyAddress: entry ID is zero-length");
                return(null);
            }
            ParticipantEntryId participantEntryId = ParticipantEntryId.TryFromEntryId(entryId);

            context.TraceDebug <string>("GetLegacyProxyAddress: entry ID is {0}", participantEntryId.GetType().Name);
            Participant.Builder builder = new Participant.Builder();
            builder.SetPropertiesFrom(participantEntryId);
            Participant participant  = builder.ToParticipant();
            string      routingType  = participant.RoutingType;
            string      emailAddress = participant.EmailAddress;

            if (routingType != "EX" || string.IsNullOrEmpty(emailAddress))
            {
                context.TraceDebug <string, string>("GetLegacyProxyAddress: returning null, address is {0}:{1}", routingType ?? "(null)", emailAddress ?? "(null)");
                return(null);
            }
            ProxyAddress proxyAddress = ProxyAddress.Parse(routingType, emailAddress);

            if (proxyAddress is InvalidProxyAddress)
            {
                context.TraceDebug <string>("GetLegacyProxyAddress: legacyDN {0} is not valid", emailAddress);
                return(null);
            }
            context.TraceDebug <string>("GetLegacyProxyAddress: returning EX:{0}", emailAddress);
            return(proxyAddress);
        }
Exemple #5
0
 protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
 {
     Participant.Builder builder = new Participant.Builder();
     if (!this.Get(propertyBag, builder))
     {
         return(new PropertyError(this, PropertyErrorCode.NotFound));
     }
     return(builder.ToParticipant());
 }
Exemple #6
0
        internal static Participant GetParticipant(byte[] entryId)
        {
            ParticipantEntryId participantEntryId = ParticipantEntryId.TryFromEntryId(entryId);

            if (participantEntryId is UnrecognizedParticipantEntryId)
            {
                return(null);
            }
            Participant.Builder builder = new Participant.Builder();
            builder.SetPropertiesFrom(participantEntryId);
            return(builder.ToParticipant());
        }
Exemple #7
0
 protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
 {
     Participant.Builder builder = new Participant.Builder();
     if (base.Get(propertyBag, builder))
     {
         bool?valueAsNullable = propertyBag.GetValueAsNullable <bool>(InternalSchema.SendRichInfo);
         if (valueAsNullable != null)
         {
             builder[ParticipantSchema.SendRichInfo] = valueAsNullable.Value;
         }
         return(builder.ToParticipant());
     }
     return(new PropertyError(this, PropertyErrorCode.NotFound));
 }
Exemple #8
0
        private static string LegDNFromParticipantEntryId(byte[] entryId)
        {
            if (entryId == null || entryId.Length == 0)
            {
                return(null);
            }
            ADParticipantEntryId adparticipantEntryId = ParticipantEntryId.TryFromEntryId(entryId) as ADParticipantEntryId;

            if (adparticipantEntryId != null)
            {
                Participant.Builder builder = new Participant.Builder();
                builder.SetPropertiesFrom(adparticipantEntryId);
                return(builder.ToParticipant().EmailAddress);
            }
            return(null);
        }
        private void SendEscalateMessageToYammer(IMessageItem escalatedMessage, string yammerEscalateAddress, IMailboxSession mailboxSession)
        {
            foreach (Recipient recipient in escalatedMessage.Recipients)
            {
                recipient.Submitted = true;
                recipient[ItemSchema.Responsibility] = false;
            }
            this.SetUniqueBody(escalatedMessage, mailboxSession);
            Participant.Builder builder = new Participant.Builder
            {
                EmailAddress = yammerEscalateAddress,
                RoutingType  = "SMTP"
            };
            Recipient recipient2 = escalatedMessage.Recipients.Add(builder.ToParticipant(), RecipientItemType.Bcc);

            recipient2[ItemSchema.Responsibility] = true;
            this.SendEscalateMessage(escalatedMessage);
        }
Exemple #10
0
 protected bool Get(PropertyBag.BasicPropertyStore propertyBag, Participant.Builder participantBuilder)
 {
     byte[] valueOrDefault = propertyBag.GetValueOrDefault <byte[]>(this.entryIdPropDef);
     if (valueOrDefault != null)
     {
         participantBuilder.SetPropertiesFrom(ParticipantEntryId.TryFromEntryId(valueOrDefault));
     }
     participantBuilder.DisplayName  = propertyBag.GetValueOrDefault <string>(this.displayNamePropDef, participantBuilder.DisplayName);
     participantBuilder.EmailAddress = propertyBag.GetValueOrDefault <string>(this.emailAddressPropDef, participantBuilder.EmailAddress);
     participantBuilder.RoutingType  = propertyBag.GetValueOrDefault <string>(this.routingTypePropDef, participantBuilder.RoutingType);
     if (this.smtpAddressPropDef != null)
     {
         string valueOrDefault2 = propertyBag.GetValueOrDefault <string>(this.smtpAddressPropDef);
         if (!string.IsNullOrEmpty(valueOrDefault2))
         {
             participantBuilder[ParticipantSchema.SmtpAddress] = valueOrDefault2;
         }
     }
     if (this.sipUriPropDef != null)
     {
         string valueOrDefault3 = propertyBag.GetValueOrDefault <string>(this.sipUriPropDef);
         if (!string.IsNullOrEmpty(valueOrDefault3))
         {
             participantBuilder[ParticipantSchema.SipUri] = valueOrDefault3;
         }
     }
     if (this.sidPropDef != null)
     {
         byte[] valueOrDefault4 = propertyBag.GetValueOrDefault <byte[]>(this.sidPropDef);
         if (valueOrDefault4 != null)
         {
             participantBuilder[ParticipantSchema.ParticipantSID] = valueOrDefault4;
         }
     }
     if (this.guidPropDef != null)
     {
         byte[] valueOrDefault5 = propertyBag.GetValueOrDefault <byte[]>(this.guidPropDef);
         if (valueOrDefault5 != null)
         {
             participantBuilder[ParticipantSchema.ParticipantGuid] = valueOrDefault5;
         }
     }
     return(!string.IsNullOrEmpty(participantBuilder.DisplayName) || !string.IsNullOrEmpty(participantBuilder.EmailAddress));
 }
Exemple #11
0
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            Participant.Builder builder = new Participant.Builder();
            byte[] valueOrDefault       = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.EntryId);
            if (valueOrDefault != null)
            {
                builder.SetPropertiesFrom(ParticipantEntryId.TryFromEntryId(valueOrDefault));
            }
            builder.DisplayName = (propertyBag.GetValueOrDefault <string>(InternalSchema.TransmitableDisplayName) ?? builder.DisplayName);
            if (!base.Get(propertyBag, builder))
            {
                return(new PropertyError(this, PropertyErrorCode.NotFound));
            }
            RecipientDisplayType?valueAsNullable = propertyBag.GetValueAsNullable <RecipientDisplayType>(InternalSchema.DisplayTypeExInternal);

            if (valueAsNullable != null)
            {
                builder[ParticipantSchema.DisplayTypeEx] = valueAsNullable.Value;
                builder.Origin = (builder.Origin ?? new DirectoryParticipantOrigin());
            }
            else if (PropertyError.IsPropertyNotFound(builder.TryGetProperty(ParticipantSchema.DisplayType)))
            {
                LegacyRecipientDisplayType?valueAsNullable2 = propertyBag.GetValueAsNullable <LegacyRecipientDisplayType>(InternalSchema.DisplayType);
                ObjectType?valueAsNullable3 = propertyBag.GetValueAsNullable <ObjectType>(InternalSchema.ObjectType);
                if (valueAsNullable2 != null)
                {
                    if (valueAsNullable2 != LegacyRecipientDisplayType.MailUser)
                    {
                        builder[ParticipantSchema.DisplayType] = (int)valueAsNullable2.Value;
                    }
                }
                else if (valueAsNullable3 != null && valueAsNullable3 == ObjectType.MAPI_DISTLIST)
                {
                    builder[ParticipantSchema.DisplayType] = 1;
                }
            }
            builder.SetOrDeleteProperty(ParticipantSchema.SendRichInfo, Util.NullIf <object>(propertyBag.GetValueAsNullable <bool>(InternalSchema.SendRichInfo), false));
            builder.SetOrDeleteProperty(ParticipantSchema.SendInternetEncoding, propertyBag.GetValueAsNullable <int>(InternalSchema.SendInternetEncoding));
            return(builder.ToParticipant());
        }
Exemple #12
0
        private static byte[] ParticipanEntryIdFromLegDN(byte[] originalEntryId, string newLegDN)
        {
            if (originalEntryId == null || originalEntryId.Length == 0)
            {
                return(null);
            }
            ADParticipantEntryId adparticipantEntryId = ParticipantEntryId.TryFromEntryId(originalEntryId) as ADParticipantEntryId;

            if (adparticipantEntryId == null)
            {
                return(null);
            }
            Participant.Builder builder = new Participant.Builder();
            builder.SetPropertiesFrom(adparticipantEntryId);
            builder.EmailAddress = newLegDN;
            ParticipantEntryId participantEntryId = ParticipantEntryId.FromParticipant(builder.ToParticipant(), ParticipantEntryIdConsumer.RecipientTableSecondary);

            if (participantEntryId == null)
            {
                return(null);
            }
            return(participantEntryId.ToByteArray());
        }
        internal static void SetContactEmailAddress(Contact contact, EmailAddressIndex emailIndex, string email, string displayName)
        {
            if (Utilities.WhiteSpaceOnlyOrNullEmpty(email))
            {
                email = null;
            }
            if (Utilities.WhiteSpaceOnlyOrNullEmpty(displayName))
            {
                displayName = null;
            }
            Participant copyFrom = contact.EmailAddresses[emailIndex];
            string      strB     = null;
            string      text     = null;

            ContactUtilities.GetContactEmailAddress(contact, emailIndex, out strB, out text);
            Participant.Builder builder;
            if (email != null && string.CompareOrdinal(email, strB) == 0)
            {
                builder = new Participant.Builder(copyFrom);
            }
            else if (email != null)
            {
                builder = new Participant.Builder(Participant.Parse(email));
                if (builder.RoutingType == null)
                {
                    builder[ParticipantSchema.EmailAddressForDisplay] = email;
                }
            }
            else
            {
                builder = new Participant.Builder();
            }
            builder.DisplayName = displayName;
            Participant value = builder.ToParticipant();

            contact.EmailAddresses[emailIndex] = value;
        }
        internal DistributionListMember(DistributionList distributionList, ParticipantEntryId mainEntryId, OneOffParticipantEntryId oneOffEntryId)
        {
            this.distributionList = distributionList;
            this.memberStatus     = MemberStatus.Normal;
            Participant.Builder  builder = new Participant.Builder();
            ADParticipantEntryId adparticipantEntryId = mainEntryId as ADParticipantEntryId;

            if (adparticipantEntryId != null)
            {
                builder.SetPropertiesFrom(adparticipantEntryId);
                if (oneOffEntryId != null)
                {
                    builder.DisplayName = oneOffEntryId.EmailDisplayName;
                    if (!string.IsNullOrEmpty(oneOffEntryId.EmailAddress) && Participant.RoutingTypeEquals(oneOffEntryId.EmailAddressType, "SMTP"))
                    {
                        builder[ParticipantSchema.SmtpAddress] = oneOffEntryId.EmailAddress;
                    }
                }
                this.participant = builder.ToParticipant();
            }
            else
            {
                StoreParticipantEntryId storeParticipantEntryId = mainEntryId as StoreParticipantEntryId;
                if (storeParticipantEntryId != null && oneOffEntryId != null)
                {
                    builder.SetPropertiesFrom(oneOffEntryId);
                    builder.SetPropertiesFrom(storeParticipantEntryId);
                    this.participant = builder.ToParticipant();
                }
                else
                {
                    OneOffParticipantEntryId oneOffParticipantEntryId = mainEntryId as OneOffParticipantEntryId;
                    if (oneOffParticipantEntryId == null)
                    {
                        oneOffParticipantEntryId = oneOffEntryId;
                        this.memberStatus        = MemberStatus.Demoted;
                    }
                    if (oneOffParticipantEntryId != null)
                    {
                        builder.SetPropertiesFrom(oneOffParticipantEntryId);
                        this.participant = builder.ToParticipant();
                    }
                    else
                    {
                        this.memberStatus = MemberStatus.Unrecognized;
                    }
                }
            }
            if (this.mainEntryId == null)
            {
                this.mainEntryId = mainEntryId;
            }
            if (this.oneOffEntryId == null)
            {
                this.oneOffEntryId = oneOffEntryId;
            }
            ExTraceGlobals.StorageTracer.Information((long)this.GetHashCode(), "Loaded a {1} DL member \"{0}\". MainEntryId=\"{2}\", OneOffEntryId=\"{3}\"", new object[]
            {
                this.participant,
                this.memberStatus,
                this.mainEntryId,
                this.oneOffEntryId
            });
        }
        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);
        }