Exemplo 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;
        }
Exemplo n.º 2
0
        public static System.Data.DataTable GetDataSource(System.Collections.Specialized.ListDictionary addressbook, bool specific, anmar.SharpWebMail.IEmailClient client)
        {
            if (!addressbook.Contains("connectionstring") ||
                !addressbook.Contains("searchstring"))
            {
                return(null);
            }
            System.String connectstring = addressbook["connectionstring"].ToString();
            System.String connectusername = null, connectpassword = null;
            if (addressbook.Contains("connectionusername") && addressbook.Contains("connectionpassword"))
            {
                connectusername = addressbook["connectionusername"].ToString();
                connectpassword = addressbook["connectionpassword"].ToString();
            }
            else if (client != null)
            {
                connectusername = client.UserName;
                connectpassword = client.Password;
            }

            System.String searchfilter;
            if (specific)
            {
                searchfilter = addressbook["searchstringrealname"].ToString();
            }
            else
            {
                searchfilter = addressbook["searchstring"].ToString();
            }
            if (client != null)
            {
                searchfilter = searchfilter.Replace("$USERNAME$", client.UserName);
            }
            else
            {
                searchfilter = searchfilter.Replace("$USERNAME$", System.String.Empty);
            }
            System.String namecolumn  = addressbook["namecolumn"].ToString();
            System.String mailcolumn  = addressbook["emailcolumn"].ToString();
            System.String ownercolumn = "owner";
            if (addressbook.Contains("ownercolumn"))
            {
                ownercolumn = addressbook["ownercolumn"].ToString();
            }
            if (addressbook["type"].Equals("ldap"))
            {
                return(GetDataSourceLDAP(addressbook["name"].ToString(), connectstring, connectusername, connectpassword, searchfilter, namecolumn, mailcolumn, ownercolumn));
            }
            else if (addressbook["type"].Equals("odbc"))
            {
                return(GetDataSourceODBC(addressbook["name"].ToString(), connectstring, connectusername, connectpassword, searchfilter, namecolumn, mailcolumn, ownercolumn));
            }
            else if (addressbook["type"].Equals("oledb"))
            {
                return(GetDataSourceOLEDB(addressbook["name"].ToString(), connectstring, connectusername, connectpassword, searchfilter, namecolumn, mailcolumn, ownercolumn));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public static bool UpdateDataSource(System.Data.DataTable data, System.Collections.Specialized.ListDictionary addressbook, anmar.SharpWebMail.IEmailClient client)
        {
            bool error = false;

            if (data == null || addressbook == null || !addressbook.Contains("connectionstring") ||
                !addressbook.Contains("searchstring") || !addressbook.Contains("allowupdate") || !((bool)addressbook["allowupdate"]))
            {
                return(false);
            }
            System.String connectstring = addressbook["connectionstring"].ToString();
            System.String connectusername = null, connectpassword = null;
            if (addressbook.Contains("connectionusername") && addressbook.Contains("connectionpassword"))
            {
                connectusername = addressbook["connectionusername"].ToString();
                connectpassword = addressbook["connectionpassword"].ToString();
            }
            else if (client != null)
            {
                connectusername = client.UserName;
                connectpassword = client.Password;
            }

            System.String searchfilter = addressbook["searchstring"].ToString();
            if (client != null)
            {
                searchfilter = searchfilter.Replace("$USERNAME$", client.UserName);
            }
            else
            {
                searchfilter = searchfilter.Replace("$USERNAME$", System.String.Empty);
            }
            System.Data.Common.DbDataAdapter adapter = GetDataAdapter(addressbook["type"].ToString(), connectstring, connectusername, connectpassword, searchfilter);
            if (adapter != null)
            {
                try {
                    if (addressbook["type"].Equals("odbc"))
                    {
                        System.Data.Odbc.OdbcCommandBuilder builder = new System.Data.Odbc.OdbcCommandBuilder(adapter as System.Data.Odbc.OdbcDataAdapter);
                        adapter.Update(data);
                        builder = null;
                    }
                    else if (addressbook["type"].Equals("oledb"))
                    {
                        System.Data.OleDb.OleDbCommandBuilder builder = new System.Data.OleDb.OleDbCommandBuilder(adapter as System.Data.OleDb.OleDbDataAdapter);
                        adapter.Update(data);
                        builder = null;
                    }
                } catch (System.Exception e) {
                    if (log.IsErrorEnabled)
                    {
                        log.Error(System.String.Concat("Error updating address book [", addressbook["name"], "] for user [", client.UserName, "]"), e);
                    }
                    error = true;
                }
            }
            else
            {
                error = true;
            }
            adapter = null;
            return(!error);
        }
Exemplo n.º 4
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;
         }
     }
 }
Exemplo n.º 5
0
        private System.String SendMailOpenSmtp(anmar.SharpWebMail.EmailServerInfo server)
        {
            System.String             message     = null;
            System.Text.Encoding      encoding    = (System.Text.Encoding)Application["sharpwebmail/send/message/charset"];
            OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
            mailMessage.Charset = encoding.HeaderName;
            mailMessage.From    = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
            System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
            foreach (System.String token in tokens)
            {
                if (anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token))
                {
                    mailMessage.To.Add(new OpenSmtp.Mail.EmailAddress(token.Trim()));
                }
            }
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if (format != null && format.Equals("html"))
            {
                mailMessage.HtmlBody = bodyStart + FCKEditor.Value + bodyEnd;
            }
            else
            {
                mailMessage.Body = FCKEditor.Value;
            }

            if (this._headers != null)
            {
                // RFC 2822 3.6.4. Identification fields
                OpenSmtp.Mail.MailHeader references = new OpenSmtp.Mail.MailHeader("References", System.String.Empty);
                if (this._headers["Message-ID"] != null)
                {
                    mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
                    references.Body = this._headers["Message-ID"];
                }
                if (this._headers["References"] != null)
                {
                    references.Body = System.String.Concat(this._headers["References"], " ", references.Body).Trim();
                }
                else if (this._headers["In-Reply-To"] != null && this._headers["In-Reply-To"].IndexOf('>') == this._headers["In-Reply-To"].LastIndexOf('>'))
                {
                    references.Body = System.String.Concat(this._headers["In-Reply-To"], " ", references.Body).Trim();
                }
                if (!references.Body.Equals(System.String.Empty))
                {
                    mailMessage.AddCustomHeader(references);
                }
            }
            mailMessage.AddCustomHeader("X-Mailer", System.String.Concat(Application["product"], " ", Application["version"]));
            this.ProcessMessageAttachments(mailMessage);
            try {
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Concat("Sending message. engine: opensmtp , protocol: ", server.Protocol));
                }
                OpenSmtp.Mail.Smtp SmtpMail = null;
                if (server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth))
                {
                    anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, client.UserName, client.Password, server.Port);
                }
                else
                {
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, server.Port);
                }
                SmtpMail.SendMail(mailMessage);
                SmtpMail = null;
                if (log.IsDebugEnabled)
                {
                    log.Debug("Message sent");
                }
            } catch (System.Exception e) {
                message = e.Message;
                if (log.IsErrorEnabled)
                {
                    log.Error(System.String.Concat("Error sending message. engine: opensmtp , protocol: ", server.Protocol), e);
                }
            }
            mailMessage = null;
            return(message);
        }