Markdown: Properly escape stuff on the way to the server; fix loading & saving from...
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 8 Dec 2013 15:25:20 +0000 (16:25 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 8 Dec 2013 15:25:20 +0000 (16:25 +0100)
webcit/event.c
webcit/messages.c
webcit/serv_func.c
webcit/static/t/edit/markdown_epic.html
webcit/tcp_sockets.h

index 13c5a3e4c1cebea1757a60b4ac97d806a01bcf8c..f5b78f4e8d0eb2086bd461a2dc5107af6b6fbbd4 100644 (file)
@@ -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':
index 9e538d234a64e106a857606ce5c3fac602f3b6c4..9f9f9730f7b9bd291fc06ab85c192b98cadd434b 100644 (file)
@@ -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("<html><body>\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("</body></html>\r\n");
        }
 
index f03ff442a6005bad75639b5352800558432624f8..dd1cc4deef70c1247a727dc9710237506682a481 100644 (file)
@@ -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);
 }
 
 
index 2bc4f9eb63b23f142ebe8ef3712377cad72bbf1d..19c8dc2844b38b1ffa791974bc738240d5b46598 100644 (file)
     </div>
 </div>
 
+<div class="entmsg" id="entmsg">
+<form id="theenterform" accept-charset="UTF-8" enctype="multipart/form-data" method="POST" action="post">
+<input type="hidden" name="postseq" value="<?DATE:NOW:NO>">
+<input type="hidden" name="return_to" value="<?BSTR("return_to")>">
+<input type="hidden" name="nonce" value="<?NONCE>">
+<input type="hidden" name="force_room" value="<?THISROOM:NAME("X")>">
+<input type="hidden" name="references" value="<?BSTR("references")>">
+<input type="hidden" name="page" value="<?BSTR("page")>">
+<input type="hidden" name="markdown" value="1">
+<textarea style="display:none" name="msgtext" id="submitmsgtext" cols="80" rows="15"><?MAIL:EDITWIKI("edit", "X")></textarea>
+</form>
+
 <div id="Author">
 <select name="display_name" size=1 id="from_id">
 <?ITERATE("PREF:VALID:EMAIL:NAME", ="prefs_section_msg_handle_select")>
 <?!("X", 3)>
 </select>
 </div>
-<div id="epiceditor">
 
+<div id="epiceditor" />
 
-<textarea id="msgtext" cols="80" rows="15"><?MAIL:EDITWIKI("edit", "X")></textarea>
-</div>
 
+</div>
 </div>
 </div>
 
 </div>
 
 <script type="text/javascript">        
-    console.log('blarg');
        $("navbar").innerHTML = $("submit-o-matic").innerHTML;
-    console.log('blub');
 
        function submit_post(which_action) {
-           
-       var p = { "postseq":"<?DATE:NOW:NO>",
-                 "return_to":"<?BSTR("return_to")>",
-                 "nonce":"<?NONCE>",
-                 "force_room":"<?THISROOM:NAME("X")>",
-                 "references":"<?BSTR("references")>",
-                 "page":"<?BSTR("page")>",
-                 "display_name":"willi",
-                 "submit_action":"",
-                 "markdown":"1",
-                 "msgtext" : editor.exportFile()
-       };
-
-       new Ajax.Request('post', {
-               method: 'post',
-               parameters: p,
-               onComplete: function(transport) { ajax_important_message(transport.responseText.substr(4));}
-       });
+           var textarea=document.getElementById('submitmsgtext');
+           textarea.value = editor.exportFile();
+           editor.unload();
+           document.getElementById("theenterform").submit();
        }
 
        function hide_attachments_form() {
 
 <script type="text/javascript"> 
 var editor = new EpicEditor().load();
+editor.importFile('CitadelEditBuffer', document.getElementById('submitmsgtext').value);
 </script>
 <?=("addressbook_popup")>
 <?=("trailing")>
index 4546669052b4cf1fb437bf04427b9afeb1e86a46..cb4987ce33881d4452665e6ac3aba6fb9de99a55 100644 (file)
@@ -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);