robber斑竹,帮我解决一下这个问题好吗?

wxyxl 2001-04-23 12:21:00
import java.io.*;
import java.net.*;
public class Pop3test
{
public static void main(String[] args)
{
try{
Socket s = new Socket(args[0],110);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String str;
str = in.readLine();
System.out.println("初始化结果"+str);

out.write("USER wxyxl\n");
out.flush();
str = in.readLine();
System.out.println("用户名输入结果 "+str);

out.write("pass wxyxl78\n");
out.flush();
str = in.readLine();
System.out.println("密码输入结果 "+str);

out.write("list\n");
out.flush();
str = in.readLine();
System.out.println("List "+str);

int i=0;
while((str = in.readLine()) != null)
{
System.out.println(str);
if (!(str.equals(".")))
{
i++;
}
else
break;
}

System.out.println("共有 "+i+" 封邮件");

String result = "";
byte[] b;
for (int j=1;j<=i;j++)
{
out.write("RETR "+j+"\n");
out.flush();
while (((str = in.readLine()) != null) &&(!(str.equals("."))))
{
b = str.getBytes("GB2312");
str = new String(b,"8859_1");
result += str + "\n";
}
System.out.println("这是第 "+j+" 封邮件");
System.out.println(result);
System.out.println("*************************");
}

s.close();
}catch(Exception e)
{}
}
}

程序的输出结果如下:

初始化+OK X1 NT-POP3 Server wxyxl.com (IMail 4.06 519-1)
用户名输入 +OK welcome
密码输入 +OK maildrop locked and ready
List +OK 1 messages (669 octets)
1 669
.
共有 1 封邮件
这是第 1 封邮件
+OK 669 octets
Received: from xieli [128.8.1.2] by wxyxl.com
(SMTPD32-4.06) id A06AA0878; Thu, 19 Apr 2001 21:51:54 PDT
Date: Thu, 19 Apr 2001 21:51:54 +0800
From: =?ISO-8859-1?Q?=CD=F5=CF=FE=D2=E5?= <xlwxy@wxyxl.com>
To: =?ISO-8859-1?Q?=D0=BB=C0=F6?= <wxyxl@wxyxl.com>
Subject:
X-mailer: FoxMail 3.1 [cn]
Mime-Version: 1.0
Content-Type: text/plain; charset="GB2312"
Content-Transfer-Encoding: quoted-printable
X-UIDL: 987714525
Status: U

=D0=BB=C0=F6=A3=AC=C4=FA=BA=C3=A3=A1

Three Email!

=D6=C2
=C0=F1=A3=A1

=CD=F5=CF=FE=D2=E5
xlwxy@wxyxl.com



*************************

我不懂的是为什么我在接受数据的时候已经坐了编码转换,
为什么还是乱码呢,请您帮忙解决一下?
...全文
120 13 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wxyxl 2001-04-27
谢谢你啦!不知道为什么CSDN总是给不了分,今天总于
可以给分了,所以拖的这么迟!希望以后能多多指教!
  • 打赏
  • 举报
回复
wxyxl 2001-04-24
因该支持!Mail Server是Imail,因该是解码的问题。
我用下面的C代码可以解码,但是转化成Java代码有问题!
你能帮我转化一下吗?
#include <stdio.h>
void main(int argc, char * argv[])
{
FILE * fp; char ch, ch1, ch2; char hz;
fp = fopen("data.txt", "rt");
for (;;)
{
ch = getc(fp); if (ch == EOF) break;
if (ch == '=')
{
ch1 = getc(fp); if (ch1 == '\n') continue;
ch2 = getc(fp);
if (ch1>=65)
ch1-=55;
else ch1-=48;
if (ch2>=65)
ch2-=55;
else ch2-=48;

hz=(ch1<<4);
hz|=ch2;
putchar(hz);
}
else putchar(ch);
}
fclose(fp);
}
  • 打赏
  • 举报
回复
虎叔 2001-04-24
你的mail server支持双字节吗?
是否是他的问题?
  • 打赏
  • 举报
