package org.subethamail.smtp.server.io;

import java.io.File;
import java.io.IOException;

import javax.mail.util.SharedFileInputStream;

/**
 * This class uses a temporary file to store big messages and asks JVM
 * to delete them when destroyed.
 * 
 * @author De Oliveira Edouard &lt;doe_wanted@yahoo.fr&gt;
 */
public class SharedTmpFileInputStream 
	extends SharedFileInputStream 
{
	private File tempFile;
	
	public SharedTmpFileInputStream(File f) throws IOException 
	{
		super(f);
		this.tempFile = f;
	}

	public void close() throws IOException 
	{
		super.close();
		if (in == null)
			this.tempFile.deleteOnExit();
	}
}

@@ -238,16 +238,23 @@
 em when 
+JVM is 
 destroye
@@ -537,97 +537,103 @@
 ;%0D%0A%09
-%7D%0D%0A%0D%0A%09public void close() throws IOException %0D%0A%09%7B%0D%0A%09%09super.close();%0D%0A%09%09if (in == null)
+%09%0D%0A%09%09// Always mark file to be deleted on exit in case streams%0D%0A%09%09// are not closed properly.
 %0D%0A
-%09
 %09%09th
@@ -665,11 +665,9 @@
 );%0D%0A%09%7D%0D%0A
+
 %7D
-%0D%0A

Fix to ensure that temp deffered file will be deleted by JVM even if shared streams are improperly closed