ATTACHMENTS: hande UID of files on the partnum param on upload. that way fresh &...
authorWilfried Goesgens <dothebart@citadel.org>
Sat, 25 Jan 2014 13:03:08 +0000 (14:03 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sat, 25 Jan 2014 13:03:08 +0000 (14:03 +0100)
webcit/messages.c

index 29fd30559e90dc02a327ae77606403d947b72342..fd886f4158ed1e503fbdecd56b5b752ee079ba3e 100644 (file)
@@ -1234,6 +1234,7 @@ void upload_attachment(void) {
        wc_mime_attachment *att;
        const StrBuf *Tmpl = sbstr("template");
        const StrBuf *MimeType = NULL;
+       const StrBuf *UID;
 
        begin_burst();
        syslog(LOG_DEBUG, "upload_attachment()\n");
@@ -1248,7 +1249,7 @@ void upload_attachment(void) {
                }
                else      wc_printf("ERROR no attachment was uploaded<br>\n");
                http_transmit_thing(ChrPtr(MimeType), 0);
-               
+
                return;
        }
 
@@ -1261,7 +1262,10 @@ void upload_attachment(void) {
        att->length = WCC->upload_length;
        att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
        att->FileName = NewStrBufDup(WCC->upload_filename);
-       
+       UID = SBSTR("qquuid");
+       if (UID)
+               att->PartNum = NewStrBufDup(UID);
+
        if (WCC->attachments == NULL) {
                WCC->attachments = NewHash(1, Flathash);
        }
@@ -1315,26 +1319,35 @@ void remove_attachment(void) {
        StrBuf *WhichAttachment;
        HashPos *at;
        long len;
+       int found=0;
        const char *key;
 
        WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
+       if (ChrPtr(WhichAttachment)[0] == '/')
+               StrBufCutLeft(WhichAttachment, 1);
        StrBufUnescape(WhichAttachment, 0);
        at = GetNewHashPos(WCC->attachments, 0);
        do {
+               vAtt = NULL;
                GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
-       
+
                att = (wc_mime_attachment*) vAtt;
-               if ((att != NULL) && 
-                   (strcmp(ChrPtr(WhichAttachment), 
-                           ChrPtr(att->FileName)   ) == 0))
+               if ((att != NULL) &&
+                   (
+                           !strcmp(ChrPtr(WhichAttachment), ChrPtr(att->FileName)) ||
+                   ((att->PartNum != NULL) &&
+                    !strcmp(ChrPtr(WhichAttachment), ChrPtr(att->PartNum)))
+                           ))
                {
                        DeleteEntryFromHash(WCC->attachments, at);
+                       found=1;
                        break;
                }
        }
        while (NextHashPos(WCC->attachments, at));
+
        FreeStrBuf(&WhichAttachment);
-       wc_printf("remove_attachment() completed\n");
+       wc_printf("remove_attachment(%d) completed\n", found);
 }