Ejemplo n.º 1
0
        public static void ReplyAll(Message source, string text)
        {
            var recipients = new SourceAddressCollection();

            recipients.AddRange(source.To);
            recipients.AddRange(source.CC);

            long channelid;

            // Remove receivers own address from list
            if (source.SourceChannelId != 0)
            {
                var channel       = ChannelsManager.GetChannelObject(source.SourceChannelId);
                var sourceAddress = channel.InputChannel.GetSourceAddress();

                if (recipients.Contains(sourceAddress))
                {
                    recipients.Remove(sourceAddress);
                }

                channelid = source.SourceChannelId;
            }
            else
            {
                var channel       = ChannelsManager.GetChannelObject(source.TargetChannelId);
                var sourceAddress = channel.InputChannel.GetSourceAddress();

                if (recipients.Contains(sourceAddress))
                {
                    recipients.Remove(sourceAddress);
                }

                channelid = source.TargetChannelId;
            }

            ClientState.Current.ViewController.MoveTo(
                PluginsManager.Current.GetPlugin <ConversationsPlugin>().NewItemView,
                new NewMessageDataHelper
            {
                SourceMessageId   = source.MessageId,
                SelectedChannelId = channelid,
                Context           = "Re: " + source.Context,
                To   = source.From.ToList(),
                Cc   = recipients,
                Body = MessageBodyGenerator.CreateBodyTextForReply(source, text),
                SuppressSignature = !String.IsNullOrEmpty(text)
            });
        }
Ejemplo n.º 2
0
        public SourceAddressCollection GetConversationMembers()
        {
            var recipients = new SourceAddressCollection();
            var comparer   = new MailAddressEqualityComparer();

            foreach (var message in Messages)
            {
                if (!recipients.Contains(message.From, comparer))
                {
                    recipients.Add(message.From);
                }

                foreach (var address in message.To)
                {
                    if (!recipients.Contains(address, comparer))
                    {
                        recipients.Add(address);
                    }
                }

                foreach (var address in message.CC)
                {
                    if (!recipients.Contains(address, comparer))
                    {
                        recipients.Add(address);
                    }
                }

                foreach (var address in message.BCC)
                {
                    if (!recipients.Contains(address, comparer))
                    {
                        recipients.Add(address);
                    }
                }
            }

            return(recipients);
        }
Ejemplo n.º 3
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);
        }
        void Send_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ClientStats.LogEvent("Quick reply all send");

            if (String.IsNullOrEmpty(QuickReplyAll.Text.Trim()))
                return;

            var newMessage = new Message();

            #region Create message

            var channel = message.SourceChannelId == 0 ?
                ChannelsManager.GetDefaultChannel() :
                ChannelsManager.GetChannelObject(Message.SourceChannelId);

            var recipients = new SourceAddressCollection();
            var sourceAddress = channel.InputChannel.GetSourceAddress();

            recipients.Add(Message.From);
            recipients.AddRange(Message.To);

            // Remove our own address from recipient list
            if (recipients.Contains(sourceAddress))
                recipients.Remove(sourceAddress);

            newMessage.InReplyTo = Message.MessageIdentifier;
            newMessage.ConversationIdentifier = Message.ConversationIdentifier;
            newMessage.Context = "Re: " + Message.Context;
            newMessage.From = channel.InputChannel.GetSourceAddress();
            newMessage.TargetChannelId = channel.Configuration.ChannelId;
            newMessage.To.AddRange(recipients);
            newMessage.CC.AddRange(Message.CC);

            var access = new ClientMessageAccess(newMessage, null,
                MessageBodyGenerator.CreateBodyTextForReply(Message, QuickReplyAll.Text.Nl2Br()));

            newMessage.BodyHtmlStreamName = access.WriteBodyHtml();
            newMessage.BodyPreview = access.GetBodyPreview();
            newMessage.IsRead = true;
            newMessage.DateSent = DateTime.Now;
            newMessage.MessageFolder = Folders.SentItems;
            newMessage.DateSent = DateTime.Now;
            newMessage.DateCreated = DateTime.Now;

            #endregion

            #region Send message

            ClientState.Current.DataService.Save(newMessage);

            // Add message to mailbox
            EventBroker.Publish(AppEvents.MessageStored, newMessage);

            // Save command
            CommandQueue.Enqueue(AppCommands.SendMessage, newMessage);

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                ClientState.Current.ShowMessage(
                    new AppMessage(Strings.MessageWillBeSentLater)
                        {
                            EntityId = newMessage.MessageId.Value,
                            EntityType = EntityType.Message
                        }, MessageType.Success);
            }

            QuickReplyAll.Text = String.Empty;

            message.TrackAction(ActionType.ReplyForward);

            #endregion
        }
