serge 01/12/05 14:11:49
Modified: src/java/org/apache/james/core MailImpl.java
MimeMessageInputStreamSource.java
MimeMessageSource.java MimeMessageWrapper.java
Log:
Renamed getSize to getMessageSize on MailImpl level, and corrected implementation
bugs accordingly. Also added check for MimeMessageWrapper so it just gets the size
without loading the object unnecessarily.
Revision Changes Path
1.9 +12 -6 jakarta-james/src/java/org/apache/james/core/MailImpl.java
Index: MailImpl.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/core/MailImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MailImpl.java 2001/10/27 18:09:20 1.8
+++ MailImpl.java 2001/12/05 22:11:48 1.9
@@ -131,11 +131,18 @@
*
* @author Stuart Roebuck <[EMAIL PROTECTED]>
*/
- public int getSize() throws MessagingException {
+ public long getMessageSize() throws MessagingException {
+ //If we have a MimeMessageWrapper, then we can ask it for just the
+ // message size and skip calculating it
+ if (message instanceof MimeMessageWrapper) {
+ MimeMessageWrapper wrapper = (MimeMessageWrapper)message;
+ return wrapper.getMessageSize();
+ }
+
//SK: Should probably eventually store this as a locally
// maintained value (so we don't have to load and reparse
// messages each time).
- int size = message.getSize();
+ long size = message.getSize();
Enumeration e = message.getAllHeaderLines();
while (e.hasMoreElements()) {
size += ((String)e.nextElement()).length();
@@ -201,12 +208,11 @@
if (message != null) {
message.writeTo(out);
} else {
- throw new MessagingException("No message set for this MailImpl.");
- }
+ throw new MessagingException("No message set for this MailImpl.");
+ }
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
- //System.err.println("saving object");
lastUpdated = new Date();
out.writeObject(sender);
out.writeObject(recipients);
@@ -247,7 +253,7 @@
out.write(line.getBytes());
}
} else {
- throw new MessagingException("No message set for this MailImpl.");
+ throw new MessagingException("No message set for this MailImpl.");
}
}
}
1.3 +9 -9
jakarta-james/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
Index: MimeMessageInputStreamSource.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/core/MimeMessageInputStreamSource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MimeMessageInputStreamSource.java 2001/10/09 03:59:16 1.2
+++ MimeMessageInputStreamSource.java 2001/12/05 22:11:48 1.3
@@ -32,32 +32,32 @@
public class MimeMessageInputStreamSource extends MimeMessageSource {
String key = null;
- InputStream in = null;
+ InputStream in = null;
File file = null;
//If you try to access this size first, it will load it into a temp file
// and work from there.
- public MimeMessageInputStreamSource(String key, InputStream in) {
+ public MimeMessageInputStreamSource(String key, InputStream in) {
this.key = key;
- this.in = in;
- }
+ this.in = in;
+ }
- /**
- * Return an input stream to the data
- */
+ /**
+ * Return an input stream to the data
+ */
public synchronized InputStream getInputStream() throws IOException {
if (file == null) {
return in;
} else {
return new BufferedInputStream(new FileInputStream(file));
}
- }
+ }
/**
* If not already, read the stream into a temp file
*/
- public synchronized long getSize() throws IOException {
+ public synchronized long getMessageSize() throws IOException {
if (file == null) {
//Create a temp file and channel the input stream into it
file = File.createTempFile(key, ".m64");
1.3 +13 -14
jakarta-james/src/java/org/apache/james/core/MimeMessageSource.java
Index: MimeMessageSource.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/core/MimeMessageSource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MimeMessageSource.java 2001/10/09 04:00:17 1.2
+++ MimeMessageSource.java 2001/12/05 22:11:48 1.3
@@ -14,24 +14,23 @@
* A source of a MimeMessage.
*/
public abstract class MimeMessageSource {
- /**
- * Return an input stream to the data
- */
+ /**
+ * Return an input stream to the data
+ */
public abstract InputStream getInputStream() throws IOException;
/**
* Return the size of all the data.
* Default implementation... others can override to do this much faster
*/
- public long getSize() throws IOException {
- int size = 0;
- InputStream in = getInputStream();
- int read = 0;
- byte[] data = new byte[1024];
- while ((read = in.read(data)) > 0) {
- size += read;
- }
- //System.err.println("size of " + this + " is " + size);
- return size;
- }
+ public long getMessageSize() throws IOException {
+ int size = 0;
+ InputStream in = getInputStream();
+ int read = 0;
+ byte[] data = new byte[1024];
+ while ((read = in.read(data)) > 0) {
+ size += read;
+ }
+ return size;
+ }
}
1.4 +23 -19
jakarta-james/src/java/org/apache/james/core/MimeMessageWrapper.java
Index: MimeMessageWrapper.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/core/MimeMessageWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MimeMessageWrapper.java 2001/10/09 04:00:17 1.3
+++ MimeMessageWrapper.java 2001/12/05 22:11:48 1.4
@@ -60,7 +60,6 @@
//Another thread has already loaded these headers
return;
}
- //System.err.println("parsing headers of " + this);
try {
InputStream in = source.getInputStream();
headers = new MailHeaders(in);
@@ -79,7 +78,6 @@
//Another thread has already loaded this message
return;
}
- //System.err.println("parsing headers and message of " + this);
try {
InputStream in = source.getInputStream();
headers = new MailHeaders(in);
@@ -354,27 +352,28 @@
}
}
+ /**
+ * We do not attempt to define the received date, although in theory this is
the last
+ * most date in the Received: headers. For now we return null, which means we
are
+ * not implementing it.
+ */
public Date getReceivedDate() throws MessagingException {
- //if (headers == null) {
- // loadHeaders();
- //}
+ if (headers == null) {
+ loadHeaders();
+ }
return null;
}
+ /**
+ * This is the MimeMessage implementation - this should return ONLY the
+ * body, not the entire message (should not count headers). Will have
+ * to parse the message.
+ */
public int getSize() throws MessagingException {
- try {
- if (message == null) {
- return (int)source.getSize();
- } else {
- //Would be better to use in memory mimemessage
- //Need to figure out size of message plus size of headers...
- return message.getSize();
- //return source.getSize();
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- throw new MessagingException("Trouble in getSize", ioe);
+ if (message == null) {
+ loadMessage();
}
+ return message.getSize();
}
/**
@@ -408,8 +407,13 @@
* actually returns number of characters in headers plus number of bytes
* in the internal content byte array.
*/
- public int getMessageSize() throws MessagingException {
- int contentSize = content.length;
+ public long getMessageSize() throws MessagingException {
+ try {
+ return source.getMessageSize();
+ } catch (IOException ioe) {
+ //Probably will fail anyway... fall back to just calculating manually
+ }
+ int contentSize = getSize();
int headerSize = 0;
Enumeration e = getAllHeaderLines();
while (e.hasMoreElements()) {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>