Now the escaping of a single dot on a line of its own is done in CtdlOutputPreloadedMsg()
authorDave West <davew@uncensored.citadel.org>
Sun, 25 May 2008 19:01:17 +0000 (19:01 +0000)
committerDave West <davew@uncensored.citadel.org>
Sun, 25 May 2008 19:01:17 +0000 (19:01 +0000)
citadel/modules/pop3/serv_pop3.c
citadel/modules/smtp/serv_smtp.c
citadel/msgbase.c
citadel/msgbase.h

index 43a2545d871d81e747c3347cceadce6d545363d1..5911f4761d16549b5dffe0978a9f1c94e5575396 100644 (file)
@@ -377,41 +377,7 @@ void pop3_retr(char *argbuf) {
        }
 
        cprintf("+OK Message %d:\r\n", which_one);
-       CC->redirect_buffer = malloc(SIZ);
-       CC->redirect_len = 0;
-       CC->redirect_alloc = SIZ;
-       CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum,
-                     MT_RFC822, HEADERS_ALL, 0, 1, NULL, 0);
-       msgtext = CC->redirect_buffer;
-       CC->redirect_buffer = NULL;
-       CC->redirect_len = 0;
-       CC->redirect_alloc = 0;
-
-       /* If we reach this point, the client is expecting data.
-        * Need to parse each line of the message here since someone may have sent
-        * a message containing a single dot on a line of its own. In that case we
-        * need to escape it in accordance with RFC821.
-        * We could do this with the tokenizer functions but num_tokens returns an
-        * int and the message may contain more lines than that, also copying each
-        * line would be slow.
-        */
-       nextline = msgtext;
-       while (*nextline)
-       {
-               chunk_to_send = nextline;
-               while (*nextline != '\n')
-                       nextline++;
-               nextline++;
-               prev_char = *nextline;
-               *nextline = '\0';
-               if (!strcmp(chunk_to_send, ".\r\n")) {
-                       client_write("..\r\n", 4);
-               }
-               else {
-                       client_write(chunk_to_send, (size_t)(nextline-chunk_to_send));
-               }
-               *nextline = prev_char;
-       }
+       CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, ESC_DOT);
        cprintf(".\r\n");
 }
 
index fada0bf9880fb2a7700643552b0bd16d48511b92..ee5ee10c777de9a3e4ab5f76e20700a1aa1ba644 100644 (file)
@@ -942,7 +942,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        CC->redirect_buffer = malloc(SIZ);
        CC->redirect_len = 0;
        CC->redirect_alloc = SIZ;
-       CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, 0);
+       CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, ESC_DOT);
        msgtext = CC->redirect_buffer;
        msg_size = CC->redirect_len;
        CC->redirect_buffer = NULL;
@@ -1202,38 +1202,8 @@ void smtp_try(const char *key, const char *addr, int *status,
                }
        }
 
-       /* If we reach this point, the server is expecting data.
-        * Need to parse each line of the message here since someone may have sent
-        * a message containing a single dot on a line of its own. In that case we
-        * need to escape it in accordance with RFC821.
-        * We could do this with the tokenizer functions but num_tokens returns an
-        * int and the message may contain more lines than that, also copying each
-        * line would be slow.
-        */
-       int bytes_written = 0;
-       nextline = msgtext;
-       while ( (*nextline) && (bytes_written >= 0) )
-       {
-               chunk_to_send = nextline;
-               while (*nextline != '\n')
-                       nextline++;
-               nextline++;
-               prev_char = *nextline;
-               *nextline = '\0';
-               if (!strcmp(chunk_to_send, ".\r\n")) {
-                       bytes_written = sock_write(sock, "..\r\n", 4);
-               }
-               else {
-                       bytes_written = sock_write(sock, chunk_to_send, (size_t)(nextline-chunk_to_send));
-               }
-               *nextline = prev_char;
-               if (bytes_written < 0) {
-                       *status = 4;
-                       strcpy(dsn, "Connection broken during SMTP message transmit");
-                       goto bail;
-               }
-       }
-       
+       /* If we reach this point, the server is expecting data.*/
+       sock_write(sock, msgtext, msg_size);
        if (msgtext[msg_size-1] != 10) {
                CtdlLogPrintf(CTDL_WARNING, "Possible problem: message did not "
                        "correctly terminate. (expecting 0x10, got 0x%02x)\n",
index 28601e5bebd4b122e4353fac637fd15b78012c26..7ce6bc5ab5a3d3fbcb2e89ea41f3109237eebd15 100644 (file)
@@ -1577,7 +1577,7 @@ int CtdlOutputPreLoadedMsg(
 ) {
        int i, j, k;
        char buf[SIZ];
-       cit_uint8_t ch;
+       cit_uint8_t ch, prev_ch;
        char allkeys[30];
        char display_name[256];
        char *mptr, *mpptr;
@@ -1764,7 +1764,7 @@ int CtdlOutputPreLoadedMsg(
                                        safestrncpy(suser, mptr, sizeof suser);
                                }
                                else if (i == 'Y') {
-                                       if (flags & QP_EADDR != 0) 
+                                       if ((flags & QP_EADDR) != 0) 
                                                mptr = qp_encode_email_addrs(mptr);
                                        cprintf("CC: %s%s", mptr, nl);
                                }
@@ -1772,7 +1772,7 @@ int CtdlOutputPreLoadedMsg(
                                        cprintf("Return-Path: %s%s", mptr, nl);
                                }
                                else if (i == 'V') {
-                                       if (flags & QP_EADDR != 0) 
+                                       if ((flags & QP_EADDR) != 0) 
                                                mptr = qp_encode_email_addrs(mptr);
                                        cprintf("Envelope-To: %s%s", mptr, nl);
                                }
@@ -1799,7 +1799,7 @@ int CtdlOutputPreLoadedMsg(
                                        }
                                        else
                                        {
-                                               if (flags & QP_EADDR != 0) 
+                                               if ((flags & QP_EADDR) != 0) 
                                                        mptr = qp_encode_email_addrs(mptr);
                                                cprintf("To: %s%s", mptr, nl);
                                        }
@@ -1897,6 +1897,7 @@ START_TEXT:
                        char outbuf[1024];
                        int outlen = 0;
                        int nllen = strlen(nl);
+                       prev_ch = 0;
                        while (ch=*mptr, ch!=0) {
                                if (ch==13) {
                                        /* do nothing */
@@ -1916,6 +1917,14 @@ START_TEXT:
                                                }
                                        }
                                }
+                               if (flags & ESC_DOT)
+                               {
+                                       if ((prev_ch == 10) && (ch == '.') && ((*(mptr+1) == 13) || (*(mptr+1) == 10)))
+                                       {
+                                               outbuf[outlen++] = '.';
+                                       }
+                               }
+                               prev_ch = ch;
                                ++mptr;
                                if (outlen > 1000) {
                                        client_write(outbuf, outlen);
index f064dbbddea66741133bf70584a1dfce2253becb..754656d58ff0d02270db87a149f514ef54e111f9 100644 (file)
@@ -144,6 +144,8 @@ int CtdlOutputMsg(long msg_num,             /* message number (local) to fetch */
 
 #define QP_EADDR (1<<0)
 #define CRLF (1<<1)
+#define ESC_DOT (1<<2)
+
 int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
                           int mode,            /* how would you like that message? */
                           int headers_only,    /* eschew the message body? */