check the message boundary and stop when you reach the attachment part, for example after you read "Content-Type: application/..."also see
A POP3 Client in C# .NEThttp://www.codeproject.com/csharp/despop3client.asp

解决方案 »

  1.   

    本身就没顾及附件,只读取正文,但依然缓慢,不使用jmail自己编程依然如故
      

  2.   

    使用jmail只读取正文,但只要附件过大就十分缓慢。
      

  3.   

    这是pop3的天生缺陷,必须整个邮件下载才能获得他的内容
    用imap4就可以在服务端分析他的内容,然后确定下载哪个部分
      

  4.   

    但对于不支持imap4的邮件服务器呢,难道就没人解决了这问题吗?
      

  5.   

    看一下下面的:
    BaseEntity class
    ------------------------------------------------------------------
    using System;namespace Mail.Pop
    {
    public class BaseEntity
    {
    protected string header; //all header 
    public string contentType;
    public string contentTransferEncoding;
    public string charset; public BaseEntity(string buffer)
    {
    GetHeader(buffer);
    this.contentType =this.GetValueFromHeader("Content-Type: ");
    this.contentTransferEncoding=this.GetValueFromHeader("Content-Transfer-Encoding: "); if (contentType.IndexOf("text/plain")!=-1 || contentType.IndexOf("text/html")!=-1)
    this.charset=GetValueEqualFromHeader("charset=");
    } protected void GetHeader(string buffer) 
    {
    int end=buffer.IndexOf("\r\n\r\n"); if (end==-1)
    throw new Exception("can't get header");

    header=buffer.Substring(0, end);
    header+="\r\n\r\n";
    } protected string GetValueFromHeader(string key)
    {
    int start=header.IndexOf(key);
    if(start<0)
    return "";
    start=header.IndexOf(' ',start);
    if (start<0)
    return "";
    int end=header.IndexOf("\r\n",start);
    if (end<=0)
    return "";
    return QuotedCoding.Decode(header.Substring(start+1, end-start-1).Trim());
    } /// <summary>
    /// z 'ala="123"'
    /// </summary>
    /// <param name="key">ala=</param>
    /// <returns>123</returns>
    protected string GetValueEqualFromHeader(string key)
    {
    int start=header.IndexOf(key);
    if (start==-1)
    return "";
    start=header.IndexOf('"',start);
    int end=header.IndexOf('"',start+1);
    if (start==-1 || end==-1)
    return "";
    return QuotedCoding.Decode(header.Substring(start+1,end-start-1));
    } }
    }
      

  6.   

    Pop3Message class
    ---------------------------------------------
    using System;
    using System.Collections;namespace Mail.Pop
    {
    public class Pop3Message : BaseEntity
    {
    public string from;
    public string replyTo;
    public string subject;
    public string date;
    public string boundary;
    public bool hasAttachments=false;
    public string body;
    public ArrayList attachments=new ArrayList();
    //buffer ma na poczatku "+OK"
    //onlyHeader mowi czy tylko header czy cala wiadomosc
    public Pop3Message(string buffer,bool onlyHeader) : base(buffer)
    {
    this.from =this.GetValueFromHeader("From: ");
    this.replyTo =this.GetValueFromHeader("Reply-To: ");
    this.subject =this.GetValueFromHeader("Subject: ");
    this.date =this.GetValueFromHeader("Date: ");
    if(contentType.IndexOf("multipart")!=-1)
    {
    boundary="--"+GetValueEqualFromHeader("boundary=");
    hasAttachments=true;
    if (onlyHeader==false)
    ParseMixedMessage(buffer);
    }
    else
    {
    hasAttachments=false;
    if (onlyHeader==false)
    this.body=GetTextMessage(buffer);
    }
    } internal string GetTextMessage(string buffer) 
    {
    // find "\r\n\r\n" denoting end of header
    int start=buffer.IndexOf("\r\n\r\n")+4;
    int end=buffer.LastIndexOf("\r\n.\r\n");
    //change charset if contentTransferEncoding is 8bit
    if (this.contentTransferEncoding.IndexOf("8bit")!=-1)
    return StringOperations.Change(buffer.Substring(start,end-start),charset);
    else
    return buffer.Substring(start,end-start);
    } internal bool ParseMixedMessage(string buffer)
    {
    int start=0,end;

    for(;;)
    {
    start=buffer.IndexOf(boundary,start);

    if (start==-1)
    break;

    end=buffer.IndexOf(boundary,start+1); if (end==-1)
    break; // remove boundary from buffer
    start += boundary.Length; Attachment a=new Attachment( buffer.Substring(start,end-start-2) ); this.attachments.Add(a);
    }
    return true;
    } /// <summary>
    /// zwraca mail pomiedzy '<' i '>'
    /// </summary>
    static public string GetMail(string s)
    {
    int start=s.IndexOf('<')+1;
    int end=s.LastIndexOf('>')-1;
    if (start==-1 || end==-1)
    return "";
    return s.Substring(start,end-start+1);
    }
    }
    }