Author: tn
Date: Wed Nov 7 21:52:11 2012
New Revision: 1406832
URL: http://svn.apache.org/viewvc?rev=1406832&view=rev
Log:
[EMAIL-120] Prevent file locking due to a missing close for a temporary input
stream.
Modified:
commons/proper/email/trunk/src/changes/changes.xml
commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
commons/proper/email/trunk/src/test/org/apache/commons/mail/MultiPartEmailTest.java
Modified: commons/proper/email/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1406832&r1=1406831&r2=1406832&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Wed Nov 7 21:52:11 2012
@@ -23,34 +23,38 @@
<body>
<release version="1.3" date="as in SVN">
- <action dev="sgoeschl" type="fix" issue="EMAIL-105" date="2012-02-04"
due-to="Siegfried Goeschl">
- The patch actually broke sending emails over a secured connection
- disabled the
- "MAIL_SMTP_SSL_CHECKSERVERIDENTITY" and "MAIL_SMTP_SSL_ENABLE"
activation. Tested
- the functionality using GMail, GMX and Office365 so the code is at
least working for
- a couple of existing SMTP servers. Also added
'sslCheckServerIdentity' including
- setter and getter. Also added a chapter regarding "Security" to
the user manual.
- </action>
- <action dev="sgoeschl" type="add" issue="EMAIL-113" date="2012-02-19"
due-to="Peter Kofler">
- Maven Site fails with error in Checkstyle configuration.
- </action>
- <action dev="sgoeschl" type="add" issue="EMAIL-112" date="2012-02-19"
due-to="Peter Kofler">
- DataSourceFileResolverTest fails under IBM JDK 1.4 and 1.6 running
on Windows.
- </action>
- <action dev="sgoeschl" type="add" issue="EMAIL-111" date="2012-02-18"
due-to="Florian Pirchner">
- Update the current trunk to be binary compatible with the
commons-email-1.2 release.
- </action>
- <action dev="sgoeschl" type="add" issue="EMAIL-110" date="2012-02-18"
due-to="Thomas Pummer">
- Added unit test to ensure that parsing the broken mime message does
not cause an OutOfMemoryException.
- </action>
- <action dev="sgoeschl" type="add" issue="EMAIL-108" date="2011-11-10"
due-to="Elisabeth Kasimir, Alexander Kasimir">
- HtmlmageEmail should support class path resources
- </action>
- <action dev="sgoeschl" type="fix" issue="EMAIL-107" date="2011-09-06"
due-to="Claus Polanka, Michael Jakl">
- Added mime.types to META-INF - the definition is actually found in
activation.jar
- but did not work.
+ <action dev="tn" type="fix" issue="EMAIL-120" date="2012-11-07"
due-to="Mike Bell">
+ Close temporary input stream in MultiPartEmail#attach(DataSource,
String, String)
+ to prevent locking of file resources on windows systems.
+ </action>
+ <action dev="sgoeschl" type="fix" issue="EMAIL-105" date="2012-02-04"
due-to="Siegfried Goeschl">
+ The patch actually broke sending emails over a secured connection -
disabled the
+ "MAIL_SMTP_SSL_CHECKSERVERIDENTITY" and "MAIL_SMTP_SSL_ENABLE"
activation. Tested
+ the functionality using GMail, GMX and Office365 so the code is at
least working for
+ a couple of existing SMTP servers. Also added 'sslCheckServerIdentity'
including
+ setter and getter. Also added a chapter regarding "Security" to the
user manual.
+ </action>
+ <action dev="sgoeschl" type="add" issue="EMAIL-113" date="2012-02-19"
due-to="Peter Kofler">
+ Maven Site fails with error in Checkstyle configuration.
+ </action>
+ <action dev="sgoeschl" type="add" issue="EMAIL-112" date="2012-02-19"
due-to="Peter Kofler">
+ DataSourceFileResolverTest fails under IBM JDK 1.4 and 1.6 running on
Windows.
+ </action>
+ <action dev="sgoeschl" type="add" issue="EMAIL-111" date="2012-02-18"
due-to="Florian Pirchner">
+ Update the current trunk to be binary compatible with the
commons-email-1.2 release.
+ </action>
+ <action dev="sgoeschl" type="add" issue="EMAIL-110" date="2012-02-18"
due-to="Thomas Pummer">
+ Added unit test to ensure that parsing the broken mime message does
not cause an OutOfMemoryException.
+ </action>
+ <action dev="sgoeschl" type="add" issue="EMAIL-108" date="2011-11-10"
due-to="Elisabeth Kasimir, Alexander Kasimir">
+ HtmlmageEmail should support class path resources
+ </action>
+ <action dev="sgoeschl" type="fix" issue="EMAIL-107" date="2011-09-06"
due-to="Claus Polanka, Michael Jakl">
+ Added mime.types to META-INF - the definition is actually found in
activation.jar
+ but did not work.
</action>
- <action dev="sgoeschl" type="fix" issue="EMAIL-106" date="2011-09-06"
due-to="Bruno Harbulot">
- STARTTLS can be used even without authenticator.
+ <action dev="sgoeschl" type="fix" issue="EMAIL-106" date="2011-09-06"
due-to="Bruno Harbulot">
+ STARTTLS can be used even without authenticator.
</action>
<action dev="sgoeschl" type="fix" issue="EMAIL-105" date="2011-09-06"
due-to="Bruno Harbulot">
Clarified the meaning of setTLS() which actually sends a "STARTTLS"
command from the
Modified:
commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
URL:
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java?rev=1406832&r1=1406831&r2=1406832&view=diff
==============================================================================
---
commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
(original)
+++
commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
Wed Nov 7 21:52:11 2012
@@ -425,7 +425,14 @@ public class MultiPartEmail extends Emai
// verify that the DataSource is valid
try
{
- if (ds == null || ds.getInputStream() == null)
+ final InputStream is = (ds != null) ? ds.getInputStream() : null;
+ if (is != null)
+ {
+ // close the input stream to prevent file locking on windows
+ is.close();
+ }
+
+ if (is == null)
{
throw new EmailException("Invalid Datasource");
}
Modified:
commons/proper/email/trunk/src/test/org/apache/commons/mail/MultiPartEmailTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/MultiPartEmailTest.java?rev=1406832&r1=1406831&r2=1406832&view=diff
==============================================================================
---
commons/proper/email/trunk/src/test/org/apache/commons/mail/MultiPartEmailTest.java
(original)
+++
commons/proper/email/trunk/src/test/org/apache/commons/mail/MultiPartEmailTest.java
Wed Nov 7 21:52:11 2012
@@ -23,6 +23,7 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
+import javax.activation.FileDataSource;
import javax.activation.URLDataSource;
import javax.mail.internet.MimeMultipart;
@@ -326,6 +327,23 @@ public class MultiPartEmailTest extends
}
}
+ public void testAttachFileLocking() throws Exception {
+
+ // ====================================================================
+ // EMAIL-120: attaching a FileDataSource may result in a locked file
+ // resource on windows systems
+ // ====================================================================
+
+ File tmpFile = File.createTempFile("attachment", ".eml");
+
+ this.email.attach(
+ new FileDataSource(tmpFile),
+ "Test Attachment",
+ "Test Attachment Desc");
+
+ assertTrue(tmpFile.delete());
+ }
+
/**
*
* @throws Exception Exception