public virtual void TestChildThrowsIndexOutOfBoundsOnMissing()
        {
            Document doc = Jsoup.Parse("<div><p>One</p><p>Two</p></div>");
            Element  div = doc.Select("div").First();

            Assert.AreEqual(2, div.Children().Count);
            Assert.AreEqual("One", div.Child(0).Text());

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => div.Child(3));
        }
示例#2
0
        public async Task <ActionResult> IndexAsync()
        {
            List <EmailContent> mails = new List <EmailContent>();

            if (await checkCredential())
            {
                ViewBag.Success = 1;

                // mới

                var request = service.Users.Messages.List("me");

                request.LabelIds         = "INBOX";
                request.IncludeSpamTrash = false;
                // request.Q = "is:unread"; // This was added because I only wanted unread emails...

                //    Get our emails
                var emailListResponse = request.Execute();

                if (emailListResponse != null && emailListResponse.Messages != null)
                {
                    // Loop through each email and get what fields you want...
                    foreach (var email in emailListResponse.Messages)
                    {
                        EmailContent mail = new EmailContent();

                        var emailInfoRequest = service.Users.Messages.Get("me", email.Id);
                        // Make another request for that email id...
                        var emailInfoResponse = emailInfoRequest.Execute();

                        if (emailInfoResponse != null)
                        {
                            // Loop through the headers and get the fields we need...
                            foreach (var mParts in emailInfoResponse.Payload.Headers)
                            {
                                if (mParts.Name == "Date")
                                {
                                    mail.date = mParts.Value;
                                }
                                else if (mParts.Name == "Delivered-To")
                                {
                                    emailAddress = mParts.Value;
                                }
                                else if (mParts.Name == "From")
                                {
                                    mail.from = mParts.Value;
                                }
                                else if (mParts.Name == "Subject")
                                {
                                    mail.subject = mParts.Value;
                                }


                                if (mail.date != "" && mail.from != "")
                                {
                                    if (emailInfoResponse.Payload.Parts == null)
                                    {
                                        byte[] data          = FromBase64ForUrlString(emailInfoResponse.Payload.Body.Data);
                                        string decodedString = Encoding.UTF8.GetString(data);
                                        mail.body = Jsoup.Parse(decodedString).Text();

                                        continue;
                                    }

                                    foreach (MessagePart p in emailInfoResponse.Payload.Parts)
                                    {
                                        if (p.MimeType == "text/html")
                                        {
                                            byte[] data          = FromBase64ForUrlString(p.Body.Data);
                                            string decodedString = Encoding.UTF8.GetString(data);
                                            mail.body = Jsoup.Parse(decodedString).Text();
                                        }
                                    }
                                }
                            }
                        }
                        mails.Add(mail);
                    }
                }

                return(View(mails));
            }
            else
            {
                ViewBag.Success = 0;

                return(View("/Home/IndexAsync"));
                //return View(mails);
            }
        }
示例#3
0
 public String html2text(String html)
 {
     return(Jsoup.Parse(html).Text());
 }