Esempio n. 1
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;
            }
        }
Esempio n. 2
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);
                        }
                        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;
        }