Beispiel #1
0
        public void OnNext(EmailAddressModel item)
        {
            try
            {
                var value = item.EmailAddress;
                var clue  = this.factory.Create(value);
                var data  = clue.Data.EntityData;

                data.EntityType = EntityType.Infrastructure.User;

                data.Name = value.Name ?? value.Address;

                //if (value.RoutingType == "EX" && !MailAddressUtility.IsValid(value.Address))
                {
                    try
                    {
                        var contactModel = this.state.JobData.Cache.GetName <ContactModel>(CacheLookup.ResolveName, item.Service, value.Address);

                        if (contactModel != null)
                        {
                            if (contactModel.Object.Id != null)
                            {
                                data.Codes.Add(new EntityCode(EntityType.Infrastructure.User, ExchangeSharedMailboxNameConstants.CodeOrigin, contactModel.Object.Id.UniqueId));
                            }

                            this.PopulateContact(clue, contactModel, item.Service);
                        }
                    }
                    catch (Exception e)
                    {
                        this.state.Log.Error(() => "EmailAddress Observer Exception", e);
                    }
                }

                if (string.IsNullOrEmpty(value.RoutingType) || MailAddressUtility.IsValid(value.Address))
                {
                    data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.SmtpAddress] = value.Address.PrintIfAvailable();
                }
                else
                {
                    data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.Address] = value.Address.PrintIfAvailable();
                }

                data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.Name]        = value.Name.PrintIfAvailable();
                data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.RoutingType] = value.RoutingType.PrintIfAvailable();
                data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.UniqueId]    = value.PrintIfAvailable(v => v.Id?.UniqueId);
                data.Properties[ExchangeSharedMailboxVocabulary.EmailAddresss.MailboxType] = value.PrintIfAvailable(v => v.MailboxType?.ToString());

                this.observer.OnNext(clue);
            }
            catch (Exception ex)
            {
                this.state.Status.Statistics.Clues.IncrementTaskFailureCount();
                this.state.Status.Statistics.Tasks.IncrementTaskFailureCount();
                this.state.Log.Error(() => "EmailAddress Observer Exception", ex);
            }
        }
Beispiel #2
0
        public IEnumerable <string> GetSmtpEmailAddresses(IEnumerable <EmailAddress> emails)
        {
            var filteredEmails = emails.Select(a => a.Address?.StartsWith("smtp:", StringComparison.InvariantCultureIgnoreCase) == true
                                                        ? a.Address.Substring(5)
                                                        : a.Address)
                                 .Where(a => !string.IsNullOrEmpty(a) && MailAddressUtility.IsValid(a)).ToList();

            return(filteredEmails);
        }
Beispiel #3
0
        public static string GetNormalizedAddress(this EmailAddress value)
        {
            var address = value.Address.StartsWith("smtp:", StringComparison.InvariantCultureIgnoreCase)
                ? value.Address.Substring(5)
                : value.Address;

            var isEmail = MailAddressUtility.IsValid(address);

            if (value.RoutingType == "EX" && !isEmail)
            {
                address = address.ToUpperInvariant(); // Normalize address value if EX Path
            }
            else if (isEmail)
            {
                address = address.ToLowerInvariant(); // Normalize address value if email address
            }
            return(address);
        }
