]> code.citadel.org Git - citadel.git/blobdiff - webcit/vcard_edit.c
Added a new screen to view the outbound SMTP queue.
[citadel.git] / webcit / vcard_edit.c
index dae082e8e98c5408daf9b088df38ae1ebcc2d209..187646193a091dad1bc3036bb8b886ce9bae8a00 100644 (file)
@@ -67,6 +67,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        title[0] = 0;
        org[0] = 0;
        extrafields[0] = 0;
+       fullname[0] = 0;
 
        safestrncpy(whatuser, "", sizeof whatuser);
 
@@ -100,7 +101,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
                serialized_vcard = malloc(total_len + 2);
        
                read_server_binary(serialized_vcard, total_len);
-       
+
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
                serialized_vcard[total_len] = 0;
@@ -307,7 +308,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        wprintf(_("Primary Internet e-mail address"));
        wprintf("<br />"
                "<input type=\"text\" name=\"primary_inetemail\" "
-               "size=40 maxlength=40 value=\"");
+               "size=40 maxlength=60 value=\"");
        escputs(primary_inetemail);
        wprintf("\"><br />"
                "</td><td valign=top>");
@@ -359,6 +360,8 @@ void edit_vcard(void) {
  * \brief parse edited vcard from the browser
  */
 void submit_vcard(void) {
+       struct vCard *v;
+       char *serialized_vcard;
        char buf[SIZ];
        int i;
 
@@ -375,19 +378,34 @@ void submit_vcard(void) {
                return;
        }
 
-       serv_puts("Content-type: text/x-vcard");
-       serv_puts("");
-       serv_puts("begin:vcard");
-       serv_printf("n:%s;%s;%s;%s;%s",
+       /** Make a vCard structure out of the data supplied in the form */
+
+       snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
+               bstr("extrafields")
+       );
+       v = vcard_load(buf);    /** Start with the extra fields */
+       if (v == NULL) {
+               safestrncpy(WC->ImportantMessage,
+                       _("An error has occurred."),
+                       sizeof WC->ImportantMessage
+               );
+               edit_vcard();
+               return;
+       }
+
+       snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
                bstr("lastname"),
                bstr("firstname"),
                bstr("middlename"),
                bstr("prefix"),
                bstr("suffix") );
-       serv_printf("title:%s", bstr("title") );
-       serv_printf("fn:%s", bstr("fullname") );
-       serv_printf("org:%s", bstr("org") );
-       serv_printf("adr:%s;%s;%s;%s;%s;%s;%s",
+       vcard_add_prop(v, "n", buf);
+       
+       vcard_add_prop(v, "title", bstr("title"));
+       vcard_add_prop(v, "fn", bstr("fullname"));
+       vcard_add_prop(v, "org", bstr("org"));
+
+       snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
                bstr("pobox"),
                bstr("extadr"),
                bstr("street"),
@@ -395,20 +413,35 @@ void submit_vcard(void) {
                bstr("state"),
                bstr("zipcode"),
                bstr("country") );
-       serv_printf("tel;home:%s", bstr("hometel") );
-       serv_printf("tel;work:%s", bstr("worktel") );
+       vcard_add_prop(v, "adr", buf);
+
+       vcard_add_prop(v, "tel;home", bstr("hometel"));
+       vcard_add_prop(v, "tel;work", bstr("worktel"));
+       vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
 
-       serv_printf("email;internet:%s\n", bstr("primary_inetemail"));  
        for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
                extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
                if (strlen(buf) > 0) {
-                       serv_printf("email;internet:%s", buf);
+                       vcard_add_prop(v, "email;internet", buf);
                }
        }
 
-       serv_printf("%s", bstr("extrafields") );
-       serv_puts("end:vcard");
+       serialized_vcard = vcard_serialize(v);
+       vcard_free(v);
+       if (serialized_vcard == NULL) {
+               safestrncpy(WC->ImportantMessage,
+                       _("An error has occurred."),
+                       sizeof WC->ImportantMessage
+               );
+               edit_vcard();
+               return;
+       }
+
+       serv_puts("Content-type: text/x-vcard; charset=UTF-8");
+       serv_puts("");
+       serv_printf("%s\r\n", serialized_vcard);
        serv_puts("000");
+       free(serialized_vcard);
 
        if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
                select_user_to_edit(NULL, NULL);