]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
Attachments: start using fineuploader.com to upload attachments to messages.
[citadel.git] / webcit / messages.c
index 9e538d234a64e106a857606ce5c3fac602f3b6c4..29fd30559e90dc02a327ae77606403d947b72342 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");
        }
 
@@ -1229,19 +1232,31 @@ void upload_attachment(void) {
        long newnlen;
        void *v;
        wc_mime_attachment *att;
+       const StrBuf *Tmpl = sbstr("template");
+       const StrBuf *MimeType = NULL;
 
+       begin_burst();
        syslog(LOG_DEBUG, "upload_attachment()\n");
-       wc_printf("upload_attachment()<br>\n");
+       if (!Tmpl) wc_printf("upload_attachment()<br>\n");
 
        if (WCC->upload_length <= 0) {
                syslog(LOG_DEBUG, "ERROR no attachment was uploaded\n");
-               wc_printf("ERROR no attachment was uploaded<br>\n");
+               if (Tmpl)
+               {
+                       putlbstr("UPLOAD_ERROR", 1);
+                       MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+               }
+               else      wc_printf("ERROR no attachment was uploaded<br>\n");
+               http_transmit_thing(ChrPtr(MimeType), 0);
+               
                return;
        }
 
        syslog(LOG_DEBUG, "Client is uploading %d bytes\n", WCC->upload_length);
-       wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
-       att = malloc(sizeof(wc_mime_attachment));
+       if (Tmpl) putlbstr("UPLOAD_LENGTH", WCC->upload_length);
+       else wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
+
+       att = (wc_mime_attachment*)malloc(sizeof(wc_mime_attachment));
        memset(att, 0, sizeof(wc_mime_attachment ));
        att->length = WCC->upload_length;
        att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
@@ -1281,6 +1296,9 @@ void upload_attachment(void) {
        att->Data = WCC->upload;
        WCC->upload = NULL;
        WCC->upload_length = 0;
+       
+       if (Tmpl) MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+       http_transmit_thing(ChrPtr(MimeType), 0);
 }