예제 #1
0
        public async Task <List <ConversationThread> > GetConversationsAsync(Scope scope, TimeSpan range, CancellationToken cancellationToken)
        {
            await CheckConnectedAsync();

            SearchCondition condition = SearchCondition.Since(DateTime.Now - range);

            string[] uids = await Client.SearchAsync(condition, uid : true);

            List <ConversationThread> conversations = new List <ConversationThread>();
            IList <MailMessage>       messages;

            if (uids.Length == 0)
            {
                messages = new MailMessage[0];
            }
            else
            {
                if (scope == Scope.HeadersAndBody || scope == Scope.Headers)
                {
                    // TODO: Consider comma joined list of UIDs
                    messages = await Client.GetMessagesAsync(uids[0], uids[uids.Length - 1], scope);
                }
                else if (scope == Scope.HeadersAndMime)
                {
                    messages = new List <MailMessage>();
                    IList <GmailMessageInfo> infos = await GetMessageIdsAsync(uids);

                    await GetEnvelopeAndStructureAsync(uids,
                                                       message =>
                    {
                        // Find the matching Ids
                        string messageId      = message.GetMessageId();
                        GmailMessageInfo info = infos.First(i => i.MessageId.Equals(messageId));

                        message.SetLabels(info.Labels);
                        message.SetFlags(info.Flags);
                        message.Uid = info.Uid;

                        messages.Add(message);

                        return(Task.FromResult(0));
                    },
                                                       cancellationToken);
                }
                else
                {
                    throw new NotSupportedException(scope.ToString());
                }
            }

            // Group by thread ID
            foreach (IGrouping <string, MailMessage> group in messages.GroupBy(message => message.GetThreadId()))
            {
                ConversationThread conversation = new ConversationThread(group.OrderByDescending(message => message.Date).ToList());
                conversation.Messages.ForEach(message => FixUpLabels(message));
                conversations.Add(conversation);
            }
            return(conversations.OrderByDescending(conversation => conversation.LatestDate).ToList());
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Account account = App.AccountManager.GetCurrentAccount();
            if (account != null)
            {
                Conversation = account.ActiveConversation;
                GetLabelsAsync();
            }

            base.OnNavigatedTo(e);
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     Account account = App.AccountManager.GetCurrentAccount();
     if (account != null)
     {
         Conversation = account.ActiveConversation;
         if (Conversation == null)
         {
             // This happens after opening an attachment and then hitting back.
             // TODO: Why do we lose app state after opening an attachment?
             NavigationService.GoBack();
         }
         DataContext = null; // Force refresh after editing labels
         DataContext = Conversation;
     }
     base.OnNavigatedTo(e);
 }
예제 #4
0
        public async Task<List<ConversationThread>> GetConversationsAsync(Scope scope, TimeSpan range, CancellationToken cancellationToken)
        {
            await CheckConnectedAsync();

            SearchCondition condition = SearchCondition.Since(DateTime.Now - range);
            string[] uids = await Client.SearchAsync(condition, uid: true);

            List<ConversationThread> conversations = new List<ConversationThread>();
            IList<MailMessage> messages;
            if (uids.Length == 0)
            {
                messages = new MailMessage[0];
            }
            else
            {
                if (scope == Scope.HeadersAndBody || scope == Scope.Headers)
                {
                    // TODO: Consider comma joined list of UIDs
                    messages = await Client.GetMessagesAsync(uids[0], uids[uids.Length - 1], scope);
                }
                else if (scope == Scope.HeadersAndMime)
                {
                    messages = new List<MailMessage>();
                    IList<GmailMessageInfo> infos = await GetMessageIdsAsync(uids);

                    await GetEnvelopeAndStructureAsync(uids,
                        message =>
                        {
                            // Find the matching Ids
                            string messageId = message.GetMessageId();
                            GmailMessageInfo info = infos.First(i => i.MessageId.Equals(messageId));

                            message.SetLabels(info.Labels);
                            message.SetFlags(info.Flags);
                            message.Uid = info.Uid;

                            messages.Add(message);

                            return Task.FromResult(0);
                        },
                        cancellationToken);
                }
                else
                {
                    throw new NotSupportedException(scope.ToString());
                }
            }

            // Group by thread ID
            foreach (IGrouping<string, MailMessage> group in messages.GroupBy(message => message.GetThreadId()))
            {
                ConversationThread conversation = new ConversationThread(group.OrderByDescending(message => message.Date).ToList());
                conversation.Messages.ForEach(message => FixUpLabels(message));
                conversations.Add(conversation);
            }
            return conversations.OrderByDescending(conversation => conversation.LatestDate).ToList();
        }
예제 #5
0
        public virtual async Task SelectConversationAsync(ConversationThread conversation)
        {
            ActiveConversation = conversation;
            await SetReadStatusAsync(conversation.Messages, true);

            // Sync full conversation body, from disk or network.
            foreach (MailMessage message in conversation.Messages)
            {
                ObjectWHeaders view = message.GetHtmlView();
                await LazyLoadBodyPartAsync(message, view);
            }
        }