messages.c: inching towards saving the attachments
authorArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 22:55:08 +0000 (18:55 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 22:55:08 +0000 (18:55 -0400)
webcit-ng/server/messages.c
webcit-ng/server/webcit.h

index 7c111863cf421d39291cd7397e3df7b58c0617ce..ef244aab059ac08a4bb4e46cc2afa1564aaf1db3 100644 (file)
@@ -186,12 +186,6 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
        char *mailbcc = get_url_param(h, "mailbcc");    // Bcc:
        if (!mailbcc) mailbcc = "";
 
-       // 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, "💥 There are attachments.  Going multipart/mixed. <%s>", att);
-       }
-
        // Mode 4 will give us metadata back after upload
        ctdl_printf(c, "ENT0 1|%s||4|%s||1|%s|%s|||%s|", mailto, subj, mailcc, mailbcc, wefw);
        ctdl_readline(c, buf, sizeof buf);
@@ -207,8 +201,8 @@ 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.
+       char *att = get_url_param(h, "att");
        if (att) {
                snprintf(mime_boundary, sizeof(mime_boundary), "citadel-multipart-%x-%x", time(NULL), rand());
                ctdl_printf(c, "MIME-Version: 1.0\r");
@@ -227,9 +221,20 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
                ctdl_write(c, HKEY("\r\n"));
        }
 
-       // If there are attachments, close the multipart/mixed MIME container.
+       // If there are attachments, add them now.
        if (att) {
-               // FIXME actually attach the attachments here.
+               int i;
+               char attid[10];
+               struct uploaded_file one_att;
+               int num_attachments = num_tokens(att, ',');
+
+               for (i=0; i<num_attachments; ++i) {
+                       extract_token(attid, att, i, ',', sizeof(attid));
+                       one_att = pop_upload(attid);
+                       syslog(LOG_DEBUG, "💥 attachment: %s", one_att.filename);
+               }
+
+               // Close the multipart/mixed MIME container.
                ctdl_printf(c, "--%s--\r", mime_boundary);
        }
 
index 0b415ade0885c52b259908b503fb725c9affc5b7..a8c1275a88858ec809fedec59554baa94c5fb4e0 100644 (file)
@@ -179,3 +179,4 @@ int webcit_tcp_server(const char *ip_addr, int port_number, int queue_len);
 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
 void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
 void upload_files(struct http_transaction *h, struct ctdlsession *c);
+struct uploaded_file pop_upload(char *id);