]> diplodocus.org Git - nmh/blobdiff - mts/smtp/smtp.c
man: Fix spelling mistakes.
[nmh] / mts / smtp / smtp.c
index b5e68fa1fa6b03cc90d8ea8e3f2ab4046febed45..fdc56b06ab921fb41d49ff3dc3cd0c59e6a06403 100644 (file)
@@ -40,9 +40,6 @@
  */
 #endif
 
-#define        TRUE    1
-#define        FALSE   0
-
 #define        NBITS ((sizeof (int)) * 8)
 
 /*
@@ -103,9 +100,9 @@ sm_init (char *client, char *server, char *port, int watch, int verbose,
     if (sm_mts == MTS_SMTP)
        return smtp_init (client, server, port, watch, verbose,
                          debug, sasl, saslmech, user, oauth_svc, tls);
-    else
-       return sendmail_init (client, watch, verbose, debug, sasl,
-                             saslmech, user);
+
+    return sendmail_init (client, watch, verbose, debug, sasl,
+                          saslmech, user);
 }
 
 static int
@@ -131,14 +128,13 @@ smtp_init (char *client, char *server, char *port, int watch, int verbose,
        } else {
            client = LocalName(1);      /* no clientname -> LocalName */
        }
-    }
 
-    /*
-     * Last-ditch check just in case client still isn't set to anything
-     */
-
-    if (client == NULL || *client == '\0')
-       client = "localhost";
+        /*
+         * Last-ditch check just in case client still isn't set to anything
+         */
+        if (client == NULL || *client == '\0')
+            client = "localhost";
+    }
 
     nsc = netsec_init();
 
@@ -299,14 +295,13 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl,
            client = clientname;
        else
            client = LocalName(1);      /* no clientname -> LocalName */
-    }
-
-    /*
-     * Last-ditch check just in case client still isn't set to anything
-     */
 
-    if (client == NULL || *client == '\0')
-       client = "localhost";
+        /*
+         * Last-ditch check just in case client still isn't set to anything
+         */
+        if (client == NULL || *client == '\0')
+            client = "localhost";
+    }
 
     nsc = netsec_init();
 
@@ -441,19 +436,36 @@ rclient (char *server, char *service)
 }
 
 int
-sm_winit (char *from, int smtputf8)
+sm_winit (char *from, int smtputf8, int eightbit)
 {
-    const char *const mail_parameters = smtputf8
-        ? " BODY=8BITMIME SMTPUTF8"
-        : "";
-
-    /* Just for information, if an attempt is made to send to an 8-bit
-       address without specifying SMTPUTF8, Gmail responds with
-       555 5.5.2 Syntax error.
-       Gmail doesn't require the 8BITMIME, but RFC 6531 Sec. 1.2 does. */
-    if (smtputf8  &&  (! EHLOset("8BITMIME") || ! EHLOset("SMTPUTF8"))) {
-       sm_end (NOTOK);
-       return RP_UCMD;
+    const char *mail_parameters = "";
+
+    if (smtputf8) {
+        /* Just for information, if an attempt is made to send to an 8-bit
+           address without specifying SMTPUTF8, Gmail responds with
+           555 5.5.2 Syntax error.
+           Gmail doesn't require the 8BITMIME, but RFC 6531 Sec. 1.2 does. */
+        if (EHLOset ("8BITMIME")  &&  EHLOset ("SMTPUTF8")) {
+            mail_parameters = " BODY=8BITMIME SMTPUTF8";
+        } else {
+            advise (NULL, "SMTP server does not support %s, not sending.\n"
+                    "Rebuild message with 7-bit headers, WITHOUT -headerencoding utf-8.",
+                    EHLOset ("SMTPUTF8") ? "8BITMIME" : "SMTPUTF8");
+            sm_end (NOTOK);
+            return RP_UCMD;
+        }
+    } else if (eightbit) {
+        /* Comply with RFC 6152, for messages that have any 8-bit characters
+           in their body. */
+        if (EHLOset ("8BITMIME")) {
+            mail_parameters = " BODY=8BITMIME";
+        } else {
+            advise (NULL, "SMTP server does not support 8BITMIME, not sending.\n"
+                    "Suggest encoding message for 7-bit transport by setting your\n"
+                    "locale to C, and/or specifying *b64 in mhbuild directives.");
+            sm_end (NOTOK);
+            return RP_UCMD;
+        }
     }
 
     switch (smtalk (SM_MAIL, "MAIL FROM:<%s>%s", from, mail_parameters)) {
@@ -799,7 +811,7 @@ again: ;
                                                 &errstr)) != NULL ; ) {
 
        if (doingEHLO
-               && strncmp (buffer, "250", sizeof("250") - 1) == 0
+               && HasPrefix(buffer, "250")
                && (buffer[3] == '-' || doingEHLO == 2)
                && buffer[4]) {
            if (doingEHLO == 2) {
@@ -861,7 +873,7 @@ again: ;
            continue;
        if (sm_reply.code < 100) {
            if (sm_verbose) {
-               printf ("%s\n", sm_reply.text);
+               puts(sm_reply.text);
                fflush (stdout);
            }
            goto again;
@@ -938,7 +950,7 @@ EHLOset (char *s)
 
     for (ehlo = EHLOkeys; *ehlo; ehlo++) {
        ep = *ehlo;
-       if (strncmp (ep, s, len) == 0) {
+       if (HasPrefix(ep, s)) {
            for (ep += len; *ep == ' '; ep++)
                continue;
            return ep;
@@ -1016,7 +1028,7 @@ sm_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
            return NOTOK;
        }
 
-       if (strncmp(line, "334 ", 4) != 0) {
+       if (!HasPrefix(line, "334 ")) {
            netsec_err(errstr, "Improper SASL protocol response: %s", line);
            return NOTOK;
        }
@@ -1065,7 +1077,7 @@ sm_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
        if (line == NULL)
            return NOTOK;
 
-       if (strncmp(line, "235 ", 4) != 0) {
+       if (!HasPrefix(line, "235 ")) {
            if (len > 4)
                netsec_err(errstr, "Authentication failed: %s", line + 4);
            else