From: Dave West Date: Sun, 25 May 2008 19:01:17 +0000 (+0000) Subject: Now the escaping of a single dot on a line of its own is done in CtdlOutputPreloadedMsg() X-Git-Tag: v7.86~2210 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=e61a54965652d093c8f94dd006866ee0086e4ec5 Now the escaping of a single dot on a line of its own is done in CtdlOutputPreloadedMsg() --- diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index 43a2545d8..5911f4761 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -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"); } diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index fada0bf98..ee5ee10c7 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -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", diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 28601e5be..7ce6bc5ab 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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); diff --git a/citadel/msgbase.h b/citadel/msgbase.h index f064dbbdd..754656d58 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -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? */