Beispiel #1
0
        private bool parse()
        {
            bool error = false;

#if LOG
            if (log.IsDebugEnabled)
            {
                log.Debug(System.String.Concat("Parsing requested, type: ", this.mi.header.TopLevelMediaType.ToString(), ", subtype: ", this.mi.header.SubType));
            }
#endif
            if (!this.IsMultipart || this.Equals(this.mi.parts.Parent))
            {
#if LOG
                if (log.IsDebugEnabled)
                {
                    log.Debug("Parsing requested and this is not a multipart or it is already parsed");
                }
#endif
                return(true);
            }
            switch (this.mi.header.TopLevelMediaType)
            {
            case anmar.SharpMimeTools.MimeTopLevelMediaType.message:
                this.mi.parts.Parent = this;
                anmar.SharpMimeTools.SharpMimeMessage message = new anmar.SharpMimeTools.SharpMimeMessage(this.message, this.mi.start_body, this.mi.end);
                this.mi.parts.Add(message);
                break;

            case anmar.SharpMimeTools.MimeTopLevelMediaType.multipart:
                this.message.SeekPoint(this.mi.start_body);
                System.String line;
#if LOG
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Format("Looking for multipart {1}, byte {0}", this.mi.start_body, this.mi.header.ContentTypeParameters["boundary"]));
                }
#endif
                this.mi.parts.Parent = this;
                System.String boundary_start = System.String.Concat("--", this.mi.header.ContentTypeParameters["boundary"]);
                System.String boundary_end   = System.String.Concat("--", this.mi.header.ContentTypeParameters["boundary"], "--");
                for (line = this.message.ReadLine(); line != null; line = this.message.ReadLine())
                {
                    // It can't be a boundary line
                    if (line.Length < 3)
                    {
                        continue;
                    }
                    // Match start boundary line
                    if (line.Length == boundary_start.Length && line == boundary_start)
                    {
                        if (this.mi.parts.Count > 0)
                        {
                            this.mi.parts.Get(this.mi.parts.Count - 1).mi.end = this.message.Position_preRead;
#if LOG
                            if (log.IsDebugEnabled)
                            {
                                log.Debug(System.String.Format("End part {1} at byte {0}", this.message.Position_preRead, boundary_start));
                            }
#endif
                        }
#if LOG
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(System.String.Format("Part     {1} found at byte {0}", this.message.Position_preRead, boundary_start));
                        }
#endif
                        anmar.SharpMimeTools.SharpMimeMessage msg = new anmar.SharpMimeTools.SharpMimeMessage(this.message, this.message.Position);
                        this.mi.parts.Add(msg);
                        // Match end boundary line
                    }
                    else if (line.Length == boundary_end.Length && line == boundary_end)
                    {
                        this.mi.end = this.message.Position_preRead;
                        if (this.mi.parts.Count > 0)
                        {
                            this.mi.parts.Get(this.mi.parts.Count - 1).mi.end = this.message.Position_preRead;
#if LOG
                            if (log.IsDebugEnabled)
                            {
                                log.Debug(System.String.Format("End part {1} at byte {0}", this.message.Position_preRead, boundary_end));
                            }
#endif
#if LOG
                        }
                        else if (log.IsDebugEnabled)
                        {
                            log.Debug(System.String.Format("End part {1} at byte {0}", this.mi.end, boundary_end));
#endif
                        }
                        break;
                    }
                }
                break;
            }
            return(!error);
        }
 private bool parse()
 {
     bool error = false;
     #if LOG
     if ( log.IsDebugEnabled ) log.Debug (System.String.Concat("Parsing requested, type: ", this.mi.header.TopLevelMediaType.ToString(), ", subtype: ", this.mi.header.SubType) );
     #endif
     if ( !this.IsMultipart || this.Equals(this.mi.parts.Parent) ) {
     #if LOG
         if ( log.IsDebugEnabled )
             log.Debug ("Parsing requested and this is not a multipart or it is already parsed");
     #endif
         return true;
     }
     switch (this.mi.header.TopLevelMediaType) {
         case anmar.SharpMimeTools.MimeTopLevelMediaType.message:
             this.mi.parts.Parent = this;
             anmar.SharpMimeTools.SharpMimeMessage message = new anmar.SharpMimeTools.SharpMimeMessage (this.message, this.mi.start_body, this.mi.end );
             this.mi.parts.Add (message);
             break;
         case anmar.SharpMimeTools.MimeTopLevelMediaType.multipart:
             this.message.SeekPoint ( this.mi.start_body );
             System.String line;
     #if LOG
             if ( log.IsDebugEnabled )
                 log.Debug (System.String.Format("Looking for multipart {1}, byte {0}", this.mi.start_body, this.mi.header.ContentTypeParameters["boundary"]));
     #endif
             this.mi.parts.Parent = this;
             System.String boundary_start = System.String.Concat("--", this.mi.header.ContentTypeParameters["boundary"]);
             System.String boundary_end = System.String.Concat("--", this.mi.header.ContentTypeParameters["boundary"], "--");
             for ( line=this.message.ReadLine(); line!=null ; line=this.message.ReadLine() ) {
                 // It can't be a boundary line
                 if ( line.Length<3 )
                     continue;
                 // Match start boundary line
                 if ( line.Length==boundary_start.Length && line==boundary_start ) {
                     if ( this.mi.parts.Count>0 ) {
                         this.mi.parts.Get( this.mi.parts.Count-1 ).mi.end = this.message.Position_preRead;
     #if LOG
                         if ( log.IsDebugEnabled )
                             log.Debug (System.String.Format("End part {1} at byte {0}", this.message.Position_preRead, boundary_start));
     #endif
                     }
     #if LOG
                     if ( log.IsDebugEnabled ) log.Debug (System.String.Format("Part     {1} found at byte {0}", this.message.Position_preRead, boundary_start));
     #endif
                     anmar.SharpMimeTools.SharpMimeMessage msg = new anmar.SharpMimeTools.SharpMimeMessage (this.message, this.message.Position );
                     this.mi.parts.Add (msg);
                 // Match end boundary line
                 } else if ( line.Length==boundary_end.Length && line==boundary_end ) {
                     this.mi.end = this.message.Position_preRead;
                     if ( this.mi.parts.Count>0 ) {
                         this.mi.parts.Get( this.mi.parts.Count-1 ).mi.end = this.message.Position_preRead;
     #if LOG
                         if ( log.IsDebugEnabled )
                             log.Debug (System.String.Format("End part {1} at byte {0}", this.message.Position_preRead, boundary_end));
     #endif
     #if LOG
                     } else if ( log.IsDebugEnabled ) {
                         log.Debug (System.String.Format("End part {1} at byte {0}", this.mi.end, boundary_end));
     #endif
                     }
                     break;
                 }
             }
             break;
     }
     return !error;
 }
 public void Add(anmar.SharpMimeTools.SharpMimeMessage msg)
 {
     messages.Add(msg);
 }
