2012-07-02 2 views
0

내 pop3 클라이언트에 문제가 있습니다. tcpclient 스트림에서 가져온 전자 메일을 utf-8 또는 iso 8859-1로 인코딩 할 수 없습니다. 이 코드입니다 :이 "? _ = questa_ = E8_una_prova_ = F2_ = EC"와 같은C#에서 tcpclient 스트림을 인코딩하는 방법은 무엇입니까?

TcpClient tcpClient = new TcpClient(); 
txtLog.Text = "Dico:\r\nConnect me to " + txtServer.Text + ":" + txtPort.Text + "\r\n\r\n"; 
tcpClient.Connect(txtServer.Text, Convert.ToInt32(txtPort.Text)); 
NetworkStream netStream = tcpClient.GetStream(); 
System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1"); 
System.IO.StreamReader strReader = new System.IO.StreamReader(netStream, iso_8859_1); 

System.Text.Encoding utf_8 = System.Text.Encoding.UTF8; 


if (tcpClient.Connected) 
{ 
    txtLog.Text = "Il server risponde:\r\n" + strReader.ReadLine() + "\r\n\r\n"; 
    byte[] WriteBuffer = new byte[100990024]; 
    ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 

    WriteBuffer = enc.GetBytes("USER " + txtUser.Text + "\r\n"); 
    txtLog.Text = "Dico:\r\nHere's the username: " + txtUser.Text + "\r\n\r\n"; 
    netStream.Write(WriteBuffer, 0, WriteBuffer.Length); 
    txtLog.Text = "Il server risponde\r\n" + strReader.ReadLine() + "\r\n\r\n"; 
    WriteBuffer = enc.GetBytes("PASS " + txtPass.Text + "\r\n"); 
    txtLog.Text = "Dico:\r\nHere's the password: " + txtPass.Text + "\r\n\r\n"; 
    netStream.Write(WriteBuffer, 0, WriteBuffer.Length); 
    txtLog.Text = "Il server risponde\r\n" + strReader.ReadLine() + "\r\n\r\n"; 

    WriteBuffer = enc.GetBytes("RETR " + messaggio.Text + "\r\n"); 
    txtLog.Text = "Messaggio: " + messaggio.Text + "\r\n\r\n"; 
    string message; 
    netStream.Write(WriteBuffer, 0, WriteBuffer.Length); 
    while (true) 
    { 
     message = strReader.ReadLine(); 
     if (message == ".") 
     { 
      if (message == "/n") break; 
      break; 
     } 
     else 
     { 
      txtLog.Text += message + "\r\n\r\n"; 
      continue; 
     } 
    } 

난 항상 얻을 뭔가. 무엇이 잘못 되었나요? 감사합니다.

답변

0

텍스트 인코딩의 결과 인 바이트를 전송하는 데 사용되는 전송 인코딩이 필요합니다.

텍스트가 UTF-8 또는 다른 문자 집합으로 인코딩 될 수 있지만 전송 인코딩은 일반적으로 base 64 또는 quoted-printable입니다. 문자열 "questa_=E8_una_prova_=F2_=EC_?="은 후자와 같습니다.

quoted-printable을 문자열로 디코딩하는 방법은 here을보고 .NET의 기존 POP3 클라이언트 구현은 here을 참조하십시오.