]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/smtp/serv_smtp.c
New config option: set smtp_advertise_starttls to nonzero to advertise STARTTLS in...
[citadel.git] / citadel / server / modules / smtp / serv_smtp.c
index c30df54092da761153ea6b3b64f59cb60b415969..005f5b5d7746fc5eb814f82500dc5256ed5086dd 100644 (file)
@@ -19,7 +19,7 @@
 // The VRFY and EXPN commands have been removed from this implementation
 // because nobody uses these commands anymore, except for spammers.
 //
-// Copyright (c) 1998-2022 by the citadel.org team
+// Copyright (c) 1998-2023 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.
@@ -50,7 +50,7 @@
 #include <arpa/inet.h>
 #include <assert.h>
 #include <libcitadel.h>
-#include "../../citadel.h"
+#include "../../citadel_defs.h"
 #include "../../server.h"
 #include "../../citserver.h"
 #include "../../support.h"
@@ -215,10 +215,12 @@ void smtp_hello(int which_command) {
                cprintf("250-SIZE %ld\r\n", CtdlGetConfigLong("c_maxmsglen"));
 
 #ifdef HAVE_OPENSSL
-               // Offer TLS, but only if TLS is not already active.
-               // Furthermore, only offer TLS when running on the SMTP-MSA port, not on the SMTP-MTA port,
-               // because if our server doesn't have a trusted certificate, some mailers will refuse to talk to it.
-               if ( (!CC->redirect_ssl) && (SMTP->is_msa) ) {
+               // Offer the STARTTLS option...
+               if (    (!CC->redirect_ssl)                                                     // not if we're already TLS
+                       && (    (SMTP->is_msa)                                                  // Always on port 587
+                               || (CtdlGetConfigInt("smtp_advertise_starttls") != 0)           // On port 25 only if enabled
+                       )
+               ) {
                        cprintf("250-STARTTLS\r\n");
                }
 #endif
@@ -248,8 +250,8 @@ void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) {
 
        if ( !CM_IsEmpty(msg, eMsgSubject) && (!strcasecmp(msg->cm_fields[eMsgSubject], "__ WebCit Preferences __"))) {
                // This is it!  Change ownership of the message text so it doesn't get freed.
-               *webcit_conf = (char *)msg->cm_fields[eMesageText];
-               msg->cm_fields[eMesageText] = NULL;
+               *webcit_conf = (char *)msg->cm_fields[eMessageText];
+               msg->cm_fields[eMessageText] = NULL;
        }
        CM_Free(msg);
 }
@@ -757,27 +759,27 @@ void smtp_data(void) {
                        return;
                }
 
-               CM_SetField(msg, eOriginalRoom, HKEY(MAILROOM));
+               CM_SetField(msg, eOriginalRoom, MAILROOM);
                if (SMTP->preferred_sender_name != NULL)
-                       CM_SetField(msg, eAuthor, SKEY(SMTP->preferred_sender_name));
+                       CM_SetField(msg, eAuthor, ChrPtr(SMTP->preferred_sender_name));
                else 
-                       CM_SetField(msg, eAuthor, CC->user.fullname, strlen(CC->user.fullname));
+                       CM_SetField(msg, eAuthor, CC->user.fullname);
 
                if (!validemail) {
                        if (SMTP->preferred_sender_email != NULL) {
-                               CM_SetField(msg, erFc822Addr, SKEY(SMTP->preferred_sender_email));
+                               CM_SetField(msg, erFc822Addr, ChrPtr(SMTP->preferred_sender_email));
                        }
                        else {
-                               CM_SetField(msg, erFc822Addr, CC->cs_inet_email, strlen(CC->cs_inet_email));
+                               CM_SetField(msg, erFc822Addr, CC->cs_inet_email);
                        }
                }
        }
 
        // Set the "envelope from" address
-       CM_SetField(msg, eMessagePath, SKEY(SMTP->from));
+       CM_SetField(msg, eMessagePath, ChrPtr(SMTP->from));
 
        // Set the "envelope to" address
-       CM_SetField(msg, eenVelopeTo, SKEY(SMTP->recipients));
+       CM_SetField(msg, eenVelopeTo, ChrPtr(SMTP->recipients));
 
        // Submit the message into the Citadel system.
        valid = validate_recipients(
@@ -799,7 +801,7 @@ void smtp_data(void) {
        if (scan_errors > 0) {  // We don't want this message!
 
                if (CM_IsEmpty(msg, eErrorMsg)) {
-                       CM_SetField(msg, eErrorMsg, HKEY("Message rejected by filter"));
+                       CM_SetField(msg, eErrorMsg, "Message rejected by filter");
                }
 
                StrBufPrintf(SMTP->OneRcpt, "550 %s\r\n", msg->cm_fields[eErrorMsg]);