* apply Sam Liddicotts save to drafts patch. Some changes: use strbuf where possible...
authorWilfried Göesgens <willi@citadel.org>
Fri, 12 Jun 2009 09:03:14 +0000 (09:03 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 12 Jun 2009 09:03:14 +0000 (09:03 +0000)
webcit/messages.c
webcit/static/t/edit_message.html

index e67642d823ffed6e1c1f86dfaa8e39b47ff75d87..d41ba14e1fbd5c36085903195ee96180f413dfb4 100644 (file)
@@ -1278,6 +1278,7 @@ void post_message(void)
        int is_anonymous = 0;
        const StrBuf *display_name = NULL;
        wcsession *WCC = WC;
+       StrBuf *Buf;
        
        if (havebstr("force_room")) {
                gotoroom(sbstr("force_room"));
@@ -1356,11 +1357,31 @@ void post_message(void)
                const StrBuf *my_email_addr = NULL;
                StrBuf *CmdBuf = NULL;
                StrBuf *references = NULL;
+               int save_to_drafts;
+
+               save_to_drafts = havebstr("save_button");
+               Buf = NewStrBuf();
+
+               if (save_to_drafts) {
+                       /** temporarily change to the drafts room */
+                       serv_puts("GOTO _DRAFTS_");
+                       StrBuf_ServGetln(Buf);
+                       if (GetServerStatus(Buf, NULL) == 2) {
+                               /* You probably don't even have a dumb Drafts folder */
+                               StrBufCutLeft(Buf, 4);
+                               lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
+                               StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
+                               StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
+                               display_enter();
+                               FreeStrBuf(&Buf);
+                               return;
+                       }
+               }
 
                if (havebstr("references"))
                {
                        const StrBuf *ref = sbstr("references");
-                       references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
+                       references = NewStrBufDup(ref);
                        if (*ChrPtr(references) == '|') {       /* remove leading '|' if present */
                                StrBufCutLeft(references, 1);
                        }
@@ -1394,40 +1415,64 @@ void post_message(void)
 
                StrBufPrintf(CmdBuf, 
                             CMD,
-                            ChrPtr(Recp),
+                            save_to_drafts?"":ChrPtr(Recp),
                             is_anonymous,
                             ChrPtr(encoded_subject),
                             ChrPtr(display_name),
-                            ChrPtr(Cc),
-                            ChrPtr(Bcc),
+                            save_to_drafts?"":ChrPtr(Cc),
+                            save_to_drafts?"":ChrPtr(Bcc),
                             ChrPtr(Wikipage),
                             ChrPtr(my_email_addr),
                             ChrPtr(references));
                FreeStrBuf(&references);
+               FreeStrBuf(&encoded_subject);
 
                lprintf(9, "%s\n", ChrPtr(CmdBuf));
                serv_puts(ChrPtr(CmdBuf));
-               serv_getln(buf, sizeof buf);
                FreeStrBuf(&CmdBuf);
-               FreeStrBuf(&encoded_subject);
-               if (buf[0] == '4') {
+
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 4) {
+                       if (save_to_drafts) {
+                               if (  (havebstr("recp"))
+                                   || (havebstr("cc"  ))
+                                   || (havebstr("bcc" )) ) {
+                                       /* save recipient headers or room to post to */
+                                       serv_printf("To: %s", ChrPtr(Recp));
+                                       serv_printf("Cc: %s", ChrPtr(Cc));
+                                       serv_printf("Bcc: %s", ChrPtr(Bcc));
+                               } else {
+                                       serv_printf("X-Citadel-Room: %s", ChrPtr(WC->wc_roomname));
+                               }
+                       }
                        post_mime_to_server();
-                       if (  (havebstr("recp"))
+                       if (save_to_drafts) {
+                               StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
+                               gotoroom(WCC->wc_roomname);
+                               display_enter();
+                               FreeStrBuf(&Buf);
+                               return;
+                       } else if (  (havebstr("recp"))
                           || (havebstr("cc"  ))
                           || (havebstr("bcc" ))
                        ) {
-                               sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
+                               StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
                        }
                        else {
-                               sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
+                               StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
                        }
                        dont_post = lbstr("postseq");
                } else {
-                       lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
-                       sprintf(WC->ImportantMessage, "%s", &buf[4]);
+                       StrBufCutLeft(Buf, 4);
+
+                       lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
+                       StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
+                       if (save_to_drafts) gotoroom(WCC->wc_roomname);
                        display_enter();
+                       FreeStrBuf(&Buf);
                        return;
                }
+               FreeStrBuf(&Buf);
        }
 
        DeleteHash(&WCC->attachments);
index 201fc7d75e3901e5bccf3362c727f02e7df4cb81..f9542637960e569ea0fc0656fb38ce15e0a261cd 100644 (file)
@@ -10,6 +10,8 @@
 <input type="hidden" name="references" value="<?BSTR("references")>">
 
 <p class="send_edit_msg">
+  <input type="submit" name="save_button" value="<?_("Save to Drafts")>">
+&nbsp;
 <?!("COND:SUBST", 1, "RCPTREQUIRED")><input type="submit" name="send_button" value="<?_("Send message")>"><?!("X", 1)>
 <??("COND:SUBST", 2, "RCPTREQUIRED")><input type="submit" name="send_button" value="<?_("Post message")>"><?!("X", 2)>
 &nbsp;