]> code.citadel.org Git - citadel.git/blobdiff - webcit/vcard_edit.c
* output errors via important_message
[citadel.git] / webcit / vcard_edit.c
index 5846fa80ac03c3d1b774228283769b89504afdf2..d823624dfde260e8568b7d5c212183a2830e8f99 100644 (file)
@@ -122,8 +122,7 @@ void fetch_ab_name(message_summary *Msg, char **namebuf) {
        memset(&summ, 0, sizeof(summ));
        //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
 
-       sprintf(buf, "MSG0 %ld|0", Msg->msgnum);        /** unfortunately we need the mime info now */
-       serv_puts(buf);
+       serv_printf(buf, "MSG0 %ld|0", Msg->msgnum);    /** unfortunately we need the mime info now */
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1') return;
 
@@ -696,10 +695,13 @@ void do_addrbook_view(addrbookent *addrbook, int num_ab) {
  * and MIME part number to fetch.  Or, specify -1 for the message number
  * to start with a blank card.
  */
-void do_edit_vcard(long msgnum, char *partnum, char *return_to, const char *force_room) {
+void do_edit_vcard(long msgnum, char *partnum, 
+                  message_summary *VCMsg,
+                  wc_mime_attachment *VCAtt,
+                  char *return_to, 
+                  const char *force_room) {
        StrBuf *Buf;
        char buf[SIZ];
-       StrBuf *serialized_vcard = NULL;
        size_t total_len = 0;
        struct vCard *v;
        int i;
@@ -754,37 +756,44 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to, const char *forc
 
        safestrncpy(whatuser, "", sizeof whatuser);
 
-       if (msgnum >= 0) {
-               sprintf(buf, "MSG0 %ld|1", msgnum);
-               serv_puts(buf);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] != '1') {
-                       convenience_page("770000", _("Error"), &buf[4]);
-                       return;
-               }
-               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       if (!strncasecmp(buf, "from=", 5)) {
-                               safestrncpy(whatuser, &buf[5], sizeof whatuser);
+       if ((msgnum >= 0) || 
+           ((VCMsg != NULL) && (VCAtt != NULL)))
+       {
+               if ((VCMsg == NULL) && (VCAtt == NULL)) {
+                       sprintf(buf, "MSG0 %ld|1", msgnum);
+                       serv_puts(buf);
+                       serv_getln(buf, sizeof buf);
+                       if (buf[0] != '1') {
+                               convenience_page("770000", _("Error"), &buf[4]);
+                               return;
+                       }
+                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                               if (!strncasecmp(buf, "from=", 5)) {
+                                       safestrncpy(whatuser, &buf[5], sizeof whatuser);
+                               }
+                               else if (!strncasecmp(buf, "node=", 5)) {
+                                       strcat(whatuser, " @ ");
+                                       strcat(whatuser, &buf[5]);
+                               }
                        }
-                       else if (!strncasecmp(buf, "node=", 5)) {
-                               strcat(whatuser, " @ ");
-                               strcat(whatuser, &buf[5]);
+                       Buf = NewStrBuf();
+                       serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
+                       StrBuf_ServGetlnBuffered(Buf);
+                       if (GetServerStatus(Buf, NULL) != 6) {
+                               convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
+                               return;
                        }
+                       
+                       StrBufCutLeft(Buf, 4);
+                       total_len = StrBufExtract_long(Buf, 0, '|');
+                       
+                       StrBuf_ServGetBLOBBuffered(Buf, total_len);
+               
+                       v = VCardLoad(Buf);
                }
-               Buf = NewStrBuf();
-               serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
-               StrBuf_ServGetlnBuffered(Buf);
-               if (GetServerStatus(Buf, NULL) != 6) {
-                       convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
-                       return;
+               else {
+                       v = VCardLoad(VCAtt->Data);
                }
-               
-               StrBufCutLeft(Buf, 4);
-               total_len = StrBufExtract_long(Buf, 0, '|');
-
-               StrBuf_ServGetBLOBBuffered(Buf, total_len);
-       
-               v = VCardLoad(Buf);
                FreeStrBuf(&Buf);
        
                /* Populate the variables for our form */
@@ -1066,7 +1075,7 @@ void edit_vcard(void) {
 
        msgnum = lbstr("msgnum");
        partnum = bstr("partnum");
-       do_edit_vcard(msgnum, partnum, "", NULL);
+       do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
 }
 
 
@@ -1075,6 +1084,7 @@ void edit_vcard(void) {
  *  parse edited vcard from the browser
  */
 void submit_vcard(void) {
+       wcsession *WCC = WC;
        struct vCard *v;
        char *serialized_vcard;
        char buf[SIZ];
@@ -1087,7 +1097,31 @@ void submit_vcard(void) {
        }
 
        if (havebstr("force_room")) {
-               gotoroom(sbstr("force_room"));
+               if (gotoroom(sbstr("force_room")) != 200) {
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            _("Unable to enter the room to save your message"),
+                                            -1, 0);
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            HKEY(": "), 0);
+                       StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            HKEY("; "), 0);
+                                              
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            _("Aborting."),
+                                            -1, 0);
+                       /// todo: call the master dispatcher again...
+                       if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
+                               select_user_to_edit(NULL);
+                       }
+                       else if (!strcmp(bstr("return_to"), "do_welcome")) {
+                               do_welcome();
+                       }
+                       else {
+                               readloop(readnew);
+                       }
+                       return;
+               }
        }
 
        sprintf(buf, "ENT0 1|||4||");
@@ -1106,9 +1140,9 @@ void submit_vcard(void) {
        v = VCardLoad(Buf);     /** Start with the extra fields */
        FreeStrBuf(&Buf);
        if (v == NULL) {
-               safestrncpy(WC->ImportantMessage,
+               safestrncpy(WCC->ImportantMessage,
                        _("An error has occurred."),
-                       sizeof WC->ImportantMessage
+                       sizeof WCC->ImportantMessage
                );
                edit_vcard();
                return;
@@ -1152,9 +1186,9 @@ void submit_vcard(void) {
        serialized_vcard = vcard_serialize(v);
        vcard_free(v);
        if (serialized_vcard == NULL) {
-               safestrncpy(WC->ImportantMessage,
+               safestrncpy(WCC->ImportantMessage,
                        _("An error has occurred."),
-                       sizeof WC->ImportantMessage
+                       sizeof WCC->ImportantMessage
                );
                edit_vcard();
                return;
@@ -1167,7 +1201,7 @@ void submit_vcard(void) {
        free(serialized_vcard);
 
        if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
-               select_user_to_edit(NULL, NULL);
+               select_user_to_edit(NULL);
        }
        else if (!strcmp(bstr("return_to"), "do_welcome")) {
                do_welcome();