+ /* Do an AUTH command if necessary */
+ if (strlen(mx_user) > 0) {
+ sprintf(buf, "%s%c%s%c%s%c", mx_user, 0, mx_user, 0, mx_pass, 0);
+ CtdlEncodeBase64(mailfrom, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 3);
+ snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", mailfrom);
+ lprintf(CTDL_DEBUG, ">%s", buf);
+ sock_write(sock, buf, strlen(buf));
+ if (ml_sock_gets(sock, buf) < 0) {
+ *status = 4;
+ strcpy(dsn, "Connection broken during SMTP AUTH");
+ goto bail;
+ }
+ lprintf(CTDL_DEBUG, "<%s\n", buf);
+ if (buf[0] != '2') {
+ if (buf[0] == '4') {
+ *status = 4;
+ safestrncpy(dsn, &buf[4], 1023);
+ goto bail;
+ }
+ else {
+ *status = 5;
+ safestrncpy(dsn, &buf[4], 1023);
+ goto bail;
+ }
+ }
+ }
+
+ /* previous command succeeded, now try the MAIL From: command */