Пример #1
0
 protected void closeSession()
 {
     if (Request.IsAuthenticated)
     {
         // Delete messages marked for deletion
         if (this.inbox != null && this.inbox.Client != null && (bool)Application["sharpwebmail/read/inbox/commit_onexit"])
         {
             this.inbox.Client.PurgeInbox(this.inbox, false);
             Session.Remove("client");
         }
         // Flush inbox content
         this.inbox       = new anmar.SharpWebMail.CTNInbox();
         Session["inbox"] = this.inbox;
         this.inbox       = null;
         // Clean up temp files
         cleanTempFolder(Session["sharpwebmail/read/message/temppath"]);
         cleanTempFolder(Session["sharpwebmail/send/message/temppath"]);
         Session.Remove("DisplayEmail");
         Session.Remove("DisplayName");
         // Logout
         System.Web.Security.FormsAuthentication.SignOut();
         // Go to login page
         Response.Redirect("default.aspx");
     }
 }
        private bool getListToIndex(System.Collections.Hashtable msgs, int total, anmar.SharpWebMail.CTNInbox inbox, int npage, int npagesize)
        {
            bool error = false;

            System.Int32[]  list    = new System.Int32[total];
            System.String[] uidlist = new System.String[total];
            if (total > 0)
            {
                // Get uid list
                error = (error)?error:!this.uidl(uidlist, 0);
                //Get messages list
                error = (error)?error:!this.list(list);
            }
            // Prepare message table with new messages
            error = (error)?error:!inbox.buildMessageTable(list, uidlist);

            list    = null;
            uidlist = null;

            //Determine what messages we have to index
            if (msgs != null)
            {
                error = (error)?error:!inbox.buildMessageList(msgs, npage, npagesize);
            }

            return(!error);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="inbox"></param>
        /// <param name="all"></param>
        /// <returns></returns>
        public bool PurgeInbox(anmar.SharpWebMail.CTNInbox inbox, bool all)
        {
            bool error = false;

            System.String filter;
            if (all)
            {
                filter = System.String.Empty;
            }
            else
            {
                filter = "delete=true";
            }
            System.Data.DataView result = inbox.Inbox;
            result.RowFilter = filter;
            if (result.Count > 0)
            {
                int total = 0, totalbytes = 0;
                error            = !this.connect();
                error            = (error)?error:!this.login(this.username, this.password);
                error            = (error)?error:!this.status(ref total, ref totalbytes);
                error            = (error)?error:!this.getListToIndex(null, total, inbox, 0, 0);
                result.RowFilter = filter;
                error            = (error)?error:!this.deletemessages(result);
                error            = (error)?error:!this.getListToIndex(null, total, inbox, 0, 0);
                this.quit();
            }
            result.RowFilter = System.String.Empty;
            return(!error);
        }
Пример #4
0
 private void ProcessMessageAttachments(System.Object message)
 {
     // Attachments
     if (this.newMessageWindowAttachmentsAddedList.Items.Count > 0)
     {
         anmar.SharpWebMail.CTNInbox inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
         System.String Value = "";
         foreach (System.Web.UI.WebControls.ListItem item in this.newMessageWindowAttachmentsList.Items)
         {
             if (item.Selected)
             {
                 if (log.IsDebugEnabled)
                 {
                     log.Debug(System.String.Format("Attaching {0} {1}", item.Text, item.Value));
                 }
                 if (!item.Value.StartsWith(Session.SessionID))
                 {
                     Value = item.Value.Substring(0, item.Value.IndexOf(System.IO.Path.DirectorySeparatorChar));
                     System.Object[] details = inbox[Value];
                     if (details == null)
                     {
                         Value = null;
                     }
                     details = null;
                 }
                 if (Value != null)
                 {
                     System.String attachment = this.getfilename(Session["sharpwebmail/send/message/temppath"], Value, item.Text.Substring(0, item.Text.LastIndexOf(" (")));
                     if (attachment == null)
                     {
                         attachment = this.getfilename(Session["sharpwebmail/read/message/temppath"], Value, item.Text.Substring(0, item.Text.LastIndexOf(" (")));
                     }
                     if (attachment != null)
                     {
                         if (message is System.Web.Mail.MailMessage)
                         {
                             ((System.Web.Mail.MailMessage)message).Attachments.Add(new System.Web.Mail.MailAttachment(attachment));
                         }
                         else if (message is DotNetOpenMail.EmailMessage)
                         {
                             ((DotNetOpenMail.EmailMessage)message).AddMixedAttachment(new DotNetOpenMail.FileAttachment(new System.IO.FileInfo(attachment)));
                         }
                         else if (message is OpenSmtp.Mail.MailMessage)
                         {
                             ((OpenSmtp.Mail.MailMessage)message).AddAttachment(attachment);
                         }
                         if (log.IsDebugEnabled)
                         {
                             log.Debug(System.String.Format("Attached {0}", attachment));
                         }
                     }
                 }
             }
         }
     }
 }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 protected void InboxDataGrid_Sort(System.Object sender, System.Web.UI.WebControls.DataGridSortCommandEventArgs args)
 {
     this.sort = args.SortExpression.ToString();
     anmar.SharpWebMail.CTNInbox inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
     if (!inbox.SortExpression.Equals(this.sort))
     {
         inbox.SortExpression = this.sort;
         this.InboxDataGrid.CurrentPageIndex = 0;
     }
     inbox = null;
 }
Пример #6
0
        public void Session_Start(System.Object sender, System.EventArgs args)
        {
            // Inbox Object
            anmar.SharpWebMail.CTNInbox inbox = new anmar.SharpWebMail.CTNInbox();
            if (Application["sharpwebmail/read/inbox/sort"] != null)
            {
                inbox.SortExpression = Application["sharpwebmail/read/inbox/sort"].ToString();
            }
            Session["inbox"] = inbox;

            Session["sharpwebmail/read/message/temppath"] = parseTempFolder(Application["sharpwebmail/read/message/temppath"], Session.SessionID);
            Session["sharpwebmail/send/message/temppath"] = parseTempFolder(Application["sharpwebmail/send/message/temppath"], Session.SessionID);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="inbox"></param>
        /// <param name="npage"></param>
        /// <param name="npagesize"></param>
        /// <param name="askserver"></param>
        /// <returns></returns>
        public virtual bool GetFolderIndex(anmar.SharpWebMail.CTNInbox inbox, int npage, int npagesize, bool askserver)
        {
            bool error      = false;
            int  total      = 0;
            int  totalbytes = 0;

            System.Collections.Hashtable list = new System.Collections.Hashtable();

            if (!askserver)
            {
                error     = !inbox.buildMessageList(list, npage, npagesize);
                askserver = (!error && list.Count > 0)?!askserver:askserver;
            }
            if (askserver)
            {
                System.Collections.Hashtable messages = new System.Collections.Hashtable();
                error = !this.connect();
                error = (error)?error:!this.login(this.username, this.password);
                error = (error)?error:!this.status(ref total, ref totalbytes);

                error = (error)?error:!this.getListToIndex(list, total, inbox, npage, npagesize);

                if (!error && total > 0 && list.Count > 0)
                {
                    System.IO.MemoryStream header = null;
                    foreach (System.Collections.DictionaryEntry msg in list)
                    {
                        error = (error)?error:!this.getMessageHeader(out header, (int)msg.Key);
                        if (!error)
                        {
                            messages.Add(msg.Value, header);
                        }
                    }
                }
                this.quit();
                foreach (System.Collections.DictionaryEntry item in messages)
                {
                    System.IO.MemoryStream stream = this.getStreamDataPortion(item.Value as System.IO.MemoryStream);
                    anmar.SharpMimeTools.SharpMimeHeader header = new anmar.SharpMimeTools.SharpMimeHeader(stream, stream.Position);
                    header.Close();
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(System.String.Concat("Parsed message header uidl[", item.Key, "] msgid[", header.MessageID, "], now adding to inbox."));
                    }
                    inbox.newMessage(item.Key.ToString(), header);
                }
            }
            return(!error);
        }
Пример #8
0
 protected void InboxDataGrid_Delete(System.Object sender, System.Web.UI.WebControls.DataGridCommandEventArgs args)
 {
     if (this.delete != null && this.delete.Count > 0)
     {
         anmar.SharpWebMail.CTNInbox inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
         foreach (System.String item in this.delete)
         {
             if (item != null)
             {
                 inbox.DeleteMessage(item);
             }
         }
         if ((bool)Application["sharpwebmail/read/inbox/commit_ondelete"])
         {
             inbox.Client.PurgeInbox(inbox, false);
         }
         this.SharpUI.setVariableLabels();
     }
 }
Пример #9
0
        /*
         * Page Events
         */
        /// <summary>
        ///
        /// </summary>
        protected void Page_Load(System.Object sender, System.EventArgs args)
        {
            // Prevent caching, so can't be viewed offline
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

            System.String msgid = Page.Request.QueryString["msgid"];
            if (msgid != null)
            {
                //Our Inbox
                anmar.SharpWebMail.CTNInbox inbox   = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
                System.Object[]             details = inbox[msgid];
                if (details != null && details.Length > 0)
                {
                    this.headers.Text = Server.HtmlEncode(((anmar.SharpMimeTools.SharpMimeHeader)details[13]).RawHeaders);
                    this.headers.Text = System.String.Format("<pre>{0}</pre>", this.headers.Text);
                }
                inbox = null;
            }
        }
Пример #10
0
        /*
         * Page Events
         */
        protected void Page_Init()
        {
            if (Request.IsAuthenticated && Session["client"] == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Concat("Session [", this.Session.SessionID, "] has inconsistent state, restarting."));
                }
                this.closeSession();
            }

            if (this.centralPanel != null)
            {
                this.centralPanel.InstantiateIn(this.centralPanelHolder);
            }
            if (this.inbox == null)
            {
                this.inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
            }
            this.resources = (System.Resources.ResourceSet)Session["resources"];
        }
