Beispiel #1
0
        private void NextMessPage_Click(object sender, EventArgs e)
        {
            MessageCache msg    = (MessageCache)Session[UC.UserName];
            long         pageid = Convert.ToInt32(MessPageID.Text);

            pageid = pageid + UC.PagingSize;
            long tocopy = UC.PagingSize;

            if (msg.LastPosition > 0 && msg.FilledTo <= pageid)
            {
                AddMsgToCache();
            }

            Message[] msgs = new Message[((MessageCache)Session[UC.UserName]).Messages.Length];
            msgs = ((MessageCache)Session[UC.UserName]).Messages;

            Message[] msgs2 = new Message[UC.PagingSize];

            if ((pageid + UC.PagingSize) >= msgs.Length)
            {
                tocopy = msgs.Length - pageid;
                msgs2  = new Message[tocopy];
            }

            Array.Copy(msgs, pageid, msgs2, 0, tocopy);
            MessPageID.Text = pageid.ToString();
            if ((pageid + UC.PagingSize) >= msgs.Length)
            {
                NextMessPage.Enabled = false;
            }
            else
            {
                NextMessPage.Enabled = true;
            }
            Repeatermsg.DataSource = msgs2;
            Repeatermsg.DataBind();

            PreviousMessPage.Enabled = true;
        }
Beispiel #2
0
        private void PreviousMessPage_Click(object sender, EventArgs e)
        {
            Message[] msgs = new Message[((MessageCache)Session[UC.UserName]).Messages.Length];
            msgs = ((MessageCache)Session[UC.UserName]).Messages;
            Message[] msgs2  = new Message[UC.PagingSize];
            int       pageid = Convert.ToInt32(MessPageID.Text);

            pageid = pageid - UC.PagingSize;
            Array.Copy(msgs, pageid, msgs2, 0, UC.PagingSize);
            MessPageID.Text = pageid.ToString();
            if ((pageid - UC.PagingSize) < 0)
            {
                PreviousMessPage.Enabled = false;
            }
            else
            {
                PreviousMessPage.Enabled = true;
            }
            Repeatermsg.DataSource = msgs2;
            Repeatermsg.DataBind();

            NextMessPage.Enabled = true;
        }