Beispiel #4
0
 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"];
     }
 }
Beispiel #5
0
        protected void Page_PreRender( System.Object sender, System.EventArgs args )
        {
            if ( msgid != null ) {
                bool deleted = false;
                System.IO.MemoryStream ms = null;
                if ( delete ) {
                    deleted = this.SharpUI.Inbox.DeleteMessage(msgid);
                    if ( deleted )
                        this.SharpUI.setVariableLabels();
                }
                // Delete messaged, we have to commit changes
                if ( deleted && (bool)Application["sharpwebmail/read/inbox/commit_ondelete"] ) {
                    this.SharpUI.Inbox.Client.PurgeInbox( this.SharpUI.Inbox, false );
                    Response.Redirect("default.aspx");
                } else {
                    // We retrieve the message body
                    this.SharpUI.Inbox.CurrentFolder = this.SharpUI.Inbox.GetMessageFolder(msgid);
                    ms = this.SharpUI.Inbox.GetMessage(msgid);
                }
                if ( ms!=null ) {
                    System.Object[] details = this.SharpUI.Inbox[ msgid ];
                    // Disable delete button if message is already deleted
                    if ( details[15].Equals(true) || deleted )
                        ((System.Web.UI.WebControls.ImageButton)this.SharpUI.FindControl("msgtoolbarDelete")).Enabled=false;
                    this.readMessageWindowDateTextLabel.Text = System.Web.HttpUtility.HtmlEncode (details[14].ToString());
                    this.readMessageWindowFromTextLabel.Text = System.Web.HttpUtility.HtmlEncode (details[6].ToString());
                    this.readMessageWindowToTextLabel.Text = System.Web.HttpUtility.HtmlEncode (details[8].ToString());
                    this.readMessageWindowSubjectTextLabel.Text = System.Web.HttpUtility.HtmlEncode (details[10].ToString());
                    this.newMessageWindowTitle.Text = System.Web.HttpUtility.HtmlEncode (details[10].ToString());
                    if ( this.newMessageWindowTitle.Text.Equals (System.String.Empty) )
                        this.newMessageWindowTitle.Text = this.SharpUI.LocalizedRS.GetString("noSubject");
                    if ( ms!=null && ms.CanRead ) {
                        anmar.SharpMimeTools.SharpMimeMessage mm = new anmar.SharpMimeTools.SharpMimeMessage ( ms );
                        this.readMessageWindowCcTextLabel.Text = System.Web.HttpUtility.HtmlEncode (anmar.SharpMimeTools.SharpMimeTools.parseFrom (mm.Header.Cc).ToString());
                        this.decodeMessage ( mm, this.readMessageWindowBodyTextHolder );
                        mm = null;
                        this.SharpUI.Inbox.readMessage ( msgid );
                    }
                    details = null;
                }
                if ( ms!=null && ms.CanRead )
                    ms.Close();
                ms = null;

            }
        }