more places to fix the new linebreak behaviour of the base64 encoder.
[citadel.git] / citadel / modules / imap / serv_imap.c
index d33e66ee65ef2ce885e7a4338b2bb5d0a317834c..278cc73323392b3883c08ff8ee58b75d1b8fa163 100644 (file)
@@ -677,7 +677,11 @@ void imap_authenticate(int num_parms, ConstStr *Params)
        }
 
        if (!strcasecmp(Params[2].Key, "LOGIN")) {
-               CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+               size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+               if (UsrBuf[len - 1] == '\n') {
+                       UsrBuf[len - 1] = '\0';
+               }
+
                IAPrintf("+ %s\r\n", UsrBuf);
                IMAP->authstate = imap_as_expecting_username;
                strcpy(IMAP->authseq, Params[0].Key);
@@ -685,7 +689,10 @@ void imap_authenticate(int num_parms, ConstStr *Params)
        }
 
        if (!strcasecmp(Params[2].Key, "PLAIN")) {
-               // CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+               // size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+               // if (UsrBuf[len - 1] == '\n') {
+               //   UsrBuf[len - 1] = '\0';
+               // }
                // IAPuts("+ %s\r\n", UsrBuf);
                IAPuts("+ \r\n");
                IMAP->authstate = imap_as_expecting_plainauth;
@@ -709,7 +716,8 @@ void imap_auth_plain(void)
        char pass[256] = "";
        int result;
        long decoded_len;
-       long len;
+       long len = 0;
+       long plen = 0;
 
        memset(pass, 0, sizeof(pass));
        decoded_len = StrBufDecodeBase64(Imap->Cmd.CmdBuf);
@@ -733,10 +741,10 @@ void imap_auth_plain(void)
 
                if (decoded_len > 0)
                {
-                       len = safestrncpy(pass, decoded_authstring, sizeof pass);
+                       plen = safestrncpy(pass, decoded_authstring, sizeof pass);
 
-                       if (len < 0)
-                               len = sizeof(pass) - 1;
+                       if (plen < 0)
+                               plen = sizeof(pass) - 1;
                }
        }
        Imap->authstate = imap_as_normal;
@@ -749,7 +757,7 @@ void imap_auth_plain(void)
        }
 
        if (result == login_ok) {
-               if (CtdlTryPassword(pass, len) == pass_ok) {
+               if (CtdlTryPassword(pass, plen) == pass_ok) {
                        IAPrintf("%s OK authentication succeeded\r\n", Imap->authseq);
                        return;
                }
@@ -767,7 +775,11 @@ void imap_auth_login_user(long state)
        case imap_as_expecting_username:
                StrBufDecodeBase64(Imap->Cmd.CmdBuf);
                CtdlLoginExistingUser(NULL, ChrPtr(Imap->Cmd.CmdBuf));
-               CtdlEncodeBase64(PWBuf, "Password:", 9, 0);
+               size_t len = CtdlEncodeBase64(PWBuf, "Password:", 9, 0);
+               if (PWBuf[len - 1] == '\n') {
+                       PWBuf[len - 1] = '\0';
+               }
+
                IAPrintf("+ %s\r\n", PWBuf);
                
                Imap->authstate = imap_as_expecting_password;
@@ -889,7 +901,7 @@ void imap_select(int num_parms, ConstStr *Params)
         * the number of messages and number of new messages.
         */
        memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
-       CtdlUserGoto(NULL, 0, 0, &msgs, &new);
+       CtdlUserGoto(NULL, 0, 0, &msgs, &new, NULL, NULL);
        Imap->selected = 1;
 
        if (!strcasecmp(Params[1].Key, "EXAMINE")) {
@@ -1195,7 +1207,7 @@ void imap_status(int num_parms, ConstStr *Params)
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
 
        /*
         * Tell the client what it wants to know.  In fact, tell it *more* than
@@ -1216,7 +1228,7 @@ void imap_status(int num_parms, ConstStr *Params)
         * our happy day without violent explosions.
         */
        if (IMAP->selected) {
-               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
        }
 
        /*
@@ -1254,14 +1266,14 @@ void imap_subscribe(int num_parms, ConstStr *Params)
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
 
        /*
         * If another folder is selected, go back to that room so we can resume
         * our happy day without violent explosions.
         */
        if (IMAP->selected) {
-               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
        }
 
        IReply("OK SUBSCRIBE completed");
@@ -1291,7 +1303,7 @@ void imap_unsubscribe(int num_parms, ConstStr *Params)
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
 
        /* 
         * Now make the API call to zap the room
@@ -1307,7 +1319,7 @@ void imap_unsubscribe(int num_parms, ConstStr *Params)
         * our happy day without violent explosions.
         */
        if (IMAP->selected) {
-               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
        }
 }
 
@@ -1337,7 +1349,7 @@ void imap_delete(int num_parms, ConstStr *Params)
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
 
        /*
         * Now delete the room.
@@ -1354,7 +1366,7 @@ void imap_delete(int num_parms, ConstStr *Params)
         * our happy day without violent explosions.
         */
        if (IMAP->selected) {
-               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
        }
 }