回复
wxyxl 2001-04-24
能否给一个可以解“quoted-printable”格式的Java程序?
  • 打赏
  • 举报
回复
wxyxl 2001-04-24
谢谢 robber(海盗) 我已经作出来啦!
  • 打赏
  • 举报
回复
wxyxl 2001-04-24
我用的环境是NT4.0、SP5、JDK1.3、Imail Version 4.06、Foxmail1.3
  • 打赏
  • 举报
回复
wxyxl 2001-04-24
to robber(海盗) :
谢谢你的热心帮助,但是还是不行,可能是你在测试的时候发的邮件使用Imai客户端发的,
如果你用Foxmail3.1发封邮件再收的话,则显示的是一些数字。因为Imail发送邮件时没有对
邮件体进行编码,而Foxmail则对其采用了”quoted-printable“格式的编码,上面你的程序
对其进行了解码,但是没有成功。上面那段C程序完全可以对“quoted-printable”进行解码,
我测试过,但是你的解码程序输出的是一些字母和数字,如下:
这是第 1 封邮件
+OK 682 octets
Received: from xieli [128.8.1.2] by wxyxl.com
(SMTPD32-4.06) id A8482E0428; Mon, 23 Apr 2001 20:51:36 PDT
Date: Mon, 23 Apr 2001 20:51:36 +0800
From: ISO-8859-1?Q?D5FE25?<xlwxy@wxyxl.com>
To: ISO-8859-1?Q?0B06?<wxyxl@wxyxl.com>
Subject:
X-mailer: FoxMail 3.1 [cn]
Mime-Version: 1.0
Content-Type: text/plain; charsetGB2312"
Content-Transfer-Encoding: quoted-printable
X-UIDL: 987714531
Status: U

0B063C4AA331

Hello!0B0631

62
0131

D5FE25
xlwxy@wxyxl.com
  • 打赏
  • 举报
回复
虎叔 2001-04-24
我的环境是windows2000 server
  • 打赏
  • 举报
回复
虎叔 2001-04-24
根据你的环境我在imail6.04+jdk1.3上调试成功!
源代码如下!!!
不好意思!这么久才解决!

import java.io.*;
import java.net.*;
public class Pop3test
{
public static void main(String[] args)
{
try{
Socket s = new Socket(args[0],110);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String str;
str = in.readLine();
System.out.println("初始化结果"+str);

out.write("USER robber\n");
out.flush();
str = in.readLine();
System.out.println("用户名输入结果 "+str);

out.write("pass 123456\n");
out.flush();
str = in.readLine();
System.out.println("密码输入结果 "+str);

out.write("list\n");
out.flush();
str = in.readLine();
System.out.println("List "+str);

int i=0;
while((str = in.readLine()) != null)
{
System.out.println(str);
if (!(str.equals(".")))
{
i++;
}
else
break;
}

System.out.println("共有 "+i+" 封邮件");

String result = "";
byte[] b;
byte[] b1;
char bb;
for (int j=1;j<=i;j++)
{
out.write("RETR "+j+"\n");
out.flush();
while (((str = in.readLine()) != null) &&(!(str.equals(".")))){
result += str + "\n";
}

System.out.println(result);

ByteArrayOutputStream brr = new ByteArrayOutputStream();
b = result.getBytes();
for(int k = 0 ; k < b.length; k++){
if( b[k] == '='){
k++;
if(b[k] != '\n') continue;
if(b[k] >= 65)
b[k] -= 55;
else
b[k] -= 48;

if(b[k+1] >= 65)
b[k+1] -= 55;
else
b[k+1] -= 48;
//bb = b[k];
//bb = bb << 4;
//bb = (char)(b[k] << 4);
//bb |= b[k+1];
k++;
brr.write(b[k+1]);
brr.write(b[k]);
brr.flush();
}
else
{brr.write(b[k]);}
}
System.out.println("这是第 "+j+" 封邮件");
System.out.println(brr.toString());
System.out.println("*************************");
}

s.close();
}catch(Exception e)
{e.printStackTrace();}
}
}

  • 打赏
  • 举报
