protected void Page_Load(object sender, EventArgs e)
 {
     int emailId = -1;
     if (Request.QueryString["emailId"] == null)
     {
         Response.Redirect("Pop3Client.aspx");
         Response.Flush();
         Response.End();
     }
     else
         Email = Session["email"].ToString();
     Password = Session["pwd"].ToString();
         emailId = Convert.ToInt32(Request.QueryString["emailId"]);
     Email email = null;
     List<MessagePart> msgParts = null;
     using (Prabhu.Pop3Client client = new Prabhu.Pop3Client (Host, Port,Email, Password, true))
     {
         client.Connect();
         email = client.FetchEmail(emailId);
         msgParts = client.FetchMessageParts(emailId);
     }
     if (email == null || msgParts == null)
     {
         Response.Redirect("Pop3Client.aspx");
         Response.Flush();
         Response.End();
     }
     MessagePart preferredMsgPart = FindMessagePart(msgParts, "text/html");
     if (preferredMsgPart == null)
         preferredMsgPart = FindMessagePart(msgParts, "text/plain");
     else if (preferredMsgPart == null && msgParts.Count > 0)
         preferredMsgPart = msgParts[0];
     string contentType, charset, contentTransferEncoding, body = null;
     if (preferredMsgPart != null)
     {
         contentType = preferredMsgPart.Headers["Content-Type"];
         charset = "us-ascii";
         contentTransferEncoding =preferredMsgPart.Headers["Content-Transfer-Encoding"];
         Match m = CharsetRegex.Match(contentType);
         if (m.Success)
             charset = m.Groups["charset"].Value;
         HeadersLiteral.Text = contentType != null ? "Content-Type: " +contentType + "<br />" : string.Empty;
         HeadersLiteral.Text += contentTransferEncoding != null ?"Content-Transfer-Encoding: " +contentTransferEncoding : string.Empty;
         if (contentTransferEncoding != null)
         {
             if (contentTransferEncoding.ToLower() == "base64")
                 body = DecodeBase64String(charset,preferredMsgPart.MessageText);
             else if (contentTransferEncoding.ToLower() =="quoted-printable")
                 body = DecodeQuotedPrintableString(preferredMsgPart.MessageText);
             else
                 body = preferredMsgPart.MessageText;
         }
         else
             body = preferredMsgPart.MessageText;
     }
     EmailIdLiteral.Text = Convert.ToString(emailId);
     DateLiteral.Text = email.UtcDateTime.ToString(); ;
     FromLiteral.Text = email.From;
     SubjectLiteral.Text = email.Subject;
     BodyLiteral.Text = preferredMsgPart != null ? (preferredMsgPart.Headers["Content-Type"].IndexOf("text/plain") != -1 ?"<pre>" + FormatUrls(body) + "</pre>" : body) : null;
     ListAttachments(msgParts);
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     int page = 1;
     if (Request.QueryString["page"] == null)
     {
         Response.Redirect("Pop3Client.aspx?page=1");
         Response.Flush();
         Response.End();
     }
     else
         page = Convert.ToInt32(Request.QueryString["page"]);
     try
     {
         Email = Session["email"].ToString();
         Password = Session["pwd"].ToString();
     }
     catch (Exception ex) { Response.Redirect("Home.aspx"); }
     int totalEmails;
     List<Email> emails;
     string emailAddress;
     using (Prabhu.Pop3Client client = new Prabhu.Pop3Client(Host, Port, Email, Password, true))
     {
         emailAddress = client.Email;
         client.Connect();
         totalEmails = client.GetEmailCount();
         emails = client.FetchEmailList(((page - 1) * NoOfEmailsPerPage) + 1, NoOfEmailsPerPage);
     }
     int totalPages;
     int mod = totalEmails % NoOfEmailsPerPage;
     if (mod == 0)
         totalPages = totalEmails / NoOfEmailsPerPage;
     else
        totalPages = ((totalEmails - mod) / NoOfEmailsPerPage) + 1;
     for (int i = 0; i < emails.Count; i++)
     {
         Email email = emails[i];
         int emailId = ((page - 1) * NoOfEmailsPerPage) + i + 1;
         TableCell noCell = new TableCell();
         noCell.CssClass = "emails-table-cell";
         noCell.Text = Convert.ToString(emailId);
         TableCell fromCell = new TableCell();
         fromCell.CssClass = "emails-table-cell";
         fromCell.Text = email.From;
         TableCell subjectCell = new TableCell();
         subjectCell.CssClass = "emails-table-cell";
         subjectCell.Style["width"] = "300px";
         subjectCell.Text = String.Format(DisplayEmailLink, emailId, email.Subject);
         TableCell dateCell = new TableCell();
         dateCell.CssClass = "emails-table-cell";
         if (email.UtcDateTime != DateTime.MinValue)
            dateCell.Text = email.UtcDateTime.ToString();
         TableRow emailRow = new TableRow();
         emailRow.Cells.Add(noCell);
         emailRow.Cells.Add(fromCell);
         emailRow.Cells.Add(subjectCell);
         emailRow.Cells.Add(dateCell);
         EmailsTable.Rows.AddAt(2 + i, emailRow);
     }
     if (totalPages > 1)
     {
         if (page > 1)
             PreviousPageLiteral.Text = String.Format(SelfLink, page - 1, "Previous Page");
         if (page > 0 && page < totalPages)
             NextPageLiteral.Text = String.Format(SelfLink, page + 1, "Next Page");
     }
     EmailFromLiteral.Text = Convert.ToString(((page - 1) * NoOfEmailsPerPage) + 1);
     EmailToLiteral.Text = Convert.ToString(page * NoOfEmailsPerPage);
     EmailTotalLiteral.Text = Convert.ToString(totalEmails);
     EmailLiteral.Text = emailAddress;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        int page = 1;

        if (Request.QueryString["page"] == null)
        {
            Response.Redirect("Pop3Client.aspx?page=1");
            Response.Flush();
            Response.End();
        }
        else
        {
            page = Convert.ToInt32(Request.QueryString["page"]);
        }
        try
        {
            Email    = Session["email"].ToString();
            Password = Session["pwd"].ToString();
        }
        catch (Exception ex) { Response.Redirect("Home.aspx"); }
        int          totalEmails;
        List <Email> emails;
        string       emailAddress;

        using (Prabhu.Pop3Client client = new Prabhu.Pop3Client(Host, Port, Email, Password, true))
        {
            emailAddress = client.Email;
            client.Connect();
            totalEmails = client.GetEmailCount();
            emails      = client.FetchEmailList(((page - 1) * NoOfEmailsPerPage) + 1, NoOfEmailsPerPage);
        }
        int totalPages;
        int mod = totalEmails % NoOfEmailsPerPage;

        if (mod == 0)
        {
            totalPages = totalEmails / NoOfEmailsPerPage;
        }
        else
        {
            totalPages = ((totalEmails - mod) / NoOfEmailsPerPage) + 1;
        }
        for (int i = 0; i < emails.Count; i++)
        {
            Email     email   = emails[i];
            int       emailId = ((page - 1) * NoOfEmailsPerPage) + i + 1;
            TableCell noCell  = new TableCell();
            noCell.CssClass = "emails-table-cell";
            noCell.Text     = Convert.ToString(emailId);
            TableCell fromCell = new TableCell();
            fromCell.CssClass = "emails-table-cell";
            fromCell.Text     = email.From;
            TableCell subjectCell = new TableCell();
            subjectCell.CssClass       = "emails-table-cell";
            subjectCell.Style["width"] = "300px";
            subjectCell.Text           = String.Format(DisplayEmailLink, emailId, email.Subject);
            TableCell dateCell = new TableCell();
            dateCell.CssClass = "emails-table-cell";
            if (email.UtcDateTime != DateTime.MinValue)
            {
                dateCell.Text = email.UtcDateTime.ToString();
            }
            TableRow emailRow = new TableRow();
            emailRow.Cells.Add(noCell);
            emailRow.Cells.Add(fromCell);
            emailRow.Cells.Add(subjectCell);
            emailRow.Cells.Add(dateCell);
            EmailsTable.Rows.AddAt(2 + i, emailRow);
        }
        if (totalPages > 1)
        {
            if (page > 1)
            {
                PreviousPageLiteral.Text = String.Format(SelfLink, page - 1, "Previous Page");
            }
            if (page > 0 && page < totalPages)
            {
                NextPageLiteral.Text = String.Format(SelfLink, page + 1, "Next Page");
            }
        }
        EmailFromLiteral.Text  = Convert.ToString(((page - 1) * NoOfEmailsPerPage) + 1);
        EmailToLiteral.Text    = Convert.ToString(page * NoOfEmailsPerPage);
        EmailTotalLiteral.Text = Convert.ToString(totalEmails);
        EmailLiteral.Text      = emailAddress;
    }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int emailId = -1;

        if (Request.QueryString["emailId"] == null)
        {
            Response.Redirect("Pop3Client.aspx");
            Response.Flush();
            Response.End();
        }
        else
        {
            Email = Session["email"].ToString();
        }
        Password = Session["pwd"].ToString();
        emailId  = Convert.ToInt32(Request.QueryString["emailId"]);
        Email email = null;
        List <MessagePart> msgParts = null;

        using (Prabhu.Pop3Client client = new Prabhu.Pop3Client(Host, Port, Email, Password, true))
        {
            client.Connect();
            email    = client.FetchEmail(emailId);
            msgParts = client.FetchMessageParts(emailId);
        }
        if (email == null || msgParts == null)
        {
            Response.Redirect("Pop3Client.aspx");
            Response.Flush();
            Response.End();
        }
        MessagePart preferredMsgPart = FindMessagePart(msgParts, "text/html");

        if (preferredMsgPart == null)
        {
            preferredMsgPart = FindMessagePart(msgParts, "text/plain");
        }
        else if (preferredMsgPart == null && msgParts.Count > 0)
        {
            preferredMsgPart = msgParts[0];
        }
        string contentType, charset, contentTransferEncoding, body = null;

        if (preferredMsgPart != null)
        {
            contentType             = preferredMsgPart.Headers["Content-Type"];
            charset                 = "us-ascii";
            contentTransferEncoding = preferredMsgPart.Headers["Content-Transfer-Encoding"];
            Match m = CharsetRegex.Match(contentType);
            if (m.Success)
            {
                charset = m.Groups["charset"].Value;
            }
            HeadersLiteral.Text  = contentType != null ? "Content-Type: " + contentType + "<br />" : string.Empty;
            HeadersLiteral.Text += contentTransferEncoding != null ?"Content-Transfer-Encoding: " + contentTransferEncoding : string.Empty;
            if (contentTransferEncoding != null)
            {
                if (contentTransferEncoding.ToLower() == "base64")
                {
                    body = DecodeBase64String(charset, preferredMsgPart.MessageText);
                }
                else if (contentTransferEncoding.ToLower() == "quoted-printable")
                {
                    body = DecodeQuotedPrintableString(preferredMsgPart.MessageText);
                }
                else
                {
                    body = preferredMsgPart.MessageText;
                }
            }
            else
            {
                body = preferredMsgPart.MessageText;
            }
        }
        EmailIdLiteral.Text = Convert.ToString(emailId);
        DateLiteral.Text    = email.UtcDateTime.ToString();;
        FromLiteral.Text    = email.From;
        SubjectLiteral.Text = email.Subject;
        BodyLiteral.Text    = preferredMsgPart != null ? (preferredMsgPart.Headers["Content-Type"].IndexOf("text/plain") != -1 ?"<pre>" + FormatUrls(body) + "</pre>" : body) : null;
        ListAttachments(msgParts);
    }