private anmar.SharpWebMail.ServerSelector ParseConfigServers(System.Xml.XmlNodeList list)
        {
            anmar.SharpWebMail.ServerSelector selector = new anmar.SharpWebMail.ServerSelector();
            foreach (System.Xml.XmlNode item in list)
            {
                if (item.NodeType.Equals(System.Xml.XmlNodeType.Element) && (item.LocalName.Equals("server") || item.LocalName.Equals("add")))
                {
                    System.Xml.XmlElement element = (System.Xml.XmlElement)item;
                    if (element.HasAttribute("key") && element.HasAttribute("value"))                       // Old format
                    {
                        selector.Add(element.GetAttribute("key"), element.GetAttribute("value"));
                    }
                    else if (element.HasAttribute("protocol") && element.HasAttribute("host") && element.HasAttribute("port"))                         // New format
                    {
                        anmar.SharpWebMail.EmailServerInfo server = new anmar.SharpWebMail.EmailServerInfo(element.GetAttribute("protocol"), element.GetAttribute("host"), element.GetAttribute("port"));
                        if (element.HasAttribute("regexp"))
                        {
                            server.SetCondition(element.GetAttribute("regexp"));
                        }
                        if (element.HasAttribute("name"))
                        {
                            server.Name = element.GetAttribute("name");
                        }

                        if (server.IsValid())
                        {
                            selector.Add(server);
                        }
                    }
                }
            }
            return(selector);
        }
Example #2
0
 public void Add(anmar.SharpWebMail.EmailServerInfo server)
 {
     if (server == null || !server.IsValid())
     {
         throw new System.ArgumentNullException();
     }
     this._servers.Add(server);
 }
Example #3
0
        public static anmar.SharpWebMail.IEmailClient CreateEmailClient(anmar.SharpWebMail.EmailServerInfo server, System.String username, System.String password)
        {
            if (server == null)
            {
                return(null);
            }
            switch (server.Protocol)
            {
            case anmar.SharpWebMail.ServerProtocol.Pop3:
                return(new anmar.SharpWebMail.CTNSimplePOP3Client(server.Host, server.Port, username, password));

            case anmar.SharpWebMail.ServerProtocol.Imap:
                return(new anmar.SharpWebMail.SimpleIMAPClient(server.Host, server.Port, username, password));
            }
            return(null);
        }
Example #4
0
 public static anmar.SharpWebMail.EmailServerInfo Parse(System.String value)
 {
     anmar.SharpWebMail.EmailServerInfo server = null;
     System.String[] values = value.ToString().Split(':');
     if (values.Length == 3)
     {
         anmar.SharpWebMail.ServerProtocol protocol = anmar.SharpWebMail.EmailServerInfo.ParseProtocol(values[0]);
         System.String host = anmar.SharpWebMail.EmailServerInfo.ParseHost(values[1]);
         int           port = anmar.SharpWebMail.EmailServerInfo.ParsePort(values[2], protocol);
         if (!protocol.Equals(anmar.SharpWebMail.ServerProtocol.Unknown) && port > 0 && host != null)
         {
             server = new anmar.SharpWebMail.EmailServerInfo(protocol, host, port);
         }
     }
     return(server);
 }
Example #5
0
        public void Add(System.Object key, System.Object value)
        {
            if (key == null || value == null)
            {
                throw new System.ArgumentNullException();
            }

            anmar.SharpWebMail.EmailServerInfo server = anmar.SharpWebMail.EmailServerInfo.Parse(value.ToString());
            if (server != null)
            {
                server.SetCondition(key.ToString());
                if (server.IsValid())
                {
                    this._servers.Add(server);
                }
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        protected void Send_Click(System.Object sender, System.EventArgs args)
        {
            System.String message = null;
            if (this.IsValid)
            {
                this.UI_case = 1;
                if ((int)Application["sharpwebmail/send/message/sanitizer_mode"] == 1)
                {
                    FCKEditor.Value = anmar.SharpWebMail.BasicSanitizer.SanitizeHTML(FCKEditor.Value, anmar.SharpWebMail.SanitizerMode.CommentBlocks | anmar.SharpWebMail.SanitizerMode.RemoveEvents);
                }
                anmar.SharpWebMail.ServerSelector  selector = (anmar.SharpWebMail.ServerSelector)Application["sharpwebmail/send/servers"];
                anmar.SharpWebMail.EmailServerInfo server   = selector.Select(User.Identity.Name, true);
                if (server != null && (server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.Smtp) ||
                                       server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth)))
                {
                    if (Application["sharpwebmail/send/message/smtp_engine"].Equals("opensmtp"))
                    {
                        message = this.SendMailOpenSmtp(server);
                    }
                    else if (Application["sharpwebmail/send/message/smtp_engine"].Equals("dotnetopenmail"))
                    {
                        message = this.SendMailDotNetOpenMail(server);
                    }
                    else
                    {
                        message = this.SendMail(server);
                    }

                    if (message == null)
                    {
                        message = this.SharpUI.LocalizedRS.GetString("newMessageSent");
                    }
                }
            }
            else
            {
                message = this.SharpUI.LocalizedRS.GetString("newMessageValidationError");
            }
            newMessageWindowConfirmation.Text = message;
        }