回复
虎叔 2001-04-24
终于成功了!!!



初始化结果+OK X1 NT-POP3 Server robber (IMail 6.06 EVAL 24-1)
用户名输入结果 +OK welcome
密码输入结果 +OK maildrop locked and ready
List +OK 2 messages (708 octets)
1 351
2 357
.
共有 2 封邮件
+OK 351 octets
Date: Tue, 24 Apr 2001 14:09:59 +0800
Message-Id: <200104241409.AA3212642@robber>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
From: "系统管理员 " <root@robber>
Reply-To: <root@robber>
To: <robber@robber>
Subject: 好孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 4
Status: U

do it


这是第 1 封邮件
+OK 351 octets
Date: Tue, 24 Apr 2001 14:09:59 +0800
Message-Id: <200104241409.AA3212642@robber>
Mime-Version: 1.0
Content-Type: text/plain; charsets-ascii
From: "系统管理员 " <root@robber>
Reply-To: <root@robber>
To: <robber@robber>
Subject: 好孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 4
Status: U

do it


*************************
+OK 351 octets
Date: Tue, 24 Apr 2001 14:09:59 +0800
Message-Id: <200104241409.AA3212642@robber>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
From: "系统管理员 " <root@robber>
Reply-To: <root@robber>
To: <robber@robber>
Subject: 好孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 4
Status: U

do it

+OK 357 octets
Date: Tue, 24 Apr 2001 14:21:06 +0800
Message-Id: <200104241421.AA722710@robber>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
From: "李进 海盗" <robber@robber>
Reply-To: <robber@robber>
To: <robber@robber>
Subject: 坏孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 5
Status: U

好孩子!


这是第 2 封邮件
+OK 351 octets
Date: Tue, 24 Apr 2001 14:09:59 +0800
Message-Id: <200104241409.AA3212642@robber>
Mime-Version: 1.0
Content-Type: text/plain; charsets-ascii
From: "系统管理员 " <root@robber>
Reply-To: <root@robber>
To: <robber@robber>
Subject: 好孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 4
Status: U

do it

+OK 357 octets
Date: Tue, 24 Apr 2001 14:21:06 +0800
Message-Id: <200104241421.AA722710@robber>
Mime-Version: 1.0
Content-Type: text/plain; charsets-ascii
From: "李进 海盗" <robber@robber>
Reply-To: <robber@robber>
To: <robber@robber>
Subject: 坏孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 5
Status: U

好孩子!


*************************
  • 打赏
  • 举报
回复
虎叔 2001-04-24

好像对Subject等等都可以,可是内容不行。




初始化结果+OK X1 NT-POP3 Server robber (IMail 6.06 EVAL 20-1)
用户名输入结果 +OK welcome
密码输入结果 +OK maildrop locked and ready
List +OK 1 messages (351 octets)
1 351
.
共有 1 封邮件
这是第 1 封邮件
+OK 351 octets
Date: Tue, 24 Apr 2001 14:09:59 +0800
Message-Id: <200104241409.AA3212642@robber>
Mime-Version: 1.0
Content-Type: text/plain; charsets-ascii
From: "系统管理员 " <root@robber>
Reply-To: <root@robber>
To: <robber@robber>
Subject: 好孩子
X-Mailer: <IMail v6.05 EVAL>
X-UIDL: 4
Status: U

do it


*************************
  • 打赏
  • 举报
回复
wxyxl 2001-04-23
很遗憾还没有,有人告诉我是编码的问题,
但是不知道怎么解码!你能给一个简单的POP3的程序,
且能正常的接收中文的,让我参考参考!谢谢!
  • 打赏
  • 举报
回复
虎叔 2001-04-23
公司网络有问题!我有很久没有上来啦!
你的问题大概已经解决啦吧!
  • 打赏
  • 举报
回复
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
社区管理员
  • Java SE
申请成为版主
帖子事件
创建了帖子
2001-04-23 12:21
社区公告
暂无公告