예제 #1
0
        private void MessageView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            StackPanel  panel   = (StackPanel)sender;
            WebBrowser  browser = (WebBrowser)panel.Children[1];
            MailMessage message = (MailMessage)panel.DataContext;

            // TODO: Check for alternate views, prefer HTML.

            // TODO: Resize the browser to fit the content?
            // http://dan.clarke.name/2011/05/resizing-wp7-webbrowser-height-to-fit-content/

            ObjectWHeaders view = message.GetHtmlView();

            string body = view.Body ?? "Unable to load body.";

            // Content-type detection.
            if (string.IsNullOrEmpty(view.ContentType) || view.ContentType.Equals("text/plain", StringComparison.OrdinalIgnoreCase))
            {
                body = body.Replace("\r\n", "<br>");
            }

            int end = body.IndexOf(">");

            if (body.TrimStart('\r', '\n', '\t', ' ').StartsWith("<!DOCTYPE") && end > 0)
            {
                // Strip off the DOCTYPE: http://www.w3schools.com/tags/tag_doctype.asp
                body = body.Substring(end + 1);
            }

            browser.NavigateToString(body);
        }
예제 #2
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);
            }
        }
예제 #3
0
 public virtual async Task LazyLoadBodyPartAsync(MailMessage message, ObjectWHeaders part)
 {
     if (part.Scope < Scope.HeadersAndBody)
     {
         if (MailStorage.HasMessagePart(message.GetThreadId(), message.GetMessageId(), part.BodyId))
         {
             part.Body = await MailStorage.GetMessagePartAsync(message.GetThreadId(), message.GetMessageId(), part.BodyId);
         }
         else
         {
             await GmailImap.GetBodyPartAsync(message.Uid, part, async() =>
             {
                 if (ActiveLabel.Info.StoreMessages)
                 {
                     await MailStorage.StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), part.BodyId, part.Body);
                 }
             }, CancellationToken.None);
         }
     }
 }
예제 #4
0
        public async Task GetBodyPartAsync(string uid, ObjectWHeaders content, Func <Task> onDataReceived,
                                           CancellationToken cancellationToken)
        {
            await CheckConnectedAsync();

            await Client.GetBodyPartAsync(new[] { uid }, uid : true, partId : content.BodyId,
                                          fields : new[] { GConstants.MessageIdHeader, GConstants.ThreadIdHeader },
                                          onDataReceived : async(stream, size) =>
            {
                string body = String.Empty;
                if (size > 0)
                {
                    body = stream.ReadToEnd(size, content.Encoding);
                }

                content.SetBody(body);

                await onDataReceived();
            }, cancellationToken : cancellationToken);
        }
예제 #5
0
        public async Task GetBodyPartAsync(string uid, ObjectWHeaders content, Func<Task> onDataReceived,
            CancellationToken cancellationToken)
        {
            await CheckConnectedAsync();

            await Client.GetBodyPartAsync(new[] { uid }, uid: true, partId: content.BodyId,
                fields: new[] { GConstants.MessageIdHeader, GConstants.ThreadIdHeader },
                onDataReceived: async (stream, size) =>
                {
                    string body = String.Empty;
                    if (size > 0)
                    {
                        body = stream.ReadToEnd(size, content.Encoding);
                    }

                    content.SetBody(body);

                    await onDataReceived();
                }, cancellationToken: cancellationToken);
        }
예제 #6
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // The query parameter is used to tell us if we're in a reply mode.
            string[] parts = e.Uri.ToString().Split('?');
            if (parts.Length > 1 && !string.IsNullOrEmpty(parts[1]))
            {
                string             query       = parts[1];
                Account            account     = App.AccountManager.GetCurrentAccount();
                ConversationThread mailThread  = account.ActiveConversation;
                MailMessage        lastMessage = mailThread.Messages.First(); // They're in reverse order.

                if (query.Equals("Forward"))
                {
                    // No addresses
                    // TODO: Prefix subject
                    SubjectField.Text = lastMessage.Subject;
                }
                else if (query.Equals("ReplyAll"))
                {
                    // Include all addresses
                    if (lastMessage.ReplyTo.Count > 0)
                    {
                        ToField.Text = string.Join(", ", lastMessage.ReplyTo);
                    }
                    else
                    {
                        ToField.Text = string.Join(", ", new[] { lastMessage.From }.Concat(
                                                       lastMessage.To.Where(mailAddress =>
                                                                            // Filter yourself out of the to line, unless you explicitly sent the e-mail.
                                                                            !mailAddress.Address.Equals(account.Info.Address, StringComparison.OrdinalIgnoreCase)
                                                                            )));
                    }
                    // TODO: CC

                    // TODO: Prefix subject
                    SubjectField.Text = lastMessage.Subject;

                    // For threading
                    _additionalHeaders.Add(new KeyValuePair <string, string>("In-Reply-To", lastMessage.MessageID));
                    _additionalHeaders.Add(new KeyValuePair <string, string>("References", lastMessage.MessageID));
                }
                else if (query.Equals("Reply"))
                {
                    // Include only the sender/reply-to
                    if (lastMessage.ReplyTo.Count > 0)
                    {
                        ToField.Text = string.Join(", ", lastMessage.ReplyTo);
                    }
                    else
                    {
                        ToField.Text = lastMessage.From.ToString();
                    }

                    // TODO: Prefix subject
                    SubjectField.Text = lastMessage.Subject;

                    // For threading
                    _additionalHeaders.Add(new KeyValuePair <string, string>("In-Reply-To", lastMessage.MessageID));
                    _additionalHeaders.Add(new KeyValuePair <string, string>("References", lastMessage.MessageID));
                }

                ObjectWHeaders view = lastMessage.GetTextView();
                await account.LazyLoadBodyPartAsync(lastMessage, view);

                BodyField.Text = "\r\n\r\nOn "
                                 + lastMessage.Date.ToString("ddd, MMM d, yyyy a\\t h:mm tt") + ", " + lastMessage.From + " wrote:\r\n\r\n> "
                                 + view.Body.Replace("\r\n", "\r\n> ");
            }

            // TODO: Signature

            base.OnNavigatedTo(e);
        }