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:24:56 UTC
svn commit: r390524 [2/7] - in
/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail:
authentication/ store/nntp/ store/nntp/newsrc/ store/pop3/
store/pop3/message/ store/pop3/response/ transport/nntp/ transport/smtp/
util/
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPRootFolder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPRootFolder.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPRootFolder.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPRootFolder.java Fri Mar 31 14:24:52 2006
@@ -18,32 +18,22 @@
package org.apache.geronimo.javamail.store.nntp;
import java.util.ArrayList;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
-import javax.mail.FetchProfile;
-import javax.mail.Flags;
import javax.mail.Folder;
-import javax.mail.Message;
import javax.mail.MessagingException;
-import javax.mail.MethodNotSupportedException;
-import javax.mail.Session;
-import javax.mail.Store;
-import javax.mail.URLName;
-import javax.mail.event.ConnectionEvent;
-
-import org.apache.geronimo.javamail.transport.nntp.NNTPConnection;
-import org.apache.geronimo.javamail.transport.nntp.NNTPReply;
import org.apache.geronimo.javamail.store.nntp.newsrc.NNTPNewsrcGroup;
-
+import org.apache.geronimo.javamail.transport.nntp.NNTPReply;
import org.apache.geronimo.mail.util.SessionUtil;
/**
- * The base NNTP implementation of the javax.mail.Folder
- * This is a base class for both the Root NNTP server and each NNTP group folder.
+ * The base NNTP implementation of the javax.mail.Folder This is a base class
+ * for both the Root NNTP server and each NNTP group folder.
+ *
* @see javax.mail.Folder
- *
+ *
* @version $Rev$
*/
public class NNTPRootFolder extends NNTPFolder {
@@ -51,58 +41,72 @@
/**
* Construct the NNTPRootFolder.
- *
- * @param store The owning Store.
- * @param name The folder name (by default, this is the server host name).
- * @param fullName The fullName to use for this server (derived from welcome string).
+ *
+ * @param store
+ * The owning Store.
+ * @param name
+ * The folder name (by default, this is the server host name).
+ * @param fullName
+ * The fullName to use for this server (derived from welcome
+ * string).
*/
- protected NNTPRootFolder(NNTPStore store, String name, String fullName) {
- super(store);
+ protected NNTPRootFolder(NNTPStore store, String name, String fullName) {
+ super(store);
this.name = name;
this.fullName = fullName;
- }
+ }
/**
- * List the subfolders. For group folders, this is a meaningless
- * so we throw a MethodNotSupportedException.
- *
- * @param pattern The folder pattern string.
- *
+ * List the subfolders. For group folders, this is a meaningless so we throw
+ * a MethodNotSupportedException.
+ *
+ * @param pattern
+ * The folder pattern string.
+ *
* @return Never returns.
* @exception MessagingException
*/
- public synchronized Folder[] list(String pattern) throws MessagingException {
- // the pattern specfied for javamail uses two wild card characters, "%" and "*". The "%" matches
- // and character except hierarchy separators. Since we have a flag hierarchy, "%" and "*" are
- // essentially the same. If we convert the "%" into "*", we can just treat this as a wildmat
- // formatted pattern and pass this on to the server rather than having to read everything and
+ public synchronized Folder[] list(String pattern) throws MessagingException {
+ // the pattern specfied for javamail uses two wild card characters, "%"
+ // and "*". The "%" matches
+ // and character except hierarchy separators. Since we have a flag
+ // hierarchy, "%" and "*" are
+ // essentially the same. If we convert the "%" into "*", we can just
+ // treat this as a wildmat
+ // formatted pattern and pass this on to the server rather than having
+ // to read everything and
// process the strings on the client side.
pattern = pattern.replace('%', '*');
- // if we're not supposed to list everything, then just filter the list of subscribed groups.
+ // if we're not supposed to list everything, then just filter the list
+ // of subscribed groups.
if (SessionUtil.getBooleanProperty(NNTP_LISTALL, false)) {
return filterActiveGroups(pattern);
- }
- else {
+ } else {
return filterSubscribedGroups(pattern);
}
- }
+ }
/**
- * Retrieve the list of subscribed folders that match the given
- * pattern string.
- *
- * @param pattern The pattern string used for the matching
- *
+ * Retrieve the list of subscribed folders that match the given pattern
+ * string.
+ *
+ * @param pattern
+ * The pattern string used for the matching
+ *
* @return An array of matching folders from the subscribed list.
*/
public Folder[] listSubscribed(String pattern) throws MessagingException {
- // the pattern specfied for javamail uses two wild card characters, "%" and "*". The "%" matches
- // and character except hierarchy separators. Since we have a flag hierarchy, "%" and "*" are
- // essentially the same. If we convert the "%" into "*", we can just treat this as a wildmat
- // formatted pattern and pass this on to the server rather than having to read everything and
+ // the pattern specfied for javamail uses two wild card characters, "%"
+ // and "*". The "%" matches
+ // and character except hierarchy separators. Since we have a flag
+ // hierarchy, "%" and "*" are
+ // essentially the same. If we convert the "%" into "*", we can just
+ // treat this as a wildmat
+ // formatted pattern and pass this on to the server rather than having
+ // to read everything and
// process the strings on the client side.
pattern = pattern.replace('%', '*');
@@ -110,14 +114,13 @@
return filterSubscribedGroups(pattern);
}
-
/**
- * Retrieve the list of matching groups from the NNTP server using
- * the LIST ACTIVE command. The server does the wildcard
- * matching for us.
- *
- * @param pattern The pattern string (in wildmat format) used to match.
- *
+ * Retrieve the list of matching groups from the NNTP server using the LIST
+ * ACTIVE command. The server does the wildcard matching for us.
+ *
+ * @param pattern
+ * The pattern string (in wildmat format) used to match.
+ *
* @return An array of folders for the matching groups.
*/
protected Folder[] filterActiveGroups(String pattern) throws MessagingException {
@@ -127,29 +130,29 @@
if (reply.getCode() == NNTPReply.COMMAND_NOT_RECOGNIZED) {
// only way to list all is to retrieve all and filter.
return filterAllGroups(pattern);
- }
- else if (reply.getCode() != NNTPReply.LIST_FOLLOWS) {
+ } else if (reply.getCode() != NNTPReply.LIST_FOLLOWS) {
throw new MessagingException("Error retrieving group list from NNTP server: " + reply);
}
- // get the response back from the server and process each returned group name.
+ // get the response back from the server and process each returned group
+ // name.
List groups = reply.getData();
Folder[] folders = new Folder[groups.size()];
for (int i = 0; i < groups.size(); i++) {
- folders[i] = getFolder(getGroupName((String)groups.get(i)));
+ folders[i] = getFolder(getGroupName((String) groups.get(i)));
}
return folders;
}
-
/**
- * Retrieve a list of all groups from the server and filter
- * on the names. Not recommended for the usenet servers, as
- * there are over 30000 groups to process.
- *
- * @param pattern The pattern string used for the selection.
- *
+ * Retrieve a list of all groups from the server and filter on the names.
+ * Not recommended for the usenet servers, as there are over 30000 groups to
+ * process.
+ *
+ * @param pattern
+ * The pattern string used for the selection.
+ *
* @return The Folders for the matching groups.
*/
protected Folder[] filterAllGroups(String pattern) throws MessagingException {
@@ -159,56 +162,56 @@
throw new MessagingException("Error retrieving group list from NNTP server: " + reply);
}
- // get the response back from the server and process each returned group name.
+ // get the response back from the server and process each returned group
+ // name.
List groups = reply.getData();
WildmatMatcher matcher = new WildmatMatcher(pattern);
List folders = new ArrayList();
for (int i = 0; i < groups.size(); i++) {
- String name = getGroupName((String)groups.get(i));
- // does this match our pattern? Add to the list
+ String name = getGroupName((String) groups.get(i));
+ // does this match our pattern? Add to the list
if (matcher.matches(name)) {
folders.add(getFolder(name));
}
}
- return (Folder [])folders.toArray(new Folder[0]);
+ return (Folder[]) folders.toArray(new Folder[0]);
}
-
/**
- * Return the set of groups from the newsrc subscribed groups
- * list that match a given filter.
- *
- * @param pattern The selection pattern.
- *
+ * Return the set of groups from the newsrc subscribed groups list that
+ * match a given filter.
+ *
+ * @param pattern
+ * The selection pattern.
+ *
* @return The Folders for the matching groups.
*/
protected Folder[] filterSubscribedGroups(String pattern) throws MessagingException {
- Iterator groups = ((NNTPStore)store).getNewsrcGroups();
+ Iterator groups = ((NNTPStore) store).getNewsrcGroups();
WildmatMatcher matcher = new WildmatMatcher(pattern);
List folders = new ArrayList();
while (groups.hasNext()) {
- NNTPNewsrcGroup group = (NNTPNewsrcGroup)groups.next();
+ NNTPNewsrcGroup group = (NNTPNewsrcGroup) groups.next();
if (group.isSubscribed()) {
- // does this match our pattern? Add to the list
+ // does this match our pattern? Add to the list
if (matcher.matches(group.getName())) {
folders.add(getFolder(group.getName()));
}
}
}
- return (Folder [])folders.toArray(new Folder[0]);
+ return (Folder[]) folders.toArray(new Folder[0]);
}
-
/**
- * Utility method for extracting a name from a group list
- * response.
- *
- * @param response The response string.
- *
+ * Utility method for extracting a name from a group list response.
+ *
+ * @param response
+ * The response string.
+ *
* @return The group name.
*/
protected String getGroupName(String response) {
@@ -216,56 +219,59 @@
return response.substring(0, blank).trim();
}
-
/**
- * Return whether this folder can hold just messages or also
- * subfolders. Only the root folder can hold other folders,
- * so it will need to override.
- *
+ * Return whether this folder can hold just messages or also subfolders.
+ * Only the root folder can hold other folders, so it will need to override.
+ *
* @return Always returns Folder.HOLDS_FOLDERS.
* @exception MessagingException
*/
- public int getType() throws MessagingException {
- return HOLDS_FOLDERS;
- }
-
+ public int getType() throws MessagingException {
+ return HOLDS_FOLDERS;
+ }
/**
- * Get a new folder from the root folder. This creates a new
- * folder, which might not actually exist on the server. If the
- * folder doesn't exist, an error will occur on folder open.
- *
- * @param name The name of the requested folder.
- *
+ * Get a new folder from the root folder. This creates a new folder, which
+ * might not actually exist on the server. If the folder doesn't exist, an
+ * error will occur on folder open.
+ *
+ * @param name
+ * The name of the requested folder.
+ *
* @return A new folder object for this folder.
* @exception MessagingException
*/
- public Folder getFolder(String name) throws MessagingException {
+ public Folder getFolder(String name) throws MessagingException {
// create a new group folder and return
- return new NNTPGroupFolder(this, (NNTPStore)store, name, ((NNTPStore)store).getNewsrcGroup(name));
- }
+ return new NNTPGroupFolder(this, (NNTPStore) store, name, ((NNTPStore) store).getNewsrcGroup(name));
+ }
/**
* Utility class to do Wildmat pattern matching on folder names.
*/
class WildmatMatcher {
- // middle match sections...because these are separated by wildcards, if they appear in
+ // middle match sections...because these are separated by wildcards, if
+ // they appear in
// sequence in the string, it is a match.
List matchSections = new ArrayList();
+
// just a "*" match, so everything is true
boolean matchAny = false;
+
// no wildcards, so this must be an exact match.
String exactMatch = null;
// a leading section which must be at the beginning
String firstSection = null;
+
// a trailing section which must be at the end of the string.
String lastSection = null;
/**
* Create a wildmat pattern matcher.
- *
- * @param pattern The wildmat pattern to apply to string matches.
+ *
+ * @param pattern
+ * The wildmat pattern to apply to string matches.
*/
public WildmatMatcher(String pattern) {
int section = 0;
@@ -287,7 +293,8 @@
return;
}
- // pattern not begin with a wildcard? We need to pull off the leading section
+ // pattern not begin with a wildcard? We need to pull off the
+ // leading section
if (!pattern.startsWith("*")) {
firstSection = pattern.substring(0, wildcard);
section = wildcard + 1;
@@ -297,12 +304,14 @@
}
}
- // now parse off the middle sections, making sure to handle the end condition correctly.
+ // now parse off the middle sections, making sure to handle the end
+ // condition correctly.
while (section < pattern.length()) {
// find the next wildcard position
wildcard = pattern.indexOf('*', section);
if (wildcard == -1) {
- // not found, we're at the end of the pattern. We need to match on the end.
+ // not found, we're at the end of the pattern. We need to
+ // match on the end.
lastSection = pattern.substring(section);
return;
}
@@ -310,11 +319,11 @@
else if (wildcard == section) {
// step over the wild card
section++;
- }
- else {
+ } else {
// pluck off the next section
matchSections.add(pattern.substring(section, wildcard));
- // step over the wild card character and check if we've reached the end.
+ // step over the wild card character and check if we've
+ // reached the end.
section = wildcard + 1;
}
}
@@ -322,16 +331,17 @@
/**
* Test if a name string matches to parsed wildmat pattern.
- *
- * @param name The name to test.
- *
+ *
+ * @param name
+ * The name to test.
+ *
* @return true if the string matches the pattern, false otherwise.
*/
public boolean matches(String name) {
// handle the easy cases first
- // full wildcard? Always matches
+ // full wildcard? Always matches
if (matchAny) {
return true;
}
@@ -358,7 +368,7 @@
for (int i = 1; i < matchSections.size(); i++) {
// if a section is not found, this is false
- String nextMatch = (String)matchSections.get(i);
+ String nextMatch = (String) matchSections.get(i);
int nextLocation = name.indexOf(nextMatch, span);
if (nextLocation == -1) {
return false;
@@ -367,9 +377,11 @@
span = nextMatch.length() + nextLocation;
}
- // we've matched everything up to this point, now check to see if need an end match
+ // we've matched everything up to this point, now check to see if
+ // need an end match
if (lastSection != null) {
- // we need to have at least the number of characters of the end string left, else this fails.
+ // we need to have at least the number of characters of the end
+ // string left, else this fails.
if (name.length() - span < lastSection.length()) {
return false;
}
@@ -383,4 +395,3 @@
}
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPStore.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPStore.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPStore.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPStore.java Fri Mar 31 14:24:52 2006
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package org.apache.geronimo.javamail.store.nntp;
import java.io.File;
@@ -35,16 +34,17 @@
import org.apache.geronimo.mail.util.SessionUtil;
/**
- * NNTP implementation of javax.mail.Store
- * POP protocol spec is implemented in
+ * NNTP implementation of javax.mail.Store POP protocol spec is implemented in
* org.apache.geronimo.javamail.store.pop3.NNTPConnection
- *
+ *
* @version $Rev$ $Date$
*/
-public class NNTPStore extends Store{
+public class NNTPStore extends Store {
protected static final String NNTP_AUTH = "auth";
+
protected static final String NNTP_PORT = "port";
+
protected static final String NNTP_NEWSRC = "newsrc";
protected static final String protocol = "nntp";
@@ -52,88 +52,97 @@
protected static final int DEFAULT_NNTP_PORT = 119;
// the active connection object.
- protected NNTPConnection connection;
+ protected NNTPConnection connection;
+
// the newsrc file where we store subscriptions and seen message markers.
protected NNTPNewsrc newsrc;
+
// the root folder
protected NNTPRootFolder root;
+
// our session provided debug output stream.
protected PrintStream debugStream;
-
/**
- * Construct an NNTPStore item. This will load the .newsrc file
- * associated with the server.
- *
- * @param session The owning javamail Session.
- * @param urlName The Store urlName, which can contain server target information.
+ * Construct an NNTPStore item. This will load the .newsrc file associated
+ * with the server.
+ *
+ * @param session
+ * The owning javamail Session.
+ * @param urlName
+ * The Store urlName, which can contain server target
+ * information.
*/
- public NNTPStore(Session session, URLName urlName) {
- super(session,urlName);
+ public NNTPStore(Session session, URLName urlName) {
+ super(session, urlName);
// get our debug output.
debugStream = session.getDebugOut();
- }
-
+ }
- /**
- * @see javax.mail.Store#getDefaultFolder()
- *
- * This returns a root folder object for all of the news groups.
- */
- public Folder getDefaultFolder() throws MessagingException {
- checkConnectionStatus();
+ /**
+ * @see javax.mail.Store#getDefaultFolder()
+ *
+ * This returns a root folder object for all of the news groups.
+ */
+ public Folder getDefaultFolder() throws MessagingException {
+ checkConnectionStatus();
if (root == null) {
return new NNTPRootFolder(this, connection.getHost(), connection.getWelcomeString());
}
return root;
- }
+ }
- /**
- * @see javax.mail.Store#getFolder(java.lang.String)
- */
- public Folder getFolder(String name) throws MessagingException {
+ /**
+ * @see javax.mail.Store#getFolder(java.lang.String)
+ */
+ public Folder getFolder(String name) throws MessagingException {
return getDefaultFolder().getFolder(name);
- }
+ }
/**
-
- * @see javax.mail.Store#getFolder(javax.mail.URLName)
- */
- public Folder getFolder(URLName url) throws MessagingException {
+ *
+ * @see javax.mail.Store#getFolder(javax.mail.URLName)
+ */
+ public Folder getFolder(URLName url) throws MessagingException {
return getDefaultFolder().getFolder(url.getFile());
- }
-
+ }
- /**
- * @see javax.mail.Service#protocolConnect(java.lang.String, int, java.lang.String, java.lang.String)
- */
- protected synchronized boolean protocolConnect(String host, int port, String username, String password) throws MessagingException {
+ /**
+ * @see javax.mail.Service#protocolConnect(java.lang.String, int,
+ * java.lang.String, java.lang.String)
+ */
+ protected synchronized boolean protocolConnect(String host, int port, String username, String password)
+ throws MessagingException {
if (debug) {
debugOut("Connecting to server " + host + ":" + port + " for user " + username);
}
- // first check to see if we need to authenticate. If we need this, then we must have a username and
- // password specified. Failing this may result in a user prompt to collect the information.
+ // first check to see if we need to authenticate. If we need this, then
+ // we must have a username and
+ // password specified. Failing this may result in a user prompt to
+ // collect the information.
boolean mustAuthenticate = getBooleanProperty(NNTP_AUTH, false);
- // if we need to authenticate, and we don't have both a userid and password, then we fail this
- // immediately. The Service.connect() method will try to obtain the user information and retry the
+ // if we need to authenticate, and we don't have both a userid and
+ // password, then we fail this
+ // immediately. The Service.connect() method will try to obtain the user
+ // information and retry the
// connection one time.
if (mustAuthenticate && (username == null || password == null)) {
return false;
}
-
- // if the port is defaulted, then see if we have something configured in the session.
+ // if the port is defaulted, then see if we have something configured in
+ // the session.
// if not configured, we just use the default default.
if (port == -1) {
- // check for a property and fall back on the default if it's not set.
+ // check for a property and fall back on the default if it's not
+ // set.
port = getIntProperty(NNTP_PORT, DEFAULT_NNTP_PORT);
}
-
// create socket and connect to server.
connection = new NNTPConnection(protocol, session, host, port, username, password, debug);
connection.connect();
@@ -143,16 +152,17 @@
File source = null;
- // not given as a property? Then look for a file in user.home
+ // not given as a property? Then look for a file in user.home
if (newsrcFile != null) {
source = new File(newsrcFile);
- }
- else {
- // ok, look for a file in the user.home directory. If possible, we'll try for a file
+ } else {
+ // ok, look for a file in the user.home directory. If possible,
+ // we'll try for a file
// with the hostname appended.
String home = SessionUtil.getProperty("user.home");
- // try for a host-specific file first. If not found, use (and potentially create) a generic
+ // try for a host-specific file first. If not found, use (and
+ // potentially create) a generic
// .newsrc file.
newsrcFile = ".newsrc-" + host;
source = new File(home, newsrcFile);
@@ -165,34 +175,35 @@
newsrc = new NNTPNewsrcFile(source);
newsrc.load();
- // we're going to return success here, but in truth, the server may end up asking for our
+ // we're going to return success here, but in truth, the server may end
+ // up asking for our
// bonafides at any time, and we'll be expected to authenticate then.
return true;
- }
-
+ }
- /**
- * @see javax.mail.Service#close()
- */
- public void close() throws MessagingException{
- // This is done to ensure proper event notification.
- super.close();
+ /**
+ * @see javax.mail.Service#close()
+ */
+ public void close() throws MessagingException {
+ // This is done to ensure proper event notification.
+ super.close();
// persist the newsrc file, if possible
newsrc.close();
connection.close();
connection = null;
- }
+ }
- private void checkConnectionStatus() throws MessagingException {
- if (!this.isConnected()){
- throw new MessagingException("Not connected ");
- }
- }
+ private void checkConnectionStatus() throws MessagingException {
+ if (!this.isConnected()) {
+ throw new MessagingException("Not connected ");
+ }
+ }
/**
* Internal debug output routine.
- *
- * @param value The string value to output.
+ *
+ * @param value
+ * The string value to output.
*/
void debugOut(String message) {
debugStream.println("NNTPTransport DEBUG: " + message);
@@ -200,9 +211,11 @@
/**
* Internal debugging routine for reporting exceptions.
- *
- * @param message A message associated with the exception context.
- * @param e The received exception.
+ *
+ * @param message
+ * A message associated with the exception context.
+ * @param e
+ * The received exception.
*/
void debugOut(String message, Throwable e) {
debugOut("Received exception -> " + message);
@@ -210,20 +223,18 @@
e.printStackTrace(debugStream);
}
-
/**
* Retrieve the server connection created by this store.
- *
+ *
* @return The active connection object.
*/
NNTPConnection getConnection() {
return connection;
}
-
/**
* Retrieve the Session object this Store is operating under.
- *
+ *
* @return The attached Session instance.
*/
Session getSession() {
@@ -231,9 +242,8 @@
}
/**
- * Retrieve all of the groups we nave persistent store information
- * about.
- *
+ * Retrieve all of the groups we nave persistent store information about.
+ *
* @return The set of groups contained in the newsrc file.
*/
Iterator getNewsrcGroups() {
@@ -241,81 +251,91 @@
}
/**
- * Retrieve the newsrc group information for a named group. If
- * the file does not currently include this group, an unsubscribed
- * group will be added to the file.
- *
- * @param name The name of the target group.
- *
+ * Retrieve the newsrc group information for a named group. If the file does
+ * not currently include this group, an unsubscribed group will be added to
+ * the file.
+ *
+ * @param name
+ * The name of the target group.
+ *
* @return The NNTPNewsrcGroup item corresponding to this name.
*/
NNTPNewsrcGroup getNewsrcGroup(String name) {
return newsrc.getGroup(name);
}
-
/**
* Get a property associated with this mail protocol.
- *
- * @param name The name of the property.
- *
- * @return The property value (returns null if the property has not been set).
+ *
+ * @param name
+ * The name of the property.
+ *
+ * @return The property value (returns null if the property has not been
+ * set).
*/
String getProperty(String name) {
- // the name we're given is the least qualified part of the name. We construct the full property name
+ // the name we're given is the least qualified part of the name. We
+ // construct the full property name
// using the protocol (either "nntp" or "nntp-post").
String fullName = "mail." + protocol + "." + name;
return session.getProperty(fullName);
}
/**
- * Get a property associated with this mail session. Returns
- * the provided default if it doesn't exist.
- *
- * @param name The name of the property.
+ * Get a property associated with this mail session. Returns the provided
+ * default if it doesn't exist.
+ *
+ * @param name
+ * The name of the property.
* @param defaultValue
- * The default value to return if the property doesn't exist.
- *
- * @return The property value (returns defaultValue if the property has not been set).
+ * The default value to return if the property doesn't exist.
+ *
+ * @return The property value (returns defaultValue if the property has not
+ * been set).
*/
String getProperty(String name, String defaultValue) {
- // the name we're given is the least qualified part of the name. We construct the full property name
+ // the name we're given is the least qualified part of the name. We
+ // construct the full property name
// using the protocol (either "nntp" or "nntp-post").
String fullName = "mail." + protocol + "." + name;
return SessionUtil.getProperty(session, fullName, defaultValue);
}
-
/**
- * Get a property associated with this mail session as an integer value. Returns
- * the default value if the property doesn't exist or it doesn't have a valid int value.
- *
- * @param name The name of the property.
+ * Get a property associated with this mail session as an integer value.
+ * Returns the default value if the property doesn't exist or it doesn't
+ * have a valid int value.
+ *
+ * @param name
+ * The name of the property.
* @param defaultValue
- * The default value to return if the property doesn't exist.
- *
+ * The default value to return if the property doesn't exist.
+ *
* @return The property value converted to an int.
*/
int getIntProperty(String name, int defaultValue) {
- // the name we're given is the least qualified part of the name. We construct the full property name
+ // the name we're given is the least qualified part of the name. We
+ // construct the full property name
// using the protocol (either "nntp" or "nntp-post").
String fullName = "mail." + protocol + "." + name;
return SessionUtil.getIntProperty(session, fullName, defaultValue);
}
-
/**
- * Get a property associated with this mail session as an boolean value. Returns
- * the default value if the property doesn't exist or it doesn't have a valid int value.
- *
- * @param name The name of the property.
+ * Get a property associated with this mail session as an boolean value.
+ * Returns the default value if the property doesn't exist or it doesn't
+ * have a valid int value.
+ *
+ * @param name
+ * The name of the property.
* @param defaultValue
- * The default value to return if the property doesn't exist.
- *
+ * The default value to return if the property doesn't exist.
+ *
* @return The property value converted to a boolean
*/
boolean getBooleanProperty(String name, boolean defaultValue) {
- // the name we're given is the least qualified part of the name. We construct the full property name
+ // the name we're given is the least qualified part of the name. We
+ // construct the full property name
// using the protocol (either "nntp" or "nntp-post").
String fullName = "mail." + protocol + "." + name;
return SessionUtil.getBooleanProperty(session, fullName, defaultValue);
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrc.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrc.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrc.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrc.java Fri Mar 31 14:24:52 2006
@@ -19,38 +19,35 @@
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.Reader;
import java.io.Writer;
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-
/**
- * Base class implementation of a standard news reader news rc
- * file. This is used to track newsgroup subscriptions and
- * SEEN flags for articles. This is an abstract class designed
- * for subclasses to bridge to the physical store type used for
- * the newsgroup information.
+ * Base class implementation of a standard news reader news rc file. This is
+ * used to track newsgroup subscriptions and SEEN flags for articles. This is an
+ * abstract class designed for subclasses to bridge to the physical store type
+ * used for the newsgroup information.
*/
public abstract class NNTPNewsrc {
// the group information we've read from the news rc file.
Map groups = new HashMap();
+
// flag to let us know of we need to persist the newsrc file on close.
boolean dirty = false;
/**
- * Base class constructor for NNTPNewsrc items. Subclasses
- * provide their own domain-specific intialization.
+ * Base class constructor for NNTPNewsrc items. Subclasses provide their own
+ * domain-specific intialization.
*/
protected NNTPNewsrc() {
}
/**
- * Load the data from the newsrc file and parse into an instore
- * group database.
+ * Load the data from the newsrc file and parse into an instore group
+ * database.
*/
public void load() {
BufferedReader in = null;
@@ -61,9 +58,11 @@
String line = in.readLine();
while (line != null) {
- // parse the line...this returns null if it's something unrecognized.
+ // parse the line...this returns null if it's something
+ // unrecognized.
NNTPNewsrcGroup group = NNTPNewsrcGroup.parse(this, line);
- // if it parsed ok, add it to the group list, and potentially to the subscribed list.
+ // if it parsed ok, add it to the group list, and potentially to
+ // the subscribed list.
if (group != null) {
groups.put(group.getName(), group);
}
@@ -73,10 +72,10 @@
in.close();
} catch (IOException e) {
- // an IOException may mean that the file just doesn't exist, which is fine. We'll ignore and
+ // an IOException may mean that the file just doesn't exist, which
+ // is fine. We'll ignore and
// proceed with the information we have.
- }
- finally {
+ } finally {
if (in != null) {
try {
in.close();
@@ -89,7 +88,7 @@
/**
* Save the newsrc file data back to the original source file.
- *
+ *
* @exception IOException
*/
public void save() throws IOException {
@@ -98,46 +97,47 @@
Iterator i = groups.values().iterator();
while (i.hasNext()) {
- NNTPNewsrcGroup group = (NNTPNewsrcGroup)i.next();
+ NNTPNewsrcGroup group = (NNTPNewsrcGroup) i.next();
group.save(out);
}
out.close();
}
-
/**
- * Abstract open method intended for sub class initialization. The
- * subclass is responsible for creating the BufferedReaded used
- * to read the .newsrc file.
- *
+ * Abstract open method intended for sub class initialization. The subclass
+ * is responsible for creating the BufferedReaded used to read the .newsrc
+ * file.
+ *
* @return A BufferedReader for reading the .newsrc file.
* @exception IOException
*/
abstract public BufferedReader getInputReader() throws IOException;
+
/**
- * Abstract open for output method intended for subclass implementation.
- * The subclasses are reponsible for opening the output stream
- * and creating an appropriate Writer for saving the .newsrc file.
- *
+ * Abstract open for output method intended for subclass implementation. The
+ * subclasses are reponsible for opening the output stream and creating an
+ * appropriate Writer for saving the .newsrc file.
+ *
* @return A Writer target at the .newsrc file save location.
* @exception IOException
*/
abstract public Writer getOutputWriter() throws IOException;
-
/**
- * Retrieve the newsrc group information for a named group. If
- * the file does not currently include this group, an unsubscribed
- * group will be added to the file.
- *
- * @param name The name of the target group.
- *
+ * Retrieve the newsrc group information for a named group. If the file does
+ * not currently include this group, an unsubscribed group will be added to
+ * the file.
+ *
+ * @param name
+ * The name of the target group.
+ *
* @return The NNTPNewsrcGroup item corresponding to this name.
*/
public NNTPNewsrcGroup getGroup(String name) {
- NNTPNewsrcGroup group = (NNTPNewsrcGroup)groups.get(name);
- // if we don't know about this, create a new one and add to the list. This
+ NNTPNewsrcGroup group = (NNTPNewsrcGroup) groups.get(name);
+ // if we don't know about this, create a new one and add to the list.
+ // This
// will be an unsubscribed one.
if (group == null) {
group = new NNTPNewsrcGroup(this, name, null, false);
@@ -155,10 +155,9 @@
dirty = true;
}
-
/**
- * Close the newsrc file, persisting it back to disk if the
- * file has changed.
+ * Close the newsrc file, persisting it back to disk if the file has
+ * changed.
*/
public void close() {
if (dirty) {
@@ -170,10 +169,9 @@
}
}
-
/**
* Retrieve the current set of loaded groups.
- *
+ *
* @return An iterator for traversing the group set.
*/
public Iterator getGroups() {
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcFile.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcFile.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcFile.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcFile.java Fri Mar 31 14:24:52 2006
@@ -22,10 +22,8 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.Reader;
import java.io.Writer;
public class NNTPNewsrcFile extends NNTPNewsrc {
@@ -33,10 +31,11 @@
File source;
/**
- * Construct a NNTPNewsrc object that is targetted at a
- * file-based backing store.
- *
- * @param source The source File for the .newsrc data.
+ * Construct a NNTPNewsrc object that is targetted at a file-based backing
+ * store.
+ *
+ * @param source
+ * The source File for the .newsrc data.
*/
public NNTPNewsrcFile(File source) {
this.source = source;
@@ -44,7 +43,7 @@
/**
* Retrieve an input reader for loading the newsrc file.
- *
+ *
* @return A BufferedReader object for reading from the newsrc file.
* @exception IOException
*/
@@ -54,7 +53,7 @@
/**
* Obtain a writer for saving a newsrc file.
- *
+ *
* @return The output writer targetted to the newsrc file.
* @exception IOException
*/
@@ -63,4 +62,3 @@
return new OutputStreamWriter(new FileOutputStream(source, false));
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcGroup.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcGroup.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcGroup.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcGroup.java Fri Mar 31 14:24:52 2006
@@ -19,29 +19,30 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
public class NNTPNewsrcGroup {
// the newsrc database we're part of
NNTPNewsrc newsrc;
+
// the name of the group
protected String name;
+
// the subscription flage
protected boolean subscribed;
+
// the range of already seen articles.
protected RangeList ranges;
/**
- * Construct a NNTPNewsrcGroup item associated with a given
- * .newsrc database.
- *
- * @param newsrc The owning .newsrc database.
- * @param line The .newsrc range entries in .newsrc format. These ranges are
- * parsed to create a set of seen flags.
- *
+ * Construct a NNTPNewsrcGroup item associated with a given .newsrc
+ * database.
+ *
+ * @param newsrc
+ * The owning .newsrc database.
+ * @param line
+ * The .newsrc range entries in .newsrc format. These ranges are
+ * parsed to create a set of seen flags.
+ *
* @return A created NNTPNewsrcGroup item.
*/
public static NNTPNewsrcGroup parse(NNTPNewsrc newsrc, String line) {
@@ -70,15 +71,17 @@
return null;
}
-
/**
* Construct a .newsrc group item.
- *
- * @param newsrc The owning newsrc database.
- * @param name The group name.
+ *
+ * @param newsrc
+ * The owning newsrc database.
+ * @param name
+ * The group name.
* @param newsrcRanges
- * The initial set of seen ranges for the group (may be null).
- * @param subscribed The initial group subscription state.
+ * The initial set of seen ranges for the group (may be null).
+ * @param subscribed
+ * The initial group subscription state.
*/
public NNTPNewsrcGroup(NNTPNewsrc newsrc, String name, String newsrcRanges, boolean subscribed) {
this.newsrc = newsrc;
@@ -87,10 +90,9 @@
this.ranges = new RangeList(newsrcRanges);
}
-
/**
* Get the group name.
- *
+ *
* @return The String name of the group.
*/
public String getName() {
@@ -99,7 +101,7 @@
/**
* Get the newsrc subscribed status for an article.
- *
+ *
* @return The current subscription flag.
*/
public boolean isSubscribed() {
@@ -108,17 +110,18 @@
/**
* Set the subscription status for an article.
- *
- * @param flag The new subscription value.
+ *
+ * @param flag
+ * The new subscription value.
*/
public void setSubscribed(boolean flag) {
- // we don't blindly set this to the new value since we only want to resave the newsrc file if
+ // we don't blindly set this to the new value since we only want to
+ // resave the newsrc file if
// something changes.
if (flag && !subscribed) {
subscribed = true;
newsrc.setDirty();
- }
- else if (!flag && subscribed) {
+ } else if (!flag && subscribed) {
subscribed = false;
newsrc.setDirty();
}
@@ -126,9 +129,10 @@
/**
* Test if an article has been seen yet.
- *
- * @param article The target article.
- *
+ *
+ * @param article
+ * The target article.
+ *
* @return The seen mark for the article.
*/
public boolean isArticleSeen(int article) {
@@ -137,8 +141,9 @@
/**
* Mark an article as seen.
- *
- * @param article The target article number.
+ *
+ * @param article
+ * The target article number.
*/
public void markArticleSeen(int article) {
ranges.setMarked(article);
@@ -149,8 +154,9 @@
/**
* Mark an article as unseen.
- *
- * @param article The target article number.
+ *
+ * @param article
+ * The target article number.
*/
public void markArticleUnseen(int article) {
ranges.setUnmarked(article);
@@ -159,12 +165,12 @@
}
}
-
/**
* Save this group definition to a .newsrc file.
- *
- * @param out The output writer to send the information to.
- *
+ *
+ * @param out
+ * The output writer to send the information to.
+ *
* @exception IOException
*/
public void save(Writer out) throws IOException {
@@ -175,4 +181,3 @@
out.write("\r\n");
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/Range.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/Range.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/Range.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/Range.java Fri Mar 31 14:24:52 2006
@@ -19,28 +19,23 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-
-
/**
- * Represent a single Range in a newsrc file. A Range can be
- * either a single number (start == end) or a span of article
- * numbers.
+ * Represent a single Range in a newsrc file. A Range can be either a single
+ * number (start == end) or a span of article numbers.
*/
public class Range {
// the low end of the range
int start;
+
// the high end of the range (start and end are inclusive);
int end;
/**
* Construct a Range item for a single digit range.
- *
- * @param spot The location of the singleton.
+ *
+ * @param spot
+ * The location of the singleton.
*/
public Range(int spot) {
this(spot, spot);
@@ -48,9 +43,12 @@
/**
* Construct a Range item.
- *
- * @param start The starting point of the Range.
- * @param end The Range end point (which may be equal to the starting point).
+ *
+ * @param start
+ * The starting point of the Range.
+ * @param end
+ * The Range end point (which may be equal to the starting
+ * point).
*/
public Range(int start, int end) {
this.start = start;
@@ -58,16 +56,18 @@
}
/**
- * Parse a section of a .newsrc range string into a single
- * Range item. The range is either a single number, or a pair of
- * numbers separated by a hyphen.
- *
- * @param range The range string.
- *
+ * Parse a section of a .newsrc range string into a single Range item. The
+ * range is either a single number, or a pair of numbers separated by a
+ * hyphen.
+ *
+ * @param range
+ * The range string.
+ *
* @return A constructed Range item, or null if there is a parsing error.
*/
static public Range parse(String range) {
- // a range from a newsrc file is either a single number or in the format 'nnnn-mmmm'. We need
+ // a range from a newsrc file is either a single number or in the format
+ // 'nnnn-mmmm'. We need
// to figure out which type this is.
int marker = range.indexOf('-');
@@ -82,8 +82,7 @@
if (start >= 0 && end >= 0) {
return new Range(start, end);
}
- }
- else {
+ } else {
// use the entire token
int start = Integer.parseInt(range);
// and start and the end are the same
@@ -98,7 +97,7 @@
/**
* Get the starting point for the Range.
- *
+ *
* @return The beginning of the mark range.
*/
public int getStart() {
@@ -107,8 +106,9 @@
/**
* Set the starting point for a Range.
- *
- * @param start The new start value.
+ *
+ * @param start
+ * The new start value.
*/
public void setStart(int start) {
this.start = start;
@@ -116,7 +116,7 @@
/**
* Get the ending point for the Range.
- *
+ *
* @return The end of the mark range.
*/
public int getEnd() {
@@ -125,8 +125,9 @@
/**
* Set the ending point for a Range.
- *
- * @param end The new end value.
+ *
+ * @param end
+ * The new end value.
*/
public void setEnd(int end) {
this.end = end;
@@ -134,10 +135,12 @@
/**
* Test if a range contains a point value.
- *
- * @param target The article location to test.
- *
- * @return True if the target is between the start and end values, inclusive.
+ *
+ * @param target
+ * The article location to test.
+ *
+ * @return True if the target is between the start and end values,
+ * inclusive.
*/
public boolean contains(int target) {
return target >= start && target <= end;
@@ -145,10 +148,12 @@
/**
* Test if one range is completely contained within another Range.
- *
- * @param other The other test range.
- *
- * @return true if the other start and end points are contained within this range.
+ *
+ * @param other
+ * The other test range.
+ *
+ * @return true if the other start and end points are contained within this
+ * range.
*/
public boolean contains(Range other) {
return contains(other.getStart()) && contains(other.getEnd());
@@ -156,9 +161,10 @@
/**
* Tests if two ranges overlap
- *
- * @param other The other test range.
- *
+ *
+ * @param other
+ * The other test range.
+ *
* @return true if the start or end points of either range are contained
* within the range of the other.
*/
@@ -168,9 +174,10 @@
/**
* Test if two ranges exactly abutt each other.
- *
- * @param other The other Range to test.
- *
+ *
+ * @param other
+ * The other Range to test.
+ *
* @return true if the end of one range abutts the start of the other range.
*/
public boolean abutts(Range other) {
@@ -178,11 +185,11 @@
}
/**
- * Tests if a single point abutts either the start or end of this
- * Range.
- *
- * @param article The point to test.
- *
+ * Tests if a single point abutts either the start or end of this Range.
+ *
+ * @param article
+ * The point to test.
+ *
* @return true if test point is equal to start - 1 or end + 1.
*/
public boolean abutts(int article) {
@@ -191,9 +198,10 @@
/**
* Test if a point is below the test Range.
- *
- * @param article The point to test.
- *
+ *
+ * @param article
+ * The point to test.
+ *
* @return true if the entire range is less than the test point.
*/
public boolean lessThan(int article) {
@@ -202,66 +210,67 @@
/**
* Test if another Range is less than this Range.
- *
- * @param other The other Range to test.
- *
+ *
+ * @param other
+ * The other Range to test.
+ *
* @return true if the other Range lies completely below this Range.
*/
public boolean lessThan(Range other) {
return end < other.start;
}
-
/**
* Test if a point is above the test Range.
- *
- * @param article The point to test.
- *
+ *
+ * @param article
+ * The point to test.
+ *
* @return true if the entire range is greater than the test point.
*/
public boolean greaterThan(int article) {
return start > article;
}
-
/**
* Test if another Range is greater than this Range.
- *
- * @param other The other Range to test.
- *
+ *
+ * @param other
+ * The other Range to test.
+ *
* @return true if the other Range lies completely below this Range.
*/
public boolean greaterThan(Range other) {
return start > other.end;
}
-
/**
- * Merge another Range into this one. Merging will increase the
- * bounds of this Range to encompass the entire span of the two.
- * If the Ranges do not overlap, the newly created range will
- * include the gap between the two.
- *
- * @param other The Range to merge.
+ * Merge another Range into this one. Merging will increase the bounds of
+ * this Range to encompass the entire span of the two. If the Ranges do not
+ * overlap, the newly created range will include the gap between the two.
+ *
+ * @param other
+ * The Range to merge.
*/
public void merge(Range other) {
if (other.start < start) {
start = other.start;
}
- if (other.end > end ) {
+ if (other.end > end) {
end = other.end;
}
}
/**
- * Split a range at a given split point. Splitting will truncate
- * at the split location - 1 and return a new range beginning
- * at location + 1; This code assumes that the split location
- * is at neither end poing.
- *
- * @param location The split location. Location must be in the range start < location < end.
- *
+ * Split a range at a given split point. Splitting will truncate at the
+ * split location - 1 and return a new range beginning at location + 1; This
+ * code assumes that the split location is at neither end poing.
+ *
+ * @param location
+ * The split location. Location must be in the range start <
+ * location < end.
+ *
* @return A new Range object for the split portion of the range.
*/
public Range split(int location) {
@@ -272,22 +281,20 @@
return new Range(location + 1, newEnd);
}
-
/**
- * Save an individual range element to a newsrc file. The range
- * is expressed either as a single number, or a hypenated pair
- * of numbers.
- *
- * @param out The output writer used to save the data.
- *
+ * Save an individual range element to a newsrc file. The range is expressed
+ * either as a single number, or a hypenated pair of numbers.
+ *
+ * @param out
+ * The output writer used to save the data.
+ *
* @exception IOException
*/
public void save(Writer out) throws IOException {
// do we have a single data point range?
if (start == end) {
out.write(Integer.toString(start));
- }
- else {
+ } else {
out.write(Integer.toString(start));
out.write("-");
out.write(Integer.toString(end));
@@ -295,15 +302,14 @@
}
/**
- * Convert a Range into String form. Used mostly for debugging.
- *
+ * Convert a Range into String form. Used mostly for debugging.
+ *
* @return The String representation of the Range.
*/
public String toString() {
if (start == end) {
return Integer.toString(start);
- }
- else {
+ } else {
return Integer.toString(start) + "-" + Integer.toString(end);
}
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java Fri Mar 31 14:24:52 2006
@@ -20,10 +20,8 @@
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
-import java.util.List;
import java.util.StringTokenizer;
-
/**
* Manage a list of ranges values from a newsrc file.
*/
@@ -33,11 +31,12 @@
ArrayList ranges = new ArrayList();
/**
- * Create a RangeList instance from a newsrc range line. Values
- * are saved as a comma separated set of range values. A range
- * value is either a single number or a hypenated pair of numbers.
- *
- * @param line The newsrc range line.
+ * Create a RangeList instance from a newsrc range line. Values are saved as
+ * a comma separated set of range values. A range value is either a single
+ * number or a hypenated pair of numbers.
+ *
+ * @param line
+ * The newsrc range line.
*/
public RangeList(String line) {
@@ -47,7 +46,7 @@
StringTokenizer tokenizer = new StringTokenizer(line, ",");
while (tokenizer.hasMoreTokens()) {
- String rangeString = (String)tokenizer.nextToken();
+ String rangeString = (String) tokenizer.nextToken();
rangeString = rangeString.trim();
if (rangeString.length() != 0) {
Range range = Range.parse(rangeString);
@@ -57,30 +56,36 @@
}
}
}
- // make sure we start out in a clean state. Any changes from this point will flip on the dirty flat.
+ // make sure we start out in a clean state. Any changes from this point
+ // will flip on the dirty flat.
dirty = false;
}
/**
- * Insert a range item into our list. If possible, the inserted
- * range will be merged with existing ranges.
- *
- * @param newRange The new range item.
+ * Insert a range item into our list. If possible, the inserted range will
+ * be merged with existing ranges.
+ *
+ * @param newRange
+ * The new range item.
*/
public void insert(Range newRange) {
// first find the insertion point
for (int i = 0; i < ranges.size(); i++) {
- Range range = (Range)ranges.get(i);
- // does an existing range fully contain the new range, we don't need to insert anything.
+ Range range = (Range) ranges.get(i);
+ // does an existing range fully contain the new range, we don't need
+ // to insert anything.
if (range.contains(newRange)) {
return;
}
// does the current one abutt or overlap with the inserted range?
if (range.abutts(newRange) || range.overlaps(newRange)) {
- // rats, we have an overlap...and it is possible that we could overlap with
- // the next range after this one too. Therefore, we merge these two ranges together,
- // remove the place where we're at, and then recursively insert the larger range into
+ // rats, we have an overlap...and it is possible that we could
+ // overlap with
+ // the next range after this one too. Therefore, we merge these
+ // two ranges together,
+ // remove the place where we're at, and then recursively insert
+ // the larger range into
// the list.
dirty = true;
newRange.merge(range);
@@ -89,8 +94,8 @@
return;
}
-
- // ok, we don't touch the current one at all. If it is completely above
+ // ok, we don't touch the current one at all. If it is completely
+ // above
// range we're adding, we can just poke this into the list here.
if (newRange.lessThan(range)) {
dirty = true;
@@ -104,17 +109,17 @@
}
/**
- * Test if a given article point falls within one of the contained
- * Ranges.
- *
- * @param article The test point.
- *
+ * Test if a given article point falls within one of the contained Ranges.
+ *
+ * @param article
+ * The test point.
+ *
* @return true if this falls within one of our current mark Ranges, false
* otherwise.
*/
public boolean isMarked(int article) {
for (int i = 0; i < ranges.size(); i++) {
- Range range = (Range)ranges.get(i);
+ Range range = (Range) ranges.get(i);
if (range.contains(article)) {
return true;
}
@@ -128,8 +133,9 @@
/**
* Mark a target article as having been seen.
- *
- * @param article The target article number.
+ *
+ * @param article
+ * The target article number.
*/
public void setMarked(int article) {
// go through the insertion logic.
@@ -138,33 +144,36 @@
/**
* Clear the seen mark for a target article.
- *
- * @param article The target article number.
+ *
+ * @param article
+ * The target article number.
*/
public void setUnmarked(int article) {
for (int i = 0; i < ranges.size(); i++) {
- Range range = (Range)ranges.get(i);
- // does this fall within an existing range? We don't need to do anything here.
+ Range range = (Range) ranges.get(i);
+ // does this fall within an existing range? We don't need to do
+ // anything here.
if (range.contains(article)) {
- // ok, we've found where to insert, now to figure out how to insert
- // article is at the beginning of the range. We can just increment the lower
- // bound, or if this is a single element range, we can remove it entirely.
+ // ok, we've found where to insert, now to figure out how to
+ // insert
+ // article is at the beginning of the range. We can just
+ // increment the lower
+ // bound, or if this is a single element range, we can remove it
+ // entirely.
if (range.getStart() == article) {
if (range.getEnd() == article) {
// piece of cake!
ranges.remove(i);
- }
- else {
+ } else {
// still pretty easy.
range.setStart(article + 1);
}
- }
- else if (range.getEnd() == article) {
+ } else if (range.getEnd() == article) {
// pretty easy also
range.setEnd(article - 1);
- }
- else {
- // split this into two ranges and insert the trailing piece after this.
+ } else {
+ // split this into two ranges and insert the trailing piece
+ // after this.
Range section = range.split(article);
ranges.add(i + 1, section);
}
@@ -177,16 +186,16 @@
return;
}
}
- // didn't find it at all. That was easy!
+ // didn't find it at all. That was easy!
}
-
/**
- * Save this List of Ranges out to a .newsrc file. This creates
- * a comma-separated list of range values from each of the Ranges.
- *
- * @param out The target output stream.
- *
+ * Save this List of Ranges out to a .newsrc file. This creates a
+ * comma-separated list of range values from each of the Ranges.
+ *
+ * @param out
+ * The target output stream.
+ *
* @exception IOException
*/
public void save(Writer out) throws IOException {
@@ -195,19 +204,19 @@
return;
}
- Range range = (Range)ranges.get(0);
+ Range range = (Range) ranges.get(0);
range.save(out);
for (int i = 1; i < ranges.size(); i++) {
out.write(",");
- range = (Range)ranges.get(i);
+ range = (Range) ranges.get(i);
range.save(out);
}
}
/**
* Return the state of the dirty flag.
- *
+ *
* @return True if the range list information has changed, false otherwise.
*/
public boolean isDirty() {
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java Fri Mar 31 14:24:52 2006
@@ -19,22 +19,22 @@
/**
* An abstraction for POP3Commands
+ *
* @see org.apache.geronimo.javamail.store.pop3.POP3CommandFactory
*
* @version $Rev$ $Date$
*/
public interface POP3Command {
-
-
- /**
- * This method will get the POP3 command in string format
- * according o rfc1939
- */
- public String getCommand();
-
- /**
- * Indicates wether this command expects a multiline response or not
- *
- */
- public boolean isMultiLineResponse();
+
+ /**
+ * This method will get the POP3 command in string format according o
+ * rfc1939
+ */
+ public String getCommand();
+
+ /**
+ * Indicates wether this command expects a multiline response or not
+ *
+ */
+ public boolean isMultiLineResponse();
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java Fri Mar 31 14:24:52 2006
@@ -18,207 +18,169 @@
package org.apache.geronimo.javamail.store.pop3;
/**
- * Provides concrete implementations of
- * org.apache.geronimo.javamail.store.pop3.POP3Command objects
- * representing the POP3 commands defined in rfc 1939
+ * Provides concrete implementations of
+ * org.apache.geronimo.javamail.store.pop3.POP3Command objects representing the
+ * POP3 commands defined in rfc 1939
*
* @link http://www.faqs.org/rfcs/rfc1939.html
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date$
*/
public final class POP3CommandFactory implements POP3Constants {
-
- public static POP3Command getCOMMAND_USER(final String user)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "USER" + SPACE + user + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_PASS(final String passwd)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "PASS" + SPACE + passwd + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_QUIT()
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "QUIT" + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_NOOP()
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "NOOP" + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_STAT()
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "STAT" + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_LIST()
- {
- return getCOMMAND_LIST(-1);
- }
-
- public static POP3Command getCOMMAND_LIST(final int msgNo)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- if(msgNo>0){
- return "LIST" + SPACE + msgNo + CRLF;
- }else{
- return "LIST" + CRLF;
- }
- }
- /**
- * If a msg num is specified then the the message details will be on the first line
- * for ex. +OK 3 4520
- *
- * if no msgnum is specified then all the msg details are return in a multiline format
- * for ex. +OK 2 messages
- * 1 456
- * 2 46456
- * .....
- * n 366
- */
- public boolean isMultiLineResponse() {
- return(msgNo<0);
- }
- };
- }
-
- public static POP3Command getCOMMAND_RETR(final int msgNo)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "RETR" + SPACE + msgNo + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return true;
- }
- };
- }
-
- public static POP3Command getCOMMAND_DELE(final int msgNo)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "DELE" + SPACE + msgNo + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_REST(final int msgNo)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "REST" + SPACE + msgNo + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return false;
- }
- };
- }
-
- public static POP3Command getCOMMAND_TOP(final int msgNo, final int numLines)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- return "TOP" + SPACE + msgNo + SPACE + numLines + CRLF;
- }
-
- public boolean isMultiLineResponse() {
- return true;
- }
- };
- }
-
- public static POP3Command getCOMMAND_UIDL()
- {
- return getCOMMAND_UIDL(-1);
- }
-
- public static POP3Command getCOMMAND_UIDL(final int msgNo)
- {
- return new POP3Command()
- {
- public String getCommand()
- {
- if(msgNo>0){
- return "UIDL" + SPACE + msgNo + CRLF;
- }else{
- return "UIDL" + CRLF;
- }
- }
-
- public boolean isMultiLineResponse() {
- return true;
- }
- };
- }
-
-
+
+ public static POP3Command getCOMMAND_USER(final String user) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "USER" + SPACE + user + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_PASS(final String passwd) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "PASS" + SPACE + passwd + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_QUIT() {
+ return new POP3Command() {
+ public String getCommand() {
+ return "QUIT" + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_NOOP() {
+ return new POP3Command() {
+ public String getCommand() {
+ return "NOOP" + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_STAT() {
+ return new POP3Command() {
+ public String getCommand() {
+ return "STAT" + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_LIST() {
+ return getCOMMAND_LIST(-1);
+ }
+
+ public static POP3Command getCOMMAND_LIST(final int msgNo) {
+ return new POP3Command() {
+ public String getCommand() {
+ if (msgNo > 0) {
+ return "LIST" + SPACE + msgNo + CRLF;
+ } else {
+ return "LIST" + CRLF;
+ }
+ }
+
+ /**
+ * If a msg num is specified then the the message details will be on
+ * the first line for ex. +OK 3 4520
+ *
+ * if no msgnum is specified then all the msg details are return in
+ * a multiline format for ex. +OK 2 messages 1 456 2 46456 ..... n
+ * 366
+ */
+ public boolean isMultiLineResponse() {
+ return (msgNo < 0);
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_RETR(final int msgNo) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "RETR" + SPACE + msgNo + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return true;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_DELE(final int msgNo) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "DELE" + SPACE + msgNo + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_REST(final int msgNo) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "REST" + SPACE + msgNo + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return false;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_TOP(final int msgNo, final int numLines) {
+ return new POP3Command() {
+ public String getCommand() {
+ return "TOP" + SPACE + msgNo + SPACE + numLines + CRLF;
+ }
+
+ public boolean isMultiLineResponse() {
+ return true;
+ }
+ };
+ }
+
+ public static POP3Command getCOMMAND_UIDL() {
+ return getCOMMAND_UIDL(-1);
+ }
+
+ public static POP3Command getCOMMAND_UIDL(final int msgNo) {
+ return new POP3Command() {
+ public String getCommand() {
+ if (msgNo > 0) {
+ return "UIDL" + SPACE + msgNo + CRLF;
+ } else {
+ return "UIDL" + CRLF;
+ }
+ }
+
+ public boolean isMultiLineResponse() {
+ return true;
+ }
+ };
+ }
+
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java Fri Mar 31 14:24:52 2006
@@ -29,130 +29,125 @@
import javax.mail.Session;
/**
- * Represents a connection with the POP3 mail server.
- * The connection is owned by a pop3 store and is only
- * associated with one user who owns the respective
+ * Represents a connection with the POP3 mail server. The connection is owned by
+ * a pop3 store and is only associated with one user who owns the respective
* POP3Store instance
- *
- * @version $Rev$ $Date$
+ *
+ * @version $Rev$ $Date$
*/
public class POP3Connection {
-
- private Socket soc;
- private Session session;
- private String host;
- private int port;
- private PrintWriter writer;
- private BufferedReader reader;
-
- POP3Connection(Session session, String host, int port){
-
- this.session = session;
- this.host = host;
- this.port = port;
- }
-
- public void open() throws Exception
- {
- try{
- soc = new Socket();
- soc.connect(new InetSocketAddress(host, port));
-
- if(session.getDebug()){
- session.getDebugOut().println("Connection successful " + this.toString() );
- }
-
- buildInputReader();
- buildOutputWriter();
-
-
- // consume the greeting
- if (session.getDebug()) {
- session.getDebugOut().println(
- "Greeting from server " + reader.readLine());
- } else {
- reader.readLine();
- }
-
- }catch(IOException e){
- Exception ex = new Exception("Error opening connection " + this.toString(),e);
- throw ex;
- }
- }
-
- void close() throws Exception
- {
- try{
- soc.close();
- if(session.getDebug()){
- session.getDebugOut().println("Connection successfuly closed " + this.toString() );
- }
-
- }catch(IOException e){
- Exception ex = new Exception("Error closing connection " + this.toString(),e);
- throw ex;
- }
-
- }
-
- public synchronized POP3Response sendCommand(POP3Command cmd) throws MessagingException
- {
- if(soc.isConnected()){
-
- //if the underlying output stream is down
- // attempt to rebuild the writer
- if(soc.isOutputShutdown()){
- buildOutputWriter();
- }
-
-
- // if the underlying inout stream is down
- // attempt to rebuild the reader
- if(soc.isInputShutdown()){
- buildInputReader();
- }
-
- if(session.getDebug()){
- session.getDebugOut().println("\nCommand sent " + cmd.getCommand() );
- }
-
- POP3Response res = null;
-
- // this method supresses IOException
- // but choose bcos of ease of use
- {
- writer.write(cmd.getCommand());
- writer.flush();
- res = POP3ResponseBuilder.buildResponse(session,reader,cmd.isMultiLineResponse());
- }
-
- return res;
- }
-
- throw new MessagingException("Connection to Mail Server is lost, connection " + this.toString());
- }
-
- private void buildInputReader() throws MessagingException{
- try{
- reader = new BufferedReader(
- new InputStreamReader(soc.getInputStream()));
- }catch(IOException e){
- throw new MessagingException("Error obtaining input stream " + this.toString(),e);
- }
- }
-
- private void buildOutputWriter() throws MessagingException{
- try{
- writer = new PrintWriter(
- new BufferedOutputStream(soc.getOutputStream()));
- }catch(IOException e){
- throw new MessagingException("Error obtaining output stream " + this.toString(),e);
- }
- }
-
- public String toString()
- {
- return "POP3Connection host: " + host + " port: " + port;
- }
+
+ private Socket soc;
+
+ private Session session;
+
+ private String host;
+
+ private int port;
+
+ private PrintWriter writer;
+
+ private BufferedReader reader;
+
+ POP3Connection(Session session, String host, int port) {
+
+ this.session = session;
+ this.host = host;
+ this.port = port;
+ }
+
+ public void open() throws Exception {
+ try {
+ soc = new Socket();
+ soc.connect(new InetSocketAddress(host, port));
+
+ if (session.getDebug()) {
+ session.getDebugOut().println("Connection successful " + this.toString());
+ }
+
+ buildInputReader();
+ buildOutputWriter();
+
+ // consume the greeting
+ if (session.getDebug()) {
+ session.getDebugOut().println("Greeting from server " + reader.readLine());
+ } else {
+ reader.readLine();
+ }
+
+ } catch (IOException e) {
+ Exception ex = new Exception("Error opening connection " + this.toString(), e);
+ throw ex;
+ }
+ }
+
+ void close() throws Exception {
+ try {
+ soc.close();
+ if (session.getDebug()) {
+ session.getDebugOut().println("Connection successfuly closed " + this.toString());
+ }
+
+ } catch (IOException e) {
+ Exception ex = new Exception("Error closing connection " + this.toString(), e);
+ throw ex;
+ }
+
+ }
+
+ public synchronized POP3Response sendCommand(POP3Command cmd) throws MessagingException {
+ if (soc.isConnected()) {
+
+ // if the underlying output stream is down
+ // attempt to rebuild the writer
+ if (soc.isOutputShutdown()) {
+ buildOutputWriter();
+ }
+
+ // if the underlying inout stream is down
+ // attempt to rebuild the reader
+ if (soc.isInputShutdown()) {
+ buildInputReader();
+ }
+
+ if (session.getDebug()) {
+ session.getDebugOut().println("\nCommand sent " + cmd.getCommand());
+ }
+
+ POP3Response res = null;
+
+ // this method supresses IOException
+ // but choose bcos of ease of use
+ {
+ writer.write(cmd.getCommand());
+ writer.flush();
+ res = POP3ResponseBuilder.buildResponse(session, reader, cmd.isMultiLineResponse());
+ }
+
+ return res;
+ }
+
+ throw new MessagingException("Connection to Mail Server is lost, connection " + this.toString());
+ }
+
+ private void buildInputReader() throws MessagingException {
+ try {
+ reader = new BufferedReader(new InputStreamReader(soc.getInputStream()));
+ } catch (IOException e) {
+ throw new MessagingException("Error obtaining input stream " + this.toString(), e);
+ }
+ }
+
+ private void buildOutputWriter() throws MessagingException {
+ try {
+ writer = new PrintWriter(new BufferedOutputStream(soc.getOutputStream()));
+ } catch (IOException e) {
+ throw new MessagingException("Error obtaining output stream " + this.toString(), e);
+ }
+ }
+
+ public String toString() {
+ return "POP3Connection host: " + host + " port: " + port;
+ }
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java Fri Mar 31 14:24:52 2006
@@ -18,20 +18,23 @@
package org.apache.geronimo.javamail.store.pop3;
/**
- * Defines a few constants that are used throught
- * the implementation.
+ * Defines a few constants that are used throught the implementation.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date$
*/
public interface POP3Constants {
- public final static String SPACE = " ";
- public final static String CRLF = "\r\n";
-
- public final static int LF = '\n';
- public final static int CR = '\r';
- public final static int DOT = '.';
-
- public final static int OK = 0;
- public final static int ERR = 1;
+ public final static String SPACE = " ";
+
+ public final static String CRLF = "\r\n";
+
+ public final static int LF = '\n';
+
+ public final static int CR = '\r';
+
+ public final static int DOT = '.';
+
+ public final static int OK = 0;
+
+ public final static int ERR = 1;
}