]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/smtp_clienthandlers.c
Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / citadel / modules / smtp / smtp_clienthandlers.c
index 70373a89623d7a51ed115d600a2196c06e9a4743..960a6e0258a7ff8be83deb99daf87041df1093f7 100644 (file)
  * RFC 2822 - Internet Message Format
  * RFC 2920 - SMTP Service Extension for Command Pipelining
  *
- * Copyright (c) 1998-2012 by the citadel.org team
+ * Copyright (c) 1998-2015 by the citadel.org team
  *
- *  This program is open source software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 3.
- *  
- *  
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  
- *  
- *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  */
 
 #include "sysdep.h"
@@ -144,8 +138,7 @@ eNextState SMTPC_send_EHLO(SmtpOutMsg *Msg)
        /* At this point we know we are talking to a real SMTP server */
 
        /* Do a EHLO command.  If it fails, try the HELO command. */
-       StrBufPrintf(Msg->IO.SendBuf.Buf,
-                    "EHLO %s\r\n", config.c_fqdn);
+       StrBufPrintf(Msg->IO.SendBuf.Buf, "EHLO %s\r\n", CtdlGetConfigStr("c_fqdn"));
 
        SMTP_DBG_SEND();
        return eReadMessage;
@@ -166,6 +159,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' */
@@ -175,8 +173,7 @@ eNextState SMTPC_read_EHLO_reply(SmtpOutMsg *Msg)
 eNextState STMPC_send_HELO(SmtpOutMsg *Msg)
 {
        AsyncIO *IO = &Msg->IO;
-       StrBufPrintf(Msg->IO.SendBuf.Buf,
-                    "HELO %s\r\n", config.c_fqdn);
+       StrBufPrintf(Msg->IO.SendBuf.Buf, "HELO %s\r\n", CtdlGetConfigStr("c_fqdn"));
 
        SMTP_DBG_SEND();
        return eReadMessage;
@@ -229,10 +226,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 +285,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 +326,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);