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
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, "attachments: <%s>", att); // FIXME write this
- }
-
// 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);
// 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", (unsigned int)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"));
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, add them now.
+ if (att) {
+ 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);
+ ctdl_printf(c, "--%s--\r", mime_boundary);
+ ctdl_printf(c, "Content-Type: %s; name=\"%s\"\r", one_att.content_type, one_att.filename);
+ ctdl_printf(c, "Content-Disposition: attachment; filename=\"%s\"\r", one_att.filename);
+ ctdl_printf(c, "Content-Transfer-Encoding: base64\r");
+ ctdl_write(c, HKEY("\r\n"));
+
+ char *raw_att = malloc(one_att.length);
+ if (raw_att) {
+ fread(raw_att, one_att.length, 1, one_att.fp);
+
+ // now encode it
+
+ }
+
+ fclose(one_att.fp);
+ }
+
+ // Close the multipart/mixed MIME container.
+ 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, "");