Beispiel #4
0
        protected override Clue MakeClueImpl(FileSystemPrincipal input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Infrastructure.User, input.Sid.ToString(), accountId);

            var data = clue.Data.EntityData;

            data.Name        = input.Principal.PrintIfAvailable(v => v.Name);
            data.Name        = data.Name ?? input.Account.PrintIfAvailable(v => v.Value);
            data.DisplayName = input.Principal.PrintIfAvailable(v => v.DisplayName);

            if (input.Principal != null)
            {
                if (input.Principal.SamAccountName != null)
                {
                    data.Aliases.Add(input.Principal.SamAccountName);
                }

                if (input.Principal.UserPrincipalName != null)
                {
                    data.Aliases.Add(input.Principal.UserPrincipalName);
                }
            }

            if (input.Account != null)
            {
                data.Aliases.Add(input.Account.ToString());
            }

            if (input.Principal != null && input.Principal.EmailAddress != null && MailAddressUtility.IsValid(input.Principal.EmailAddress))
            {
                data.Codes.Add(new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), input.Principal.EmailAddress.ToLowerInvariant()));
            }

            if (input.Principal != null && input.Principal.UserPrincipalName != null && MailAddressUtility.IsValid(input.Principal.UserPrincipalName))
            {
                data.Codes.Add(new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), input.Principal.UserPrincipalName.ToLowerInvariant()));
            }

            data.Properties[FileSystemVocabulary.UserPrincipal.EmailAddress]         = input.Principal.PrintIfAvailable(v => v.EmailAddress);
            data.Properties[FileSystemVocabulary.UserPrincipal.EmployeeId]           = input.Principal.PrintIfAvailable(v => v.EmployeeId);
            data.Properties[FileSystemVocabulary.UserPrincipal.GivenName]            = input.Principal.PrintIfAvailable(v => v.GivenName);
            data.Properties[FileSystemVocabulary.UserPrincipal.MiddleName]           = input.Principal.PrintIfAvailable(v => v.MiddleName);
            data.Properties[FileSystemVocabulary.UserPrincipal.Surname]              = input.Principal.PrintIfAvailable(v => v.Surname);
            data.Properties[FileSystemVocabulary.UserPrincipal.Name]                 = input.Principal.PrintIfAvailable(v => v.Name);
            data.Properties[FileSystemVocabulary.UserPrincipal.VoiceTelephoneNumber] = input.Principal.PrintIfAvailable(v => v.VoiceTelephoneNumber);
            data.Properties[FileSystemVocabulary.UserPrincipal.Guid]                 = input.Principal.PrintIfAvailable(v => v.Guid);
            data.Properties[FileSystemVocabulary.UserPrincipal.Description]          = input.Principal.PrintIfAvailable(v => v.Description);
            data.Properties[FileSystemVocabulary.UserPrincipal.DisplayName]          = input.Principal.PrintIfAvailable(v => v.DisplayName);
            data.Properties[FileSystemVocabulary.UserPrincipal.SamAccountName]       = input.Principal.PrintIfAvailable(v => v.SamAccountName);
            data.Properties[FileSystemVocabulary.UserPrincipal.UserPrincipalName]    = input.Principal.PrintIfAvailable(v => v.UserPrincipalName);

            data.Properties[FileSystemVocabulary.UserPrincipal.Account] = input.Account.PrintIfAvailable(v => v.Value);

            data.Properties[FileSystemVocabulary.UserPrincipal.Sid] = input.Sid.PrintIfAvailable(v => v.Value);

            {
                var distinguishedName = input.Principal.PrintIfAvailable(v => v.DistinguishedName);

                if (distinguishedName != null)
                {
                    Regex regex = new Regex(@"^CN=.+DC=.+$", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);

                    if (regex.IsMatch(distinguishedName))
                    {
                        data.Properties[FileSystemVocabulary.UserPrincipal.LdapDistinguishedName] = distinguishedName;
                    }
                    else
                    {
                        data.Properties[FileSystemVocabulary.UserPrincipal.DistinguishedName] = distinguishedName;
                    }
                }
            }

            _factory.CreateEntityRootReference(clue, EntityEdgeType.ManagedIn);

            clue.ValidationRuleSuppressions.AddRange(new[]
            {
                RuleConstants.METADATA_002_Uri_MustBeSet
            });

            return(clue);
        }
