]> diplodocus.org Git - nmh/blobdiff - uip/popsbr.c
Put parameter names in h/utils.h memory function prototypes.
[nmh] / uip / popsbr.c
index 638fa4116b7f4bce3fb8a1728760be3da89b6cf9..cf6b804223e5b77cbc998d7aac8a27aefa930b8f 100644 (file)
@@ -146,14 +146,6 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy,
     if (user)
        netsec_set_userid(nsc, user);
 
-    if (tls) {
-       if (netsec_set_tls(nsc, 1, &errstr) != OK) {
-           snprintf(response, sizeof(response), "%s", errstr);
-           free(errstr);
-           return NOTOK;
-       }
-    }
-
     if (oauth_svc != NULL) {
        if (netsec_set_oauth_service(nsc, oauth_svc) != OK) {
            snprintf(response, sizeof(response), "OAuth2 not supported");
@@ -222,6 +214,12 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy,
     netsec_set_snoop(nsc, snoop);
 
     if (tls) {
+       if (netsec_set_tls(nsc, 1, &errstr) != OK) {
+           snprintf(response, sizeof(response), "%s", errstr);
+           free(errstr);
+           return NOTOK;
+       }
+
        if (netsec_negotiate_tls(nsc, &errstr) != OK) {
            snprintf(response, sizeof(response), "%s", errstr);
            free(errstr);
@@ -349,6 +347,7 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
                rc = netsec_printf(nsc, errstr, "AUTH %s %s\r\n", mech,
                                   b64data);
                free(b64data);
+               netsec_set_snoop_callback(nsc, NULL, NULL);
                if (rc != OK)
                    return NOTOK;
                if (netsec_flush(nsc, errstr) != OK)
@@ -384,10 +383,12 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
            *outdata = NULL;
            *outdatalen = 0;
        } else {
-           rc = decodeBase64(line + 2, (const char **) outdata, &len, 0, NULL);
+           rc = decodeBase64(line + 2, outdata, &len, 0, NULL);
            *outdatalen = len;
-           if (rc != OK)
+           if (rc != OK) {
+               netsec_err(errstr, "Unable to decode base64 response");
                return NOTOK;
+           }
        }
        break;
 
@@ -413,8 +414,6 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
 
        if (netsec_flush(nsc, errstr) != OK)
            return NOTOK;
-
-       return OK;
        break;
 
     /*
@@ -449,7 +448,8 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
            return NOTOK;
        break;
     }
-return OK;
+
+    return OK;
 }
 
 /*
@@ -533,7 +533,7 @@ pop_retr (int msgno, int (*action)(char *))
 static int
 traverse (int (*action)(char *), const char *fmt, ...)
 {
-    int result;
+    int result, snoopstate;
     va_list ap;
     char buffer[sizeof(response)];
 
@@ -545,13 +545,18 @@ traverse (int (*action)(char *), const char *fmt, ...)
        return NOTOK;
     strncpy (buffer, response, sizeof(buffer));
 
+    if ((snoopstate = netsec_get_snoop(nsc)))
+       netsec_set_snoop(nsc, 0);
+
     for (;;)
        switch (multiline ()) {
            case NOTOK: 
+               netsec_set_snoop(nsc, snoopstate);
                return NOTOK;
 
            case DONE: 
                strncpy (response, buffer, sizeof(response));
+               netsec_set_snoop(nsc, snoopstate);
                return OK;
 
            case OK: 
@@ -721,7 +726,7 @@ pop_getline (char *s, int n, netsec_context *ns)
      * someday.
      */
 
-    destlen = len < ((size_t) (n - 1)) ? len : n - 1;
+    destlen = len < ((size_t) (n - 1)) ? len : (size_t) (n - 1);
 
     memcpy(s, p, destlen);
     s[destlen] = '\0';