Example #7
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;
         }
     }
 }
Example #8
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);
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        private System.String SendMail(anmar.SharpWebMail.EmailServerInfo server)
        {
            System.String message = null;
            System.Web.Mail.SmtpMail.SmtpServer = server.Host;

            System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
            mailMessage.To      = this.toemail.Value;
            mailMessage.From    = System.String.Format("{0} <{1}>", this.fromname.Value, this.GetFromAddress());
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if (format != null && format.Equals("html"))
            {
                mailMessage.BodyFormat = System.Web.Mail.MailFormat.Html;
                mailMessage.Body       = bodyStart + FCKEditor.Value + bodyEnd;
            }
            else
            {
                mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text;
                mailMessage.Body       = FCKEditor.Value;
            }

            if (this._headers != null)
            {
                // RFC 2822 3.6.4. Identification fields
                if (this._headers["Message-ID"] != null)
                {
                    mailMessage.Headers["In-Reply-To"] = this._headers["Message-ID"];
                    mailMessage.Headers["References"]  = this._headers["Message-ID"];
                }
                if (this._headers["References"] != null)
                {
                    mailMessage.Headers["References"] = System.String.Concat(this._headers["References"], " ", mailMessage.Headers["References"]).Trim();
                }
                else if (this._headers["In-Reply-To"] != null && this._headers["In-Reply-To"].IndexOf('>') == this._headers["In-Reply-To"].LastIndexOf('>'))
                {
                    mailMessage.Headers["References"] = System.String.Concat(this._headers["In-Reply-To"], " ", mailMessage.Headers["References"]).Trim();
                }
            }
            mailMessage.Headers["X-Mailer"] = System.String.Format("{0} {1}", Application["product"], Application["version"]);
            this.ProcessMessageAttachments(mailMessage);
            try {
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Concat("Sending message. engine: internal , protocol: ", server.Protocol));
                }
                System.Web.Mail.SmtpMail.Send(mailMessage);
                if (log.IsDebugEnabled)
                {
                    log.Debug("Message sent");
                }
            } catch (System.Exception e) {
                message = e.Message;
#if DEBUG && !MONO
                message += ". <br>InnerException: " + e.InnerException.Message;
#endif
                if (log.IsErrorEnabled)
                {
                    log.Error(System.String.Concat("Error sending message. engine: internal , protocol: ", server.Protocol), e);
                }
                if (log.IsErrorEnabled)
                {
                    log.Error("Error sending message (InnerException)", e.InnerException);
                }
            }
            mailMessage = null;
            return(message);
        }
        private ServerSelector ParseConfigServers(XmlNodeList list )
        {
            ServerSelector selector = new ServerSelector();
            foreach (XmlNode item in list ) {
                if ( item.NodeType.Equals(XmlNodeType.Element) && (item.LocalName.Equals("server") || item.LocalName.Equals("add")) ) {
                    XmlElement element = (XmlElement)item;
                    if ( element.HasAttribute("key") && element.HasAttribute("value") ) // Old format
                        selector.Add(element.GetAttribute("key"), element.GetAttribute("value"));
                    else if ( element.HasAttribute("protocol") && element.HasAttribute("host") && element.HasAttribute("port") ) { // New format
                        anmar.SharpWebMail.EmailServerInfo server = new anmar.SharpWebMail.EmailServerInfo(element.GetAttribute("protocol"), element.GetAttribute("host"), element.GetAttribute("port"));
                        if ( element.HasAttribute("regexp") )
                            server.SetCondition (element.GetAttribute("regexp"));
                        if ( element.HasAttribute("name") )
                            server.Name = element.GetAttribute("name");

                        if ( server.IsValid() )
                            selector.Add(server);
                    }
                }
            }
            return selector;
        }