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 [1/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/
Author: jlaskowski
Date: Fri Mar 31 14:24:52 2006
New Revision: 390524
URL: http://svn.apache.org/viewcvs?rev=390524&view=rev
Log:
Formatting + import organizing
Modified:
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/ClientAuthenticator.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/CramMD5Authenticator.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/DigestMD5Authenticator.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/LoginAuthenticator.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/PlainAuthenticator.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPFolder.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPGroupFolder.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPRootFolder.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPStore.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrc.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcFile.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/NNTPNewsrcGroup.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/Range.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/nntp/NNTPConnection.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/nntp/NNTPReply.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/nntp/NNTPTransport.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/nntp/StringListInputStream.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/MalformedSMTPReplyException.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPAddressFailedException.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPAddressSucceededException.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPMessage.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPSTransport.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPSendFailedException.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransportException.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/MIMEOutputStream.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/ClientAuthenticator.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/ClientAuthenticator.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/ClientAuthenticator.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/ClientAuthenticator.java Fri Mar 31 14:24:52 2006
@@ -20,65 +20,65 @@
import javax.mail.MessagingException;
/**
- * Simplified version of the Java 5 SaslClient interface. This
- * is used to implement a javamail authentication framework that
- * mimics the Sasl framework on a 1.4.2 JVM. Only the methods
- * required by the Javamail code are implemented here, but it
- * should be a simple migration to the fuller SASL interface.
+ * Simplified version of the Java 5 SaslClient interface. This is used to
+ * implement a javamail authentication framework that mimics the Sasl framework
+ * on a 1.4.2 JVM. Only the methods required by the Javamail code are
+ * implemented here, but it should be a simple migration to the fuller SASL
+ * interface.
*/
public interface ClientAuthenticator {
/**
- * Evaluate a challenge and return a response that can be sent
- * back to the server. Bot the challenge information and the
- * response information are "raw data", minus any special
- * encodings used by the transport. For example, SMTP
- * DIGEST-MD5 authentication protocol passes information as
- * Base64 encoded strings. That encoding must be removed before
- * calling evaluateChallenge() and the resulting respose must
- * be Base64 encoced before transmission to the server.
- *
- * It is the authenticator's responsibility to keep track of the
- * state of the evaluations. That is, if the authentication
- * process requires multiple challenge/response cycles, then
- * the authenticator needs to keep track of context of the
- * challenges.
- *
- * @param challenge The challenge data.
- *
+ * Evaluate a challenge and return a response that can be sent back to the
+ * server. Bot the challenge information and the response information are
+ * "raw data", minus any special encodings used by the transport. For
+ * example, SMTP DIGEST-MD5 authentication protocol passes information as
+ * Base64 encoded strings. That encoding must be removed before calling
+ * evaluateChallenge() and the resulting respose must be Base64 encoced
+ * before transmission to the server.
+ *
+ * It is the authenticator's responsibility to keep track of the state of
+ * the evaluations. That is, if the authentication process requires multiple
+ * challenge/response cycles, then the authenticator needs to keep track of
+ * context of the challenges.
+ *
+ * @param challenge
+ * The challenge data.
+ *
* @return An appropriate response for the challenge data.
*/
public byte[] evaluateChallenge(byte[] challenge) throws MessagingException;
+
/**
- * Indicates that the authenticator has data that should be
- * sent when the authentication process is initiated. For example,
- * the SMTP PLAIN authentication sends userid/password without
- * waiting for a challenge response.
- *
- * If this method returns true, then the initial response is
- * retrieved using evaluateChallenge() passing null for the
- * challenge information.
- *
- * @return True if the challenge/response process starts with an
- * initial response on the client side.
+ * Indicates that the authenticator has data that should be sent when the
+ * authentication process is initiated. For example, the SMTP PLAIN
+ * authentication sends userid/password without waiting for a challenge
+ * response.
+ *
+ * If this method returns true, then the initial response is retrieved using
+ * evaluateChallenge() passing null for the challenge information.
+ *
+ * @return True if the challenge/response process starts with an initial
+ * response on the client side.
*/
public boolean hasInitialResponse();
+
/**
- * Indicates whether the client believes the challenge/response
- * sequence is now complete.
- *
- * @return true if the client has evaluated what it believes to be the
- * last challenge, false if there are additional stages to
- * evaluate.
+ * Indicates whether the client believes the challenge/response sequence is
+ * now complete.
+ *
+ * @return true if the client has evaluated what it believes to be the last
+ * challenge, false if there are additional stages to evaluate.
*/
public boolean isComplete();
+
/**
* Return the mechanism name implemented by this authenticator.
- *
- * @return The string name of the authentication mechanism. This name
- * should match the names commonly used by the mail servers
- * (e.g., "PLAIN", "LOGIN", "DIGEST-MD5", etc.).
+ *
+ * @return The string name of the authentication mechanism. This name should
+ * match the names commonly used by the mail servers (e.g., "PLAIN",
+ * "LOGIN", "DIGEST-MD5", etc.).
*/
public String getMechanismName();
}
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/CramMD5Authenticator.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/CramMD5Authenticator.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/CramMD5Authenticator.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/CramMD5Authenticator.java Fri Mar 31 14:24:52 2006
@@ -23,13 +23,13 @@
import javax.mail.MessagingException;
-import org.apache.geronimo.mail.util.Base64;
import org.apache.geronimo.mail.util.Hex;
public class CramMD5Authenticator implements ClientAuthenticator {
// the user we're authenticating
protected String username;
+
// the user's password (the "shared secret")
protected String password;
@@ -38,9 +38,11 @@
/**
* Main constructor.
- *
- * @param username The login user name.
- * @param password The login password.
+ *
+ * @param username
+ * The login user name.
+ * @param password
+ * The login password.
*/
public CramMD5Authenticator(String username, String password) {
this.username = username;
@@ -48,9 +50,9 @@
}
/**
- * Respond to the hasInitialResponse query. This mechanism
- * does not have an initial response.
- *
+ * Respond to the hasInitialResponse query. This mechanism does not have an
+ * initial response.
+ *
* @return Always returns false.
*/
public boolean hasInitialResponse() {
@@ -59,7 +61,7 @@
/**
* Indicate whether the challenge/response process is complete.
- *
+ *
* @return True if the last challenge has been processed, false otherwise.
*/
public boolean isComplete() {
@@ -68,25 +70,26 @@
/**
* Retrieve the authenticator mechanism name.
- *
+ *
* @return Always returns the string "CRAM-MD5"
*/
public String getMechanismName() {
return "CRAM-MD5";
}
-
/**
- * Evaluate a CRAM-MD5 login challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as a byte array.
- *
+ * Evaluate a CRAM-MD5 login challenge, returning the a result string that
+ * should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as a byte array.
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
public byte[] evaluateChallenge(byte[] challenge) throws MessagingException {
- // we create the challenge from the userid and password information (the "shared secret").
+ // we create the challenge from the userid and password information (the
+ // "shared secret").
byte[] passBytes;
try {
@@ -95,7 +98,8 @@
// compute the password digest using the key
byte[] digest = computeCramDigest(passBytes, challenge);
- // create a unified string using the user name and the hex encoded digest
+ // create a unified string using the user name and the hex encoded
+ // digest
String responseString = username + " " + new String(Hex.encode(digest));
complete = true;
return responseString.getBytes();
@@ -106,19 +110,19 @@
}
-
/**
- * Compute a CRAM digest using the hmac_md5 algorithm. See the
- * description of RFC 2104 for algorithm details.
- *
- * @param key The key (K) for the calculation.
- * @param input The encrypted text value.
- *
+ * Compute a CRAM digest using the hmac_md5 algorithm. See the description
+ * of RFC 2104 for algorithm details.
+ *
+ * @param key
+ * The key (K) for the calculation.
+ * @param input
+ * The encrypted text value.
+ *
* @return The computed digest, as a byte array value.
* @exception NoSuchAlgorithmException
*/
- protected byte[] computeCramDigest(byte[] key, byte[] input) throws MessagingException
- {
+ protected byte[] computeCramDigest(byte[] key, byte[] input) throws MessagingException {
// CRAM digests are computed using the MD5 algorithm.
MessageDigest digest;
try {
@@ -127,14 +131,16 @@
throw new MessagingException("Unable to access MD5 message digest", e);
}
- // if the key is longer than 64 bytes, then we get a digest of the key and use that instead.
+ // if the key is longer than 64 bytes, then we get a digest of the key
+ // and use that instead.
// this is required by RFC 2104.
if (key.length > 64) {
digest.update(key);
key = digest.digest();
}
- // now we create two 64 bit padding keys, initialized with the key information.
+ // now we create two 64 bit padding keys, initialized with the key
+ // information.
byte[] ipad = new byte[64];
byte[] opad = new byte[64];
@@ -148,20 +154,20 @@
opad[i] ^= 0x5c;
}
- // now there are a pair of MD5 operations performed, and inner and an outer. The spec defines this as
+ // now there are a pair of MD5 operations performed, and inner and an
+ // outer. The spec defines this as
// H(K XOR opad, H(K XOR ipad, text)), where H is the MD5 operation.
// inner operation
digest.reset();
digest.update(ipad);
- digest.update(input); // this appends the text to the pad
+ digest.update(input); // this appends the text to the pad
byte[] md5digest = digest.digest();
// outer operation
digest.reset();
digest.update(opad);
digest.update(md5digest);
- return digest.digest(); // final result
+ return digest.digest(); // final result
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/DigestMD5Authenticator.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/DigestMD5Authenticator.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/DigestMD5Authenticator.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/DigestMD5Authenticator.java Fri Mar 31 14:24:52 2006
@@ -23,38 +23,44 @@
import java.security.SecureRandom;
import java.util.ArrayList;
-import javax.mail.MessagingException;
import javax.mail.AuthenticationFailedException;
+import javax.mail.MessagingException;
import org.apache.geronimo.mail.util.Base64;
import org.apache.geronimo.mail.util.Hex;
-import sun.security.provider.MD5;
-
/**
- * Process a DIGEST-MD5 authentication, using the
- * challenge/response mechanisms.
+ * Process a DIGEST-MD5 authentication, using the challenge/response mechanisms.
*/
public class DigestMD5Authenticator implements ClientAuthenticator {
protected static final int AUTHENTICATE_CLIENT = 0;
+
protected static final int AUTHENTICATE_SERVER = 1;
+
protected static final int AUTHENTICATION_COMPLETE = 2;
// the host server name
protected String host;
+
// the user we're authenticating
protected String username;
+
// the user's password (the "shared secret")
protected String password;
+
// the target login realm
protected String realm;
+
// our message digest for processing the challenges.
MessageDigest digest;
+
// the string we send to the server on the first challenge.
protected String clientResponse;
+
// the response back from an authentication challenge.
protected String authenticationResponse = null;
+
// our list of realms received from the server (normally just one).
protected ArrayList realms;
@@ -66,11 +72,15 @@
/**
* Main constructor.
- *
- * @param host The server host name.
- * @param username The login user name.
- * @param password The login password.
- * @param realm The target login realm (can be null).
+ *
+ * @param host
+ * The server host name.
+ * @param username
+ * The login user name.
+ * @param password
+ * The login password.
+ * @param realm
+ * The target login realm (can be null).
*/
public DigestMD5Authenticator(String host, String username, String password, String realm) {
this.host = host;
@@ -80,9 +90,9 @@
}
/**
- * Respond to the hasInitialResponse query. This mechanism
- * does not have an initial response.
- *
+ * Respond to the hasInitialResponse query. This mechanism does not have an
+ * initial response.
+ *
* @return Always returns false.
*/
public boolean hasInitialResponse() {
@@ -91,7 +101,7 @@
/**
* Indicate whether the challenge/response process is complete.
- *
+ *
* @return True if the last challenge has been processed, false otherwise.
*/
public boolean isComplete() {
@@ -100,57 +110,59 @@
/**
* Retrieve the authenticator mechanism name.
- *
+ *
* @return Always returns the string "DIGEST-MD5"
*/
public String getMechanismName() {
return "DIGEST-MD5";
}
-
/**
- * Evaluate a DIGEST-MD5 login challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as a string.
- *
+ * Evaluate a DIGEST-MD5 login challenge, returning the a result string that
+ * should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as a string.
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
public byte[] evaluateChallenge(byte[] challenge) throws MessagingException {
- // DIGEST-MD5 authentication goes in two stages. First state involves us validating with the
- // server, the second stage is the server validating with us, using the shared secret.
+ // DIGEST-MD5 authentication goes in two stages. First state involves us
+ // validating with the
+ // server, the second stage is the server validating with us, using the
+ // shared secret.
switch (stage) {
- // stage one of the process.
- case AUTHENTICATE_CLIENT: {
- // get the response and advance the processing stage.
- byte[] response = authenticateClient(challenge);
- stage = AUTHENTICATE_SERVER;
- return response;
- }
-
- // stage two of the process.
- case AUTHENTICATE_SERVER: {
- // get the response and advance the processing stage to completed.
- byte[] response = authenticateServer(challenge);
- stage = AUTHENTICATION_COMPLETE;
- return response;
- }
-
- // should never happen.
- default:
- throw new MessagingException("Invalid LOGIN challenge");
+ // stage one of the process.
+ case AUTHENTICATE_CLIENT: {
+ // get the response and advance the processing stage.
+ byte[] response = authenticateClient(challenge);
+ stage = AUTHENTICATE_SERVER;
+ return response;
+ }
+
+ // stage two of the process.
+ case AUTHENTICATE_SERVER: {
+ // get the response and advance the processing stage to completed.
+ byte[] response = authenticateServer(challenge);
+ stage = AUTHENTICATION_COMPLETE;
+ return response;
+ }
+
+ // should never happen.
+ default:
+ throw new MessagingException("Invalid LOGIN challenge");
}
}
-
/**
- * Evaluate a DIGEST-MD5 login server authentication challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as a string.
- *
+ * Evaluate a DIGEST-MD5 login server authentication challenge, returning
+ * the a result string that should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as a string.
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
@@ -161,7 +173,8 @@
}
try {
- // like all of the client validation steps, the following is order critical.
+ // like all of the client validation steps, the following is order
+ // critical.
// first add in the URI information.
digest.update((":smtp/" + host).getBytes("US-ASCII"));
// now mix in the response we sent originally
@@ -171,25 +184,26 @@
// now convert that into a hex encoded string.
String validationText = new String(Hex.encode(digest.digest()));
- // if everything went well, this calculated value should match what we got back from the server.
+ // if everything went well, this calculated value should match what
+ // we got back from the server.
// our response back is just a null string....
if (validationText.equals(authenticationResponse)) {
return new byte[0];
}
throw new AuthenticationFailedException("Invalid DIGEST-MD5 response from server");
- } catch (UnsupportedEncodingException e ) {
+ } catch (UnsupportedEncodingException e) {
throw new MessagingException("Invalid character encodings");
}
}
-
/**
- * Evaluate a DIGEST-MD5 login client authentication challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as a string.
- *
+ * Evaluate a DIGEST-MD5 login client authentication challenge, returning
+ * the a result string that should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as a string.
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
@@ -200,7 +214,8 @@
}
SecureRandom randomGenerator;
- // before doing anything, make sure we can get the required crypto support.
+ // before doing anything, make sure we can get the required crypto
+ // support.
try {
randomGenerator = new SecureRandom();
digest = MessageDigest.getInstance("MD5");
@@ -208,32 +223,34 @@
throw new MessagingException("Unable to access cryptography libraries");
}
- // if not configured for a realm, take the first realm from the list, if any
+ // if not configured for a realm, take the first realm from the list, if
+ // any
if (realm == null) {
// if not handed any realms, just use the host name.
if (realms.isEmpty()) {
realm = host;
- }
- else {
+ } else {
// pretty arbitrary at this point, so just use the first one.
- realm = (String)realms.get(0);
+ realm = (String) realms.get(0);
}
}
- // use secure random to generate a collection of bytes. that is our cnonce value.
+ // use secure random to generate a collection of bytes. that is our
+ // cnonce value.
byte[] cnonceBytes = new byte[32];
randomGenerator.nextBytes(cnonceBytes);
// and get this as a base64 encoded string.
String cnonce = new String(Base64.encode(cnonceBytes));
-
- // Now the digest computation part. This gets a bit tricky, and must be done in strict order.
+ // Now the digest computation part. This gets a bit tricky, and must be
+ // done in strict order.
try {
// this identifies where we're logging into.
String idString = username + ":" + realm + ":" + password;
- // we get a digest for this string, then use the digest for the first stage
+ // we get a digest for this string, then use the digest for the
+ // first stage
// of the next digest operation.
digest.update(digest.digest(idString.getBytes("US-ASCII")));
@@ -242,10 +259,11 @@
digest.update(nonceString.getBytes("US-ASCII"));
// hex encode this digest, and add on the string values
- // NB, we only support "auth" for the quality of protection value (qop). We save this in an
- // instance variable because we'll need this to validate the response back from the server.
- clientResponse = new String(Hex.encode(digest.digest())) + ":" + nonce + ":00000001:" + cnonce + ":auth:";
-
+ // NB, we only support "auth" for the quality of protection value
+ // (qop). We save this in an
+ // instance variable because we'll need this to validate the
+ // response back from the server.
+ clientResponse = new String(Hex.encode(digest.digest())) + ":" + nonce + ":00000001:" + cnonce + ":auth:";
// now we add in identification values to the hash.
String authString = "AUTHENTICATE:smtp/" + host;
@@ -256,11 +274,12 @@
// and this gets fed back into the digest
digest.update(responseString.getBytes("US-ASCII"));
- // and FINALLY, the challege digest is hex encoded for sending back to the server (whew).
+ // and FINALLY, the challege digest is hex encoded for sending back
+ // to the server (whew).
String challengeResponse = new String(Hex.encode(digest.digest()));
-
- // now finally build the keyword/value part of the challenge response. These can be
+ // now finally build the keyword/value part of the challenge
+ // response. These can be
// in any order.
StringBuffer response = new StringBuffer();
@@ -272,7 +291,8 @@
response.append(realm);
response.append("\"");
- // we only support auth qop values, and the nonce-count (nc) is always 1.
+ // we only support auth qop values, and the nonce-count (nc) is
+ // always 1.
response.append(",qop=auth");
response.append(",nc=00000001");
@@ -293,18 +313,18 @@
return response.toString().getBytes("US-ASCII");
- } catch (UnsupportedEncodingException e ) {
+ } catch (UnsupportedEncodingException e) {
throw new MessagingException("Invalid character encodings");
}
}
-
/**
- * Parse the challege string, pulling out information required
- * for our challenge response.
- *
- * @param challenge The challenge data.
- *
+ * Parse the challege string, pulling out information required for our
+ * challenge response.
+ *
+ * @param challenge
+ * The challenge data.
+ *
* @return true if there were no errors parsing the string, false otherwise.
* @exception MessagingException
*/
@@ -313,7 +333,8 @@
DigestParser parser = new DigestParser(new String(challenge));
- // parse the entire string...but we ignore everything but the options we support.
+ // parse the entire string...but we ignore everything but the options we
+ // support.
while (parser.hasMore()) {
NameValuePair pair = parser.parseNameValuePair();
@@ -327,7 +348,8 @@
else if (name.equalsIgnoreCase("nonce")) {
nonce = pair.value;
}
- // rspauth is the challenge replay back, which allows us to validate that server is also legit.
+ // rspauth is the challenge replay back, which allows us to validate
+ // that server is also legit.
else if (name.equalsIgnoreCase("rspauth")) {
authenticationResponse = pair.value;
}
@@ -336,24 +358,25 @@
return true;
}
-
/**
- * Inner class for parsing a DIGEST-MD5 challenge string, which
- * is composed of "name=value" pairs, separated by "," characters.
+ * Inner class for parsing a DIGEST-MD5 challenge string, which is composed
+ * of "name=value" pairs, separated by "," characters.
*/
class DigestParser {
// the challenge we're parsing
String challenge;
+
// length of the challenge
int length;
+
// current parsing position
int position;
-
/**
* Normal constructor.
- *
- * @param challenge The challenge string to be parsed.
+ *
+ * @param challenge
+ * The challenge string to be parsed.
*/
public DigestParser(String challenge) {
this.challenge = challenge;
@@ -363,9 +386,9 @@
/**
* Test if there are more values to parse.
- *
- * @return true if we've not reached the end of the challenge string, false
- * if the challenge has been completely consumed.
+ *
+ * @return true if we've not reached the end of the challenge string,
+ * false if the challenge has been completely consumed.
*/
private boolean hasMore() {
return position < length;
@@ -373,7 +396,7 @@
/**
* Return the character at the current parsing position.
- *
+ *
* @return The string character for the current parse position.
*/
private char currentChar() {
@@ -387,7 +410,6 @@
position++;
}
-
/**
* Skip over any white space characters in the challenge string.
*/
@@ -397,15 +419,15 @@
}
}
-
/**
- * Parse a quoted string used with a name/value pair, accounting
- * for escape characters embedded within the string.
- *
+ * Parse a quoted string used with a name/value pair, accounting for
+ * escape characters embedded within the string.
+ *
* @return The string value of the character string.
*/
private String parseQuotedValue() {
- // we're here because we found the starting double quote. Step over it and parse to the closing
+ // we're here because we found the starting double quote. Step over
+ // it and parse to the closing
// one.
nextChar();
@@ -430,10 +452,9 @@
nextChar();
// return the constructed string.
return value.toString();
- }
- else
- {
- // step over the character and contine with the next characteer1
+ } else {
+ // step over the character and contine with the next
+ // characteer1
value.append(ch);
}
nextChar();
@@ -444,8 +465,9 @@
/**
* Parse a token value used with a name/value pair.
- *
- * @return The string value of the token. Returns null if nothing is found up to the separater.
+ *
+ * @return The string value of the token. Returns null if nothing is
+ * found up to the separater.
*/
private String parseTokenValue() {
@@ -454,51 +476,52 @@
while (hasMore()) {
char ch = currentChar();
switch (ch) {
- // process the token separators.
- case ' ':
- case '\t':
- case '(':
- case ')':
- case '<':
- case '>':
- case '@':
- case ',':
- case ';':
- case ':':
- case '\\':
- case '"':
- case '/':
- case '[':
- case ']':
- case '?':
- case '=':
- case '{':
- case '}':
- // no token characters found? this is bad.
+ // process the token separators.
+ case ' ':
+ case '\t':
+ case '(':
+ case ')':
+ case '<':
+ case '>':
+ case '@':
+ case ',':
+ case ';':
+ case ':':
+ case '\\':
+ case '"':
+ case '/':
+ case '[':
+ case ']':
+ case '?':
+ case '=':
+ case '{':
+ case '}':
+ // no token characters found? this is bad.
+ if (value.length() == 0) {
+ return null;
+ }
+ // return the accumulated characters.
+ return value.toString();
+
+ default:
+ // is this a control character? That's a delimiter (likely
+ // invalid for the next step,
+ // but it is a token terminator.
+ if (ch < 32 || ch > 127) {
+ // no token characters found? this is bad.
if (value.length() == 0) {
return null;
}
// return the accumulated characters.
return value.toString();
-
- default:
- // is this a control character? That's a delimiter (likely invalid for the next step,
- // but it is a token terminator.
- if (ch < 32 || ch > 127) {
- // no token characters found? this is bad.
- if (value.length() == 0) {
- return null;
- }
- // return the accumulated characters.
- return value.toString();
- }
- value.append(ch);
- break;
+ }
+ value.append(ch);
+ break;
}
// step to the next character.
nextChar();
}
- // no token characters found? this is bad.
+ // no token characters found? this is bad.
if (value.length() == 0) {
return null;
}
@@ -506,10 +529,9 @@
return value.toString();
}
-
/**
* Parse out a name token of a name/value pair.
- *
+ *
* @return The string value of the name.
*/
private String parseName() {
@@ -520,10 +542,9 @@
return parseTokenValue();
}
-
/**
* Parse out a a value of a name/value pair.
- *
+ *
* @return The string value associated with the name.
*/
private String parseValue() {
@@ -539,12 +560,10 @@
return parseTokenValue();
}
-
/**
* Parse a name/value pair in an DIGEST-MD5 string.
- *
- * @return A NameValuePair object containing the two parts of the
- * value.
+ *
+ * @return A NameValuePair object containing the two parts of the value.
* @exception MessagingException
*/
public NameValuePair parseNameValuePair() throws MessagingException {
@@ -568,14 +587,16 @@
throw new MessagingException("Name/value pair syntax error");
}
- // skip forward to the terminator, which should either be the end of the line or a ","
+ // skip forward to the terminator, which should either be the end of
+ // the line or a ","
skipSpaces();
// all that work, only to have a syntax error at the end (sigh)
if (hasMore()) {
if (currentChar() != ',') {
throw new MessagingException("Name/value pair syntax error");
}
- // step over, and make sure we position ourselves at either the end or the first
+ // step over, and make sure we position ourselves at either the
+ // end or the first
// real character for parsing the next name/value pair.
nextChar();
skipSpaces();
@@ -589,6 +610,7 @@
*/
public class NameValuePair {
public String name;
+
public String value;
NameValuePair(String name, String value) {
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/LoginAuthenticator.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/LoginAuthenticator.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/LoginAuthenticator.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/LoginAuthenticator.java Fri Mar 31 14:24:52 2006
@@ -21,17 +21,18 @@
import javax.mail.MessagingException;
-import org.apache.geronimo.mail.util.Base64;
-
public class LoginAuthenticator implements ClientAuthenticator {
// constants for the authentication stages
protected static final int USERNAME = 0;
+
protected static final int PASSWORD = 1;
+
protected static final int COMPLETE = 2;
// the user we're authenticating
protected String username;
+
// the user's password (the "shared secret")
protected String password;
@@ -40,9 +41,11 @@
/**
* Main constructor.
- *
- * @param username The login user name.
- * @param password The login password.
+ *
+ * @param username
+ * The login user name.
+ * @param password
+ * The login password.
*/
public LoginAuthenticator(String username, String password) {
this.username = username;
@@ -50,9 +53,9 @@
}
/**
- * Respond to the hasInitialResponse query. This mechanism
- * does not have an initial response.
- *
+ * Respond to the hasInitialResponse query. This mechanism does not have an
+ * initial response.
+ *
* @return Always returns false;
*/
public boolean hasInitialResponse() {
@@ -61,7 +64,7 @@
/**
* Indicate whether the challenge/response process is complete.
- *
+ *
* @return True if the last challenge has been processed, false otherwise.
*/
public boolean isComplete() {
@@ -70,20 +73,20 @@
/**
* Retrieve the authenticator mechanism name.
- *
+ *
* @return Always returns the string "LOGIN"
*/
public String getMechanismName() {
return "LOGIN";
}
-
/**
- * Evaluate a PLAIN login challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as a byte array
- *
+ * Evaluate a PLAIN login challenge, returning the a result string that
+ * should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as a byte array
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
@@ -91,44 +94,45 @@
// process the correct stage for the challenge
switch (stage) {
- // should never happen
- case COMPLETE:
- throw new MessagingException("Invalid LOGIN challenge");
-
- case USERNAME: {
- byte[] userBytes;
-
- try {
- // get the username and password in an UTF-8 encoding to create the token
- userBytes = username.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- // got an error, fail this (this should never happen).
- throw new MessagingException("Invalid encoding");
- }
-
- // next time through we're looking for a password.
- stage = PASSWORD;
- // the user bytes are the entire challenge respose.
- return userBytes;
+ // should never happen
+ case COMPLETE:
+ throw new MessagingException("Invalid LOGIN challenge");
+
+ case USERNAME: {
+ byte[] userBytes;
+
+ try {
+ // get the username and password in an UTF-8 encoding to create
+ // the token
+ userBytes = username.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // got an error, fail this (this should never happen).
+ throw new MessagingException("Invalid encoding");
}
- case PASSWORD: {
- byte[] passBytes;
+ // next time through we're looking for a password.
+ stage = PASSWORD;
+ // the user bytes are the entire challenge respose.
+ return userBytes;
+ }
+
+ case PASSWORD: {
+ byte[] passBytes;
- try {
- // get the username and password in an UTF-8 encoding to create the token
- passBytes = password.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- // got an error, fail this (this should never happen).
- throw new MessagingException("Invalid encoding");
- }
- // we're finished
- stage = COMPLETE;
- return passBytes;
+ try {
+ // get the username and password in an UTF-8 encoding to create
+ // the token
+ passBytes = password.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // got an error, fail this (this should never happen).
+ throw new MessagingException("Invalid encoding");
}
+ // we're finished
+ stage = COMPLETE;
+ return passBytes;
+ }
}
// should never get here.
throw new MessagingException("Invalid LOGIN challenge");
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/PlainAuthenticator.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/PlainAuthenticator.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/PlainAuthenticator.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/authentication/PlainAuthenticator.java Fri Mar 31 14:24:52 2006
@@ -21,12 +21,11 @@
import javax.mail.MessagingException;
-import org.apache.geronimo.mail.util.Base64;
-
public class PlainAuthenticator implements ClientAuthenticator {
// the user we're authenticating
protected String username;
+
// the user's password (the "shared secret")
protected String password;
@@ -35,9 +34,11 @@
/**
* Main constructor.
- *
- * @param username The login user name.
- * @param password The login password.
+ *
+ * @param username
+ * The login user name.
+ * @param password
+ * The login password.
*/
public PlainAuthenticator(String username, String password) {
this.username = username;
@@ -45,9 +46,9 @@
}
/**
- * Respond to the hasInitialResponse query. This mechanism
- * does have an initial response, which is the entire challenge sequence.
- *
+ * Respond to the hasInitialResponse query. This mechanism does have an
+ * initial response, which is the entire challenge sequence.
+ *
* @return Always returns true.
*/
public boolean hasInitialResponse() {
@@ -56,7 +57,7 @@
/**
* Indicate whether the challenge/response process is complete.
- *
+ *
* @return True if the last challenge has been processed, false otherwise.
*/
public boolean isComplete() {
@@ -65,30 +66,32 @@
/**
* Retrieve the authenticator mechanism name.
- *
+ *
* @return Always returns the string "PLAIN"
*/
public String getMechanismName() {
return "PLAIN";
}
-
/**
- * Evaluate a PLAIN login challenge, returning the a result
- * string that should satisfy the clallenge.
- *
- * @param challenge The decoded challenge data, as byte array.
- *
+ * Evaluate a PLAIN login challenge, returning the a result string that
+ * should satisfy the clallenge.
+ *
+ * @param challenge
+ * The decoded challenge data, as byte array.
+ *
* @return A formatted challege response, as an array of bytes.
* @exception MessagingException
*/
public byte[] evaluateChallenge(byte[] challenge) throws MessagingException {
try {
- // get the username and password in an UTF-8 encoding to create the token
+ // get the username and password in an UTF-8 encoding to create the
+ // token
byte[] userBytes = username.getBytes("UTF-8");
byte[] passBytes = password.getBytes("UTF-8");
- // our token has two copies of the username, one copy of the password, and nulls
+ // our token has two copies of the username, one copy of the
+ // password, and nulls
// between
byte[] tokenBytes = new byte[(userBytes.length * 2) + passBytes.length + 2];
@@ -105,5 +108,3 @@
}
}
}
-
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPFolder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPFolder.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPFolder.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPFolder.java Fri Mar 31 14:24:52 2006
@@ -17,9 +17,6 @@
package org.apache.geronimo.javamail.store.nntp;
-import java.util.Vector;
-
-import javax.mail.FetchProfile;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.IllegalWriteException;
@@ -27,365 +24,382 @@
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;
/**
- * 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 NNTPFolder extends Folder {
// our active connection.
protected NNTPConnection connection;
+
// our attached session
protected Session session;
- // the name of this folder (either the name of the server for the root or the news group name).
+
+ // the name of this folder (either the name of the server for the root or
+ // the news group name).
protected String name;
- // the "full" name of the folder. For the root folder, this is the name returned by the connection
- // welcome string. Otherwise, this is the same as the name.
+
+ // the "full" name of the folder. For the root folder, this is the name
+ // returned by the connection
+ // welcome string. Otherwise, this is the same as the name.
protected String fullName;
- // the parent folder. For the root folder, this is null. For a group folder, this is the root.
+
+ // the parent folder. For the root folder, this is null. For a group folder,
+ // this is the root.
protected Folder parent;
+
// the folder open state
- protected boolean folderOpen = false;
- // the folder message count. For the root folder, this is always 0.
+ protected boolean folderOpen = false;
+
+ // the folder message count. For the root folder, this is always 0.
protected int messageCount = 0;
+
// the persistent flags we save in the store (basically just the SEEN flag).
protected Flags permanentFlags;
-
/**
* Super class constructor the base NNTPFolder class.
- *
- * @param store The javamail store this folder is attached to.
- */
- protected NNTPFolder(NNTPStore store) {
- super(store);
- // get the active connection from the store...all commands are sent there
- this.connection = store.getConnection();
- this.session = store.getSession();
+ *
+ * @param store
+ * The javamail store this folder is attached to.
+ */
+ protected NNTPFolder(NNTPStore store) {
+ super(store);
+ // get the active connection from the store...all commands are sent
+ // there
+ this.connection = store.getConnection();
+ this.session = store.getSession();
// set up our permanent flags bit.
permanentFlags = new Flags();
permanentFlags.add(Flags.Flag.SEEN);
- }
+ }
/**
* Retrieve the folder name.
- *
+ *
* @return The folder's name.
*/
- public String getName() {
+ public String getName() {
return name;
- }
+ }
/**
- * Retrieve the folder's full name (including hierarchy information).
- * NNTP folders are flat, so the full name is generally the same
- * as the name.
- *
+ * Retrieve the folder's full name (including hierarchy information). NNTP
+ * folders are flat, so the full name is generally the same as the name.
+ *
* @return The full name value.
*/
- public String getFullName() {
+ public String getFullName() {
return fullName;
- }
+ }
- /**
- * Returns the parent folder for this folder. Returns null if this is the
+ /**
+ * Returns the parent folder for this folder. Returns null if this is the
* root folder.
- */
- public Folder getParent() throws MessagingException {
+ */
+ public Folder getParent() throws MessagingException {
return parent;
- }
+ }
/**
- * Indicated whether the folder "exists" or not. Existance in this
- * context indicates that the group still exists on the server.
- *
+ * Indicated whether the folder "exists" or not. Existance in this context
+ * indicates that the group still exists on the server.
+ *
* @return
* @exception MessagingException
*/
- public boolean exists() throws MessagingException {
- // by default, return true. This is really only the case for the root. The group folder will
+ public boolean exists() throws MessagingException {
+ // by default, return true. This is really only the case for the root.
+ // The group folder will
// need to override this.
- return true;
- }
-
+ return true;
+ }
/**
- * 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 Folder[] list(String pattern) throws MessagingException {
- throw new MethodNotSupportedException("NNTP group folders cannot contain sub folders");
- }
+ public Folder[] list(String pattern) throws MessagingException {
+ throw new MethodNotSupportedException("NNTP group folders cannot contain sub folders");
+ }
/**
- * 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 {
- throw new MethodNotSupportedException("NNTP group folders cannot contain sub folders");
+ throw new MethodNotSupportedException("NNTP group folders cannot contain sub folders");
}
- /**
- * No sub folders, hence there is no notion of a seperator. We return a null character (consistent
- * with what Sun returns for POP3 folders).
- */
- public char getSeparator() throws MessagingException {
+ /**
+ * No sub folders, hence there is no notion of a seperator. We return a null
+ * character (consistent with what Sun returns for POP3 folders).
+ */
+ public char getSeparator() throws MessagingException {
return '\0';
- }
+ }
/**
- * 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 Either Folder.HOLDS_MESSAGES or Folder.HOLDS_FOLDERS.
* @exception MessagingException
*/
- public int getType() throws MessagingException {
- return HOLDS_MESSAGES;
- }
+ public int getType() throws MessagingException {
+ return HOLDS_MESSAGES;
+ }
/**
- * Create a new folder. NNTP folders are read only, so this is a nop.
- *
- * @param type The type of folder.
- *
+ * Create a new folder. NNTP folders are read only, so this is a nop.
+ *
+ * @param type
+ * The type of folder.
+ *
* @return Not support, throws an exception.
* @exception MessagingException
*/
- public boolean create(int type) throws MessagingException {
- throw new MethodNotSupportedException("Sub folders cannot be created in NNTP");
- }
+ public boolean create(int type) throws MessagingException {
+ throw new MethodNotSupportedException("Sub folders cannot be created in NNTP");
+ }
/**
- * Check for new messages. We always return false for the
- * root folder. The group folders will need to override.
- *
+ * Check for new messages. We always return false for the root folder. The
+ * group folders will need to override.
+ *
* @return Always returns false.
* @exception MessagingException
*/
- public boolean hasNewMessages() throws MessagingException {
+ public boolean hasNewMessages() throws MessagingException {
return false;
- }
+ }
/**
- * Get a named subfolder from this folder. This only has
- * meaning from the root NNTP folder.
- *
- * @param name The requested name.
- *
+ * Get a named subfolder from this folder. This only has meaning from the
+ * root NNTP folder.
+ *
+ * @param name
+ * The requested name.
+ *
* @return If the folder exists, returns a Folder object representing the
* named folder.
* @exception MessagingException
*/
- public Folder getFolder(String name) throws MessagingException {
- throw new MethodNotSupportedException("NNTP Group folders do not support sub folders");
- }
+ public Folder getFolder(String name) throws MessagingException {
+ throw new MethodNotSupportedException("NNTP Group folders do not support sub folders");
+ }
/**
- * Delete a folder. This is not supported for NNTP.
- *
- * @param recurse The recusion flag.
- *
+ * Delete a folder. This is not supported for NNTP.
+ *
+ * @param recurse
+ * The recusion flag.
+ *
* @return Never returns.
* @exception MessagingException
*/
- public boolean delete(boolean recurse) throws MessagingException {
- throw new MethodNotSupportedException("Deleting of NNTP folders is not supported");
- }
+ public boolean delete(boolean recurse) throws MessagingException {
+ throw new MethodNotSupportedException("Deleting of NNTP folders is not supported");
+ }
/**
- * Rename a folder. Not supported for NNTP folders.
- *
- * @param f The new folder specifying the rename location.
- *
+ * Rename a folder. Not supported for NNTP folders.
+ *
+ * @param f
+ * The new folder specifying the rename location.
+ *
* @return
* @exception MessagingException
*/
- public boolean renameTo(Folder f) throws MessagingException {
- throw new MethodNotSupportedException("Renaming of NNTP folders is not supported.");
- }
-
- /**
- * @see javax.mail.Folder#open(int)
- */
- public void open(int mode) throws MessagingException {
+ public boolean renameTo(Folder f) throws MessagingException {
+ throw new MethodNotSupportedException("Renaming of NNTP folders is not supported.");
+ }
- // we don't support READ_WRITE mode, so don't allow opening in that mode.
+ /**
+ * @see javax.mail.Folder#open(int)
+ */
+ public void open(int mode) throws MessagingException {
+
+ // we don't support READ_WRITE mode, so don't allow opening in that
+ // mode.
if (mode == READ_WRITE) {
throw new IllegalWriteException("Newsgroup folders cannot be opened read/write");
}
+ // an only be performed on a closed folder
+ checkClosed();
- // an only be performed on a closed folder
- checkClosed();
-
- this.mode = mode;
+ this.mode = mode;
// perform folder type-specific open actions.
openFolder();
folderOpen = true;
- notifyConnectionListeners(ConnectionEvent.OPENED);
- }
+ notifyConnectionListeners(ConnectionEvent.OPENED);
+ }
/**
- * Perform folder type-specific open actions. The default
- * action is to do nothing.
- *
+ * Perform folder type-specific open actions. The default action is to do
+ * nothing.
+ *
* @exception MessagingException
*/
- protected void openFolder() throws MessagingException {}
+ protected void openFolder() throws MessagingException {
+ }
/**
- * Peform folder type-specific close actions. The default action
- * is to do nothing.
- *
+ * Peform folder type-specific close actions. The default action is to do
+ * nothing.
+ *
* @exception MessagingException
*/
- protected void closeFolder() throws MessagingException {}
+ protected void closeFolder() throws MessagingException {
+ }
/**
- * Close the folder. Cleans up resources, potentially expunges
- * messages marked for deletion, and sends an event notification.
- *
- * @param expunge The expunge flag, which is ignored for NNTP folders.
- *
+ * Close the folder. Cleans up resources, potentially expunges messages
+ * marked for deletion, and sends an event notification.
+ *
+ * @param expunge
+ * The expunge flag, which is ignored for NNTP folders.
+ *
* @exception MessagingException
*/
- public void close(boolean expunge) throws MessagingException {
- // Can only be performed on an open folder
- checkOpen();
+ public void close(boolean expunge) throws MessagingException {
+ // Can only be performed on an open folder
+ checkOpen();
// give the subclasses an opportunity to do some cleanup
closeFolder();
- folderOpen = false;
- notifyConnectionListeners(ConnectionEvent.CLOSED);
- }
+ folderOpen = false;
+ notifyConnectionListeners(ConnectionEvent.CLOSED);
+ }
/**
* Tests the open status of the folder.
- *
+ *
* @return true if the folder is open, false otherwise.
*/
- public boolean isOpen() {
- return folderOpen;
- }
+ public boolean isOpen() {
+ return folderOpen;
+ }
/**
* Get the permanentFlags
- *
+ *
* @return The set of permanent flags we support (only SEEN).
*/
- public Flags getPermanentFlags() {
+ public Flags getPermanentFlags() {
// we need a copy of our master set.
- return new Flags(permanentFlags);
- }
+ return new Flags(permanentFlags);
+ }
/**
* Get the count of messages in this folder.
- *
+ *
* @return The message count.
* @exception MessagingException
*/
- public int getMessageCount() throws MessagingException {
- return messageCount;
- }
-
- /**
- * Checks wether the message is in cache, if not
- * will create a new message object and return it.
- * @see javax.mail.Folder#getMessage(int)
- */
- public Message getMessage(int msgNum) throws MessagingException {
+ public int getMessageCount() throws MessagingException {
+ return messageCount;
+ }
+
+ /**
+ * Checks wether the message is in cache, if not will create a new message
+ * object and return it.
+ *
+ * @see javax.mail.Folder#getMessage(int)
+ */
+ public Message getMessage(int msgNum) throws MessagingException {
// for the base, we just throw an exception.
throw new MethodNotSupportedException("Root NNTP folder does not contain messages");
- }
+ }
/**
- * Append messages to a folder. NNTP folders are read only, so this
- * is not supported.
- *
- * @param msgs The list of messages to append.
- *
+ * Append messages to a folder. NNTP folders are read only, so this is not
+ * supported.
+ *
+ * @param msgs
+ * The list of messages to append.
+ *
* @exception MessagingException
*/
- public void appendMessages(Message[] msgs) throws MessagingException {
+ public void appendMessages(Message[] msgs) throws MessagingException {
throw new MethodNotSupportedException("Root NNTP folder does not contain messages");
- }
+ }
/**
- * Expunge messages marked for deletion and return a list of the
- * Messages. Not supported for NNTP.
- *
+ * Expunge messages marked for deletion and return a list of the Messages.
+ * Not supported for NNTP.
+ *
* @return Never returns.
* @exception MessagingException
*/
- public Message[] expunge() throws MessagingException {
+ public Message[] expunge() throws MessagingException {
throw new MethodNotSupportedException("Root NNTP folder does not contain messages");
- }
-
+ }
- /**
- * Below is a list of convenience methods that avoid repeated checking for a
- * value and throwing an exception
- */
+ /**
+ * Below is a list of convenience methods that avoid repeated checking for a
+ * value and throwing an exception
+ */
/** Ensure the folder is open */
protected void checkOpen() throws IllegalStateException {
- if (!folderOpen){
- throw new IllegalStateException("Folder is not Open");
- }
+ if (!folderOpen) {
+ throw new IllegalStateException("Folder is not Open");
+ }
}
/** Ensure the folder is not open */
protected void checkClosed() throws IllegalStateException {
- if (folderOpen){
- throw new IllegalStateException("Folder is Open");
- }
+ if (folderOpen) {
+ throw new IllegalStateException("Folder is Open");
+ }
}
/**
- * @see javax.mail.Folder#notifyMessageChangedListeners(int, javax.mail.Message)
- *
- * this method is protected and cannot be used outside of Folder, therefore had to
- * explicitly expose it via a method in NNTPFolder, so that NNTPMessage has access to it
- *
+ * @see javax.mail.Folder#notifyMessageChangedListeners(int,
+ * javax.mail.Message)
+ *
+ * this method is protected and cannot be used outside of Folder, therefore
+ * had to explicitly expose it via a method in NNTPFolder, so that
+ * NNTPMessage has access to it
+ *
* Bad design on the part of the Java Mail API.
*/
public void notifyMessageChangedListeners(int type, Message m) {
- super.notifyMessageChangedListeners(type, m);
+ super.notifyMessageChangedListeners(type, m);
}
-
/**
- * Retrieve the subscribed status for a folder. This default
- * implementation just returns false (which is true for the
- * root folder).
- *
+ * Retrieve the subscribed status for a folder. This default implementation
+ * just returns false (which is true for the root folder).
+ *
* @return Always returns true.
*/
public boolean isSubscribed() {
@@ -394,9 +408,10 @@
/**
* Set the subscribed status for a folder.
- *
- * @param flag The new subscribed status.
- *
+ *
+ * @param flag
+ * The new subscribed status.
+ *
* @exception MessagingException
*/
public void setSubscribed(boolean flag) throws MessagingException {
@@ -405,9 +420,10 @@
/**
* Test if a given article number is marked as SEEN.
- *
- * @param article The target article number.
- *
+ *
+ * @param article
+ * The target article number.
+ *
* @return The articles current seen status.
*/
public boolean isSeen(int article) {
@@ -416,10 +432,12 @@
/**
* Set the SEEN status for an article.
- *
- * @param article The target article.
- * @param flag The new seen setting.
- *
+ *
+ * @param article
+ * The target article.
+ * @param flag
+ * The new seen setting.
+ *
* @exception MessagingException
*/
public void setSeen(int article, boolean flag) throws MessagingException {
@@ -427,4 +445,3 @@
}
}
-
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPGroupFolder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPGroupFolder.java?rev=390524&r1=390523&r2=390524&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPGroupFolder.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/nntp/NNTPGroupFolder.java Fri Mar 31 14:24:52 2006
@@ -17,43 +17,36 @@
package org.apache.geronimo.javamail.store.nntp;
-import java.util.StringTokenizer;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.ArrayList;
import java.util.Map;
+import java.util.StringTokenizer;
import javax.mail.FetchProfile;
-import javax.mail.Flags;
-import javax.mail.Folder;
import javax.mail.FolderNotFoundException;
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.store.nntp.newsrc.NNTPNewsrcGroup;
-
-import org.apache.geronimo.javamail.transport.nntp.NNTPConnection;
import org.apache.geronimo.javamail.transport.nntp.NNTPReply;
/**
- * The NNTP implementation of the javax.mail.Folder
- * Note that only INBOX is supported in NNTP
+ * The NNTP implementation of the javax.mail.Folder Note that only INBOX is
+ * supported in NNTP
* <p>
* <url>http://www.faqs.org/rfcs/rfc1939.html</url>
* </p>
+ *
* @see javax.mail.Folder
- *
+ *
* @version $Rev$ $Date$
*/
public class NNTPGroupFolder extends NNTPFolder {
// holders for status information returned by the GROUP command.
protected int firstArticle = -1;
+
protected int lastArticle = -1;
// retrieved articles, mapped by article number.
@@ -64,48 +57,53 @@
/**
* Construct a "real" folder representing an NNTP news group.
- *
- * @param parent The parent root folder.
- * @param store The Store this folder is attached to.
- * @param name The folder name.
- * @param groupInfo The newsrc group information attached to the newsrc database. This
- * contains subscription and article "SEEN" information.
+ *
+ * @param parent
+ * The parent root folder.
+ * @param store
+ * The Store this folder is attached to.
+ * @param name
+ * The folder name.
+ * @param groupInfo
+ * The newsrc group information attached to the newsrc database.
+ * This contains subscription and article "SEEN" information.
*/
- protected NNTPGroupFolder(NNTPRootFolder parent, NNTPStore store, String name, NNTPNewsrcGroup groupInfo) {
- super(store);
+ protected NNTPGroupFolder(NNTPRootFolder parent, NNTPStore store, String name, NNTPNewsrcGroup groupInfo) {
+ super(store);
// the name and the full name are the same.
this.name = name;
this.fullName = name;
// set the parent appropriately.
this.parent = parent = parent;
this.groupInfo = groupInfo;
- }
+ }
/**
- * Ping the server and update the group count, first, and last
- * information.
- *
+ * Ping the server and update the group count, first, and last information.
+ *
* @exception MessagingException
*/
private void updateGroupStats() throws MessagingException {
- // ask the server for information about the group. This is a one-line reponse with status on
+ // ask the server for information about the group. This is a one-line
+ // reponse with status on
// the group, if it exists.
NNTPReply reply = connection.sendCommand("GROUP " + name);
// explicitly not there?
if (reply.getCode() == NNTPReply.NO_SUCH_NEWSGROUP) {
throw new FolderNotFoundException(this, "Folder does not exist on server: " + reply);
- }
- else if (reply.getCode() != NNTPReply.GROUP_SELECTED) {
+ } else if (reply.getCode() != NNTPReply.GROUP_SELECTED) {
throw new MessagingException("Error requesting group information: " + reply);
}
- // we've gotten back a good response, now parse out the group specifics from the
+ // we've gotten back a good response, now parse out the group specifics
+ // from the
// status response.
StringTokenizer tokenizer = new StringTokenizer(reply.getMessage());
- // we should have a least 3 tokens here, in the order "count first last".
+ // we should have a least 3 tokens here, in the order "count first
+ // last".
// article count
if (tokenizer.hasMoreTokens()) {
@@ -139,81 +137,82 @@
}
/**
- * Test to see if this folder actually exists. This pings the
- * server for information about the GROUP and updates the
- * article count and index information.
- *
+ * Test to see if this folder actually exists. This pings the server for
+ * information about the GROUP and updates the article count and index
+ * information.
+ *
* @return true if the newsgroup exists on the server, false otherwise.
* @exception MessagingException
*/
- public boolean exists() throws MessagingException {
+ public boolean exists() throws MessagingException {
try {
- // update the group statistics. If the folder doesn't exist, we'll get an exception that we
+ // update the group statistics. If the folder doesn't exist, we'll
+ // get an exception that we
// can turn into a false reply.
updateGroupStats();
// updated ok, so it must be there.
return true;
- } catch (FolderNotFoundException e ) {
+ } catch (FolderNotFoundException e) {
return false;
}
- }
+ }
/**
- * Ping the NNTP server to check if a newsgroup has any new
- * messages.
- *
+ * Ping the NNTP server to check if a newsgroup has any new messages.
+ *
* @return True if the server has new articles from the last time we
- * checked. Also returns true if this is the first time we've
+ * checked. Also returns true if this is the first time we've
* checked.
* @exception MessagingException
*/
- public boolean hasNewMessages() throws MessagingException {
+ public boolean hasNewMessages() throws MessagingException {
int oldLast = lastArticle;
updateGroupStats();
return lastArticle > oldLast;
- }
-
+ }
/**
- * Open the folder for use. This retrieves article count information
- * from the server.
- *
+ * Open the folder for use. This retrieves article count information from
+ * the server.
+ *
* @exception MessagingException
*/
- public void openFolder() throws MessagingException {
+ public void openFolder() throws MessagingException {
// update the group specifics, especially the message count.
updateGroupStats();
// get a cache for retrieve articles
articles = new HashMap();
- }
-
+ }
/**
* Close the folder, which also clears out the article caches.
- *
+ *
* @exception MessagingException
*/
- public void closeFolder() throws MessagingException {
- // get ride of any retrieve articles, and flip over the open for business sign.
+ public void closeFolder() throws MessagingException {
+ // get ride of any retrieve articles, and flip over the open for
+ // business sign.
articles = null;
- }
+ }
- /**
- * Checks wether the message is in cache, if not
- * will create a new message object and return it.
- * @see javax.mail.Folder#getMessage(int)
- */
- public Message getMessage(int msgNum) throws MessagingException {
- // Can only be performed on an Open folder
- checkOpen();
+ /**
+ * Checks wether the message is in cache, if not will create a new message
+ * object and return it.
+ *
+ * @see javax.mail.Folder#getMessage(int)
+ */
+ public Message getMessage(int msgNum) throws MessagingException {
+ // Can only be performed on an Open folder
+ checkOpen();
- // get an object form to look up in the retrieve messages list (oh how I wish there was
+ // get an object form to look up in the retrieve messages list (oh how I
+ // wish there was
// something like Map that could use integer keys directly!).
Integer key = new Integer(msgNum);
- NNTPMessage message = (NNTPMessage)articles.get(key);
+ NNTPMessage message = (NNTPMessage) articles.get(key);
if (message != null) {
// piece of cake!
return message;
@@ -223,7 +222,8 @@
// but first, make sure the group is still valid.
updateGroupStats();
- // just send a STAT command to this message. Right now, all we want is existance proof. We'll
+ // just send a STAT command to this message. Right now, all we want is
+ // existance proof. We'll
// retrieve the other bits when requested.
NNTPReply reply = connection.sendCommand("STAT " + Integer.toString(msgNum));
if (reply.getCode() != NNTPReply.REQUEST_TEXT_SEPARATELY) {
@@ -236,24 +236,26 @@
int idStart = response.indexOf('<');
int idEnd = response.indexOf('>');
- message = new NNTPMessage(this, (NNTPStore)store, msgNum, response.substring(idStart + 1, idEnd));
+ message = new NNTPMessage(this, (NNTPStore) store, msgNum, response.substring(idStart + 1, idEnd));
// add this to the article cache.
articles.put(key, message);
return message;
- }
-
+ }
/**
* Retrieve all articles in the group.
- *
+ *
* @return An array of all messages in the group.
*/
public Message[] getMessages() throws MessagingException {
- // we're going to try first with XHDR, which will allow us to retrieve everything in one shot. If that
- // fails, we'll fall back on issing STAT commands for the entire article range.
- NNTPReply reply = connection.sendCommand("XHDR Message-ID " + Integer.toString(firstArticle) + "-" + Integer.toString(lastArticle), NNTPReply.HEAD_FOLLOWS);
+ // we're going to try first with XHDR, which will allow us to retrieve
+ // everything in one shot. If that
+ // fails, we'll fall back on issing STAT commands for the entire article
+ // range.
+ NNTPReply reply = connection.sendCommand("XHDR Message-ID " + Integer.toString(firstArticle) + "-"
+ + Integer.toString(lastArticle), NNTPReply.HEAD_FOLLOWS);
List messages = new ArrayList();
@@ -261,17 +263,17 @@
List lines = reply.getData();
for (int i = 0; i < lines.size(); i++) {
- String line = (String)lines.get(i);
+ String line = (String) lines.get(i);
try {
int pos = line.indexOf(' ');
int articleID = Integer.parseInt(line.substring(0, pos));
String messageID = line.substring(pos + 1);
Integer key = new Integer(articleID);
- // see if we have this message cached, If not, create it.
- Message message = (Message)articles.get(key);
+ // see if we have this message cached, If not, create it.
+ Message message = (Message) articles.get(key);
if (message == null) {
- message = new NNTPMessage(this, (NNTPStore)store, key.intValue(), messageID);
+ message = new NNTPMessage(this, (NNTPStore) store, key.intValue(), messageID);
articles.put(key, message);
}
@@ -281,61 +283,61 @@
// should never happen, but just skip this entry if it does.
}
}
- }
- else {
- // grumble, we need to stat each article id to see if it exists....lots of round trips.
+ } else {
+ // grumble, we need to stat each article id to see if it
+ // exists....lots of round trips.
for (int i = firstArticle; i <= lastArticle; i++) {
try {
messages.add(getMessage(i));
} catch (MessagingException e) {
- // just assume if there is an error, it's because the message id doesn't exist.
+ // just assume if there is an error, it's because the
+ // message id doesn't exist.
}
}
}
- return (Message[])messages.toArray(new Message[0]);
+ return (Message[]) messages.toArray(new Message[0]);
}
- /**
- * @see javax.mail.Folder#fetch(javax.mail.Message[], javax.mail.FetchProfile)
- *
- * The JavaMail API recommends that this method be overrident to provide a meaningfull
- * implementation.
- */
- public void fetch(Message[] msgs, FetchProfile fp) throws MessagingException {
- // Can only be performed on an Open folder
- checkOpen();
-
- for (int i=0; i < msgs.length;i++)
- {
- Message msg = msgs[i];
+ /**
+ * @see javax.mail.Folder#fetch(javax.mail.Message[],
+ * javax.mail.FetchProfile)
+ *
+ * The JavaMail API recommends that this method be overrident to provide a
+ * meaningfull implementation.
+ */
+ public void fetch(Message[] msgs, FetchProfile fp) throws MessagingException {
+ // Can only be performed on an Open folder
+ checkOpen();
+
+ for (int i = 0; i < msgs.length; i++) {
+ Message msg = msgs[i];
// we can only perform this operation for NNTPMessages.
- if (msg == null || !(msg instanceof NNTPMessage)) {
+ if (msg == null || !(msg instanceof NNTPMessage)) {
// we can't fetch if it's the wrong message type
continue;
- }
+ }
// fetching both the headers and body?
if (fp.contains(FetchProfile.Item.ENVELOPE) && fp.contains(FetchProfile.Item.CONTENT_INFO)) {
// retrive everything
- ((NNTPMessage)msg).loadArticle();
+ ((NNTPMessage) msg).loadArticle();
}
// headers only?
else if (fp.contains(FetchProfile.Item.ENVELOPE)) {
- ((NNTPMessage)msg).loadHeaders();
+ ((NNTPMessage) msg).loadHeaders();
+ } else if (fp.contains(FetchProfile.Item.CONTENT_INFO)) {
+ ((NNTPMessage) msg).loadContent();
}
- else if(fp.contains(FetchProfile.Item.CONTENT_INFO)) {
- ((NNTPMessage)msg).loadContent();
- }
- }
- }
-
+ }
+ }
/**
* Return the subscription status of this folder.
- *
- * @return true if the folder is marked as subscribed, false for unsubscribed.
+ *
+ * @return true if the folder is marked as subscribed, false for
+ * unsubscribed.
*/
public boolean isSubscribed() {
return groupInfo.isSubscribed();
@@ -343,8 +345,9 @@
/**
* Set or clear the subscription status of a file.
- *
- * @param flag The new subscription state.
+ *
+ * @param flag
+ * The new subscription state.
*/
public void setSubscribed(boolean flag) {
groupInfo.setSubscribed(flag);
@@ -352,11 +355,12 @@
/**
* Return the "seen" state for an article in a folder.
- *
- * @param article The article number.
- *
- * @return true if the article is marked as seen in the newsrc file, false for
- * unseen files.
+ *
+ * @param article
+ * The article number.
+ *
+ * @return true if the article is marked as seen in the newsrc file, false
+ * for unseen files.
*/
public boolean isSeen(int article) {
return groupInfo.isArticleSeen(article);
@@ -364,15 +368,16 @@
/**
* Set the seen state for an article in a folder.
- *
- * @param article The article number.
- * @param flag The new seen state.
+ *
+ * @param article
+ * The article number.
+ * @param flag
+ * The new seen state.
*/
public void setSeen(int article, boolean flag) {
if (flag) {
groupInfo.markArticleSeen(article);
- }
- else {
+ } else {
groupInfo.markArticleUnseen(article);
}
}