Author: norman
Date: Mon Nov 1 17:49:39 2010
New Revision: 1029762
URL: http://svn.apache.org/viewvc?rev=1029762&view=rev
Log:
Make MimeMessageWrapper copy of Message configurable, default is use file
(JAMES-1100)
Modified:
james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
Modified:
james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java?rev=1029762&r1=1029761&r2=1029762&view=diff
==============================================================================
---
james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
(original)
+++
james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
Mon Nov 1 17:49:39 2010
@@ -28,6 +28,7 @@ import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.util.Enumeration;
+import java.util.UUID;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
@@ -51,6 +52,12 @@ public class MimeMessageWrapper
implements Disposable {
/**
+ * System property which tells JAMES if it should copy a message in memory
or via a temporary file.
+ * Default is the file
+ */
+ public final static String USE_MEMORY_COPY = "james.message.usememorycopy";
+
+ /**
* Can provide an input stream to the data
*/
protected MimeMessageSource source = null;
@@ -113,20 +120,38 @@ public class MimeMessageWrapper
flags = original.getFlags();
if (source == null) {
- ByteArrayOutputStream bos;
- int size = original.getSize();
- if (size > 0)
- bos = new ByteArrayOutputStream(size);
- else
- bos = new ByteArrayOutputStream();
+ InputStream in;
+
+ boolean useMemoryCopy =false;
+ String memoryCopy = System.getProperty(USE_MEMORY_COPY);
+ if (memoryCopy != null) {
+ useMemoryCopy = Boolean.valueOf(memoryCopy);
+ }
try {
- original.writeTo(bos);
- bos.close();
- SharedByteArrayInputStream bis =
- new SharedByteArrayInputStream(bos.toByteArray());
- parse(bis);
- bis.close();
- saved = true;
+
+ if (useMemoryCopy) {
+ ByteArrayOutputStream bos;
+ int size = original.getSize();
+ if (size > 0) {
+ bos = new ByteArrayOutputStream(size);
+ } else {
+ bos = new ByteArrayOutputStream();
+ }
+ original.writeTo(bos);
+ bos.close();
+ in = new SharedByteArrayInputStream(bos.toByteArray());
+ parse(in);
+ in.close();
+ saved = true;
+ } else {
+ MimeMessageInputStreamSource src = new
MimeMessageInputStreamSource("MailCopy-" + UUID.randomUUID().toString());
+ OutputStream out = src.getWritableOutputStream();
+ original.writeTo(out);
+ out.close();
+ source = src;
+ }
+
+
} catch (IOException ex) {
// should never happen, but just in case...
throw new MessagingException("IOException while copying
message",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]