Пример #11
0
        public void Session_Start( System.Object sender, System.EventArgs args )
        {
            // Inbox Object
            anmar.SharpWebMail.CTNInbox inbox = new anmar.SharpWebMail.CTNInbox();
            if ( Application["sharpwebmail/read/inbox/sort"]!=null )
                inbox.SortExpression = Application["sharpwebmail/read/inbox/sort"].ToString();
            Session["inbox"] = inbox;

            Session["sharpwebmail/read/message/temppath"] = parseTempFolder(Application["sharpwebmail/read/message/temppath"], Session.SessionID);
            Session["sharpwebmail/send/message/temppath"] = parseTempFolder(Application["sharpwebmail/send/message/temppath"], Session.SessionID);
        }
Пример #12
0
        /*
         * Page Events
        */
        protected void Page_Init()
        {
            if ( Request.IsAuthenticated && Session["client"]==null ) {
                if ( log.IsDebugEnabled )
                    log.Debug (System.String.Concat("Session [", this.Session.SessionID, "] has inconsistent state, restarting."));
                this.closeSession();
            }

            if ( this.centralPanel!=null ) {
                this.centralPanel.InstantiateIn (this.centralPanelHolder);
            }
            if ( this.inbox==null) {
                this.inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];
            }
            this.resources = (System.Resources.ResourceSet) Session["resources"];
        }
