]> diplodocus.org Git - nmh/blobdiff - test/fakesmtp.c
Also trap ambiguous post switch.
[nmh] / test / fakesmtp.c
index 449fdec0ee908d5b9ccc8aa7d2a80ccdccc5a607..c4fa3e7c69cc1babd3e5b6a3ec4095c0aa8a9b1c 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * fakesmtp - A fake SMTP server used by the nmh test suite
+/* fakesmtp - A fake SMTP server used by the nmh test suite
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -41,6 +40,7 @@ main(int argc, char *argv[])
        int rc, conn, smtp_state;
        FILE *f;
        const char *xoauth = getenv("XOAUTH");
+       const char *smtputf8 = getenv("SMTPUTF8");
 
        if (argc != 3) {
                fprintf(stderr, "Usage: %s output-filename port\n", argv[0]);
@@ -70,7 +70,8 @@ main(int argc, char *argv[])
                if (rc == -1)
                        break;  /* EOF */
 
-               fprintf(f, "%s\n", line);
+                fputs(line, f);
+                putc('\n', f);
 
                switch (smtp_state) {
                case SMTP_DATA:
@@ -101,17 +102,20 @@ main(int argc, char *argv[])
                        smtp_state = SMTP_DATA;
                        continue;
                }
-               if (xoauth == NULL) {
+               if (strncmp(line, "EHLO", 4) == 0) {
                        putcrlf(conn, "250-ready");
-                       putcrlf(conn, "250-8BITMIME");
-                       putcrlf(conn, "250-SMTPUTF8");
-               } else {
-                       /* XOAUTH2 support enabled; handle EHLO and AUTH. */
-                       if (strncmp(line, "EHLO", 4) == 0) {
-                               putcrlf(conn, "250-ready");
-                               putcrlf(conn, "250 AUTH XOAUTH2");
-                               continue;
+                       if (smtputf8 != NULL) {
+                               putcrlf(conn, "250-8BITMIME");
+                               putcrlf(conn, "250-SMTPUTF8");
+                       }
+                       if (xoauth != NULL) {
+                               putcrlf(conn, "250-AUTH XOAUTH2");
                        }
+                       putcrlf(conn, "250 I'll buy that for a dollar!");
+                       continue;
+               }
+               if (xoauth != NULL) {
+                       /* XOAUTH2 support enabled; handle AUTH (and EHLO above). */
                        if (strncmp(line, "AUTH", 4) == 0) {
                                if (strncmp(line, "AUTH XOAUTH2", 12) == 0
                                    && strstr(line, xoauth) != NULL) {