You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2006/04/01 00:20:24 UTC
svn commit: r390523 - in
/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store:
nntp/NNTPMessage.java pop3/message/POP3Message.java
Author: jlaskowski
Date: Fri Mar 31 14:20:22 2006
New Revision: 390523
URL: http://svn.apache.org/viewcvs?rev=390523&view=rev
Log:
GERONIMO-1765 - POP3 and NNTP messages should throw an exception if headers are modified
Submitted by: Rick McGuire
Modified:
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPMessage.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPMessage.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPMessage.java?rev=390523&r1=390522&r2=390523&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPMessage.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPMessage.java Fri Mar 31 14:20:22 2006
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2003-2005 The Apache Software Foundation
+ * Copyright 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,22 +17,15 @@
package org.apache.geronimo.javamail.store.nntp;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Enumeration;
import javax.mail.Flags;
-import javax.mail.Folder;
-import javax.mail.Header;
import javax.mail.IllegalWriteException;
import javax.mail.MessagingException;
import javax.mail.Session;
-import javax.mail.Store;
-import javax.mail.event.MessageChangedEvent;
import javax.mail.internet.InternetHeaders;
import javax.mail.internet.MimeMessage;
@@ -42,15 +35,16 @@
/**
* NNTP implementation of javax.mail.internet.MimeMessage
- *
- * Only the most basic information is given and
- * Message objects created here is a light-weight reference to the actual Message
- * As per the JavaMail spec items from the actual message will get filled up on demand
- *
- * If some other items are obtained from the server as a result of one call, then the other
- * details are also processed and filled in. For ex if RETR is called then header information
- * will also be processed in addition to the content
- *
+ *
+ * Only the most basic information is given and Message objects created here is
+ * a light-weight reference to the actual Message As per the JavaMail spec items
+ * from the actual message will get filled up on demand
+ *
+ * If some other items are obtained from the server as a result of one call,
+ * then the other details are also processed and filled in. For ex if RETR is
+ * called then header information will also be processed in addition to the
+ * content
+ *
* @version $Rev$ $Date$
*/
public class NNTPMessage extends MimeMessage {
@@ -59,73 +53,78 @@
// our attached session
protected Session session;
+
// the Store we're stored in (which manages the connection and other stuff).
protected NNTPStore store;
+
// our active connection.
protected NNTPConnection connection;
- // used to force loading of headers
- protected boolean headersLoaded = false;
+ // used to force loading of headers
+ protected boolean headersLoaded = false;
+
// use to force content loading
protected boolean contentLoaded = false;
-
-
/**
* Contruct an NNTPMessage instance.
- *
- * @param folder The hosting folder for the message.
- * @param store The Store owning the article (and folder).
- * @param msgnum The article message number.
- * @param messageID The article messageID (as assigned by the server).
- *
+ *
+ * @param folder
+ * The hosting folder for the message.
+ * @param store
+ * The Store owning the article (and folder).
+ * @param msgnum
+ * The article message number.
+ * @param messageID
+ * The article messageID (as assigned by the server).
+ *
* @exception MessagingException
*/
- NNTPMessage(NNTPFolder folder, NNTPStore store, int msgnum, String messageID) throws MessagingException {
- super(folder, msgnum);
+ NNTPMessage(NNTPFolder folder, NNTPStore store, int msgnum, String messageID) throws MessagingException {
+ super(folder, msgnum);
this.messageID = messageID;
- this.store = store;
- this.session = ((NNTPStore)store).getSession();
- // get the active connection from the store...all commands are sent there
- this.connection = ((NNTPStore)store).getConnection();
+ this.store = store;
+ this.session = ((NNTPStore) store).getSession();
+ // get the active connection from the store...all commands are sent
+ // there
+ this.connection = ((NNTPStore) store).getConnection();
// get our flag set from the folder.
flags = folder.getPermanentFlags();
// now check our initial SEEN state and set the flags appropriately
if (folder.isSeen(msgnum)) {
flags.add(Flags.Flag.SEEN);
- }
- else {
+ } else {
flags.remove(Flags.Flag.SEEN);
}
- }
-
+ }
/**
- * Retrieve the size of the message content. The content will
- * be retrieved from the server, if necessary.
- *
+ * Retrieve the size of the message content. The content will be retrieved
+ * from the server, if necessary.
+ *
* @return The size of the content.
* @exception MessagingException
*/
- public int getSize() throws MessagingException {
- // make sure we've retrieved the message content and continue with the superclass version.
+ public int getSize() throws MessagingException {
+ // make sure we've retrieved the message content and continue with the
+ // superclass version.
loadContent();
return super.getSize();
- }
+ }
/**
- * Get a line count for the NNTP message. This is potentially
- * stored in the Lines article header. If not there, we return
- * a default of -1.
- *
+ * Get a line count for the NNTP message. This is potentially stored in the
+ * Lines article header. If not there, we return a default of -1.
+ *
* @return The header line count estimate, or -1 if not retrieveable.
* @exception MessagingException
*/
public int getLineCount() throws MessagingException {
String[] headers = getHeader("Lines");
- // hopefully, there's only a single one of these. No sensible way of interpreting
+ // hopefully, there's only a single one of these. No sensible way of
+ // interpreting
// multiples.
if (headers.length == 1) {
try {
@@ -139,75 +138,90 @@
return -1;
}
-
-
- /**
- * @see javax.mail.internet.MimeMessage#getContentStream()
- */
- protected InputStream getContentStream() throws MessagingException {
+ /**
+ * @see javax.mail.internet.MimeMessage#getContentStream()
+ */
+ protected InputStream getContentStream() throws MessagingException {
// get the article information.
loadArticle();
- return super.getContentStream();
- }
-
+ return super.getContentStream();
+ }
- /******************************************************************
- * Following is a set of methods that deal with headers
- * These methods are just overrides on the superclass methods to
- * allow lazy loading of the header information.
- ********************************************************************/
+ /***************************************************************************
+ * Following is a set of methods that deal with headers These methods are
+ * just overrides on the superclass methods to allow lazy loading of the
+ * header information.
+ **************************************************************************/
- public String[] getHeader(String name) throws MessagingException {
+ public String[] getHeader(String name) throws MessagingException {
loadHeaders();
- return headers.getHeader(name);
- }
+ return headers.getHeader(name);
+ }
- public String getHeader(String name, String delimiter) throws MessagingException {
+ public String getHeader(String name, String delimiter) throws MessagingException {
loadHeaders();
- return headers.getHeader(name, delimiter);
- }
+ return headers.getHeader(name, delimiter);
+ }
- public Enumeration getAllHeaders() throws MessagingException {
+ public Enumeration getAllHeaders() throws MessagingException {
loadHeaders();
- return headers.getAllHeaders();
- }
+ return headers.getAllHeaders();
+ }
- public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
+ public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
loadHeaders();
- return headers.getMatchingHeaders(names);
- }
+ return headers.getMatchingHeaders(names);
+ }
- public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
+ public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
loadHeaders();
- return headers.getNonMatchingHeaders(names);
- }
+ return headers.getNonMatchingHeaders(names);
+ }
- public Enumeration getAllHeaderLines() throws MessagingException {
+ public Enumeration getAllHeaderLines() throws MessagingException {
loadHeaders();
- return headers.getAllHeaderLines();
- }
+ return headers.getAllHeaderLines();
+ }
- public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
+ public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
loadHeaders();
- return headers.getMatchingHeaderLines(names);
- }
+ return headers.getMatchingHeaderLines(names);
+ }
- public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
+ public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
loadHeaders();
- return headers.getNonMatchingHeaderLines(names);
- }
+ return headers.getNonMatchingHeaderLines(names);
+ }
+
+ // the following are overrides for header modification methods. These
+ // messages are read only,
+ // so the headers cannot be modified.
+ public void addHeader(String name, String value) throws MessagingException {
+ throw new IllegalWriteException("NNTP messages are read-only");
+ }
- /**
- * We cannot modify these messages
- */
- public void saveChanges() throws MessagingException {
- throw new IllegalWriteException("NNTP messages are read-only");
- }
+ public void setHeader(String name, String value) throws MessagingException {
+ throw new IllegalWriteException("NNTP messages are read-only");
+ }
+
+ public void removeHeader(String name) throws MessagingException {
+ throw new IllegalWriteException("NNTP messages are read-only");
+ }
+
+ public void addHeaderLine(String line) throws MessagingException {
+ throw new IllegalWriteException("IMAP messages are read-only");
+ }
+ /**
+ * We cannot modify these messages
+ */
+ public void saveChanges() throws MessagingException {
+ throw new IllegalWriteException("NNTP messages are read-only");
+ }
/**
* Retrieve the message headers from the NNTP server.
- *
+ *
* @exception MessagingException
*/
public void loadHeaders() throws MessagingException {
@@ -216,7 +230,6 @@
return;
}
-
NNTPReply reply = connection.sendCommand("HEAD " + messageID, NNTPReply.HEAD_FOLLOWS);
if (reply.getCode() == NNTPReply.HEAD_FOLLOWS) {
@@ -226,17 +239,17 @@
} catch (IOException e) {
throw new MessagingException("Error retrieving article headers from server", e);
}
- }
- else {
+ } else {
throw new MessagingException("Error retrieving article headers from server: " + reply);
}
}
/**
* Update the message headers from an input stream.
- *
- * @param in The InputStream source for the header information.
- *
+ *
+ * @param in
+ * The InputStream source for the header information.
+ *
* @exception MessagingException
*/
public void updateHeaders(InputStream in) throws MessagingException {
@@ -245,10 +258,9 @@
headersLoaded = true;
}
-
/**
* Load just the message content from the NNTP server.
- *
+ *
* @exception MessagingException
*/
public void loadContent() throws MessagingException {
@@ -265,17 +277,15 @@
} catch (IOException e) {
throw new MessagingException("Error retrieving article body from server", e);
}
- }
- else {
+ } else {
throw new MessagingException("Error retrieving article body from server: " + reply);
}
}
-
/**
- * Load the entire article from the NNTP server. This updates
- * both the headers and the content.
- *
+ * Load the entire article from the NNTP server. This updates both the
+ * headers and the content.
+ *
* @exception MessagingException
*/
public void loadArticle() throws MessagingException {
@@ -297,18 +307,17 @@
} catch (IOException e) {
throw new MessagingException("Error retrieving article from server", e);
}
- }
- else {
+ } else {
throw new MessagingException("Error retrieving article from server: " + reply);
}
}
-
/**
* Update the article content from an input stream.
- *
- * @param in The content data source.
- *
+ *
+ * @param in
+ * The content data source.
+ *
* @exception MessagingException
*/
public void updateContent(InputStream in) throws MessagingException {
@@ -317,7 +326,8 @@
byte[] buffer = new byte[4096];
- // copy the content data from the stream into a byte buffer for the content.
+ // copy the content data from the stream into a byte buffer for the
+ // content.
while (true) {
int read = in.read(buffer);
if (read == -1) {
@@ -335,26 +345,27 @@
/**
* Get the server assigned messageid for the article.
- *
+ *
* @return The server assigned message id.
*/
public String getMessageId() {
return messageID;
}
-
/**
- * Override of setFlags(). We need to ensure that if the SEEN
- * flag is set or cleared, that the newsrc file correctly
- * reflects the current state.
- *
- * @param flag The flag being set.
- * @param newvalue The new flag value.
- *
+ * Override of setFlags(). We need to ensure that if the SEEN flag is set or
+ * cleared, that the newsrc file correctly reflects the current state.
+ *
+ * @param flag
+ * The flag being set.
+ * @param newvalue
+ * The new flag value.
+ *
* @exception MessagingException
*/
public void setFlags(Flags flag, boolean newvalue) throws MessagingException {
- // if this is the SEEN flag, make sure we shadow this in the newsrc file.
+ // if this is the SEEN flag, make sure we shadow this in the newsrc
+ // file.
if (flag.contains(Flags.Flag.SEEN)) {
((NNTPFolder) folder).setSeen(msgnum, newvalue);
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java?rev=390523&r1=390522&r2=390523&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java Fri Mar 31 14:20:22 2006
@@ -17,17 +17,14 @@
package org.apache.geronimo.javamail.store.pop3.message;
-import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Enumeration;
import javax.mail.Flags;
import javax.mail.Folder;
-import javax.mail.Header;
import javax.mail.IllegalWriteException;
import javax.mail.MessagingException;
import javax.mail.Session;
@@ -41,7 +38,6 @@
import org.apache.geronimo.javamail.store.pop3.POP3Response;
import org.apache.geronimo.javamail.store.pop3.response.POP3ListResponse;
import org.apache.geronimo.javamail.store.pop3.response.POP3ResponseFactory;
-import org.apache.geronimo.javamail.store.pop3.response.POP3StatusResponse;
/**
@@ -245,6 +241,24 @@
loadHeaders();
return headers.getNonMatchingHeaderLines(names);
}
+
+ // the following are overrides for header modification methods. These messages are read only,
+ // so the headers cannot be modified.
+ public void addHeader(String name, String value) throws MessagingException {
+ throw new IllegalWriteException("POP3 messages are read-only");
+ }
+
+ public void setHeader(String name, String value) throws MessagingException {
+ throw new IllegalWriteException("POP3 messages are read-only");
+ }
+
+ public void removeHeader(String name) throws MessagingException {
+ throw new IllegalWriteException("POP3 messages are read-only");
+ }
+
+ public void addHeaderLine(String line) throws MessagingException {
+ throw new IllegalWriteException("POP3 messages are read-only");
+ }
/**
* We cannot modify these messages