if( !tmpfile.createNewFile())
{
throw new MessagingException("Temporary file already exists");
}
OutputStream out = new BufferedOutputStream(new FileOutputStream(tmpfile));
src.writeTo(out); // write message to tmp/tmpname
out.close(); // flush and close
File file = new File(seen ? this.curdir.dir
: this.newdir.dir, tmpname);
tmpfile.renameTo(file); // link to final location
tmpfile.delete(); // delete temporary file