?? newmessage.cs
字號:
// -----------------------------------------------------------------------
//
// Copyright (C) 2003-2005 Angel Marin
//
// This file is part of SharpWebMail.
//
// SharpWebMail is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpWebMail is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SharpWebMail; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// -----------------------------------------------------------------------
using System;
namespace anmar.SharpWebMail.UI
{
public class newmessage : System.Web.UI.Page {
#region General Fields
// General Fields
protected anmar.SharpWebMail.UI.globalUI SharpUI;
protected static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static System.String bodyStart = "<html><head><title></title></head><body bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">";
private static System.String bodyEnd = "</body></html>";
private anmar.SharpMimeTools.SharpMimeHeader _headers=null;
private int UI_case=0;
private anmar.SharpWebMail.UI.MessageMode _message_mode = anmar.SharpWebMail.UI.MessageMode.None;
#endregion General variables
#region UI Fields
//Form
protected System.Web.UI.HtmlControls.HtmlForm sharpwebmailform;
// Input boxes
protected System.Web.UI.HtmlControls.HtmlInputText fromemail;
protected System.Web.UI.HtmlControls.HtmlInputText fromname;
protected System.Web.UI.HtmlControls.HtmlInputText subject;
protected System.Web.UI.HtmlControls.HtmlInputText toemail;
// Labels
protected System.Web.UI.WebControls.Label newMessageWindowConfirmation;
//Editor
protected FredCK.FCKeditorV2.FCKeditor FCKEditor;
//PlaceHolders
protected System.Web.UI.WebControls.PlaceHolder attachmentsPH;
protected System.Web.UI.WebControls.PlaceHolder confirmationPH;
protected System.Web.UI.WebControls.PlaceHolder newMessageFromPH;
protected System.Web.UI.WebControls.PlaceHolder newMessagePH;
protected System.Web.UI.WebControls.PlaceHolder newattachmentPH;
//Other form elements
protected System.Web.UI.HtmlControls.HtmlInputFile newMessageWindowAttachFile;
protected System.Web.UI.WebControls.CheckBoxList newMessageWindowAttachmentsList;
protected System.Web.UI.WebControls.DataList newMessageWindowAttachmentsAddedList;
#endregion UI variables
#region Private Methods
protected void AttachmentSelect ( System.String key ) {
foreach ( System.Web.UI.WebControls.ListItem item in this.newMessageWindowAttachmentsList.Items ) {
if ( item.Value.Equals(key) ) {
item.Selected = true;
break;
}
}
}
protected void bindAttachments () {
System.Collections.ArrayList selected = null;
System.Collections.SortedList attachments = new System.Collections.SortedList();
bindAttachments ( attachments, Session["sharpwebmail/read/message/temppath"] );
if ( !Session["sharpwebmail/read/message/temppath"].Equals(Session["sharpwebmail/send/message/temppath"]) )
bindAttachments ( attachments, Session["sharpwebmail/send/message/temppath"] );
if ( this.newMessageWindowAttachmentsList.SelectedIndex!=-1 ) {
selected = new System.Collections.ArrayList();
foreach ( System.Web.UI.WebControls.ListItem item in this.newMessageWindowAttachmentsList.Items ) {
if ( item.Selected )
selected.Add(item.Value);
}
}
this.newMessageWindowAttachmentsList.DataSource = attachments;
this.newMessageWindowAttachmentsList.DataTextField = "Value";
this.newMessageWindowAttachmentsList.DataValueField = "Key";
this.newMessageWindowAttachmentsList.DataBind();
if ( selected!=null ) {
foreach ( System.String itemselected in selected ) {
this.AttachmentSelect(itemselected);
}
}
}
protected void bindAttachments ( System.Collections.SortedList attachments, System.Object pathname ) {
if ( pathname!=null ) {
System.String path = pathname.ToString();
System.IO.DirectoryInfo basedir = new System.IO.DirectoryInfo(path);
if ( basedir.Exists ) {
foreach ( System.IO.FileInfo file in basedir.GetFiles() ) {
attachments.Add ( System.IO.Path.Combine(file.Directory.Name, file.Name), System.String.Format ("{0} ({1:F2} KB)", file.Name, file.Length/1024.0));
}
foreach ( System.String dir in System.IO.Directory.GetDirectories (path) ){
foreach ( System.IO.FileInfo file in (new System.IO.DirectoryInfo(dir)).GetFiles() ) {
attachments.Add (System.IO.Path.Combine(file.Directory.Name, file.Name), System.String.Format ("{0} ({1:F2} KB)", file.Name, file.Length/1024.0));
}
}
}
basedir = null;
}
}
private System.String getfilename ( System.Object temppath, params System.String[] parts ) {
System.String path = null;
if ( temppath!=null ) {
path = temppath.ToString();
System.IO.DirectoryInfo basedir = new System.IO.DirectoryInfo(path);
if ( basedir.Exists ) {
foreach ( System.String part in parts ) {
try {
path = System.IO.Path.Combine (path, part);
} catch ( System.ArgumentException e ) {
if ( log.IsErrorEnabled )
log.Error("Filename has invalid chars", e);
// Remove invalid chars
System.String tmppart = part;
foreach ( char ichar in System.IO.Path.InvalidPathChars ) {
tmppart = tmppart.Replace ( ichar.ToString(), System.String.Empty );
}
path = System.IO.Path.Combine (path, tmppart);
}
}
System.IO.FileInfo file = new System.IO.FileInfo ( path );
System.IO.DirectoryInfo filedir = new System.IO.DirectoryInfo (file.Directory.FullName);
if ( !file.Exists || (!basedir.FullName.Equals(filedir.FullName) && !basedir.FullName.Equals(filedir.Parent.FullName) ) ) {
path = null;
}
filedir = null;
file = null;
} else {
path = null;
}
basedir = null;
}
if ( log.IsDebugEnabled ) log.Debug ("Path: " + path );
return path;
}
private System.String GetFromAddress () {
System.String from = null;
switch ( (int)Application["sharpwebmail/login/mode"] ) {
case 2:
from = this.fromemail.Value.Trim();
break;
case 1:
case 3:
default:
from = User.Identity.Name;
break;
}
return from;
}
/// <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);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -