From 4bde8611a7a9af19f8239459b8aab07a5542b03b Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 8 Dec 2013 16:25:20 +0100 Subject: [PATCH] Markdown: Properly escape stuff on the way to the server; fix loading & saving from the editor. --- webcit/event.c | 5 +- webcit/messages.c | 9 ++-- webcit/serv_func.c | 68 ++----------------------- webcit/static/t/edit/markdown_epic.html | 42 +++++++-------- webcit/tcp_sockets.h | 2 +- 5 files changed, 35 insertions(+), 91 deletions(-) diff --git a/webcit/event.c b/webcit/event.c index 13c5a3e4c..f5b78f4e8 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -796,6 +796,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, */ void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread, calview *calv) { + StrBuf *Buf; char buf[SIZ]; icalproperty *prop; icalcomponent *vevent, *encaps; @@ -1162,7 +1163,9 @@ STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDE serv_puts("Content-type: text/calendar"); serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); - text_to_server_qp(icalcomponent_as_ical_string(encaps)); + Buf = NewStrBufPlain(icalcomponent_as_ical_string(encaps), -1); + text_to_server_qp(Buf); + FreeStrBuf(&Buf); // serv_puts(icalcomponent_as_ical_string(encaps)); serv_puts("000"); case '4': diff --git a/webcit/messages.c b/webcit/messages.c index 9e538d234..9f9f9730f 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -930,6 +930,7 @@ void post_mime_to_server(void) { /* Remember, serv_printf() appends an extra newline */ if (include_text_alt) { + StrBuf *Buf; serv_printf("Content-type: multipart/alternative; " "boundary=\"%s\"\n", alt_boundary); serv_printf("This is a multipart message in MIME format.\n"); @@ -939,9 +940,11 @@ void post_mime_to_server(void) { serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0); - text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */ + Buf = NewStrBufPlain(txtmail, -1); free(txtmail); + text_to_server_qp(Buf); /* Transmit message in quoted-printable encoding */ + FreeStrBuf(&Buf); serv_printf("\n--%s", alt_boundary); } @@ -950,7 +953,7 @@ void post_mime_to_server(void) { serv_puts("Content-type: text/x-markdown; charset=utf-8"); serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); - text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */ + text_to_server_qp(sbstr("msgtext")); /* Transmit message in quoted-printable encoding */ } else { @@ -958,7 +961,7 @@ void post_mime_to_server(void) { serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); serv_puts("\r\n"); - text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */ + text_to_server_qp(sbstr("msgtext")); /* Transmit message in quoted-printable encoding */ serv_puts("\r\n"); } diff --git a/webcit/serv_func.c b/webcit/serv_func.c index f03ff442a..dd1cc4dee 100644 --- a/webcit/serv_func.c +++ b/webcit/serv_func.c @@ -376,71 +376,13 @@ void text_to_server(char *ptr) /* * Transmit message text (in memory) to the server, converting to Quoted-Printable encoding as we go. */ -void text_to_server_qp(char *ptr) +void text_to_server_qp(const StrBuf *SendMeEncoded) { - unsigned char ch, buf[256]; - int pos; - int output_len = 0; + StrBuf *ServBuf; - pos = 0; - buf[0] = 0; - output_len = 0; - - while (ptr[pos] != 0) { - ch = (unsigned char)(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((char *)&buf[output_len-1], "=%02X", buf[output_len-1]); - output_len += 2; - } - } - buf[output_len++] = 0; - serv_puts((char *)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((char *)&buf[output_len], "=%02X", ch); - output_len += 3; - } - - if (output_len > 72) { - /* soft line break */ - if (isspace(buf[output_len-1])) { - sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]); - output_len += 2; - } - buf[output_len++] = '='; - buf[output_len++] = 0; - serv_puts((char *)buf); - output_len = 0; - } - } - - /* end of data - transmit anything that's left */ - if (output_len > 0) { - if (isspace(buf[output_len-1])) { - sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]); - output_len += 2; - } - buf[output_len++] = 0; - serv_puts((char *)buf); - output_len = 0; - } + ServBuf = StrBufRFC2047encodeMessage(SendMeEncoded); + serv_putbuf(ServBuf); + FreeStrBuf(&ServBuf); } diff --git a/webcit/static/t/edit/markdown_epic.html b/webcit/static/t/edit/markdown_epic.html index 2bc4f9eb6..19c8dc284 100644 --- a/webcit/static/t/edit/markdown_epic.html +++ b/webcit/static/t/edit/markdown_epic.html @@ -14,6 +14,18 @@ +
+
+ +"> + +"> +"> +"> + + +
+
-
+
- -
+
@@ -78,29 +89,13 @@ diff --git a/webcit/tcp_sockets.h b/webcit/tcp_sockets.h index 454666905..cb4987ce3 100644 --- a/webcit/tcp_sockets.h +++ b/webcit/tcp_sockets.h @@ -46,6 +46,6 @@ int StrBuf_ServGetBLOBBuffered(StrBuf *buf, long BlobSize); int read_server_text(StrBuf *Buf, long *nLines); void text_to_server(char *ptr); -void text_to_server_qp(char *ptr); +void text_to_server_qp(const StrBuf *SendMeEncoded); void server_to_text(void); int lingering_close(int fd); -- 2.30.2