james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From charl...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/util Base64.java
Date Mon, 25 Jun 2001 18:13:35 GMT
charlesb    01/06/25 11:13:34

  Modified:    src/java/org/apache/james/nntpserver/repository
                        ArticleIDRepository.java
               src/java/org/apache/james/smtpserver SMTPHandler.java
               src/java/org/apache/james/util Base64.java
  Log:
  Extend Base64 util, remove sun import from NNTP, fix 250 mesg in SMTP
  
  Revision  Changes    Path
  1.2       +15 -2     jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java
  
  Index: ArticleIDRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArticleIDRepository.java	2001/05/15 14:41:39	1.1
  +++ ArticleIDRepository.java	2001/06/25 18:13:15	1.2
  @@ -14,8 +14,9 @@
   import org.apache.avalon.excalibur.io.AndFileFilter;
   import org.apache.james.nntpserver.NNTPException;
   import org.apache.james.nntpserver.DateSinceFileFilter;
  -import sun.misc.BASE64Encoder;
  +import org.apache.james.util.Base64;
   
  +
   /** 
    * ArticleIDRepository: contains one file for each article.
    * the file name is Base64 encoded article ID
  @@ -35,15 +36,18 @@
           this.root = root;
           this.articleIDDomainSuffix = articleIDDomainSuffix;
       }
  +
       public File getPath() {
           return root;
       }
  +
       String generateArticleID() {
           int idx = Math.abs(counter++);
           String unique = Thread.currentThread().hashCode()+"."+
               System.currentTimeMillis()+"."+idx;
           return "<"+unique+"@"+articleIDDomainSuffix+">";
       }
  +
       /** @param prop contains the newsgroup name and article number */
       void addArticle(String articleID,Properties prop) throws IOException {
           if ( articleID == null )
  @@ -52,12 +56,21 @@
           prop.store(fout,new Date().toString());
           fout.close();
       }
  +
       File getFileFromID(String articleID) {
  -        return new File(root,new BASE64Encoder().encode(articleID.getBytes()));
  +        String b64Id;
  +        try {
  +            b64Id = Base64.encodeAsString(articleID);
  +        } catch (Exception e) {
  +            throw new RuntimeException("This shouldn't happen: " + e);
  +	}
  +        return new File(root, b64Id);
       }
  +
       boolean isExists(String articleID) {
           return ( articleID == null ) ? false : getFileFromID(articleID).exists();
       }
  +
       NNTPArticle getArticle(NNTPRepository repo,String id) throws IOException {
           File f = getFileFromID(id);
           if ( f.exists() == false )
  
  
  
  1.5       +9 -8      jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
  
  Index: SMTPHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SMTPHandler.java	2001/06/25 17:00:25	1.4
  +++ SMTPHandler.java	2001/06/25 18:13:19	1.5
  @@ -43,8 +43,8 @@
    * @author Jason Borden <jborden@javasense.com>
    * @author Matthew Pangaro <mattp@lokitech.com>
    *
  - * This is $Revision: 1.4 $
  - * Committed on $Date: 2001/06/25 17:00:25 $ by: $Author: charlesb $ 
  + * This is $Revision: 1.5 $
  + * Committed on $Date: 2001/06/25 18:13:19 $ by: $Author: charlesb $ 
    */
   public class SMTPHandler
       extends BaseConnectionHandler
  @@ -279,12 +279,13 @@
   	    if (authRequired) {
   	        out.println("250-AUTH LOGIN PLAIN");
               }
  +	    if (maxmessagesize > 0) {
  +	        out.println("250-SIZE " + maxmessagesize);
  +            }
               out.println( "250 " + state.get(SERVER_NAME) + " Hello "
                           + argument + " (" + state.get(REMOTE_NAME)
                           + " [" + state.get(REMOTE_IP) + "])");
  -	    if (maxmessagesize > 0) {
  -	        //    out.println("250 SIZE " + maxmessagesize);
  -            }
  +
   
           }
   
  @@ -309,7 +310,7 @@
               } else
                   userpass = argument1.trim();
               authTokenizer = new StringTokenizer(
  -                              Base64.decode(userpass).readLine().trim(), "\0");
  +                              Base64.decodeAsString(userpass), "\0");
               user = authTokenizer.nextToken();
               pass = authTokenizer.nextToken();
               // Authenticate user
  @@ -330,9 +331,9 @@
                   user = in.readLine().trim();
               } else
                   user = argument1.trim();
  -            user = Base64.decode(user).readLine().trim();
  +            user = Base64.decodeAsString(user);
               out.println("334 UGFzc3dvcmQ6"); // base64 encoded "Password:" 
  -            pass = Base64.decode(in.readLine().trim()).readLine().trim();
  +            pass = Base64.decodeAsString(in.readLine().trim());
               //Authenticate user
               if (users.test(user, pass)) {
                   state.put(AUTH, user);
  
  
  
  1.2       +36 -4     jakarta-james/src/java/org/apache/james/util/Base64.java
  
  Index: Base64.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/util/Base64.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Base64.java	2001/06/14 13:05:03	1.1
  +++ Base64.java	2001/06/25 18:13:27	1.2
  @@ -7,15 +7,20 @@
    */
   package org.apache.james.util;
   
  -import java.io.*;
  -import javax.mail.internet.*;
  +import java.io.BufferedReader;
  +import java.io.BufferedWriter;
  +import java.io.InputStreamReader;
  +import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
  +import javax.mail.internet.MimeUtility;
   
  +
   /**
    * Simple Base64 string decoding function
    * @author Jason Borden <jborden@javasense.com>
    *
  - * This is $Revision: 1.1 $
  - * Committed on $Date: 2001/06/14 13:05:03 $ by: $Author: charlesb $ 
  + * This is $Revision: 1.2 $
  + * Committed on $Date: 2001/06/25 18:13:27 $ by: $Author: charlesb $ 
    */
   
   public class Base64 {
  @@ -27,4 +32,31 @@
                               new ByteArrayInputStream(
                                   b64string.getBytes()), "base64")));
       }
  +
  +    public static String decodeAsString(String b64string) throws Exception {
  +        return  decode(b64string).readLine().trim();
  +    }
  +
  +    public static ByteArrayOutputStream encode(String plaintext)
  +            throws Exception {
  +	ByteArrayOutputStream out = new ByteArrayOutputStream();
  +	byte[] in = plaintext.getBytes();
  +	ByteArrayOutputStream inStream = new ByteArrayOutputStream();
  +	inStream.write(in, 0, in.length);
  +	// pad
  +	if ((in.length % 3 ) == 1){
  +            inStream.write(0);
  +            inStream.write(0);
  +	} else if((in.length % 3 ) == 2){
  +            inStream.write(0);
  +	}
  +	inStream.writeTo( MimeUtility.encode(out, "base64")  );
  +        return out;
  +    }
  +
  +    public static String encodeAsString(String plaintext) throws Exception {
  +        return  encode(plaintext).toString();
  +    }
  +
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message