Got multipart/mixed being transmitted
authorArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 22:36:29 +0000 (18:36 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 22:36:29 +0000 (18:36 -0400)
webcit-ng/server/messages.c

index ee5f3424964720c6c90759a6e866faa0432265f6..7c111863cf421d39291cd7397e3df7b58c0617ce 100644 (file)
@@ -167,6 +167,7 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
        long new_msgnum;
        char new_euid[1024];
        char response_string[1024];
+       char mime_boundary[80];
 
        if ((h->request_body == NULL) || (h->request_body_length < 1)) {
                do_404(h);                              // Refuse to post a null message
@@ -187,8 +188,8 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
 
        // If there are attachments, we have to merge them into the message text.
        char *att = get_url_param(h, "att");
-       if (!att) {
-               syslog(LOG_DEBUG, "attachments: <%s>", att);            // FIXME write this
+       if (att) {
+               syslog(LOG_DEBUG, "💥 There are attachments.  Going multipart/mixed. <%s>", att);
        }
 
        // Mode 4 will give us metadata back after upload
@@ -206,6 +207,18 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
        // Remember, ctdl_printf() appends \n on its own, so when adding a CRLF newline, only use \r
        // Or for a blank line, use ctdl_write() with \r\n
 
+
+       // If there are attachments, open up a multipart/mixed MIME container.
+       if (att) {
+               snprintf(mime_boundary, sizeof(mime_boundary), "citadel-multipart-%x-%x", time(NULL), rand());
+               ctdl_printf(c, "MIME-Version: 1.0\r");
+               ctdl_printf(c, "Content-Type: multipart/mixed; boundary=\"%s\"\r", mime_boundary);
+               ctdl_write(c, HKEY("\r\n"));
+               ctdl_write(c, HKEY("\r\n"));
+               ctdl_printf(c, "--%s\r", mime_boundary);        // start of message body
+       }
+
+       // This section
        content_type = header_val(h, "Content-type");
        ctdl_printf(c, "Content-type: %s\r", (content_type ? content_type : "application/octet-stream"));
        ctdl_write(c, HKEY("\r\n"));
@@ -213,10 +226,17 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
        if (h->request_body[h->request_body_length] != '\n') {
                ctdl_write(c, HKEY("\r\n"));
        }
-       ctdl_printf(c, "000");
 
-       // Now handle the response from the Citadel server.
+       // If there are attachments, close the multipart/mixed MIME container.
+       if (att) {
+               // FIXME actually attach the attachments here.
+               ctdl_printf(c, "--%s--\r", mime_boundary);
+       }
+
+       // Done writing to the Citadel Server.
+       ctdl_printf(c, "000");
 
+       // Now handle the response from the Citadel Server.
        n = 0;
        new_msgnum = 0;
        strcpy(new_euid, "");