Пример #13
0
 protected void closeSession()
 {
     if ( Request.IsAuthenticated ) {
         // Delete messages marked for deletion
         if ( this.inbox!=null && this.inbox.Client!=null && (bool)Application["sharpwebmail/read/inbox/commit_onexit"] ) {
             this.inbox.Client.PurgeInbox ( this.inbox, false );
             Session.Remove ("client");
         }
         // Flush inbox content
         this.inbox = new anmar.SharpWebMail.CTNInbox();
         Session["inbox"] = this.inbox;
         this.inbox = null;
         // Clean up temp files
         cleanTempFolder(Session["sharpwebmail/read/message/temppath"]);
         cleanTempFolder(Session["sharpwebmail/send/message/temppath"]);
         Session.Remove ("DisplayEmail");
         Session.Remove ("DisplayName");
         // Logout
         System.Web.Security.FormsAuthentication.SignOut();
         // Go to login page
         Response.Redirect("default.aspx");
     }
 }
Пример #14
0
        protected void Page_Load(System.Object sender, System.EventArgs args)
        {
            //Our Inbox
            anmar.SharpWebMail.CTNInbox inbox = (anmar.SharpWebMail.CTNInbox)Session["inbox"];

            System.String msgid  = System.Web.HttpUtility.HtmlEncode(Page.Request.QueryString["msgid"]);
            System.String name   = Page.Request.QueryString["name"];
            System.String inline = Page.Request.QueryString["i"];
            if (msgid != null && name != null && Session["sharpwebmail/read/message/temppath"] != null)
            {
                System.Object[] details = inbox[msgid];
                if (details != null && details.Length > 0)
                {
                    System.String path = Session["sharpwebmail/read/message/temppath"].ToString();
                    try {
                        path = System.IO.Path.Combine(path, msgid);
                    } catch (System.ArgumentException) {
                        // Remove invalid chars
                        foreach (char ichar in System.IO.Path.InvalidPathChars)
                        {
                            msgid = msgid.Replace(ichar.ToString(), System.String.Empty);
                        }
                        path = System.IO.Path.Combine(path, msgid);
                    }
                    try {
                        name = System.IO.Path.GetFileName(name);
                    } catch (System.ArgumentException) {
                        // Remove invalid chars
                        foreach (char ichar in System.IO.Path.InvalidPathChars)
                        {
                            name = name.Replace(ichar.ToString(), System.String.Empty);
                        }
                        name = System.IO.Path.GetFileName(name);
                    }
                    System.IO.FileInfo      file = new System.IO.FileInfo(System.IO.Path.Combine(path, name));
                    System.IO.DirectoryInfo dir  = new System.IO.DirectoryInfo(path);
                    if (dir.Exists && file.Exists && dir.FullName.Equals(new System.IO.DirectoryInfo(file.Directory.FullName).FullName))
                    {
                        Page.Response.Clear();
                        //FIXME: return correct Content-Type
                        Response.AppendHeader("Content-Type", "application/octet-stream");
                        System.String header;
                        if (inline != null && inline.Equals("1"))
                        {
                            header = "inline";
                        }
                        else
                        {
                            header = "attachment";
                        }
                        header = System.String.Format("{0}; filename=\"{1}\"; size=\"{2}\";", header, name, file.Length);
                        Response.AppendHeader("Content-Disposition", header);
                        Response.AppendHeader("Content-Length", file.Length.ToString());
                        Response.WriteFile(file.FullName);
                    }
                    file = null;
                    dir  = null;
                }
                details = null;
            }
            inbox = null;
        }
