Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            grabPOP = Session["isPOP"].ToString();

            if (grabPOP.Equals("True"))
            {

                try
                {
                    grabPOPHost = Session["popsv"].ToString();
                    grabPOPPort = Convert.ToInt32(Session["popPort"]);
                    grabEmail = Session["email"].ToString();
                    grabPassword = Session["pwd"].ToString();

                }
                catch (Exception) { Response.Redirect("Default.aspx"); }

                using (popClient = new z.popSession(grabPOPHost, grabPOPPort, grabEmail, grabPassword, true))
                {
                    grabEmail = popClient.popMail;
                    popClient.doConnect();
                    welcomeLbl.Text = "Welcome " + popClient.popMail + " !";
                }

                isLoggedIn = true;
                Session["loggedin"] = isLoggedIn;
                
            }

            else
            {
                grabIMAP = Session["isIMAP"].ToString();

                if (grabIMAP.Equals("True"))
                {
                    //toimplement
                }
            }
        }
        catch (Exception) { Response.Redirect("Default.aspx"); }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int mailID = -1; //loads without ID to prevent errors.

        if (Request.QueryString["mailID"] == null)
        {
            Response.Redirect("Inbox.aspx", false);
        }

        else
        {
            popHost = Session["popsv"].ToString();
            popPort = Convert.ToInt32(Session["popPort"]);
            getMail = Session["email"].ToString();
            getPW = Session["pwd"].ToString();
	        mailID = Convert.ToInt32(Request.QueryString["mailID"]); //gets ID from Inbox.aspx

		z.getMail mail = null;
		List<z.getMessage> fetchParts = null;

		using (popSession client = new popSession(popHost, popPort, getMail, getPW, true))
		{
			client.doConnect();
			mail = client.grab(mailID); //grabs message
			fetchParts = client.getParts(mailID); //grabs message body
		}

		if (mail == null || fetchParts == null)
		{
			Response.Redirect("Inbox.aspx", false);
		}

		z.getMessage preferredPart = findPart(fetchParts, "text/html"); //finds text

		if (preferredPart == null)
        {
            preferredPart = findPart(fetchParts, "text/plain");
        }

		else if (preferredPart == null && fetchParts.Count > 0)
        {
			preferredPart = fetchParts[0];
        }

		string contentType, charset, contentTransferEncoding, body = null;

		if (preferredPart != null)
		{
			contentType = preferredPart.getHeaders["Content-Type"];
			charset = "us-ascii";
			contentTransferEncoding =preferredPart.getHeaders["Content-Transfer-Encoding"];
			Match m = charRegex.Match(contentType);

			if (m.Success)
            {
				charset = m.Groups["charset"].Value; //gets charset type of message
            }

            //parses message content-type and encoding
			Headers.Text = contentType != null ? "Content-Type: " +contentType + "<br />" : string.Empty;
			Headers.Text += contentTransferEncoding != null ?"Content-Transfer-Encoding: " +contentTransferEncoding : string.Empty;

			if (contentTransferEncoding != null) //decodes message
			{
				if (contentTransferEncoding.ToLower() == "base64")
                {
					body = decodeB64(charset,preferredPart.getMessageText);
                }

				else if (contentTransferEncoding.ToLower() =="quoted-printable")
                {
					body = decodequoteString(preferredPart.getMessageText);
                }

				else
                {
					body = preferredPart.getMessageText;
                }
			}

			else
            {
				body = preferredPart.getMessageText;
            }
		}

		mailIDL.Text = Convert.ToString(mailID);
		Date.Text = mail.getDateTime.ToString(); ;
		From.Text = mail.getFrom;
		Subject.Text = mail.getSubject;
		Body.Text = preferredPart != null ? (preferredPart.getHeaders["Content-Type"].IndexOf("text/plain") != -1 ?"<pre>" + uriFormat(body) + "</pre>" : body) : null; //parses message body text
		getAttach(fetchParts); //gets attachments if any
	}
    }
