From: Art Cancro Date: Mon, 30 Jan 2006 05:15:09 +0000 (+0000) Subject: HTML messages are now encoded as "Quoted-Printable" before being X-Git-Tag: v7.86~4252 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=124ab56a15b0de7b3db6b3896445c479ef7becc8 HTML messages are now encoded as "Quoted-Printable" before being transmitted to the server. New utility function text_to_server_qp() handles this. --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 3014c39dd..01a426bc7 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,5 +1,10 @@ $Id$ +Mon Jan 30 00:14:06 EST 2006 ajc +* HTML messages are now encoded as "Quoted-Printable" before being + transmitted to the server. New utility function text_to_server_qp() + handles this. + Sun Jan 29 23:20:48 EST 2006 ajc * Removed the "convert_to_html" option from text_to_server() because we no longer have any callers which require it. diff --git a/webcit/messages.c b/webcit/messages.c index 37aeb321f..8dadcf0ce 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -2443,12 +2443,12 @@ void post_mime_to_server(void) { } serv_puts("Content-type: text/html; charset=utf-8"); + serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); - serv_puts("\n"); /** Future templates go here */ - text_to_server(bstr("msgtext")); - serv_puts("\n"); + serv_puts("\r\n"); + text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */ + serv_puts("\r\n"); - if (is_multipart) { /** Add in the attachments */ diff --git a/webcit/serv_func.c b/webcit/serv_func.c index 2325d8dbf..9f946ddbc 100644 --- a/webcit/serv_func.c +++ b/webcit/serv_func.c @@ -225,6 +225,81 @@ void text_to_server(char *ptr) } +/** + * \brief Transmit message text (in memory) to the server, + * converting to Quoted-Printable encoding as we go. + * + * \param ptr Pointer to the message being transmitted + */ +void text_to_server_qp(char *ptr) +{ + char buf[256]; + int ch, pos; + int output_len = 0; + + pos = 0; + buf[0] = 0; + output_len = 0; + + while (ptr[pos] != 0) { + ch = ptr[pos++]; + + if (ch == 13) { + /* ignore carriage returns */ + } + else if (ch == 10) { + /* hard line break */ + if (output_len > 0) { + if (isspace(buf[output_len-1])) { + sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]); + output_len += 2; + } + } + buf[output_len++] = 0; + serv_puts(buf); + output_len = 0; + } + else if (ch == 9) { + buf[output_len++] = ch; + } + else if ( (ch >= 32) && (ch <= 60) ) { + buf[output_len++] = ch; + } + else if ( (ch >= 62) && (ch <= 126) ) { + buf[output_len++] = ch; + } + else { + sprintf(&buf[output_len], "=%02X", ch); + output_len += 3; + } + + if (output_len > 72) { + /* soft line break */ + if (isspace(buf[output_len-1])) { + sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]); + output_len += 2; + } + buf[output_len++] = '='; + buf[output_len++] = 0; + serv_puts(buf); + output_len = 0; + } + } + + /* end of data - transmit anything that's left */ + if (output_len > 0) { + if (isspace(buf[output_len-1])) { + sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]); + output_len += 2; + } + buf[output_len++] = 0; + serv_puts(buf); + output_len = 0; + } +} + + + /** * \brief translate server message output to text diff --git a/webcit/webcit.h b/webcit/webcit.h index 953b798fb..ffa329a7d 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -482,6 +482,7 @@ void embed_message(char *msgnum_as_string); void print_message(char *msgnum_as_string); void display_headers(char *msgnum_as_string); void text_to_server(char *ptr); +void text_to_server_qp(char *ptr); void display_enter(void); void post_message(void); void confirm_delete_msg(void);