* load attachments in forwarded messages
authorWilfried Göesgens <willi@citadel.org>
Thu, 11 Dec 2008 00:00:36 +0000 (00:00 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 11 Dec 2008 00:00:36 +0000 (00:00 +0000)
* just one mime struct should fit it all.

webcit/context_loop.c
webcit/messages.c
webcit/msg_renderers.c
webcit/static/t/load_attachments.html [new file with mode: 0644]
webcit/static/t/view_message_replyquote.html
webcit/webcit.c
webcit/webcit.h

index 7af1790c1cbf491564e47fb61071ae1fddf11870..128487dc04663c1ffce5b34652bf773b96a68421 100644 (file)
@@ -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)
 {
index 2286a04217fca82b8bac9cf887d2fbc0b3dac3b0..a3e44fddd801a8826f3d4348dbe37612c9515c1d 100644 (file)
@@ -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();
index 90c3e5eab62ceaf605370930829aee8123f9c889..9531aa83ac6e6d44a655dbbc335693d21635429d 100644 (file)
@@ -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 (file)
index 0000000..2e89c63
--- /dev/null
@@ -0,0 +1,3 @@
+--------------------------------------------------------------------------------
+<?MAIL:MIME:LOADDATA>
+--------------------------------------------------------------------------------
index 4de24c17e492d0ab854dc79db3bf20616839db50..56ee8bb7fdfb3bf2a9c726ea0e4fb5d9df41e92a 100644 (file)
@@ -6,7 +6,7 @@
       <?!("COND:MAIL:ANON",2)>***<??("X", 2)>
     </span>
     <p class="message_subject"><?MAIL:SUMM:SUBJECT></p>
-  </div>
+  </div><?ITERATE("MAIL:MIME:ATTACH:ATT", "load_attachments")>
   
   <div class="message_content">
   <?MAIL:BODY>    
index d6aa8a0d2d26b8f9b7d152b2de6201a14ab8f50e..0c8d142c6932fdfd55f0bfd101236c06674068e9 100644 (file)
@@ -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);
 }
 
 
index a2eb57c92ccf71aef51bb59f02432d89ea28aea2..e2f171cc3c5769e014f1f9b3f7cebe719eae2e0c 100644 (file)
@@ -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;