more places to fix the new linebreak behaviour of the base64 encoder.
[citadel.git] / citadel / modules / smtp / smtp_clienthandlers.c
index 70373a89623d7a51ed115d600a2196c06e9a4743..198649e1f2c00522b2f738b7ee04cbf15e1840ef 100644 (file)
@@ -166,6 +166,11 @@ eNextState SMTPC_read_EHLO_reply(SmtpOutMsg *Msg)
                {
                        if (strstr(ChrPtr(Msg->IO.IOBuf), "LOGIN") != NULL)
                                Msg->SendLogin = 1;
+                       else if ((Msg->MultiLineBuf != NULL) &&
+                                strstr(ChrPtr(Msg->MultiLineBuf), "LOGIN") != NULL)
+                       {
+                               Msg->SendLogin = 1;
+                       }
                }
        }
        /* else we fall back to 'helo' */
@@ -229,10 +234,14 @@ eNextState SMTPC_send_auth(SmtpOutMsg *Msg)
                                Msg->pCurrRelay->User, '\0',
                                Msg->pCurrRelay->Pass);
                        
-                       CtdlEncodeBase64(encoded, buf,
-                                        strlen(Msg->pCurrRelay->User) * 2 +
-                                        strlen(Msg->pCurrRelay->Pass) + 2, 0);
-                       
+                       size_t len = CtdlEncodeBase64(encoded, buf,
+                                                     strlen(Msg->pCurrRelay->User) * 2 +
+                                                     strlen(Msg->pCurrRelay->Pass) + 2, 0);
+
+                       if (buf[len - 1] == '\n') {
+                               buf[len - 1] = '\0';
+                       }
+
                        StrBufPrintf(Msg->IO.SendBuf.Buf,
                                     "AUTH PLAIN %s\r\n",
                                     encoded);
@@ -284,6 +293,10 @@ eNextState SMTPC_send_authplain_1(SmtpOutMsg *Msg)
                Msg->pCurrRelay->User,
                strlen(Msg->pCurrRelay->User),
                0);
+       if (encoded[encodedlen - 1] == '\n') {
+               encodedlen --;
+               encoded[encodedlen] = '\0';
+       }
 
        StrBufPlain(Msg->IO.SendBuf.Buf,
                    encoded,
@@ -321,10 +334,15 @@ eNextState SMTPC_send_authplain_2(SmtpOutMsg *Msg)
        
        encodedlen = CtdlEncodeBase64(
                encoded,
-               Msg->pCurrRelay->User,
-               strlen(Msg->pCurrRelay->User),
+               Msg->pCurrRelay->Pass,
+               strlen(Msg->pCurrRelay->Pass),
                0);
 
+       if (encoded[encodedlen - 1] == '\n') {
+               encodedlen --;
+               encoded[encodedlen] = '\0';
+       }
+
        StrBufPlain(Msg->IO.SendBuf.Buf,
                    encoded,
                    encodedlen);