From 87f08c14c5d31bcca509685a8a4fc8af8f221120 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 11 Dec 2008 00:00:36 +0000 Subject: [PATCH] * load attachments in forwarded messages * just one mime struct should fit it all. --- webcit/context_loop.c | 11 --- webcit/messages.c | 71 ++++++++++---------- webcit/msg_renderers.c | 37 ++++++++-- webcit/static/t/load_attachments.html | 3 + webcit/static/t/view_message_replyquote.html | 2 +- webcit/webcit.c | 15 +++-- webcit/webcit.h | 14 ---- 7 files changed, 80 insertions(+), 73 deletions(-) create mode 100644 webcit/static/t/load_attachments.html diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 7af1790c1..128487dc0 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -19,17 +19,6 @@ struct wcsession *SessionList = NULL; /**< our sessions ????*/ pthread_key_t MyConKey; /**< TSD key for MySession() */ -/* - * free the memory used for viewing atachments - */ -void free_attachment(void *vattach) { - wc_attachment *att = (wc_attachment*) vattach; - FreeStrBuf(&att->content_type); - FreeStrBuf(&att->filename); - free(att->data); - free(att); -} - void DestroySession(struct wcsession **sessions_to_kill) { diff --git a/webcit/messages.c b/webcit/messages.c index 2286a0421..a3e44fddd 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -348,7 +348,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers char *attachments = NULL; char *ptr = NULL; int num_attachments = 0; - wc_attachment *att; + //wc_attachment *att; char m_subject[1024]; char from[256]; char node[256]; @@ -618,25 +618,25 @@ ENDBODY: lprintf(9, "fwd dispose : %s\n", mime_disposition); lprintf(9, "fwd length : %d\n", mime_length); - if ( (!strcasecmp(mime_disposition, "inline")) - || (!strcasecmp(mime_disposition, "attachment")) ) { +/// if ( (!strcasecmp(mime_disposition, "inline")) +/// || (!strcasecmp(mime_disposition, "attachment")) ) { - int n; - char N[64]; - /* Create an attachment struct from this mime part... */ - att = malloc(sizeof(wc_attachment)); - memset(att, 0, sizeof(wc_attachment)); - att->length = mime_length; - att->content_type = NewStrBufPlain(mime_content_type, -1); - att->filename = NewStrBufPlain(mime_filename, -1); - att->data = load_mimepart(msgnum, mime_partnum); - - if (WCC->attachments == NULL) - WCC->attachments = NewHash(1, NULL); - /* And add it to the list. */ - n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1); - Put(WCC->attachments, N, n, att, free_attachment); - } +///// int n; +///// char N[64]; +///// /* Create an attachment struct from this mime part... */ +///// att = malloc(sizeof(wc_attachment)); +///// memset(att, 0, sizeof(wc_attachment)); +///// att->length = mime_length; +///// att->content_type = NewStrBufPlain(mime_content_type, -1); +///// att->filename = NewStrBufPlain(mime_filename, -1); +///// att->data = load_mimepart(msgnum, mime_partnum); +///// +///// if (WCC->attachments == NULL) +///// WCC->attachments = NewHash(1, NULL); +///// /* And add it to the list. */ +///// n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1); +///// Put(WCC->attachments, N, n, att, free_attachment); +///// } } } @@ -1355,7 +1355,7 @@ void post_mime_to_server(void) { char alt_boundary[SIZ]; int is_multipart = 0; static int seq = 0; - wc_attachment *att; + wc_mime_attachment *att; char *encoded; size_t encoded_length; size_t encoded_strlen; @@ -1421,15 +1421,15 @@ void post_mime_to_server(void) { /* Add in the attachments */ it = GetNewHashPos(WCC->attachments, 0); while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) { - att = (wc_attachment*)vAtt; + att = (wc_mime_attachment *)vAtt; encoded_length = ((att->length * 150) / 100); encoded = malloc(encoded_length); if (encoded == NULL) break; - encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1); + encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1); serv_printf("--%s", top_boundary); - serv_printf("Content-type: %s", ChrPtr(att->content_type)); - serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->filename)); + serv_printf("Content-type: %s", ChrPtr(att->ContentType)); + serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName)); serv_puts("Content-transfer-encoding: base64"); serv_puts(""); serv_write(encoded, encoded_strlen); @@ -1461,7 +1461,7 @@ void post_message(void) char buf[1024]; StrBuf *encoded_subject = NULL; static long dont_post = (-1L); - wc_attachment *att; + wc_mime_attachment *att; int is_anonymous = 0; const StrBuf *display_name = NULL; struct wcsession *WCC = WC; @@ -1485,38 +1485,39 @@ void post_message(void) lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length); /** There's an attachment. Save it to this struct... */ - att = malloc(sizeof(wc_attachment)); - memset(att, 0, sizeof(wc_attachment)); + att = malloc(sizeof(wc_mime_attachment)); + memset(att, 0, sizeof(wc_mime_attachment )); att->length = WCC->upload_length; - att->content_type = NewStrBufPlain(WCC->upload_content_type, -1); - att->filename = NewStrBufPlain(WCC->upload_filename, -1); + att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1); + att->FileName = NewStrBufPlain(WCC->upload_filename, -1); if (WCC->attachments == NULL) WCC->attachments = NewHash(1, NULL); /* And add it to the list. */ n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1); - Put(WCC->attachments, N, n, att, free_attachment); + Put(WCC->attachments, N, n, att, DestroyMime); /** * Mozilla sends a simple filename, which is what we want, * but Satan's Browser sends an entire pathname. Reduce * the path to just a filename if we need to. */ - pch = strrchr(ChrPtr(att->filename), '/'); + pch = strrchr(ChrPtr(att->FileName), '/'); if (pch != NULL) { - StrBufCutLeft(att->filename, pch - ChrPtr(att->filename)); + StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName)); } - pch = strrchr(ChrPtr(att->filename), '\\'); + pch = strrchr(ChrPtr(att->FileName), '\\'); if (pch != NULL) { - StrBufCutLeft(att->filename, pch - ChrPtr(att->filename)); + StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName)); } /** * Transfer control of this memory from the upload struct * to the attachment struct. */ - att->data = WCC->upload; + att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length); + free(WCC->upload); WCC->upload_length = 0; WCC->upload = NULL; display_enter(); diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index 90c3e5eab..9531aa83a 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -6,6 +6,7 @@ * message index functions */ + void DestroyMimeParts(wc_mime_attachment *Mime) { FreeStrBuf(&Mime->Name); @@ -909,6 +910,31 @@ void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void /// TODO: check whether we need to load it now? } +void tmplput_MIME_LoadData(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + struct wcsession *WCC = WC; + wc_mime_attachment *mime = (wc_mime_attachment*) Context; + wc_mime_attachment *att; + + if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))|| + (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) ) + { + + int n; + char N[64]; + /* steal this mime part... */ + att = malloc(sizeof(wc_mime_attachment)); + memcpy(att, mime, sizeof(wc_mime_attachment)); + memset(mime, 0, sizeof(wc_mime_attachment)); + + if (WCC->attachments == NULL) + WCC->attachments = NewHash(1, NULL); + /* And add it to the list. */ + n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1); + Put(WCC->attachments, N, n, att, DestroyMime); + } +} + void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { wc_mime_attachment *mime = (wc_mime_attachment*) Context; @@ -922,20 +948,20 @@ HashList *iterate_get_registered_Attachments(StrBuf *Target, int nArgs, WCTempla void tmplput_ATT_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { - wc_attachment *att = (wc_attachment*) Context; + wc_mime_attachment *att = (wc_mime_attachment*) Context; StrBufAppendPrintf(Target, "%ld", att->length); } void tmplput_ATT_Contenttype(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { - wc_attachment *att = (wc_attachment*) Context; - StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->content_type, 0); + wc_mime_attachment *att = (wc_mime_attachment*) Context; + StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->ContentType, 0); } void tmplput_ATT_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { - wc_attachment *att = (wc_attachment*) Context; - StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->filename, 0); + wc_mime_attachment *att = (wc_mime_attachment*) Context; + StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->FileName, 0); } @@ -1051,6 +1077,7 @@ InitModule_MSGRENDERERS RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH); RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH); RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH); + RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, CTX_MIME_ATACH); RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments, NULL, NULL, CTX_ATT, CTX_NONE); diff --git a/webcit/static/t/load_attachments.html b/webcit/static/t/load_attachments.html new file mode 100644 index 000000000..2e89c639c --- /dev/null +++ b/webcit/static/t/load_attachments.html @@ -0,0 +1,3 @@ +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- diff --git a/webcit/static/t/view_message_replyquote.html b/webcit/static/t/view_message_replyquote.html index 4de24c17e..56ee8bb7f 100644 --- a/webcit/static/t/view_message_replyquote.html +++ b/webcit/static/t/view_message_replyquote.html @@ -6,7 +6,7 @@ ***

- +
diff --git a/webcit/webcit.c b/webcit/webcit.c index d6aa8a0d2..0c8d142c6 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -962,21 +962,21 @@ void display_vcard_photo_img(void) void postpart(StrBuf *partnum, StrBuf *filename, int force_download) { void *vPart; - char content_type[256]; - wc_attachment *part; + StrBuf *content_type; + wc_mime_attachment *part; if (GetHash(WC->attachments, SKEY(partnum), &vPart) && (vPart != NULL)) { - part = (wc_attachment*) vPart; + part = (wc_mime_attachment*) vPart; if (force_download) { - strcpy(content_type, "application/octet-stream"); + content_type = NewStrBufPlain(HKEY("application/octet-stream")); } else { - strncpy(content_type, ChrPtr(part->content_type), sizeof content_type); + content_type = NewStrBufDup(part->ContentType); } output_headers(0, 0, 0, 0, 0, 0); - StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0); - http_transmit_thing(content_type, 0); + StrBufAppendBuf(WC->WBuf, part->Data, 0); + http_transmit_thing(ChrPtr(content_type), 0); } else { hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum)); output_headers(0, 0, 0, 0, 0, 0); @@ -985,6 +985,7 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download) ChrPtr(partnum), ChrPtr(filename)); end_burst(); } + FreeStrBuf(&content_type); } diff --git a/webcit/webcit.h b/webcit/webcit.h index a2eb57c92..e2f171cc3 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -410,17 +410,6 @@ enum { WCS_LONG /* its an integer */ }; -/* - * \brief mail attachment ??? - */ -typedef struct _wc_attachment { - size_t length; /* length of the contenttype */ - StrBuf *content_type; /* the content itself ???*/ - StrBuf *filename; /* the filename hooked to this content ??? */ - char *data; /* the data pool; aka this content */ - long lvalue; /* if we put a long... */ -} wc_attachment; -void free_attachment(void *vattach); typedef struct wc_mime_attachment wc_mime_attachment; @@ -436,9 +425,6 @@ struct wc_mime_attachment { StrBuf *Data; size_t length; /* length of the mimeatachment */ long size_known; - char content_type[SIZ]; /* the content itself ???*/ - char filename[SIZ]; /* the filename hooked to this content ??? */ - char *data; /* the data pool; aka this content */ long lvalue; /* if we put a long... */ long msgnum; /**< the message number on the citadel server derived from message_summary */ RenderMimeFunc Renderer; -- 2.30.2