Ejemplo n.º 1
0
        /*
         * General functions
         */
        /// <summary>
        ///
        /// </summary>
        protected void bindInbox()
        {
            anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];

            if (!this.refresh && ((int)Application["sharpwebmail/read/inbox/stat"]) == 1)
            {
                this.refresh = true;
            }

            System.String pattern;
            if (this.searchPattern(out pattern))
            {
                if (client != null)
                {
                    client.GetFolderIndex(this.SharpUI.Inbox, 0, this.SharpUI.Inbox.Count, this.refresh);
                }
            }
            else
            {
                // Ask for new messages if necessary
                if (client != null)
                {
                    client.GetFolderIndex(this.SharpUI.Inbox, this.InboxDataGrid.CurrentPageIndex, (int)Application["sharpwebmail/read/inbox/pagesize"], this.refresh);
                }
                // Update message count
                if (this.refresh)
                {
                    this.SharpUI.setVariableLabels();
                }
            }
            this.buildDataGrid();
            System.Data.DataView tmpV = this.SharpUI.Inbox.Inbox;
            this.sort = this.SharpUI.Inbox.SortExpression;
            if ((this.sort == null || this.sort.Length == 0) && Application["sharpwebmail/read/inbox/sort"] != null)
            {
                this.sort = Application["sharpwebmail/read/inbox/sort"].ToString();
            }
            if (this.sort == null || this.sort.Length == 0)
            {
                this.sort = "msgnum DESC";
            }
            tmpV.RowFilter = pattern;
            tmpV.Sort      = this.sort;
            this.InboxDataGrid.DataSource = tmpV;
            if ((this.InboxDataGrid.CurrentPageIndex + 1) * this.InboxDataGrid.PageSize > tmpV.Count)
            {
                this.InboxDataGrid.CurrentPageIndex = (tmpV.Count - 1) / this.InboxDataGrid.PageSize;
            }
            this.InboxDataGrid.DataBind();

            this.mainInterface( );

            client = null;
        }
Ejemplo n.º 2
0
 protected void Login_Click(System.Object sender, System.EventArgs args)
 {
     // authenticate user
     if (this.IsValid)
     {
         int login_mode = (int)Application["sharpwebmail/login/mode"];
         if (login_mode == 3 && Application["sharpwebmail/login/append"] != null)
         {
             if (this.username.Value.IndexOf("@") == -1)
             {
                 this.username.Value = System.String.Format("{0}@{1}", this.username.Value, Application["sharpwebmail/login/append"]);
             }
             this.usernameValidator.ValidationExpression = "^" + anmar.SharpMimeTools.ABNF.addr_spec + "$";
             this.usernameValidator.Validate();
         }
         if (this.IsValid)
         {
             this.username.Value = this.PrepareLogin(this.username.Value);
             anmar.SharpWebMail.ServerSelector  selector = (anmar.SharpWebMail.ServerSelector)Application["sharpwebmail/read/servers"];
             anmar.SharpWebMail.EmailServerInfo server   = null;
             if (selectserver != null && selectserver.Visible)
             {
                 server = selector.Select(this.selectserver.Value, false);
             }
             else
             {
                 server = selector.Select(this.username.Value, true);
             }
             anmar.SharpWebMail.IEmailClient client = anmar.SharpWebMail.EmailClientFactory.CreateEmailClient(server, this.username.Value, password.Value);
             anmar.SharpWebMail.CTNInbox     inbox  = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
             inbox.Client = client;
             System.String folder = Page.Request.QueryString["mode"];
             if (folder == null || folder.Length == 0)
             {
                 folder = "inbox";
             }
             inbox.CurrentFolder = folder;
             if (client != null && client.GetFolderIndex(inbox, 0, (int)Application["sharpwebmail/read/inbox/pagesize"], true))
             {
                 Session["client"] = client;
                 Session["inbox"]  = inbox;
                 if (login_mode == 2)
                 {
                     Session["DisplayEmail"] = client.UserName;
                 }
                 if (Application["sharpwebmail/send/addressbook"] != null)
                 {
                     System.Collections.SortedList addressbooks = (System.Collections.SortedList)Application["sharpwebmail/send/addressbook"];
                     foreach (System.Collections.Specialized.ListDictionary addressbook in addressbooks.Values)
                     {
                         if (addressbook.Contains("searchstringrealname"))
                         {
                             System.Data.DataTable result = anmar.SharpWebMail.UI.AddressBook.GetDataSource(addressbook, true, client);
                             if (result == null)
                             {
                                 continue;
                             }
                             if (result.Rows.Count == 1)
                             {
                                 Session["DisplayName"] = result.Rows[0][addressbook["namecolumn"].ToString()];
                                 if (login_mode == 2)
                                 {
                                     Session["DisplayEmail"] = result.Rows[0][addressbook["emailcolumn"].ToString()];
                                 }
                                 break;
                             }
                         }
                     }
                 }
                 if (log.IsDebugEnabled)
                 {
                     log.Debug(System.String.Concat("Successful authentication for user [", this.username.Value, "], found [", inbox.Count, "] messages. Setting cookie and redirecting."));
                 }
                 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.username.Value, false);
             }
             else
             {
                 errorMsgLogin.Visible = true;
             }
             client   = null;
             inbox    = null;
             selector = null;
         }
     }
 }