X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fpop3%2Fserv_pop3.c;h=e839f5ec9c6e4c72c0148069ed759206c96211e6;hb=457881d8c1cd754d4d319496617bf80d3f8ef8cc;hp=c8bcb2fc93f425c902c60b17c90bc7c10be8ca31;hpb=a1af3c2833ea0c5e6e7e7b4e42c5f72ca94c95cc;p=citadel.git diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index c8bcb2fc9..e839f5ec9 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -360,6 +360,10 @@ void pop3_stat(char *argbuf) { */ void pop3_retr(char *argbuf) { int which_one; + char *msgtext; + char *nextline; + char *chunk_to_send; + char prev_char; which_one = atoi(argbuf); if ( (which_one < 1) || (which_one > POP3->num_msgs) ) { @@ -373,7 +377,41 @@ void pop3_retr(char *argbuf) { } cprintf("+OK Message %d:\r\n", which_one); - CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL); + 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); + 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; + } cprintf(".\r\n"); }