e(新行标识)。文件的名称和路径由pathFileName指定。
该方法的剩余部分
ReadLines方法剩余的代码如下:
StringBuffer strBuf = new StringBuffer();
try{
BufferedReader inDataMsg = new BufferedReader(new FileReader(pathFileName));
String data;
boolean isSave = false;
while((data = inDataMsg.readLine())!= null){
if(((firstLine == null) ||(data.startsWith(firstLine))) && (isSave == false)){
isSave = true;
}// if结束
if(isSave){ strBuf.append(data + "\n");
}// if结束
if((lastLine != null) && (data.startsWith(lastLine))){
break;//不需要读取更多信息了
}// if结束
}// while循环结束
inDataMsg.close();//关闭文件
}catch(Exception e){e.printStackTrace();}
return new String(strBuf);
}//读取数据行结束
Java设计防病毒电子邮件程序(5)
时间:2010-09-13
消息的格式
为了使我设计的readLines更加通用,我计划把它设计为从未处理的消息中提取文本行,因此看一个消息的例子对你来说可能是有益的。
下图显示了一个为了演示目的而发送给自己的未处理的简单的电子邮件消息文本(请注意,我在文本中插入和大量的行分隔符,这样才能显示如下)。
Return-Path: <Baldwin@DickBaldwin.com>
Received: from ms-smtp-01-eri0.texas.rr.com
(ms-smtp-01.texas.rr.com [24.93.47.40])
by omnistarhost.com (8.11.6/8.11.6)
with ESMTP id i1G1PeX29829
for <baldwin@dickbaldwin.com>; Sun,
15 Feb 2004 19:25:40 -0600
Received: from DickBaldwin.com
(cs24339-166.austin.rr.com [24.243.39.166])
by ms-smtp-01-eri0.texas.rr.com
(8.12.10/8.12.7) with ESMTP id i1G1JHLc003760
for <baldwin@dickbaldwin.com>;
Sun, 15 Feb 2004 19:19:20 -0600 (CST)
Message-ID: <40301A94.6070504@DickBaldwin.com>
Date: Sun, 15 Feb 2004 19:19:16 -0600
From: Richard Baldwin <Baldwin@DickBaldwin.com>
Reply-To: Baldwin@DickBaldwin.com
User-Agent: Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.4) Gecko/20030624
Netscape/7.1 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: baldwin@dickbaldwin.com
Subject: A test msg to illustrate messagestructure
Content-Type: text/plain;
charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-MailScanner-Information: Please
contact the ISP for more information
X-MailScanner: Found to be clean
Status:
This is a test message.
--
Richard G. Baldwin (Dick Baldwin)
Home of Baldwin''s on-line Java Tutorials
http://www.DickBaldwin.com
Professor of Computer Information Technology
Austin Community College
(512) 223-4758 or (512) 250-8682
mailto:Baldwin@DickBaldwin.com
http://www.austincc.edu/baldwin/
在图1中我使用加亮显示了两行。
主题行和状态行
在forwardEmailMsg方法的代码中主题行将扮演重要的角色。在程序中,在消息被转发到秘密的电子邮件帐号之前,消息编号被插入到主题行中。
状态行之前的信息都被认为是消息头部信息。状态行后面的部分都被认为是消息主体。如果你在文本编辑器中阅读未处理的电子邮件消息,你一般注意电子邮件主体中的消息。
返回到forwardEmailMsg方法
private boolean forwardEmailMsg(String recipient,
String smtpServer,String tag, String pathFileName){
ForwardEmailMsg方法输入的参数是:
· recipient(接收者)—&md |