Ejemplo n.º 5
0
        void Send_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ClientStats.LogEvent("Quick reply all send");

            if (String.IsNullOrEmpty(QuickReplyAll.Text.Trim()))
            {
                return;
            }

            var newMessage = new Message();

            #region Create message

            var channel = message.SourceChannelId == 0 ?
                          ChannelsManager.GetDefaultChannel() :
                          ChannelsManager.GetChannelObject(Message.SourceChannelId);

            var recipients    = new SourceAddressCollection();
            var sourceAddress = channel.InputChannel.GetSourceAddress();

            recipients.Add(Message.From);
            recipients.AddRange(Message.To);

            // Remove our own address from recipient list
            if (recipients.Contains(sourceAddress))
            {
                recipients.Remove(sourceAddress);
            }

            newMessage.InReplyTo = Message.MessageIdentifier;
            newMessage.ConversationIdentifier = Message.ConversationIdentifier;
            newMessage.Context         = "Re: " + Message.Context;
            newMessage.From            = channel.InputChannel.GetSourceAddress();
            newMessage.TargetChannelId = channel.Configuration.ChannelId;
            newMessage.To.AddRange(recipients);
            newMessage.CC.AddRange(Message.CC);

            var access = new ClientMessageAccess(newMessage, null,
                                                 MessageBodyGenerator.CreateBodyTextForReply(Message, QuickReplyAll.Text.Nl2Br()));

            newMessage.BodyHtmlStreamName = access.WriteBodyHtml();
            newMessage.BodyPreview        = access.GetBodyPreview();
            newMessage.IsRead             = true;
            newMessage.DateSent           = DateTime.Now;
            newMessage.MessageFolder      = Folders.SentItems;
            newMessage.DateSent           = DateTime.Now;
            newMessage.DateCreated        = DateTime.Now;

            #endregion

            #region Send message

            ClientState.Current.DataService.Save(newMessage);

            // Add message to mailbox
            EventBroker.Publish(AppEvents.MessageStored, newMessage);

            // Save command
            CommandQueue.Enqueue(AppCommands.SendMessage, newMessage);

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                ClientState.Current.ShowMessage(
                    new AppMessage(Strings.MessageWillBeSentLater)
                {
                    EntityId   = newMessage.MessageId.Value,
                    EntityType = EntityType.Message
                }, MessageType.Success);
            }

            QuickReplyAll.Text = String.Empty;

            message.TrackAction(ActionType.ReplyForward);

            #endregion
        }
Ejemplo n.º 6
0
        public static void ReplyAll(Message source, string text)
        {
            var recipients = new SourceAddressCollection();
            recipients.AddRange(source.To);
            recipients.AddRange(source.CC);

            long channelid;

            // Remove receivers own address from list
            if (source.SourceChannelId != 0)
            {
                var channel = ChannelsManager.GetChannelObject(source.SourceChannelId);
                var sourceAddress = channel.InputChannel.GetSourceAddress();

                if (recipients.Contains(sourceAddress))
                    recipients.Remove(sourceAddress);

                channelid = source.SourceChannelId;
            }
            else
            {
                var channel = ChannelsManager.GetChannelObject(source.TargetChannelId);
                var sourceAddress = channel.InputChannel.GetSourceAddress();

                if (recipients.Contains(sourceAddress))
                    recipients.Remove(sourceAddress);

                channelid = source.TargetChannelId;
            }

            ClientState.Current.ViewController.MoveTo(
                PluginsManager.Current.GetPlugin<ConversationsPlugin>().NewItemView,
                new NewMessageDataHelper
                    {
                        SourceMessageId = source.MessageId,
                        SelectedChannelId = channelid,
                        Context = "Re: " + source.Context,
                        To = source.From.ToList(),
                        Cc = recipients,
                        Body = MessageBodyGenerator.CreateBodyTextForReply(source, text),
                        SuppressSignature = !String.IsNullOrEmpty(text)
                    });
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        public SourceAddressCollection GetConversationMembers()
        {
            var recipients = new SourceAddressCollection();
            var comparer = new MailAddressEqualityComparer();

            foreach (var message in Messages)
            {
                if (!recipients.Contains(message.From, comparer))
                    recipients.Add(message.From);

                foreach (var address in message.To)
                {
                    if (!recipients.Contains(address, comparer))
                        recipients.Add(address);
                }

                foreach (var address in message.CC)
                {
                    if (!recipients.Contains(address, comparer))
                        recipients.Add(address);
                }

                foreach (var address in message.BCC)
                {
                    if (!recipients.Contains(address, comparer))
                        recipients.Add(address);
                }
            }

            return recipients;
        }