IEnumerable <SourceAddress> FilterByTargetChannel(IEnumerable <SourceAddress> source, ChannelInstance channel)
        {
            foreach (var address in source)
            {
                if (channel.Configuration.Charasteristics.SupportsEmail)
                {
                    // Mail channels allow everything that is a valid email address
                    if (SourceAddress.IsValidEmail(address.Address))
                    {
                        yield return(address);
                    }
                }
                else
                {
                    // Social channels only allow entries that are available in the addressbook
                    SourceAddress address1 = address;

                    using (mailbox.Profiles.ReaderLock)
                        if (mailbox.Profiles.Where(p => p.Address == address1.Address).Count() > 0)
                        {
                            yield return(address);
                        }
                }
            }
        }
示例#2
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            Person person = DispatcherActivator <Person> .Create();

            person.Name = address.DisplayName;
            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;;
            person.DateCreated = DateTime.Now;

            mailbox.Persons.Add(person);

            Thread.CurrentThread.ExecuteOnUIThread(() => person.Messages.Add(message));

            person.RebuildScore();

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return(person.PersonId.Value);
        }
示例#3
0
        void ProcessCurrentWord()
        {
            TextRange range = WordBreaker.GetWordRange(Editor.CaretPosition);

            string text = range.Text.Trim();

            // Validate if the email address is valid
            if (!SourceAddress.IsValidEmail(text))
            {
                if (ValidationEnabled)
                {
                    range.ApplyPropertyValue(TextBlock.ForegroundProperty, FindResource("TabAndLightButtonText"));

                    SuppressListForCurrentWord = false;
                }

                return;
            }

            SuppressListForCurrentWord = false;

            SourceAddress address = new SourceAddress(text);

            AddRecipient(address);

            // Notify listeners of new entry
            RebuildRecipientsList();
        }
 string GetAppendAddress(SourceAddress address)
 {
     if (String.IsNullOrEmpty(address.DisplayName))
     {
         return(SourceAddress.IsValidEmail(address.Address) ?
                address.Address.Split('@')[0] :
                address.ToString());
     }
     else
     {
         return(SourceAddress.IsValidEmail(address.DisplayName) ?
                address.DisplayName.Split('@')[0] :
                PersonName.Parse(address.DisplayName).Firstname);
     }
 }
示例#5
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            var person = new Person();

            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;;

            person.Name        = address.DisplayName;
            person.DateCreated = DateTime.Now;

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return(person.PersonId.Value);
        }
        /// <summary>
        /// Handles the LostFocus event of the UsernameTextBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        void UsernameTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            var usernameTextBox = e.Source as TextBox;

            // See if we need to append the defaultDomain to the current entry
            if (String.IsNullOrEmpty(ChannelConfiguration.DefaultDomain) ||
                String.IsNullOrEmpty(usernameTextBox.Text))
            {
                return;
            }

            if (SourceAddress.IsValidEmail(usernameTextBox.Text))
            {
                return;
            }

            if (usernameTextBox.Text.Contains("@"))
            {
                return;
            }

            usernameTextBox.Text = String.Format("{0}@{1}", usernameTextBox.Text, ChannelConfiguration.DefaultDomain);
        }
示例#7
0
        void SaveProfile(Person person, SourceAddress address)
        {
            // Create new profile
            var profile = new Profile();

            profile.PersonId = person.PersonId.Value;

            // SourceChannelId is 0 if its a valid email (because soft email addresses are not
            // nescessarily tied to any channel), otherwise its the SourceChannelId of the message
            // (usually Facebook/Twitter/etc)
            profile.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;

            profile.ScreenName    = address.DisplayName;
            profile.Address       = address.Address;
            profile.SourceAddress = address;
            profile.ProfileType   = ProfileType.Default;
            profile.IsSoft        = true;
            profile.DateCreated   = DateTime.Now;

            ClientState.Current.DataService.Save(profile);

            Logger.Debug("Profile saved successfully in ProfileMatcher. Person = {0}, Profile.SourceAddress = {1}", LogSource.Sync, person.PersonId, profile.SourceAddress);
        }