Пример #15
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;
         }
     }
 }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        protected void mainInterface(anmar.SharpWebMail.CTNInbox inbox)
        {
            this.newattachmentPH                      = (System.Web.UI.WebControls.PlaceHolder) this.SharpUI.FindControl("newattachmentPH");
            this.attachmentsPH                        = (System.Web.UI.WebControls.PlaceHolder) this.SharpUI.FindControl("attachmentsPH");
            this.confirmationPH                       = (System.Web.UI.WebControls.PlaceHolder) this.SharpUI.FindControl("confirmationPH");
            this.newMessagePH                         = (System.Web.UI.WebControls.PlaceHolder) this.SharpUI.FindControl("newMessagePH");
            this.newMessageWindowAttachFile           = (System.Web.UI.HtmlControls.HtmlInputFile) this.SharpUI.FindControl("newMessageWindowAttachFile");
            this.newMessageWindowAttachmentsList      = (System.Web.UI.WebControls.CheckBoxList) this.SharpUI.FindControl("newMessageWindowAttachmentsList");
            this.newMessageWindowAttachmentsAddedList = (System.Web.UI.WebControls.DataList) this.SharpUI.FindControl("newMessageWindowAttachmentsAddedList");

            this.FCKEditor = (FredCK.FCKeditorV2.FCKeditor) this.SharpUI.FindControl("FCKEditor");
            this.fromname  = (System.Web.UI.HtmlControls.HtmlInputText) this.SharpUI.FindControl("fromname");
            this.fromemail = (System.Web.UI.HtmlControls.HtmlInputText) this.SharpUI.FindControl("fromemail");
            this.subject   = (System.Web.UI.HtmlControls.HtmlInputText) this.SharpUI.FindControl("subject");
            this.toemail   = (System.Web.UI.HtmlControls.HtmlInputText) this.SharpUI.FindControl("toemail");

#if MONO
            System.Web.UI.WebControls.RequiredFieldValidator rfv = (System.Web.UI.WebControls.RequiredFieldValidator) this.SharpUI.FindControl("ReqbodyValidator");
            rfv.Enabled = false;
            this.Validators.Remove(rfv);
#endif

            this.newMessageWindowConfirmation = (System.Web.UI.WebControls.Label) this.SharpUI.FindControl("newMessageWindowConfirmation");

            this.SharpUI.refreshPageImageButton.Click += new System.Web.UI.ImageClickEventHandler(refreshPageButton_Click);

            // Disable PlaceHolders
            this.attachmentsPH.Visible  = false;
            this.confirmationPH.Visible = false;

            // Disable some things
            this.SharpUI.nextPageImageButton.Enabled = false;
            this.SharpUI.prevPageImageButton.Enabled = false;
            // Get mode
            if (Page.Request.QueryString["mode"] != null)
            {
                try {
                    this._message_mode = (anmar.SharpWebMail.UI.MessageMode)System.Enum.Parse(typeof(anmar.SharpWebMail.UI.MessageMode), Page.Request.QueryString["mode"], true);
                } catch (System.Exception) {}
            }
            // Get message ID
            System.String msgid = System.Web.HttpUtility.HtmlEncode(Page.Request.QueryString["msgid"]);
            System.Guid   guid  = System.Guid.Empty;
            if (msgid != null)
            {
                guid = new System.Guid(msgid);
            }
            if (!this.IsPostBack && !guid.Equals(System.Guid.Empty))
            {
                System.Object[] details = inbox[guid];
                if (details != null)
                {
                    if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.None))
                    {
                        this._message_mode = anmar.SharpWebMail.UI.MessageMode.reply;
                    }
                    this._headers = (anmar.SharpMimeTools.SharpMimeHeader)details[13];
                    if (!this.IsPostBack)
                    {
                        bool html_content = this.FCKEditor.CheckBrowserCompatibility();

                        this.subject.Value = System.String.Concat(this.SharpUI.LocalizedRS.GetString(System.String.Concat(this._message_mode, "Prefix")), ":");
                        if (details[10].ToString().ToLower().IndexOf(this.subject.Value.ToLower()) != -1)
                        {
                            this.subject.Value = details[10].ToString().Trim();
                        }
                        else
                        {
                            this.subject.Value = System.String.Concat(this.subject.Value, " ", details[10]).Trim();
                        }
                        // Get the original message
                        inbox.CurrentFolder = details[18].ToString();
                        System.IO.MemoryStream            ms      = inbox.GetMessage((int)details[1], msgid);
                        anmar.SharpMimeTools.SharpMessage message = null;
                        if (ms != null && ms.CanRead)
                        {
                            System.String path = null;
                            if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.forward))
                            {
                                path = Session["sharpwebmail/read/message/temppath"].ToString();
                                path = System.IO.Path.Combine(path, msgid);
                                path = System.IO.Path.GetFullPath(path);
                            }
                            bool attachments = false;
                            if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.forward))
                            {
                                attachments = (bool)Application["sharpwebmail/send/message/forwardattachments"];
                            }
                            message = new anmar.SharpMimeTools.SharpMessage(ms, attachments, html_content, path);
                            ms.Close();
                        }
                        ms = null;
                        if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.reply))
                        {
                            // From name if present on original message's To header
                            // and we don't have it already
                            if (Session["DisplayName"] == null)
                            {
                                foreach (anmar.SharpMimeTools.SharpMimeAddress address in (System.Collections.IEnumerable)details[8])
                                {
                                    if (address["address"] != null && address["address"].Equals(User.Identity.Name) &&
                                        address["name"].Length > 0 && !address["address"].Equals(address["name"]))
                                    {
                                        this.fromname.Value = address["name"];
                                        break;
                                    }
                                }
                            }
                            // To addresses
                            foreach (anmar.SharpMimeTools.SharpMimeAddress address in (System.Collections.IEnumerable)details[9])
                            {
                                if (address["address"] != null && !address["address"].Equals(User.Identity.Name))
                                {
                                    if (this.toemail.Value.Length > 0)
                                    {
                                        this.toemail.Value += ", ";
                                    }
                                    this.toemail.Value += address["address"];
                                }
                            }
                        }
                        else if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.forward))
                        {
                            // If the original message has attachments, preserve them
                            if (message != null && message.Attachments != null && message.Attachments.Count > 0)
                            {
                                this.bindAttachments();
                                foreach (anmar.SharpMimeTools.SharpAttachment attachment in message.Attachments)
                                {
                                    if (attachment.SavedFile == null)
                                    {
                                        continue;
                                    }
                                    this.AttachmentSelect(System.IO.Path.Combine(attachment.SavedFile.Directory.Name, attachment.SavedFile.Name));
                                }
                                this.Attach_Click(this, null);
                            }
                        }
                        // Preserve the original body and some properties
                        if (message != null)
                        {
                            System.Text.StringBuilder sb_body  = new System.Text.StringBuilder();
                            System.String             line_end = null;
                            if (html_content)
                            {
                                line_end = "<br />\r\n";
                            }
                            else
                            {
                                line_end = "\r\n";
                            }
                            sb_body.Append(this.SharpUI.LocalizedRS.GetString(System.String.Concat(this._message_mode, "PrefixBody")));
                            sb_body.Append(line_end);
                            sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowFromNameLabel"));
                            sb_body.Append(" ");
                            sb_body.Append(message.From);
                            sb_body.Append(" [mailto:");
                            sb_body.Append(message.FromAddress);
                            sb_body.Append("]");
                            sb_body.Append(line_end);
                            sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowDateLabel"));
                            sb_body.Append(" ");
                            sb_body.Append(message.Date.ToString());
                            sb_body.Append(line_end);
                            sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowToEmailLabel"));
                            sb_body.Append(" ");
                            if (html_content)
                            {
                                sb_body.Append(System.Web.HttpUtility.HtmlEncode(message.To.ToString()));
                            }
                            else
                            {
                                sb_body.Append(message.To);
                            }
                            sb_body.Append(line_end);
                            sb_body.Append(this.SharpUI.LocalizedRS.GetString("newMessageWindowSubjectLabel"));
                            sb_body.Append(" ");
                            sb_body.Append(message.Subject);
                            sb_body.Append(line_end);
                            sb_body.Append(line_end);
                            if (!message.HasHtmlBody && html_content)
                            {
                                sb_body.Append("<pre>");
                            }
                            sb_body.Append(message.Body);
                            if (!message.HasHtmlBody && html_content)
                            {
                                sb_body.Append("</pre>");
                            }
                            if (this._message_mode.Equals(anmar.SharpWebMail.UI.MessageMode.reply))
                            {
                                if (html_content)
                                {
                                    sb_body.Insert(0, System.String.Concat("<blockquote style=\"", Application["sharpwebmail/send/message/replyquotestyle"], "\">"));
                                    sb_body.Append("</blockquote>");
                                }
                                else
                                {
                                    sb_body.Insert(0, Application["sharpwebmail/send/message/replyquotechar"].ToString());
                                    sb_body.Replace("\n", System.String.Concat("\n", Application["sharpwebmail/send/message/replyquotechar"]));
                                }
                            }
                            sb_body.Insert(0, line_end);
                            sb_body.Insert(0, " ");
                            this.FCKEditor.Value = sb_body.ToString();
                        }
                    }
                    details = null;
                }
            }
            else if (!this.IsPostBack)
            {
                System.String to = Page.Request.QueryString["to"];
                if (to != null && to.Length > 0)
                {
                    this.toemail.Value = to;
                }
            }
            if (this.fromname.Value.Length > 0 || this.IsPostBack)
            {
                Session["DisplayName"] = this.fromname.Value;
            }
            if (this.fromname.Value.Length == 0 && Session["DisplayName"] != null)
            {
                this.fromname.Value = Session["DisplayName"].ToString();
            }
            if (this.fromemail.Value.Length > 0 || this.IsPostBack)
            {
                Session["DisplayEmail"] = this.fromemail.Value;
            }
        }