classpathx-javamail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Classpathx-javamail] POP3Connection.java patch updated to handle -ERR r


From: Doug Porter
Subject: [Classpathx-javamail] POP3Connection.java patch updated to handle -ERR response to APOP
Date: Sun, 07 Sep 2003 12:56:22 -0800

diff -r
/usr/src/CVS/classpathx/mail/source/gnu/mail/providers/pop3/POP3Connection.java
/usr/src/tiger-0.5.2-test/thirdparty/classpathx-javamail-customized/mail/source/gnu/mail/providers/pop3/POP3Connection.java
34a35,37
> import java.util.Date;
> import java.util.TimeZone;
> import java.text.SimpleDateFormat;
99a103,110
>   
>     /**
>      * Concurrency debugging support
>      */
>     static int instanceCount = 0;
>     int instanceIndex = 0;
>     final boolean DEBUG_SHOW_TIMESTAMP = true;
>     final boolean DEBUG_SHOW_INSTANCES = true;
116a128,129
>     ++instanceCount;
>     instanceIndex = instanceCount;
153,170c166,168
<               if (username==null)
<                       return false;
<               String cmd;
<               if (timestamp!=null)
<               {
<                       // APOP <username> <digest>
<                       try
<                       {
<         byte[] secret = password.getBytes("US-ASCII");
<         // compute digest
<         byte[] target = new byte[timestamp.length + secret.length];
<         System.arraycopy(timestamp, 0, target, 0, timestamp.length);
<         System.arraycopy(secret, 0, target, timestamp.length,
secret.length);
<                               MessageDigest md5 =
MessageDigest.getInstance("MD5");
<                               byte[] db = md5.digest(target);
<         // create hexadecimal representation
<                               StringBuffer digest = new StringBuffer();
<         for (int i=0; i<db.length; i++)
---
>         boolean authenticated = false;
>         String cmd;
>               if (username != null)
172,175c170,206
<           int c = (int)db[i];
<           if (c<0)
<             c += 256;
<           digest.append(Integer.toHexString(c));
---
>             if (timestamp!=null)
>             {
>                 // APOP <username> <digest>
>                 try
>                 {
>                     byte[] secret = password.getBytes("US-ASCII");
>                     // compute digest
>                     byte[] target = new byte[timestamp.length + 
> secret.length];
>                     System.arraycopy(timestamp, 0, target, 0, 
> timestamp.length);
>                     System.arraycopy(secret, 0, target, timestamp.length, 
> secret.length);
>                             MessageDigest md5 = 
> MessageDigest.getInstance("MD5");
>                             byte[] db = md5.digest(target);
>                     // create hexadecimal representation
>                             StringBuffer digest = new StringBuffer();
>                     for (int i=0; i<db.length; i++)
>                     {
>                       int c = (int)db[i];
>                       if (c<0)
>                         c += 256;
>                       digest.append(Integer.toHexString(c));
>                     }
>                     // send command
>                     cmd = new StringBuffer(APOP)
>                         .append(' ')
>                         .append(username)
>                         .append(' ')
>                         .append(digest.toString())
>                         .toString();
>                     send(cmd);
>                     authenticated = getResponse();
>                 }
>                 catch (NoSuchAlgorithmException e)
>                 {
>                     System.err.println("MD5 algorithm not found, falling back 
> "+
>                             "to plain authentication");
>                 }
>             }
177,209c208,232
<                               // send command
<                               cmd = new StringBuffer(APOP)
<                                       .append(' ')
<                                       .append(username)
<                                       .append(' ')
<                                       .append(digest.toString())
<                                       .toString();
<                               send(cmd);
<                               return getResponse();
<                       }
<                       catch (NoSuchAlgorithmException e)
<                       {
<                               System.err.println("MD5 algorithm not
found, falling back "+
<                                               "to plain
authentication");
<                       }
<               }
<     if (password==null)
<       return false;
<               // USER <username>
<               cmd = new StringBuffer(USER)
<                       .append(' ')
<                       .append(username)
<                       .toString();
<               send(cmd);
<               if (!getResponse())
<                       return false;
<               // PASS <password>
<               cmd = new StringBuffer(PASS)
<                       .append(' ')
<                       .append(password)
<                       .toString();
<               send(cmd);
<               return getResponse();
---
>         
>         if (! authenticated)
>         {
>             if (password!=null)
>             {
>                 // USER <username>
>                 cmd = new StringBuffer(USER)
>                     .append(' ')
>                     .append(username)
>                     .toString();
>                 send(cmd);
>                 if (getResponse())
>                 {
>                 // PASS <password>
>                 cmd = new StringBuffer(PASS)
>                     .append(' ')
>                     .append(password)
>                     .toString();
>                 send(cmd);
>                 authenticated = getResponse();
>                 }
>             }
>         }
>         
>         return authenticated;
380c403
<       System.err.println("POP> "+command);
---
>       System.err.println(popDebugPrefix()+"> "+command);
396c419
<       System.err.println("POP< "+response);
---
>       System.err.println(popDebugPrefix()+"< "+response);
430a454,475
>   
>     private String popDebugPrefix () {
>         String prefix = "";
>         if (DEBUG_SHOW_TIMESTAMP) {
>             prefix += getDateTimeStamp () + " ";
>         }
>         prefix += "POP";
>         if (DEBUG_SHOW_INSTANCES &&
>             instanceIndex > 1) {
>             prefix += "[" + instanceIndex + "]";
>         }
>         return prefix;
>     }
>     
>     private String getDateTimeStamp () {
>         TimeZone gmt = TimeZone.getTimeZone ("GMT");
>         // DateFormat df = DateFormat.getDateTimeInstance ();
>         SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd 
> hh:mm:ss.SSS");
>         df.setTimeZone (gmt);
>         Date now = new Date ();
>         return df.format (now);
>     }
-- 
  Doug Porter
  address@hidden

-- 
http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]