out.append("Content-Disposition: attachment;").append(CRLF);
out.append(" filename=\"").append(sStrippedFileName).append("\"").append(CRLF);
out.append(CRLF);
Base64Encoder encoder = null;
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
encoder = new Base64Encoder(baos);
final byte[] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
encoder.write(buf, 0, bytesRead);
}
encoder.flush();
out.append(baos.toString("US-ASCII"));
}
catch (Throwable e) {
Log.log(Log.FATAL, "lazyj.mail.Sendmail", "writeAttachment" + e);
this.iSentOk = SENT_ERROR;
this.sError = "exception while writing an attachment : " + e.getMessage();
return false;
}
finally{
if (in != null)
try{
in.close();
}
catch (IOException e){
// ignore
}
if (encoder != null){
try{
encoder.close();
}
catch (IOException e){
// ignore
}
}