james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1686793 - in /james/mailet/trunk: pom.xml standard/pom.xml standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
Date Mon, 22 Jun 2015 08:03:16 GMT
Author: btellier
Date: Mon Jun 22 08:03:15 2015
New Revision: 1686793

URL: http://svn.apache.org/r1686793
Log:
MAILET-95 Use FileUtils when deleting files - Contributed by Antoine Duprat

Modified:
    james/mailet/trunk/pom.xml
    james/mailet/trunk/standard/pom.xml
    james/mailet/trunk/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
    james/mailet/trunk/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java

Modified: james/mailet/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/mailet/trunk/pom.xml?rev=1686793&r1=1686792&r2=1686793&view=diff
==============================================================================
--- james/mailet/trunk/pom.xml (original)
+++ james/mailet/trunk/pom.xml Mon Jun 22 08:03:15 2015
@@ -47,6 +47,7 @@
         <activation.version>1.1.1</activation.version>
         <bcmail-jdk16.version>1.46</bcmail-jdk16.version>
         <commons-collections.version>3.2.1</commons-collections.version>
+        <commons-io.version>2.4</commons-io.version>
         <httpclient-osgi.version>4.2.2</httpclient-osgi.version>
         <!-- maven-mailetdocs-plugin artifacts -->
         <maven-artifact.version>3.0-alpha-1</maven-artifact.version>
@@ -119,6 +120,11 @@
                 <version>${commons-collections.version}</version>
             </dependency>
             <dependency>
+                <groupId>commons-io</groupId>
+                <artifactId>commons-io</artifactId>
+                <version>${commons-io.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>httpclient-osgi</artifactId>
                 <version>${httpclient-osgi.version}</version>

Modified: james/mailet/trunk/standard/pom.xml
URL: http://svn.apache.org/viewvc/james/mailet/trunk/standard/pom.xml?rev=1686793&r1=1686792&r2=1686793&view=diff
==============================================================================
--- james/mailet/trunk/standard/pom.xml (original)
+++ james/mailet/trunk/standard/pom.xml Mon Jun 22 08:03:15 2015
@@ -64,6 +64,10 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

Modified: james/mailet/trunk/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
URL: http://svn.apache.org/viewvc/james/mailet/trunk/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java?rev=1686793&r1=1686792&r2=1686793&view=diff
==============================================================================
--- james/mailet/trunk/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
(original)
+++ james/mailet/trunk/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
Mon Jun 22 08:03:15 2015
@@ -26,7 +26,11 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 import javax.mail.Message;
@@ -36,6 +40,7 @@ import javax.mail.Part;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeUtility;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetException;
 import org.apache.mailet.base.GenericMailet;
@@ -159,11 +164,7 @@ public class StripAttachment extends Gen
 
         if (directoryName != null) {
             try {
-                File saveDirectory;
-                saveDirectory = new File(directoryName);
-                if (!saveDirectory.exists()) {
-                    saveDirectory.mkdirs();
-                }
+                FileUtils.forceMkdir(new File(directoryName));
             } catch (Exception e) {
                 throw new MailetException("Could not create directory ["
                         + directoryName + "].", e);

Modified: james/mailet/trunk/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
URL: http://svn.apache.org/viewvc/james/mailet/trunk/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java?rev=1686793&r1=1686792&r2=1686793&view=diff
==============================================================================
--- james/mailet/trunk/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
(original)
+++ james/mailet/trunk/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
Mon Jun 22 08:03:15 2015
@@ -19,22 +19,6 @@
 
 package org.apache.james.transport.mailets;
 
-import org.apache.james.transport.mailets.OnlyText;
-import org.apache.james.transport.mailets.RecoverAttachment;
-import org.apache.james.transport.mailets.StripAttachment;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Mailet;
-import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Assert;
-import org.junit.Test;
-
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -44,6 +28,21 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.Properties;
 
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.mailet.Mail;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.junit.Assert;
+import org.junit.Test;
+
 public class StripAttachmentTest {
 
     @Test
@@ -94,13 +93,14 @@ public class StripAttachmentTest {
         String name = c.iterator().next();
 
         File f = new File("./" + name);
-        InputStream is = new FileInputStream(f);
-        String savedFile = toString(is);
-        is.close();
-        Assert.assertEquals(body, savedFile);
-
-        f.delete();
-
+        try {
+            InputStream is = new FileInputStream(f);
+            String savedFile = toString(is);
+            is.close();
+            Assert.assertEquals(body, savedFile);
+        } finally {
+            FileUtils.deleteQuietly(f);
+        }
     }
 
     public String toString(final InputStream is) throws IOException {
@@ -168,13 +168,14 @@ public class StripAttachmentTest {
         String name = c.iterator().next();
 
         File f = new File("./" + name);
-        InputStream is = new FileInputStream(f);
-        String savedFile = toString(is);
-        is.close();
-        Assert.assertEquals(body, savedFile);
-
-        f.delete();
-
+        try {
+            InputStream is = new FileInputStream(f);
+            String savedFile = toString(is);
+            is.close();
+            Assert.assertEquals(body, savedFile);
+        } finally {
+            FileUtils.deleteQuietly(f);
+        }
     }
 
     @Test
@@ -234,13 +235,14 @@ public class StripAttachmentTest {
         Assert.assertTrue(name.startsWith("e_Pubblicita_e_vietata_Milano9052"));
 
         File f = new File("./" + name);
-        InputStream is = new FileInputStream(f);
-        String savedFile = toString(is);
-        is.close();
-        Assert.assertEquals(body, savedFile);
-
-        f.delete();
-
+        try {
+            InputStream is = new FileInputStream(f);
+            String savedFile = toString(is);
+            is.close();
+            Assert.assertEquals(body, savedFile);
+        } finally {
+            FileUtils.deleteQuietly(f);
+        }
     }
 
     @Test



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message