X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=6c1bc97cd81b51a4e1a53997964e42b7853f81c5;hb=42e5566f6512bc39f9377d183f26dddfc36d10ea;hp=3130d394672e43ed0439f79bc5db7a9e4bf42424;hpb=dd9dcfceb5d639bd9b217dccf9c5a0d7ed94b1ba;p=citadel.git
diff --git a/webcit/messages.c b/webcit/messages.c
index 3130d3946..6c1bc97cd 100644
--- a/webcit/messages.c
+++ b/webcit/messages.c
@@ -982,6 +982,67 @@ DONE:
}
+/*
+ * Back end for post_message() ... this is where the actual message
+ * gets transmitted to the server.
+ */
+void post_mime_to_server(void) {
+ char boundary[SIZ];
+ int is_multipart = 0;
+ static int seq = 0;
+ struct wc_attachment *att;
+ char *encoded;
+ size_t encoded_length;
+
+ /* If there are attachments, we have to do multipart/mixed */
+ if (WC->first_attachment != NULL) {
+ is_multipart = 1;
+ }
+
+ if (is_multipart) {
+ sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
+ serv_info.serv_fqdn,
+ getpid(),
+ ++seq
+ );
+
+ /* Remember, serv_printf() appends an extra newline */
+ serv_printf("Content-type: multipart/mixed; "
+ "boundary=\"%s\"\n", boundary);
+ serv_printf("This is a multipart message in MIME format.\n");
+ serv_printf("--%s", boundary);
+ }
+
+ serv_puts("Content-type: text/html");
+ serv_puts("");
+ text_to_server(bstr("msgtext"), 1);
+
+ if (is_multipart) {
+
+ /* Add in the attachments */
+ for (att = WC->first_attachment; att!=NULL; att=att->next) {
+
+ encoded_length = ((att->length * 150) / 100);
+ encoded = malloc(encoded_length);
+ if (encoded == NULL) break;
+ CtdlEncodeBase64(encoded, att->data, att->length);
+
+ serv_printf("--%s", boundary);
+ serv_printf("Content-type: %s", att->content_type);
+ serv_printf("Content-disposition: attachment; "
+ "filename=\"%s\"", att->filename);
+ serv_puts("Content-transfer-encoding: base64");
+ serv_puts("");
+ serv_write(encoded, strlen(encoded));
+ serv_puts("");
+ serv_puts("");
+ free(encoded);
+ }
+ serv_printf("--%s--", boundary);
+ }
+
+ serv_puts("000");
+}
/*
@@ -999,11 +1060,31 @@ void post_message(void)
{
char buf[SIZ];
static long dont_post = (-1L);
+ struct wc_attachment *att;
+
+ if (WC->upload_length > 0) {
+
+ att = malloc(sizeof(struct wc_attachment));
+ memset(att, 0, sizeof(struct wc_attachment));
+ att->next = WC->first_attachment;
+ WC->first_attachment = att;
+ att->length = WC->upload_length;
+ strcpy(att->content_type, WC->upload_content_type);
+ strcpy(att->filename, WC->upload_filename);
+
+ /* Transfer control of this memory from the upload struct
+ * to the attachment struct.
+ */
+ att->data = WC->upload;
+ WC->upload_length = 0;
+ WC->upload = NULL;
+ display_enter();
+ return;
+ }
output_headers(1);
- strcpy(buf, bstr("sc"));
- if (strcasecmp(buf, "Save message")) {
+ if (strcasecmp(bstr("sc"), "Save message")) {
wprintf("Cancelled. Message was not posted.
\n");
} else if (atol(bstr("postseq")) == dont_post) {
wprintf("Automatically cancelled because you have already "
@@ -1015,10 +1096,7 @@ void post_message(void)
serv_puts(buf);
serv_gets(buf);
if (buf[0] == '4') {
- serv_puts("Content-type: text/html");
- serv_puts("");
- text_to_server(bstr("msgtext"), 1);
- serv_puts("000");
+ post_mime_to_server();
wprintf("Message has been posted.
\n");
dont_post = atol(bstr("postseq"));
} else {
@@ -1027,6 +1105,7 @@ void post_message(void)
}
wDumpContent(1);
+ free_attachments(WC);
}
@@ -1040,6 +1119,7 @@ void display_enter(void)
char buf[SIZ];
long now;
struct tm *tm;
+ struct wc_attachment *att;
output_headers(1);
@@ -1074,20 +1154,39 @@ void display_enter(void)
wprintf("in %s> ", WC->wc_roomname);
wprintf("