]> Pileus Git - ~andy/fetchmail/blobdiff - rfc822.c
Fix typo repsonsible -> responsible.
[~andy/fetchmail] / rfc822.c
index 38ff48b7b73119f40fd5cb94388cdf728452baab..4efba8349eb6a79c494cae0d95aa54e9b72fb7dc 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -19,19 +19,27 @@ is part of fetchmail and the Unix Cookbook, and are released under the
 MIT license.  Compile with -DMAIN to build the demonstrator.
 
 ******************************************************************************/
+
+#define _XOPEN_SOURCE 600
+#define __BSD_VISIBLE 1
+
+#include "config.h"
+#include "fetchmail.h"
+
 #include  <stdio.h>
 #include  <ctype.h>
 #include  <string.h>
+#include  <strings.h>
 #include  <stdlib.h>
 
-#include "fetchmail.h"
+#include "sdump.h"
 
 #ifndef MAIN
-#include "i18n.h"
+#include "gettext.h"
 #else
 #include  <unistd.h>
 static int verbose;
-char *program_name = "rfc822";
+const char *program_name = "rfc822";
 #endif /* MAIN */
 
 #ifndef TRUE
@@ -41,6 +49,8 @@ char *program_name = "rfc822";
 
 #define HEADER_END(p)  ((p)[0] == '\n' && ((p)[1] != ' ' && (p)[1] != '\t'))
 
+#define BEFORE_EOL(s)  (strcspn((s), "\r\n"))
+
 char *reply_hack(
        char *buf               /* header to be hacked */,
        const char *host        /* server hostname */,
@@ -72,14 +82,16 @@ char *reply_hack(
     }
 
 #ifndef MAIN
-    if (outlevel >= O_DEBUG)
-       report_build(stdout, GT_("About to rewrite %s"), buf);
+    if (outlevel >= O_DEBUG) {
+       report_build(stdout, GT_("About to rewrite %s...\n"), (cp = sdump(buf, BEFORE_EOL(buf))));
+       xfree(cp);
+    }
 
     /* make room to hack the address; buf must be malloced */
     for (cp = buf; *cp; cp++)
        if (*cp == ',' || isspace((unsigned char)*cp))
            addresscount++;
-    buf = xrealloc(buf, strlen(buf) + addresscount * (strlen(host) + 1) + 1);
+    buf = (char *)xrealloc(buf, strlen(buf) + addresscount * (strlen(host) + 1) + 1);
 #endif /* MAIN */
 
     /*
@@ -96,7 +108,7 @@ char *reply_hack(
        if (verbose)
        {
            printf("state %d: %s", state, buf);
-           printf("%*s^\n", from - buf + 10, " ");
+           printf("%*s^\n", (int)(from - buf + 10), " ");
        }
 #endif /* MAIN */
        if (state != 2)
@@ -208,8 +220,12 @@ char *reply_hack(
     }
 
 #ifndef MAIN
-    if (outlevel >= O_DEBUG)
-       report_complete(stdout, GT_("Rewritten version is %s\n"), buf);
+    if (outlevel >= O_DEBUG) {
+       report_complete(stdout, GT_("...rewritten version is %s.\n"),
+                       (cp = sdump(buf, BEFORE_EOL(buf))));
+       xfree(cp)
+    }
+
 #endif /* MAIN */
     *length = strlen(buf);
     return(buf);
@@ -247,13 +263,15 @@ char *nxtaddr(const char *hdr /* header to be parsed, NUL to continue previous h
        tp = 0;
     }
 
+    if (!hp) return NULL;
+
     for (; *hp; hp++)
     {
 #ifdef MAIN
        if (verbose)
        {
            printf("state %d: %s", state, orighdr);
-           printf("%*s^\n", hp - orighdr + 10, " ");
+           printf("%*s^\n", (int)(hp - orighdr + 10), " ");
        }
 #endif /* MAIN */
 
@@ -424,6 +442,8 @@ int main(int argc, char *argv[])
            break;
        }
 
+    longbuf[0] = '\0';
+
     while (fgets(buf, sizeof(buf)-1, stdin))
     {
        if (buf[0] == ' ' || buf[0] == '\t')