]> Pileus Git - ~andy/fetchmail/blobdiff - transact.c
Add Doxyfile to allow generation of documentation with Dimitri Heesch's great
[~andy/fetchmail] / transact.c
index fcacc62d8115360566de9c810c6a1ade11f9f670..ba84f47dd32fa9d9fc4a731c9d4513cdb008704f 100644 (file)
@@ -91,9 +91,7 @@ static void find_server_names(const char *hdr,
     {
        char    *cp;
 
-       for (cp = nxtaddr((const unsigned char *)hdr);
-            cp != NULL;
-            cp = nxtaddr(NULL))
+       for (cp = nxtaddr(hdr); cp != NULL; cp = nxtaddr(NULL))
        {
            char        *atsign;
 
@@ -129,10 +127,10 @@ static void find_server_names(const char *hdr,
                for (idp = ctl->server.localdomains; idp; idp = idp->next) {
                    char        *rhs;
 
-                   rhs = atsign + (strlen(atsign) - strlen((char *)idp->id));
+                   rhs = atsign + (strlen(atsign) - strlen(idp->id));
                    if (rhs > atsign &&
                        (rhs[-1] == '.' || rhs[-1] == '@') &&
-                       strcasecmp(rhs, (char *)idp->id) == 0)
+                       strcasecmp(rhs, idp->id) == 0)
                    {
                        if (outlevel >= O_DEBUG)
                            report(stdout, GT_("passed through %s matching %s\n"), 
@@ -426,7 +424,6 @@ int readheaders(int sock,
     for (remaining = fetchlen; remaining > 0 || protocol->delimited; )
     {
        char *line, *rline;
-       int overlong = FALSE; /* XXX FIXME: this is unused */
 
        line = xmalloc(sizeof(buf));
        linelen = 0;
@@ -467,7 +464,6 @@ int readheaders(int sock,
             */
            if (n && buf[n-1] != '\n') 
            {
-               overlong = TRUE;
                rline = (char *) realloc(line, linelen + 1);
                if (rline == NULL)
                {
@@ -545,6 +541,16 @@ int readheaders(int sock,
             * send out robotmail that's missing the RFC822 delimiter blank
             * line before the body! Without this check fetchmail segfaults.
             * With it, we treat such messages as spam and refuse them.
+            *
+            * Frederic Marchal reported in February 2006 that hotmail
+            * or something improperly wrapped a very long TO header
+            * (wrapped without inserting whitespace in the continuation
+            * line) and found that this code thus refused a message
+            * that should have been delivered.
+            *
+            * XXX FIXME: we should probably wrap the message up as
+            * message/rfc822 attachment and forward to postmaster (Rob
+            * MacGregor)
             */
            if (!refuse_mail && !isspace((unsigned char)line[0]) && !strchr(line, ':'))
            {
@@ -603,7 +609,7 @@ int readheaders(int sock,
            continue;
        }
 
-       /* we see an ordinary (non-header, non-message-delimiter line */
+       /* we see an ordinary (non-header, non-message-delimiter) line */
        if (linelen != strlen (line))
            has_nuls = TRUE;
 
@@ -848,8 +854,8 @@ int readheaders(int sock,
                sscanf(line+12, "%s", id);
                if (!str_find( &ctl->newsaved, num))
                {
-                   struct idlist *new = save_str(&ctl->newsaved,id,UID_SEEN);
-                   new->val.status.num = num;
+                   struct idlist *newl = save_str(&ctl->newsaved,id,UID_SEEN);
+                   newl->val.status.num = num;
                }
            }
        }
@@ -863,7 +869,7 @@ int readheaders(int sock,
                || !strncasecmp("Bcc:", line, 4)
                || !strncasecmp("Apparently-To:", line, 14))
            {
-               *to_chainptr = xmalloc(sizeof(struct addrblk));
+               *to_chainptr = (struct addrblk *)xmalloc(sizeof(struct addrblk));
                (*to_chainptr)->offset = (line - msgblk.headers);
                to_chainptr = &(*to_chainptr)->next; 
                *to_chainptr = NULL;
@@ -873,7 +879,7 @@ int readheaders(int sock,
                     || !strncasecmp("Resent-Cc:", line, 10)
                     || !strncasecmp("Resent-Bcc:", line, 11))
            {
-               *resent_to_chainptr = xmalloc(sizeof(struct addrblk));
+               *resent_to_chainptr = (struct addrblk *)xmalloc(sizeof(struct addrblk));
                (*resent_to_chainptr)->offset = (line - msgblk.headers);
                resent_to_chainptr = &(*resent_to_chainptr)->next; 
                *resent_to_chainptr = NULL;
@@ -1158,7 +1164,7 @@ int readheaders(int sock,
                    saddr, sizeof(saddr), NULL, 0,
                    NI_NUMERICHOST);
            if (e)
-               snprintf(saddr, sizeof(saddr), "(%-.*s)", sizeof(saddr) - 3, gai_strerror(e));
+               snprintf(saddr, sizeof(saddr), "(%-.*s)", (int)(sizeof(saddr) - 3), gai_strerror(e));
            snprintf(buf, sizeof(buf),
                    "Received: from %s [%s]\r\n", 
                    ctl->server.truename, saddr);
@@ -1184,6 +1190,10 @@ int readheaders(int sock,
                        " polling %s account %s",
                        ctl->server.pollname,
                        ctl->remotename);
+               if (ctl->folder)
+                   snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+                           " folder %s",
+                           ctl->folder);
            }
            snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), ")\r\n");
            n = stuffline(ctl, buf);
@@ -1308,8 +1318,8 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
 /*   forward:          TRUE to forward */
 {
     int        linelen;
-    unsigned char buf[MSGBUFSIZE+4];
-    unsigned char *inbufp = buf;
+    char buf[MSGBUFSIZE+4];
+    char *inbufp = buf;
     flag issoftline = FALSE;
 
     /*
@@ -1325,6 +1335,9 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
     while (protocol->delimited || len > 0)
     {
        set_timeout(mytimeout);
+       /* XXX FIXME: for undelimited protocols that ship the size, such
+        * as IMAP, we might want to use the count of remaining characters
+        * instead of the buffer size -- not for fetchmail 6.3.X though */
        if ((linelen = SockRead(sock, inbufp, sizeof(buf)-4-(inbufp-buf)))==-1)
        {
            set_timeout(0);
@@ -1347,6 +1360,20 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
                sizeticker -= SIZETICKER;
            }
        }
+
+       /* Mike Jones, Manchester University, 2006:
+        * "To fix IMAP MIME Messages in which fetchmail adds the remainder of
+        * the IMAP packet including the ')' character (part of the IMAP)
+        * Protocol causing the addition of an extra MIME boundary locally."
+        *
+        * However, we shouldn't do this for delimited protocols:
+        * many POP3 servers (Microsoft, qmail) goof up message sizes
+        * so we might end truncating messages prematurely.
+        */
+       if (!protocol->delimited && linelen > len) {
+           inbufp[len] = '\0';
+       }
+
        len -= linelen;
 
        /* check for end of message */
@@ -1470,11 +1497,10 @@ va_dcl
     }
 }
 
-int gen_recv(sock, buf, size)
-/* get one line of input from the server */
-int sock;      /* socket to which server is connected */
-char *buf;     /* buffer to receive input */
-int size;      /* length of buffer */
+/** get one line of input from the server */
+int gen_recv(int sock  /** socket to which server is connected */,
+            char *buf /* buffer to receive input */,
+            int size  /* length of buffer */)
 {
     int oldphase = phase;      /* we don't have to be re-entrant */
 
@@ -1537,7 +1563,8 @@ va_dcl
     va_end(ap);
 
     snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "\r\n");
-    if (SockWrite(sock, buf, strlen(buf)) < strlen(buf)) {
+    ok = SockWrite(sock, buf, strlen(buf));
+    if (ok == -1 || (size_t)ok != strlen(buf)) {
        /* short write, bail out */
        return PS_SOCKET;
     }