* add Remove button
authorWilfried Göesgens <willi@citadel.org>
Sat, 24 Apr 2010 13:31:29 +0000 (13:31 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 24 Apr 2010 13:31:29 +0000 (13:31 +0000)
* post_message(): use IKEY and Flathash, we just use numbers anyway.
* post_message(): add handler for removal of attachments; it seems as if 'filename' comes out URL-encoded, so we need to decode it.
  We need to iterate and strcmp() so we find the right one :(
* post_message(): when adding a new item just using count+1 isn't sufficient anymore; we need to use the key value + 1 of the last item in the list instead

webcit/messages.c
webcit/static/t/edit_message.html

index 8a814afe13b1a3a039515672af11061e3e42dec7..28c1431ef0a5feeeb970ae32bebc6aba1b0aa6c4 100644 (file)
@@ -1011,7 +1011,9 @@ void post_message(void)
        if (WCC->upload_length > 0) {
                const char *pch;
                int n;
-               char N[64];
+               const char *newn;
+               long newnlen;
+               void *v;
 
                /* There's an attachment.  Save it to this struct... */
                lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
@@ -1022,12 +1024,17 @@ void post_message(void)
                att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
                
                if (WCC->attachments == NULL) {
-                       WCC->attachments = NewHash(1, NULL);
+                       WCC->attachments = NewHash(1, Flathash);
                }
 
                /* And add it to the list. */
-               n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
-               Put(WCC->attachments, N, n, att, DestroyMime);
+               n = 0;
+               if ((GetCount(WCC->attachments) > 0) && 
+                   GetHashAt(WCC->attachments, 
+                             GetCount(WCC->attachments) -1, 
+                             &newnlen, &newn, &v))
+                   n = *((int*) newn) + 1;
+               Put(WCC->attachments, IKEY(n), att, DestroyMime);
 
                /*
                 * Mozilla sends a simple filename, which is what we want,
@@ -1063,7 +1070,34 @@ void post_message(void)
        } else if (lbstr("postseq") == dont_post) {
                sprintf(WCC->ImportantMessage, 
                        _("Automatically cancelled because you have already "
-                       "saved this message."));
+                         "saved this message."));
+       } else if (havebstr("remove_attach_button")) {
+               /* now thats st00pit. need to find it by name. */
+               void *vAtt;
+               StrBuf *WhichAttachment;
+               HashPos *at;
+               long len;
+               const char *key;
+
+               WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
+               StrBufUnescape(WhichAttachment, 0);
+               at = GetNewHashPos(WCC->attachments, 0);
+               do {
+                       GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
+               
+                       att = (wc_mime_attachment*) vAtt;
+                       if ((att != NULL) && 
+                           (strcmp(ChrPtr(WhichAttachment), 
+                                   ChrPtr(att->FileName)   ) == 0))
+                       {
+                               DeleteEntryFromHash(WCC->attachments, at);
+                               break;
+                       }
+               }
+               while (NextHashPos(WCC->attachments, at));
+               FreeStrBuf(&WhichAttachment);
+               display_enter();
+               return;
        } else {
                const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
                const StrBuf *Recp = NULL; 
@@ -1471,8 +1505,10 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
        void *vPart;
        StrBuf *content_type;
        wc_mime_attachment *part;
-       
-       if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
+       int i;
+
+       i = StrToi(partnum);
+       if (GetHash(WC->attachments, IKEY(i), &vPart) &&
            (vPart != NULL)) {
                part = (wc_mime_attachment*) vPart;
                if (force_download) {
index fc9d47879aa075a8c9347f6739c57a0fdbce054a..6c973f0805d356e797ff9bf7c1f2a9780e23230f 100644 (file)
 &nbsp;&nbsp;&nbsp;<?_("Attach file:")>
 <input name="attachfile" class="attachfile" size=16 type="file">
 &nbsp;&nbsp;<input type="submit" name="attach_button" value="<?_("Add")>">
+&nbsp;&nbsp;<input type="submit" name="remove_attach_button" value="<?_("Remove")>">
 
 </div></td></tr></table></form>