]> Pileus Git - ~andy/fetchmail/blobdiff - transact.c
Remove unused code.
[~andy/fetchmail] / transact.c
index 93962526d5db472ac8677e1a20e215c15459d864..55d251684179f0ea1dbbb381ad91760c2efd754b 100644 (file)
@@ -23,6 +23,7 @@
 #else
 #include  <varargs.h>
 #endif
+#include <limits.h>
 
 #ifdef HAVE_NET_SOCKET_H
 #include <net/socket.h>
 #include "socket.h"
 #include "fetchmail.h"
 
+#define _FIX_INT_MIN(x) ((x) < INT_MIN ? INT_MIN : (x))
+#define _FIX_INT_MAX(x) ((x) > INT_MAX ? INT_MAX : (x))
+#define CAST_TO_INT(x) ((int)(_FIX_INT_MIN(_FIX_INT_MAX(x))))
+#define UCAST_TO_INT(x) ((int)(_FIX_INT_MAX(x)))
+
 /* global variables: please reinitialize them explicitly for proper
  * working in daemon mode */
 
@@ -43,7 +49,7 @@ int suppress_tags = FALSE;    /* emit tags? */
 char tag[TAGLEN];
 static int tagnum;
 #define GENSYM (sprintf(tag, "A%04d", ++tagnum % TAGMOD), tag)
-static struct method *protocol;
+static const struct method *protocol;
 char shroud[PASSWORDLEN*2+3];  /* string to shroud in debug output */
 
 /* session variables initialized in do_session() */
@@ -592,7 +598,7 @@ eoh:
                    has_nuls = TRUE;
                if (outlevel > O_SILENT)
                    report(stdout,
-                          GT_("incorrect header line found while scanning headers\n"));
+                          GT_("incorrect header line found - see manpage for bad-header option\n"));
                if (outlevel >= O_VERBOSE)
                    report (stdout, GT_("line: %s"), line);
                refuse_mail = 1;
@@ -624,7 +630,7 @@ eoh:
             * our terminating combination \n\0, we move backwards to
             * make sure that we don't catch some \n\0 stored in the
             * decoded part of the message */
-           for (tcp = line + linelen - 1; tcp > line && (*tcp != 0 || tcp[-1] != '\n'); tcp--);
+           for (tcp = line + linelen - 1; tcp > line && (*tcp != 0 || tcp[-1] != '\n'); tcp--) { }
            if  (tcp > line) linelen = tcp - line;
        }
 
@@ -749,17 +755,17 @@ eoh:
         * turns on the dropstatus flag.
         */
        {
-           char        *cp;
+           char        *tcp;
 
            if (!strncasecmp(line, "Status:", 7))
-               cp = line + 7;
+               tcp = line + 7;
            else if (!strncasecmp(line, "X-Mozilla-Status:", 17))
-               cp = line + 17;
+               tcp = line + 17;
            else
-               cp = NULL;
-           if (cp) {
-               while (*cp && isspace((unsigned char)*cp)) cp++;
-               if (!*cp || ctl->dropstatus)
+               tcp = NULL;
+           if (tcp) {
+               while (*tcp && isspace((unsigned char)*tcp)) tcp++;
+               if (!*tcp || ctl->dropstatus)
                {
                    free(line);
                    continue;
@@ -1082,15 +1088,25 @@ process_headers:
            free(sdps_envto);
        } else
 #endif /* SDPS_ENABLE */ 
-       if (env_offs > -1)          /* We have the actual envelope addressee */
-           find_server_names(msgblk.headers + env_offs, ctl, &msgblk.recipients);
+           if (env_offs > -1) {            /* We have the actual envelope addressee */
+               if (outlevel >= O_DEBUG) {
+                   const char *tmps = msgblk.headers + env_offs;
+                   size_t l = strcspn(tmps, "\r\n");
+                   report(stdout, GT_("Parsing envelope \"%s\" names \"%-.*s\"\n"), ctl->server.envelope, UCAST_TO_INT(l), tmps);
+               }
+               find_server_names(msgblk.headers + env_offs, ctl, &msgblk.recipients);
+           }
        else if (delivered_to && ctl->server.envelope != STRING_DISABLED &&
-      ctl->server.envelope && !strcasecmp(ctl->server.envelope, "Delivered-To"))
-   {
+               ctl->server.envelope && !strcasecmp(ctl->server.envelope, "Delivered-To"))
+       {
+           if (outlevel >= O_DEBUG) {
+               const char *tmps = delivered_to + 2 + strlen(ctl->server.envelope);
+               size_t l = strcspn(tmps, "\r\n");
+               report(stdout, GT_("Parsing envelope \"%s\" names \"%-.*s\"\n"), ctl->server.envelope, UCAST_TO_INT(l), tmps);
+           }
            find_server_names(delivered_to, ctl, &msgblk.recipients);
            xfree(delivered_to);
-   }
-       else if (received_for)
+       } else if (received_for) {
            /*
             * We have the Received for addressee.  
             * It has to be a mailserver address, or we
@@ -1098,9 +1114,13 @@ process_headers:
             * We use find_server_names() to let local 
             * hostnames go through.
             */
+           if (outlevel >= O_DEBUG) {
+               const char *tmps = received_for + 2;
+               size_t l = strcspn(tmps, "\r\n");
+               report(stdout, GT_("Parsing Received names \"%-.*s\"\n"), UCAST_TO_INT(l), tmps);
+           }
            find_server_names(received_for, ctl, &msgblk.recipients);
-       else
-       {
+       } else {
            /*
             * We haven't extracted the envelope address.
             * So check all the "Resent-To" header addresses if 
@@ -1108,6 +1128,8 @@ process_headers:
             * the "To" addresses.
             */
            register struct addrblk *nextptr;
+          if (outlevel >= O_DEBUG)
+                  report(stdout, GT_("No envelope recipient found, resorting to header guessing.\n"));
            if (resent_to_addrchain) {
                /* delete the "To" chain and substitute it 
                 * with the "Resent-To" list 
@@ -1122,6 +1144,12 @@ process_headers:
            }
            /* now look for remaining adresses */
            while (to_addrchain) {
+               if (outlevel >= O_DEBUG) {
+                   const char *tmps = msgblk.headers+to_addrchain->offset;
+                   size_t l = strcspn(tmps, "\r\n");
+                   report(stdout, GT_("Guessing from header \"%-.*s\".\n"), UCAST_TO_INT(l), tmps);
+               }
+
                find_server_names(msgblk.headers+to_addrchain->offset, ctl, &msgblk.recipients);
                nextptr = to_addrchain->next;
                free(to_addrchain);
@@ -1238,8 +1266,9 @@ process_headers:
                    for (idp = msgblk.recipients; idp; idp = idp->next)
                        if (idp->val.status.mark == XMIT_ACCEPT)
                            break;      /* only report first address */
-                   snprintf(buf+1, sizeof(buf)-1,
-                           "for <%s>", rcpt_address (ctl, idp->id, 1));
+                   if (idp)
+                       snprintf(buf+1, sizeof(buf)-1,
+                               "for <%s>", rcpt_address (ctl, idp->id, 1));
                    snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf)-1,
                            " (%s); ",
                            MULTIDROP(ctl) ? "multi-drop" : "single-drop");
@@ -1462,7 +1491,7 @@ void init_transact(const struct method *proto)
     suppress_tags = FALSE;
     tagnum = 0;
     tag[0] = '\0';     /* nuke any tag hanging out from previous query */
-    protocol = (struct method *)proto;
+    protocol = proto;
     shroud[0] = '\0';
 }