}
+// When reloading attachments already in an existing message, accept only parts that are tagged as attachments.
+void attachment_filter(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, char *cbcharset,
+ size_t length, char *encoding, char *cbid, void *userdata)
+{
+ struct uploaded_file u;
+
+ if (!strcasecmp(disp, "attachment")) {
+ upload_handler(name, filename, partnum, disp, content, cbtype, cbcharset, length, encoding, cbid, userdata);
+ }
+}
+
+
// Load the attachments from an existing message. This is typically used when forwarding a message,
// so the attachments don't have to be sent out to the browser and back.
void load_attachments_from_message(struct http_transaction *h, struct ctdlsession *c, char *name) {
return;
}
+ JsonValue *j_uploads = NewJsonArray(HKEY(""));
+ Body = NewStrBuf();
while (ctdl_readline(c, buf, sizeof buf), strcmp(buf, "000")) {
- // do something
+ StrBufAppendPrintf(Body, "%s\n", buf);
}
+ char *raw_message = SmashStrBuf(&Body);
+ mime_parser(raw_message, NULL, *attachment_filter, NULL, NULL, j_uploads, 0);
+ free(raw_message);
- do_405(h);
+ // probably do something more clever here
+ h->response_code = 200;
+ h->response_string = strdup("OK");
+
+ // send back a JSON array of all files uploaded
+ StrBuf *sj = NewStrBuf();
+ SerializeJson(sj, j_uploads, 1); // '1' == free the source object
+ add_response_header(h, strdup("Content-type"), strdup("application/json"));
+ h->response_code = 200;
+ h->response_string = strdup("OK");
+ h->response_body_length = StrLength(sj);
+ h->response_body = SmashStrBuf(&sj);
+ syslog(LOG_DEBUG, "upload: %s", h->response_body);
}