(no subject)



Hi all,

In libbalsa/pop3.c responses from the pop server are case-sensitive.
this is correct according to RFC 1939, however RFC 1737 which it obsoletes
is silent on the case of server responses.

The following patch changes a number of case sensitive comparisons for the
insenstive counterparts.  This may help to ensure that balsa works with
older RFC 1737 pop servers which might reply in lower case, i.e. "+ok ...".
The change is harmless for modern servers.

To avoid problems with sscanf on server responses, code like
'sscanf (buffer, "+OK ...' is changed to sscanf (buffer + 3, ' ...'

The patch also adds a (size_t) cast to avoid a compiler warning.

Regards
Brian
--- pop3.c.orig	Tue Aug 28 14:37:04 2001
+++ pop3.c	Tue Aug 28 14:27:37 2001
@@ -259,7 +259,7 @@
     char buffer[2048];
     
     if (getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
-    if (strncmp (buffer, "+OK", 3) != 0)            return POP_COMMAND_ERR;
+    if (strncasecmp (buffer, "+OK", 3) != 0)        return POP_COMMAND_ERR;
     
     DM("pop_auth %s %s %d", pop_user, "(password hidden)", use_apop);
     /* handle apop secret transmission, if needed -kabir */
@@ -277,7 +277,7 @@
 	write (s, buffer, strlen (buffer));
 	
 	if (getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
-	if (strncmp (buffer, "+OK", 3) != 0)            return POP_COMMAND_ERR;
+	if (strncasecmp (buffer, "+OK", 3) != 0)        return POP_COMMAND_ERR;
 	
 	snprintf (buffer, sizeof(buffer), "pass %s\r\n", pop_pass);
 	DM("POP3 C: 'pass (password hidden)'");
@@ -285,7 +285,7 @@
     } 
   
     if (getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
-    if (strncmp (buffer, "+OK", 3) != 0)            return POP_AUTH_FAILED;
+    if (strncasecmp (buffer, "+OK", 3) != 0)        return POP_AUTH_FAILED;
     return POP_OK;
 }
 
@@ -302,9 +302,9 @@
     write(s, "stat\r\n", 6);
     
     if (getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
-    if (strncmp (buffer, "+OK", 3) != 0)            return POP_COMMAND_ERR;
+    if (strncasecmp (buffer, "+OK", 3) != 0)        return POP_COMMAND_ERR;
     
-    if( sscanf (buffer, "+OK %d %d", msgs, &bytes) < 2 ) {
+    if( sscanf (buffer + 3, " %d %d", msgs, &bytes) < 2 ) {
 	
     }
     
@@ -326,20 +326,20 @@
 	    
 	    if(getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
 	    
-	    if (strncmp (buffer, "+OK", 3) != 0) {
+	    if (strncasecmp (buffer, "+OK", 3) != 0) {
 	        /* Check if "last" cmd is supported */
 	        write (s, "last\r\n", 6);
 		if(getLine (s, buffer, sizeof (buffer)) == -1)
 		    return POP_CONN_ERR;
-		if (strncmp (buffer, "+OK", 3) == 0) {       
-		    sscanf (buffer, "+OK %d", first_msg);
+		if (strncasecmp (buffer, "+OK", 3) == 0) {       
+		    sscanf (buffer + 3, " %d", first_msg);
 		    (*first_msg)++; /* fix the off-by-one msg index  */
 		    break;
 		} 
 		/* none of uidl or last recognised, fail.. */
 		return POP_COMMAND_ERR;
 	    }
-	    sscanf( buffer, "+OK %d %s", &tmp, uid);
+	    sscanf( buffer + 3, " %d %s", &tmp, uid);
 	    
 	    if(i == *msgs) {
 		strcpy(last_uid, uid); /* save uid of the last message */
@@ -369,7 +369,7 @@
 	write (s, buffer, strlen(buffer));
 	if ( getLine (s, buffer, sizeof(buffer)) == -1) return POP_CONN_ERR;
     
-	if (sscanf (buffer,"+OK %d %d",&i,&num_bytes) != 2) {
+	if (sscanf (buffer + 3," %d %d",&i,&num_bytes) != 2) {
 	    DM( "Error on list message %d encountered", i );
 	    *tot_bytes=-1;
 	    break;
@@ -387,7 +387,7 @@
     DM("POP3 C: '%s'", buffer);
     if(write (s, buffer, strlen (buffer)) == -1) return POP_CONN_ERR;
     if (getLine (s, buffer, bufsz) == -1)        return POP_CONN_ERR;
-    if (strncmp (buffer, "+OK", 3) != 0)         return POP_COMMAND_ERR;
+    if (strncasecmp (buffer, "+OK", 3) != 0)     return POP_COMMAND_ERR;
     return POP_OK;
 }
 
@@ -447,7 +447,8 @@
 	    p = buffer;
 	
 	/* fwrite(p, 1, chunk, stdout); */
-	if(fwrite (p, 1, (size_t)chunk, msg) != chunk) return POP_WRITE_ERR;
+	if(fwrite (p, 1, (size_t) chunk, msg) != (size_t) chunk)
+            return POP_WRITE_ERR;
     } /* end of while */
     
     DM("POP3: Message %d retrieved", msgno);
@@ -466,7 +467,7 @@
 	    
     /* eat the server response */
     if(getLine (s, buffer, sizeof (buffer)) == -1) return POP_CONN_ERR;
-    if (strncmp (buffer, "+OK", 3) != 0)           return POP_COMMAND_ERR;
+    if (strncasecmp (buffer, "+OK", 3) != 0)       return POP_COMMAND_ERR;
     return POP_OK;
 }
 


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