示例#8
0
        /// <summary>
        /// Matches the conversation on the the subject field.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="conversation">The conversation.</param>
        /// <returns></returns>
        ExecutionResult MatchOnSubject(Message message, out Conversation conversation)
        {
            if (message.MessageFolder == Folders.SentItems)
            {
                Logger.Debug("MatchOnSubject: Message {0} is a sent item. Creating new conversation because it is not a reply but a new message", LogSource.MessageMatcher, message);

                conversation = CreateNewConversation(message);

                return(ExecutionResult.Break);
            }

            if (message.MessageFolder == Folders.Drafts)
            {
                Logger.Debug("MatchOnSubject: Message {0} is a concept message. Creating new conversation", LogSource.MessageMatcher, message);

                conversation = CreateNewConversation(message);

                return(ExecutionResult.Break);
            }

            if (String.IsNullOrEmpty(message.Context) || String.IsNullOrEmpty(message.Context.ToClearSubject()) || message.Context.Trim().Length == 0)
            {
                Logger.Debug("MatchOnSubject: Message {0} has an empty context. Creating new conversation", LogSource.MessageMatcher, message);

                conversation = CreateNewConversation(message);

                return(ExecutionResult.Break);
            }

            Logger.Debug("MatchOnSubject: trying to find conversation for Message {0} with Context {1}", LogSource.MessageMatcher, message, message.Context.ToClearSubject());

            string context = message.Context.ToClearSubject();

            // Determine if the recipients in the message match with the current recipients
            List <Message> messagesWithSameContext;

            using (mailbox.Messages.ReaderLock)
                messagesWithSameContext = mailbox.Messages.Where(
                    m => m.MessageId != message.MessageId && (m.Context == context || m.Context.ToClearSubject() == context))
                                          .ToList();

            string conversationId = null;

            var recentRelatedMessage = messagesWithSameContext.Where(m => DateTime.Compare((m.SortDate).AddDays(3), DateTime.Now) >= 0).FirstOrDefault();

            if (recentRelatedMessage != null)
            {
                conversationId = recentRelatedMessage.ConversationIdentifier;
            }
            else
            {
                if (message.MessageFolder == Folders.Inbox)
                {
                    if (messagesWithSameContext.Count > 0)
                    {
                        // This is an incoming message
                        SourceAddress from           = message.From;
                        bool          isEmailChannel = SourceAddress.IsValidEmail(from.Address);

                        //Get all channels for user
                        var addresses = ChannelsManager
                                        .Channels
                                        .Where(c => c.InputChannel != null)
                                        .Select(c => c.InputChannel.SourceAdress)
                                        .ToList();

                        foreach (var contextMessage in messagesWithSameContext)
                        {
                            var addressCollection = new SourceAddressCollection();
                            addressCollection.AddRange(contextMessage.To);
                            addressCollection.AddRange(contextMessage.CC);
                            addressCollection.AddRange(contextMessage.BCC);
                            addressCollection.Add(contextMessage.From);

                            if (addressCollection.Contains(from, new SourceAddressComparer()))
                            {
                                bool hasMatchedConversation = false;

                                if (message.To.Count(
                                        c => addresses.Contains(c.Address) || addressCollection.Contains(c)) > 0)
                                {
                                    hasMatchedConversation = true;
                                }

                                if (!hasMatchedConversation && !isEmailChannel)
                                {
                                    if (message.To.Count(addressCollection.Contains) > 0)
                                    {
                                        hasMatchedConversation = true;
                                    }
                                }

                                if (hasMatchedConversation)
                                {
                                    conversationId = contextMessage.ConversationIdentifier;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(conversationId))
            {
                Logger.Debug("MatchOnSubject: Message {0} has no matching conversation, creating a new one", LogSource.MessageMatcher, message);

                // Nothing found, create new conversation
                conversation = CreateNewConversation(message);
            }
            else
            {
                using (mailbox.Conversations.ReaderLock)
                    conversation = mailbox.Conversations.FirstOrDefault(c => c.ConversationIdentifier == conversationId);

                Logger.Debug("MatchOnSubject: Message {0} has matching conversation with ConversationId {1}", LogSource.MessageMatcher, message, conversation.ConversationId);

                UpdateMessage(message, conversation);

                Logger.Debug("MatchOnSubject: Message {0} now has ConversationId {1}", LogSource.MessageMatcher, message, message.ConversationIdentifier);
            }

            // End of line
            return(ExecutionResult.Break);
        }