Ejemplo n.º 3
0
    public const string displayMailLink = "<a href=\"showmail.aspx?mailID={0}\">{1}</a>"; //gets mail ID and shows the proper message
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        { //gets if there's a user logged in
            checkLoggedIn = Session["loggedin"].ToString();

            if (checkLoggedIn.Equals("False"))
            {
                Response.Redirect("Default.aspx");
            }

            else
            {
                if (Request.QueryString["page"] == null)
                {
                    Response.Redirect("Inbox.aspx?page=1", false);
                }

                else
                {
                    page = Convert.ToInt32(Request.QueryString["page"]);
                }

                try
                {
                    popHost = Session["popsv"].ToString();
                    popPort = Convert.ToInt32(Session["popPort"]);
                    getMail = Session["email"].ToString();
                    getPW = Session["pwd"].ToString();
                }

                catch (Exception)
                {
                    Response.Redirect("Welcome.aspx");
                }


            }

        }

        catch (Exception) { Response.Redirect("Default.aspx"); }

        int totalMail;
        List<z.getMail> mails; //creates mail list
        string mailAddress;

        using (popSession client = new popSession(popHost, popPort, getMail, getPW, true))
        {
            mailAddress = client.popMail;
            client.doConnect();

            totalMail = client.countMail();

            mails = client.grabList(((page - 1) * perPage) + 1, perPage);
        }

        int getTotal; //total messages inbox
        int doMod = totalMail % perPage; //so we can order mail per page

        if (doMod == 0)
        {
            getTotal = totalMail / perPage;
        }

        else
        {
            getTotal = ((totalMail - doMod) / perPage) + 1;
        }

        for (int i = 0; i < mails.Count; i++) //organizes emails in a array
        {
            z.getMail mail = mails[i];

            int mailID = ((page - 1) * perPage) + i + 1;

            TableCell noCell = new TableCell();
            noCell.CssClass = "mail-table-cell";
            noCell.Text = Convert.ToString(mailID);

            TableCell fromCell = new TableCell();
            fromCell.CssClass = noCell.CssClass;
            fromCell.Text = mail.getFrom;

            TableCell subjectCell = new TableCell();
            subjectCell.CssClass = noCell.CssClass;
            subjectCell.Style["width"] = "300px";
            subjectCell.Text = String.Format(displayMailLink, mailID, mail.getSubject);

            TableCell datetimeCell = new TableCell();
            datetimeCell.CssClass = noCell.CssClass;
            if (mail.getDateTime != DateTime.MinValue)
            {
                datetimeCell.Text = mail.getDateTime.ToString();
            }

            TableRow mailRow = new TableRow();
            mailRow.Cells.Add(noCell);
            mailRow.Cells.Add(fromCell);
            mailRow.Cells.Add(subjectCell);
            mailRow.Cells.Add(datetimeCell);
            mailTable.Rows.AddAt(2 + i, mailRow);
        }

        if (totalMail > 1) //page navigation
        {
            if (page > 1)
            {
                previousPage.Text = String.Format(fixLink, page - 1, "Previous Page");
            }

            if (page > 0 && page < totalMail)
            {
                nextPage.Text = String.Format(fixLink, page + 1, "Next Page");
            }
        }

        mailFrom.Text = Convert.ToString(((page - 1) * perPage) + 1);
        mailTo.Text = Convert.ToString(page * perPage);
        mailTotal.Text = Convert.ToString(totalMail);
        getownMail.Text = mailAddress;
    }
Ejemplo n.º 4
0
    protected void logoutBtn_Click(object sender, EventArgs e)
    {
        string checkLoggedIn;

        try
        {
            checkLoggedIn = Session["loggedin"].ToString();

            if (checkLoggedIn.Equals("True"))
            {

                grabPOP = Session["isPOP"].ToString();

                if (grabPOP.Equals("True"))
                {
                    using (popClient = new z.popSession(grabPOPHost, grabPOPPort, grabEmail, grabPassword, true))
                    {
                        grabEmail = popClient.popMail;
                        popClient.doConnect(); //calls a new client so it can logout successfully.


                        popClient.Dispose();

                        isLoggedIn = false;
                        Session["loggedin"] = isLoggedIn;

                    }
                }
                Response.Redirect("Default.aspx", false);
            }
        }

        catch (Exception) { }
    }