开发者

TcpClient response stream with POP3, cant read more then one line

开发者 https://www.devze.com 2023-03-31 10:13 出处:网络
I am working on my own lib for pop3 since i didnt find what I needed in the ones that were suggested here. My problem is when opening a message it can only read a line up to a certain point (usually a

I am working on my own lib for pop3 since i didnt find what I needed in the ones that were suggested here. My problem is when opening a message it can only read a line up to a certain point (usually a link in the text) and it stops, looping but not crashing. code is:

Data = "RETR 1" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
txtLog.Text += RdStrm.ReadLine() + CRLF;
for (int i = 0; i < 33; i++)
{

    txtLog.Text += RdStrm.ReadLine() + CRLF;
}


string szTemp;
szTemp = RdStrm.ReadLine();
// here it's supposed to start reading the actual message
while(szTemp != "-")
    {

        tx开发者_如何学JAVAtLog.Text += szTemp + CRLF;
        szTemp = RdStrm.ReadLine();

    }


Match reg1 = Regex.Match(ifOk, "OK(.*)", RegexOptions.IgnoreCase);

if (reg1.Success)
{
    txtLog.Text += "Ready To Start!\r\n";

    Data = "USER XXXX" + CRLF;
    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
    NetStrm.Write(szData, 0, szData.Length);
    txtLog.Text += RdStrm.ReadLine() + CRLF;

    Data = "PASS XXXX" + CRLF;
    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
    NetStrm.Write(szData, 0, szData.Length);
    txtLog.Text += RdStrm.ReadLine() + CRLF;

    Data = "STAT" + CRLF;
    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
    NetStrm.Write(szData, 0, szData.Length);
    txtLog.Text += RdStrm.ReadLine() + CRLF + CRLF + CRLF + CRLF + CRLF;

    Data = "RETR 1" + CRLF;
    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
    NetStrm.Write(szData, 0, szData.Length);
    txtLog.Text += RdStrm.ReadLine() + CRLF;

    string szTemp;

    szTemp = RdStrm.ReadLine();

    // POP3 uses . as the end of a message
    while(szTemp != ".")
    {                   
        txtLog.Text += szTemp + CRLF;
        szTemp = RdStrm.ReadLine();                                               
    }              
}

that settles it, looks like the internet is in a need for a good, open source, easy to modify lib, so that's what i'll do next. Thanks everyone. Works perfectly now


If the service at the other end returns lines that end with CRLF, then the lines you get from Readline will have a CR at the end. So the returned string will always be != "-".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号