msnlib源代码中MimeMessage的parse是通过
来获得每一行的内容,但是发现br.readline是以\r(0X0A),\n(0X0D)中的任何一个字符即认为是行结束符。
这样,在获取48字节头的时候,如果字节内容正好包括0D的时候,就会发生截取出来的头少于48个字节而引起indexbound错误。
因此,修改如下:
BufferedReader br=new BufferedReader(new StringReader(raw));
addProperty( br.readLine()); // MIME-Version
addProperty( br.readLine()); // Content-Type
addProperty( br.readLine()); // MIME-Version
addProperty( br.readLine()); // Content-Type
这样,在获取48字节头的时候,如果字节内容正好包括0D的时候,就会发生截取出来的头少于48个字节而引起indexbound错误。
因此,修改如下:
package rath.msnm.msg;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class MimeMessageBufferedReader extends BufferedReader {
private String charcode;
public MimeMessageBufferedReader(Reader in,String charcode) {
super(in);
this.charcode =charcode;
}
public MimeMessageBufferedReader(Reader in,int sz,String charcode) {
super(in,sz);
this.charcode=charcode;
}
public String readLine()
throws IOException
{
CharArrayWriter caw=new CharArrayWriter(6);
ByteArrayOutputStream bo=new ByteArrayOutputStream();
int c=this.read();
if(c==-1)
{
return null;
}
while(c!=-1){
if(c==13){
int d=this.read();
if(d==10){
break;
}else
{caw.write(c);
caw.write(d);
}
}else{
caw.write(c);
}
byte[] bt=new String(caw.toCharArray()).getBytes(charcode);
bo.write(bt);
caw.reset();
c=this.read();
}
return new String(bo.toByteArray(),charcode);
}
}
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class MimeMessageBufferedReader extends BufferedReader {
private String charcode;
public MimeMessageBufferedReader(Reader in,String charcode) {
super(in);
this.charcode =charcode;
}
public MimeMessageBufferedReader(Reader in,int sz,String charcode) {
super(in,sz);
this.charcode=charcode;
}
public String readLine()
throws IOException
{
CharArrayWriter caw=new CharArrayWriter(6);
ByteArrayOutputStream bo=new ByteArrayOutputStream();
int c=this.read();
if(c==-1)
{
return null;
}
while(c!=-1){
if(c==13){
int d=this.read();
if(d==10){
break;
}else
{caw.write(c);
caw.write(d);
}
}else{
caw.write(c);
}
byte[] bt=new String(caw.toCharArray()).getBytes(charcode);
bo.write(bt);
caw.reset();
c=this.read();
}
return new String(bo.toByteArray(),charcode);
}
}
public void parse( String raw ) throws Exception
{
MimeMessageBufferedReader br = new MimeMessageBufferedReader(new StringReader(raw),rath.msnm.msnmConstant.getCharacterCode());
}
{
MimeMessageBufferedReader br = new MimeMessageBufferedReader(new StringReader(raw),rath.msnm.msnmConstant.getCharacterCode());
}