Beispiel #3
0
        private void FillMsgIn(bool force, bool firstLoad)
        {
            try
            {
                long    msgLoop = 0;
                DataRow dtpop3  = DatabaseConnection.CreateDataset("SELECT MAILSERVER,MAILUSER,MAILPASSWORD FROM ACCOUNT WHERE UID=" + UC.UserId).Tables[0].Rows[0];
                if (dtpop3[1].ToString().Length > 0 && dtpop3[2].ToString().Length > 0 && dtpop3[0].ToString().Length > 0)
                {
                    string pop3   = dtpop3[0].ToString();
                    bool   secure = false;
                    if (pop3.StartsWith("!"))
                    {
                        pop3   = pop3.Substring(1);
                        secure = true;
                    }

                    using (Pop3Client email = new Pop3Client(dtpop3[1].ToString(), dtpop3[2].ToString(), pop3, secure))
                    {
                        email.OpenInbox();

                        Message[] msgs = new Message[email.MessageCount];

                        if (msgs.Length > 0)
                        {
                            if ((Session[UC.UserName] == null || ((Session[UC.UserName] is MessageCache) && email.IsNewMessages(((MessageCache)Session[UC.UserName]).LastSerial))) || force)
                            {
                                msgLoop = msgs.Length - 1;
                                long posid = 1;
                                if (msgs.Length > UC.PagingSize)
                                {
                                    email.PositionID = msgs.Length - UC.PagingSize;
                                    posid            = msgs.Length - UC.PagingSize;
                                    msgLoop          = msgs.Length - email.PositionID - 1;
                                    if (msgLoop < 0)
                                    {
                                        msgLoop = 0;
                                    }
                                }
                                else
                                {
                                    email.PositionID = 0;
                                    msgLoop          = 0;
                                }
                                long filledTo = msgLoop;
                                while (email.NextEmail(true))                                 // solo top
                                {
                                    Message msg = new Message();

                                    try
                                    {
                                        msg.From = (email.From.Length > 0) ? email.From : " ";
                                    }
                                    catch
                                    {
                                        msg.From = " ";
                                    }

                                    try
                                    {
                                        msg.To = (email.To.Length > 0) ? email.To : " ";
                                    }
                                    catch
                                    {
                                        msg.To = " ";
                                    }

                                    try
                                    {
                                        msg.Subject = (email.Subject.Length > 0) ? email.Subject : " ";
                                    }
                                    catch
                                    {
                                        msg.Subject = " ";
                                    }

                                    try
                                    {
                                        msg.Size = email.Size;
                                    }
                                    catch
                                    {
                                        msg.Size = 0;
                                    }

                                    try
                                    {
                                        msg.MessageID = (email.MessageID != null) ? Regex.Replace(email.MessageID.Trim('<', '>'), @"[^a-zA-Z0-9_]", "_") : "";
                                    }
                                    catch
                                    {
                                        msg.MessageID = String.Empty;
                                    }

                                    msg.MsgID     = email.PositionID;
                                    msg.MsgSerial = email.GetSerial;
                                    try
                                    {
                                        msg.MsgDate = UC.LTZ.ToLocalTime(email.Date);
                                    }
                                    catch
                                    {
                                        msg.MsgDate = new DateTime(1980, 1, 1);
                                    }

                                    if (msgs.Length > UC.PagingSize)
                                    {
                                        msgs[msgLoop--] = msg;
                                    }
                                    else
                                    {
                                        msgs[msgLoop++] = msg;
                                    }
                                }

                                MessageCache MCache = new MessageCache(msgs, email.LastSerial);
                                MCache.LastPosition = posid;
                                MCache.FilledTo     = filledTo;

                                if (msgs.Length < UC.PagingSize)
                                {
                                    Array.Reverse(msgs);
                                }

                                Session.Add(UC.UserName, MCache);
                            }
                            else
                            {
                                msgs    = ((MessageCache)Session[UC.UserName]).Messages;
                                msgLoop = ((MessageCache)Session[UC.UserName]).LastPosition;
                            }
                        }
                        else
                        {
                            lblError.Text = "<br><center>" + Root.rm.GetString("WebMLtxt12") + "</center>";
                        }

                        email.CloseConnection();
                        if (msgs.Length > 0)
                        {
                            if (msgs.Length > UC.PagingSize)
                            {
                                if (firstLoad)
                                {
                                    msgLoop = -1;
                                }
                                Message[] msgs2 = new Message[UC.PagingSize];
                                Array.Copy(msgs, msgLoop + 1, msgs2, 0, UC.PagingSize);
                                tblpaging.Visible        = true;
                                MessPageID.Text          = "0";
                                PreviousMessPage.Enabled = false;
                                NextMessPage.Enabled     = true;
                                Repeatermsg.DataSource   = msgs2;
                                Repeatermsg.DataBind();
                            }
                            else
                            {
                                tblpaging.Visible      = false;
                                Repeatermsg.DataSource = msgs;
                                Repeatermsg.DataBind();
                            }


                            Lblmsginfo.Text = "<b>" + dtpop3[1].ToString() + "</b>&nbsp;" + String.Format(Root.rm.GetString("Mailtxt8"), msgs.Length.ToString(), Convert.ToString(email.TotalBytes / 1024));

                            if (msgs.Length == 0)
                            {
                                dgmessages.Visible = false;
                            }

                            messages.Visible = true;
                        }
                    }
                }
                else
                {
                    lblError.Text = "<br><br><center><div style=\"color:red;font-size:12px;width:600px;\">" + Root.rm.GetString("WebMLtxt8") + "</div></center>";
                }
            }

            catch (Pop3PasswordException)
            {
                Context.Items.Add("warning", Root.rm.GetString("Mailtxt16"));
            }
            catch (Pop3LoginException)
            {
                Context.Items.Add("warning", Root.rm.GetString("Mailtxt17"));
            }
            catch (Pop3ConnectException)
            {
                Context.Items.Add("warning", Root.rm.GetString("Mailtxt16"));
            }


            this.dgmessages.Visible = false;
            Repeatermsg.Visible     = true;
        }