internal MessageInfo ( anmar.SharpMimeTools.SharpMimeMessageStream m, long start ) { this.start = start; this.header = new anmar.SharpMimeTools.SharpMimeHeader ( m, this.start ); this.start_body = this.header.BodyPosition; this.end = -1; parts = new anmar.SharpMimeTools.SharpMimeMessageCollection(); }
internal SharpMimeHeader(anmar.SharpMimeTools.SharpMimeMessageStream message, long startpoint) { this.startpoint = startpoint; this.message = message; if ( this.startpoint==0 ) { System.String line = this.message.ReadLine(); // Perhaps there is part of the POP3 response if ( line!=null && line.Length>3 && line[0]=='+' && line[1]=='O' && line[2]=='K' ) { #if LOG if ( log.IsDebugEnabled ) log.Debug ("+OK present at top of the message"); #endif this.startpoint = this.message.Position; } else this.message.ReadLine_Undo(line); } this.headers = new System.Collections.Specialized.HybridDictionary(2, true); this.parse(); }
protected override String buildcommand( anmar.SharpWebMail.EmailClientCommand cmd, params Object[] args ) { String command = String.Empty; this.randomTag(); switch ( cmd ) { case EmailClientCommand.Delete: if ( args.Length==1 ) command = String.Format("{0} STORE {1}:{1} +FLAGS.SILENT (\\Deleted)", this.tag, args[0]); break; case EmailClientCommand.Header: if ( args.Length==2 ) command = String.Format("{0} FETCH {1}:{1} (RFC822.HEADER)", this.tag, args[0], args[1]); break; case EmailClientCommand.ListSize: command = System.String.Format("{0} FETCH 1:* (RFC822.SIZE)", this.tag); break; case EmailClientCommand.ListUID: if ( args.Length==1 ) { if ( args[0].ToString().Equals(String.Empty) ) command = String.Format("{0} FETCH 1:* (UID)", this.tag); else command = String.Format("{0} FETCH {1}:{1} (UID)", this.tag, args[0]); } break; case EmailClientCommand.Login: if ( args.Length==2 ) command = String.Format("{0} LOGIN {1} {2}", this.tag, args[0], args[1]); break; case EmailClientCommand.Logout: command = String.Concat(this.tag, " LOGOUT"); break; case EmailClientCommand.Message: if ( args.Length==1 ) command = String.Format("{0} FETCH {1}:{1} (BODY.PEEK[])", this.tag, args[0]); break; case EmailClientCommand.Status: command = String.Format("{0} EXAMINE {1}", this.tag, this.folder); break; } return command; }
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("usernamecolumn") ) ownercolumn = addressbook["usernamecolumn"].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; }
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; }
private System.String ReplaceUrlTokens( System.String url, anmar.SharpMimeTools.SharpAttachment attachment ) { if ( url==null || url.Length==0 || url.IndexOf('[')==-1 || url.IndexOf(']')==-1 ) return url; if ( url.IndexOf("[MessageID]")!=-1 ) { url = url.Replace("[MessageID]", System.Web.HttpUtility.UrlEncode(anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(this.MessageID))); } if ( attachment!=null && attachment.ContentID!=null ) { if ( url.IndexOf("[ContentID]")!=-1 ) { url = url.Replace("[ContentID]", System.Web.HttpUtility.UrlEncode(anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(attachment.ContentID))); } if ( url.IndexOf("[Name]")!=-1 ) { if ( attachment.SavedFile!=null ) { url = url.Replace("[Name]", System.Web.HttpUtility.UrlEncode(attachment.SavedFile.Name)); } else { url = url.Replace("[Name]", System.Web.HttpUtility.UrlEncode(attachment.Name)); } } } return url; }
private void ParseMessage( anmar.SharpMimeTools.SharpMimeMessage part, anmar.SharpMimeTools.MimeTopLevelMediaType types, bool html, SharpDecodeOptions options, System.String preferredtextsubtype, System.String path ) { if ( (types&part.Header.TopLevelMediaType)!=part.Header.TopLevelMediaType ) { #if LOG if ( log.IsDebugEnabled ) log.Debug (System.String.Concat("Mime-Type [", part.Header.TopLevelMediaType, "] is not an accepted Mime-Type. Skiping part.")); #endif return; } switch ( part.Header.TopLevelMediaType ) { case anmar.SharpMimeTools.MimeTopLevelMediaType.multipart: case anmar.SharpMimeTools.MimeTopLevelMediaType.message: // TODO: allow other subtypes of "message" // Only message/rfc822 allowed, other subtypes ignored if ( part.Header.TopLevelMediaType.Equals(anmar.SharpMimeTools.MimeTopLevelMediaType.message) && !part.Header.SubType.Equals("rfc822") ) break; if ( part.Header.SubType.Equals ("alternative") ) { if ( part.PartsCount>0 ) { anmar.SharpMimeTools.SharpMimeMessage altenative = null; // Get the first mime part of the alternatives that has a accepted Mime-Type for ( int i=part.PartsCount; i>0; i-- ) { anmar.SharpMimeTools.SharpMimeMessage item = part.GetPart(i-1); if ( (types&part.Header.TopLevelMediaType)!=part.Header.TopLevelMediaType || ( !html && item.Header.TopLevelMediaType.Equals(anmar.SharpMimeTools.MimeTopLevelMediaType.text) && item.Header.SubType.Equals("html") ) ) { #if LOG if ( log.IsDebugEnabled ) log.Debug (System.String.Concat("Mime-Type [", item.Header.TopLevelMediaType, "/", item.Header.SubType, "] is not an accepted Mime-Type. Skiping alternative part.")); #endif continue; } // First allowed one. if ( altenative==null ) { altenative=item; // We don't have to select body part based on subtype if not asked for, or not a text one // or it's already the preferred one if ( preferredtextsubtype==null || item.Header.TopLevelMediaType!=anmar.SharpMimeTools.MimeTopLevelMediaType.text || (preferredtextsubtype!=null && item.Header.SubType==preferredtextsubtype) ) { break; } // This one is preferred over the last part } else if ( preferredtextsubtype!=null && item.Header.TopLevelMediaType==anmar.SharpMimeTools.MimeTopLevelMediaType.text && item.Header.SubType==preferredtextsubtype ) { altenative=item; break; } } if ( altenative!=null ) { // If message body as html is allowed and part has a Content-ID field // add an anchor to mark this body part if ( html && part.Header.Contains("Content-ID") && (options&anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors)==anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors ) { // There is a previous text body, so enclose it in <pre> if ( !this._body_html && this._body.Length>0 ) { this._body = System.String.Concat ("<pre>", System.Web.HttpUtility.HtmlEncode(this._body), "</pre>"); this._body_html = true; } // Add the anchor this._body = System.String.Concat (this._body, "<a name=\"", anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(this.MessageID), "_", anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(part.Header.ContentID), "\"></a>"); } this.ParseMessage(altenative, types, html, options, preferredtextsubtype, path); } } // TODO: Take into account each subtype of "multipart" } else if ( part.PartsCount>0 ) { foreach ( anmar.SharpMimeTools.SharpMimeMessage item in part ) { this.ParseMessage(item, types, html, options, preferredtextsubtype, path); } } break; case anmar.SharpMimeTools.MimeTopLevelMediaType.text: if ( ( part.Disposition==null || !part.Disposition.Equals("attachment") ) && ( part.Header.SubType.Equals("plain") || part.Header.SubType.Equals("html") ) ) { bool body_was_html = this._body_html; // HTML content not allowed if ( part.Header.SubType.Equals("html") ) { if ( !html ) break; else this._body_html=true; } if ( html && part.Header.Contains("Content-ID") && (options&anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors)==anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors ) { this._body_html = true; } if ( this._body_html && !body_was_html && this._body.Length>0 ) { this._body = System.String.Concat ("<pre>", System.Web.HttpUtility.HtmlEncode(this._body), "</pre>"); } // If message body is html and this part has a Content-ID field // add an anchor to mark this body part if ( this._body_html && part.Header.Contains("Content-ID") && (options&anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors)==anmar.SharpMimeTools.SharpDecodeOptions.NamedAnchors ) { this._body = System.String.Concat (this._body, "<a name=\"", anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(this.MessageID), "_", anmar.SharpMimeTools.SharpMimeTools.Rfc2392Url(part.Header.ContentID), "\"></a>"); } if ( this._body_html && part.Header.SubType.Equals("plain") ) { this._body = System.String.Concat (this._body, "<pre>", System.Web.HttpUtility.HtmlEncode(part.BodyDecoded), "</pre>"); } else this._body = System.String.Concat (this._body, part.BodyDecoded); } else { if ( (types&anmar.SharpMimeTools.MimeTopLevelMediaType.application)!=anmar.SharpMimeTools.MimeTopLevelMediaType.application ) { #if LOG if ( log.IsDebugEnabled ) log.Debug (System.String.Concat("Mime-Type [", anmar.SharpMimeTools.MimeTopLevelMediaType.application, "] is not an accepted Mime-Type. Skiping part.")); #endif return; } goto case anmar.SharpMimeTools.MimeTopLevelMediaType.application; } break; case anmar.SharpMimeTools.MimeTopLevelMediaType.application: case anmar.SharpMimeTools.MimeTopLevelMediaType.audio: case anmar.SharpMimeTools.MimeTopLevelMediaType.image: case anmar.SharpMimeTools.MimeTopLevelMediaType.video: // Attachments not allowed. if ( (options&anmar.SharpMimeTools.SharpDecodeOptions.AllowAttachments)!=anmar.SharpMimeTools.SharpDecodeOptions.AllowAttachments ) break; anmar.SharpMimeTools.SharpAttachment attachment = null; // Save to a file if ( path!=null ) { System.IO.FileInfo file = part.DumpBody(path, true); if ( file!=null ) { attachment = new anmar.SharpMimeTools.SharpAttachment(file); attachment.Name = file.Name; attachment.Size = file.Length; } // Save to a stream } else { System.IO.MemoryStream stream = new System.IO.MemoryStream(); if ( part.DumpBody(stream) ) { attachment = new anmar.SharpMimeTools.SharpAttachment(stream); if ( part.Name!=null ) attachment.Name = part.Name; else attachment.Name = System.String.Concat("generated_", part.GetHashCode(), ".", part.Header.SubType); attachment.Size = stream.Length; } stream = null; } if ( attachment!=null && part.Header.SubType=="ms-tnef" && (options&anmar.SharpMimeTools.SharpDecodeOptions.DecodeTnef)==anmar.SharpMimeTools.SharpDecodeOptions.DecodeTnef ) { // Try getting attachments form a tnef stream #if LOG if ( log.IsDebugEnabled ) { log.Debug(System.String.Concat("Decoding ms-tnef stream.")); } #endif System.IO.Stream stream = attachment.Stream; if ( stream!=null && stream.CanSeek ) stream.Seek(0, System.IO.SeekOrigin.Begin); anmar.SharpMimeTools.SharpTnefMessage tnef = new anmar.SharpMimeTools.SharpTnefMessage(stream); if ( tnef.Parse(path) ) { if ( tnef.Attachments!=null ) { this._attachments.AddRange(tnef.Attachments); } attachment.Close(); // Delete the raw tnef file if ( attachment.SavedFile!=null ) { if ( stream!=null && stream.CanRead ) stream.Close(); attachment.SavedFile.Delete(); } attachment = null; tnef.Close(); #if LOG if ( log.IsDebugEnabled ) { log.Debug(System.String.Concat("ms-tnef stream decoded successfully. Found [", ((tnef.Attachments!=null)?tnef.Attachments.Count:0),"] attachments.")); } #endif } else { // The read-only stream is no longer needed and locks the file if ( attachment.SavedFile!=null && stream!=null && stream.CanRead ) stream.Close(); } stream = null; tnef = null; } if ( attachment!=null ) { if ( part.Disposition!=null && part.Disposition=="inline" ) { attachment.Inline = true; } attachment.MimeTopLevelMediaType = part.Header.TopLevelMediaType; attachment.MimeMediaSubType = part.Header.SubType; // Store attachment's CreationTime if ( part.Header.ContentDispositionParameters.ContainsKey("creation-date") ) attachment.CreationTime = anmar.SharpMimeTools.SharpMimeTools.parseDate ( part.Header.ContentDispositionParameters["creation-date"] ); // Store attachment's LastWriteTime if ( part.Header.ContentDispositionParameters.ContainsKey("modification-date") ) attachment.LastWriteTime = anmar.SharpMimeTools.SharpMimeTools.parseDate ( part.Header.ContentDispositionParameters["modification-date"] ); if ( part.Header.Contains("Content-ID") ) attachment.ContentID = part.Header.ContentID; this._attachments.Add(attachment); } break; default: break; } }
internal SharpMimeHeader( anmar.SharpMimeTools.SharpMimeMessageStream message ) : this ( message, 0 ){}
/// <summary> /// Initializes a new instance of the <see cref="anmar.SharpMimeTools.SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="types">A <see cref="anmar.SharpMimeTools.MimeTopLevelMediaType" /> value that specifies the allowed Mime-Types to being decoded.</param> /// <param name="html"><b>true</b> to allow HTML content; <b>false</b> to ignore the html content.</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> /// <param name="preferredtextsubtype">A <see cref="System.String" /> specifying the subtype to select for text parts that contain aternative content (plain, html, ...). Specify the <b>null</b> reference to maintain the default behavior (prefer whatever the originator sent as the preferred part). If there is not a text part with this subtype, the default one is used.</param> public SharpMessage( System.IO.Stream message, anmar.SharpMimeTools.MimeTopLevelMediaType types, bool html, System.String path, System.String preferredtextsubtype ) : this(message, types, ((html)?SharpDecodeOptions.Default:SharpDecodeOptions.AllowAttachments), path, preferredtextsubtype) { }
/// <summary> /// Initializes a new instance of the <see cref="anmar.SharpMimeTools.SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="types">A <see cref="anmar.SharpMimeTools.MimeTopLevelMediaType" /> value that specifies the allowed Mime-Types to being decoded.</param> /// <param name="html"><b>true</b> to allow HTML content; <b>false</b> to ignore the html content.</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> public SharpMessage( System.IO.Stream message, anmar.SharpMimeTools.MimeTopLevelMediaType types, bool html, System.String path ) : this(message, types, html, path, null) { }
public void Add ( anmar.SharpMimeTools.SharpMimeAddress address ) { list.Add ( address); }
private System.String SendMailOpenSmtp( anmar.SharpWebMail.EmailServerInfo server ) { System.String message = null; OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage(); 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.Error ( "Sending message" ); 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.Error ( "Message sent" ); } catch (System.Exception e) { message = e.Message; if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e ); } mailMessage = null; return message; }
/// <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.Error ( "Sending message" ); System.Web.Mail.SmtpMail.Send(mailMessage); if ( log.IsDebugEnabled) log.Error ( "Message sent" ); } catch (System.Exception e) { message = e.Message; #if DEBUG && !MONO message += ". <br>InnerException: " + e.InnerException.Message; #endif if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e ); if ( log.IsErrorEnabled ) log.Error ( "Error sending message (InnerException)", e.InnerException ); } mailMessage = null; return message; }
/// <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; }
private SharpMimeMessage( anmar.SharpMimeTools.SharpMimeMessageStream message, long startpoint, long endpoint ) { this.message = message; this.mi = new MessageInfo ( this.message, startpoint ); this.mi.end = endpoint; }
public void Add( anmar.SharpMimeTools.SharpMimeMessage msg ) { messages.Add( msg ); }
/// <summary> /// Initializes a new instance of the <see cref="anmar.SharpMimeTools.SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="types">A <see cref="anmar.SharpMimeTools.MimeTopLevelMediaType" /> value that specifies the allowed Mime-Types to being decoded.</param> /// <param name="options"><see cref="anmar.SharpMimeTools.SharpDecodeOptions" /> to determine how to do the decoding (must be combined as a bit map).</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> /// <param name="preferredtextsubtype">A <see cref="System.String" /> specifying the subtype to select for text parts that contain aternative content (plain, html, ...). Specify the <b>null</b> reference to maintain the default behavior (prefer whatever the originator sent as the preferred part). If there is not a text part with this subtype, the default one is used.</param> public SharpMessage( System.IO.Stream message, anmar.SharpMimeTools.MimeTopLevelMediaType types, SharpDecodeOptions options, System.String path, System.String preferredtextsubtype ) { if ( path!=null && (options&SharpDecodeOptions.CreateFolder)!=SharpDecodeOptions.CreateFolder && !System.IO.Directory.Exists(path) ) { #if LOG if ( log.IsErrorEnabled ) log.Error(System.String.Concat("Path [", path, "] does not exist and 'SharpDecodeOptions.CreateFolder' was not specified.")); #endif path=null; } this.ParseMessage(message, types, options, preferredtextsubtype, path); }
private void ParseMessage( System.IO.Stream stream, anmar.SharpMimeTools.MimeTopLevelMediaType types, SharpDecodeOptions options, System.String preferredtextsubtype, System.String path ) { this._attachments = new System.Collections.ArrayList(); anmar.SharpMimeTools.SharpMimeMessage message = new anmar.SharpMimeTools.SharpMimeMessage(stream); this.ParseMessage(message, types, (options&SharpDecodeOptions.AllowHtml)==SharpDecodeOptions.AllowHtml, options, preferredtextsubtype, path); this._headers = message.Header; message.Close(); message = null; // find and decode uuencoded content if configured to do so (and attachments a allowed) if ( (options&anmar.SharpMimeTools.SharpDecodeOptions.UuDecode)==anmar.SharpMimeTools.SharpDecodeOptions.UuDecode && (options&anmar.SharpMimeTools.SharpDecodeOptions.AllowAttachments)==anmar.SharpMimeTools.SharpDecodeOptions.AllowAttachments ) this.UuDecode(path); // Date this._date = anmar.SharpMimeTools.SharpMimeTools.parseDate(this._headers.Date); if ( this._date.Equals(System.DateTime.MinValue) ) { System.String date = this._headers["Received"]; if ( date==null ) date = System.String.Empty; if ( date.IndexOf("\r\n")>0 ) date = date.Substring(0, date.IndexOf("\r\n")); if ( date.LastIndexOf(';')>0 ) date = date.Substring(date.LastIndexOf(';')+1).Trim(); else date = System.String.Empty; this._date = anmar.SharpMimeTools.SharpMimeTools.parseDate(date); } // Subject this._subject = anmar.SharpMimeTools.SharpMimeTools.parserfc2047Header(this._headers.Subject); // To this._to = anmar.SharpMimeTools.SharpMimeAddressCollection.Parse(this._headers.To); // From anmar.SharpMimeTools.SharpMimeAddressCollection from = anmar.SharpMimeTools.SharpMimeAddressCollection.Parse(this._headers.From); foreach ( anmar.SharpMimeTools.SharpMimeAddress item in from ) { this._from_name = item["name"]; this._from_addr = item["address"]; if ( this._from_name==null || this._from_name.Equals(System.String.Empty) ) this._from_name = item["address"]; } }
private void decodeMessage( anmar.SharpMimeTools.SharpMimeMessage mm, System.Web.UI.WebControls.PlaceHolder entity ) { System.String inline = System.String.Empty; switch ( mm.Header.TopLevelMediaType ) { case anmar.SharpMimeTools.MimeTopLevelMediaType.multipart: case anmar.SharpMimeTools.MimeTopLevelMediaType.message: // TODO: allow other subtypes of "message" // Only message/rfc822 allowed, other subtypes ignored if ( mm.Header.TopLevelMediaType.Equals(anmar.SharpMimeTools.MimeTopLevelMediaType.message) && !mm.Header.SubType.Equals("rfc822") ) break; if ( mm.Header.SubType.Equals ("alternative") ) { if ( mm.PartsCount>0 ) { this.decodeMessage ( mm.GetPart(mm.PartsCount-1), entity); } // TODO: Take into account each subtype of "multipart" } else if ( mm.PartsCount>0 ) { System.Web.UI.WebControls.PlaceHolder nestedentity = new System.Web.UI.WebControls.PlaceHolder (); System.Collections.IEnumerator enu = mm.GetEnumerator(); while ( enu.MoveNext() ) { this.decodeMessage ((anmar.SharpMimeTools.SharpMimeMessage) enu.Current, nestedentity); } entity.Controls.Add (nestedentity); } break; case anmar.SharpMimeTools.MimeTopLevelMediaType.text: if ( ( mm.Disposition==null || !mm.Disposition.Equals("attachment") ) && ( mm.Header.SubType.Equals("plain") || mm.Header.SubType.Equals("html") ) ) { System.Web.UI.WebControls.Label label = new System.Web.UI.WebControls.Label (); label.Text = mm.BodyDecoded; if ( mm.IsTextBrowserDisplay ) { label.Text = System.Web.HttpUtility.HtmlEncode (label.Text); label.Text = label.Text.Insert (0, "<pre id=\"message\">"); label.Text = label.Text.Insert (label.Text.Length, "</pre>"); } else { label.CssClass = "XPFormText"; if ( (int)Application["sharpwebmail/read/message/sanitizer_mode"]==1 ) { label.Text = anmar.SharpWebMail.BasicSanitizer.SanitizeHTML(label.Text, anmar.SharpWebMail.SanitizerMode.CommentBlocks|anmar.SharpWebMail.SanitizerMode.RemoveEvents); } } entity.Controls.Add (label); break; } else { goto case anmar.SharpMimeTools.MimeTopLevelMediaType.application; } case anmar.SharpMimeTools.MimeTopLevelMediaType.application: case anmar.SharpMimeTools.MimeTopLevelMediaType.audio: case anmar.SharpMimeTools.MimeTopLevelMediaType.image: case anmar.SharpMimeTools.MimeTopLevelMediaType.video: System.Web.UI.WebControls.HyperLink attachment = new System.Web.UI.WebControls.HyperLink (); System.Web.UI.WebControls.Image image = null; attachment.CssClass = "XPDownload"; if ( mm.Name!=null ) attachment.Text = System.String.Format ("{0} ({1} bytes)", System.IO.Path.GetFileName(mm.Name), mm.Size); if ( Session["sharpwebmail/read/message/temppath"]!=null ) { System.String path = Session["sharpwebmail/read/message/temppath"].ToString(); path = System.IO.Path.Combine (path, msgid); // Dump file contents System.IO.FileInfo file = mm.DumpBody ( path, true ); if ( file!=null && file.Exists ) { System.String urlstring = System.String.Format("download.aspx?msgid={0}&name={1}&i={2}", Server.UrlEncode(msgid), Server.UrlEncode(file.Name), inline); if ( mm.Disposition!=null && mm.Disposition.Equals("inline") ) { inline = "1"; if ( mm.Header.TopLevelMediaType.Equals(anmar.SharpMimeTools.MimeTopLevelMediaType.image) && ( mm.Header.SubType.Equals("gif") || mm.Header.SubType.Equals("jpg") || mm.Header.SubType.Equals("png")) ) { image = new System.Web.UI.WebControls.Image (); image.ImageUrl = urlstring; } } attachment.NavigateUrl = urlstring; attachment.Text = System.String.Format ("{0} ({1} bytes)", file.Name, file.Length); } } this.readMessageWindowAttachmentsHolder.Controls.Add (attachment); // Display inline image if ( image!=null ) { entity.Controls.Add (image); } break; default: break; } }