Beispiel #5
0
        protected void PopulateEmailMessage(Clue clue, IEmailMessageModelBase <EmailMessage> message, ExchangeSharedMailboxMailBaseVocabulary vocabulary, ExchangeService service)
        {
            var value = message.Object;
            var data  = clue.Data.EntityData;

            this.PopulateItem(clue, message, vocabulary, service);

            data.Name        = value.ExPrintIfAvailable(v => v.Subject);
            data.CreatedDate = value.ExGetIfAvailable(v => (DateTimeOffset?)v.DateTimeReceived, null)
                               ?? value.ExGetIfAvailable(v => (DateTimeOffset?)v.DateTimeSent, null)
                               ?? value.ExGetIfAvailable(v => (DateTimeOffset?)v.DateTimeCreated, null);

            if (!string.IsNullOrEmpty(value.InternetMessageId))
            {
                data.Codes.Add(new EntityCode(data.EntityType, CodeOrigin.CluedIn.CreateSpecific("InternetMessageId"), value.InternetMessageId));
            }

            // TODO: Get OWA address
            //data.Uri = new Uri(service.Url, "/owa/" + value.WebClientReadFormQueryString);

            data.Properties[vocabulary.DateTimeReceived]           = value.ExPrintIfAvailable(v => v.DateTimeReceived);
            data.Properties[vocabulary.DateTimeSent]               = value.ExPrintIfAvailable(v => v.DateTimeSent);
            data.Properties[vocabulary.IsRead]                     = value.ExPrintIfAvailable(v => v.IsRead);
            data.Properties[vocabulary.InternetMessageId]          = value.ExPrintIfAvailable(v => v.InternetMessageId);
            data.Properties[vocabulary.ConversationTopic]          = value.ExPrintIfAvailable(v => v.ConversationTopic);
            data.Properties[vocabulary.IsAssociated]               = value.ExPrintIfAvailable(v => v.IsAssociated);
            data.Properties[vocabulary.IsDeliveryReceiptRequested] = value.ExPrintIfAvailable(v => v.IsDeliveryReceiptRequested);
            data.Properties[vocabulary.IsResponseRequested]        = value.ExPrintIfAvailable(v => v.IsResponseRequested);
            data.Properties[vocabulary.References]                 = value.ExPrintIfAvailable(v => v.References);

            this.WriteAddressProperty(data, vocabulary.ReceivedBy, value.ExGetIfAvailable(v => v.ReceivedBy, null));
            this.WriteAddressProperty(data, vocabulary.ReceivedRepresenting, value.ExGetIfAvailable(v => v.ReceivedRepresenting, null));

            if (value.ReplyTo != null)
            {
                if (value.ReplyTo.Count == 1)
                {
                    this.WriteAddressProperty(data, vocabulary.ReplyTo, value.ReplyTo.First());
                }
                else
                {
                    data.Properties[vocabulary.ReplyTo] = string.Join(";", value.ReplyTo.Where(a => a.Address != null && MailAddressUtility.IsValid(a.Address)).Select(a => a.Address));
                }
            }

            PersonReference fromReference = null;

            // From
            if (value.From != null)
            {
                fromReference = this.AddCreatedBy(clue, value.From, vocabulary.From);
            }

            // Sender
            if (value.Sender != null)
            {
                this.AddCreatedBy(clue, value.Sender, vocabulary.Sender);
                data.LastChangedBy = fromReference ?? data.LastChangedBy;
            }

            // Recipients
            {
                var tmp = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.ToRecipients, EmailMessageSchema.BccRecipients, EmailMessageSchema.CcRecipients, ItemSchema.Attachments);
                var iv  = new ItemView(1000)
                {
                    PropertySet = tmp
                };

                value.ExLoad(this.state, tmp);

                this.AddEmailAddressEdges(clue, value.BccRecipients, EntityEdgeType.Recipient);
                this.AddEmailAddressEdges(clue, value.CcRecipients, EntityEdgeType.Recipient);
                this.AddEmailAddressEdges(clue, value.ToRecipients, EntityEdgeType.Recipient);
            }
        }