* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[citadel.git] / webcit / vcard_edit.c
index 65f0f3fc1c25eec7526820808ab2f51c7bd56396..ee51e4b75d14e7030fdcaeb9abadeb94f5e31b1a 100644 (file)
 #include "vcard.h"
 
 
-
+/* Edit the vCard component of a MIME message.  Supply the message number
+ * 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) {
        char buf[SIZ];
        char *serialized_vcard = NULL;
@@ -53,7 +56,8 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        char country[SIZ];
        char hometel[SIZ];
        char worktel[SIZ];
-       char inetemail[SIZ];
+       char primary_inetemail[SIZ];
+       char other_inetemail[SIZ];
        char extrafields[SIZ];
 
        lastname[0] = 0;
@@ -70,97 +74,106 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        country[0] = 0;
        hometel[0] = 0;
        worktel[0] = 0;
-       inetemail[0] = 0;
+       primary_inetemail[0] = 0;
+       other_inetemail[0] = 0;
        extrafields[0] = 0;
 
-       output_headers(3);
+       output_headers(1, 1, 0, 0, 0, 0, 0);
 
        strcpy(whatuser, "");
-       sprintf(buf, "MSG0 %ld|1", msgnum);
-       serv_puts(buf);
-       serv_gets(buf);
-       if (buf[0] != '1') {
-               wDumpContent(1);
-               return;
-       }
-       while (serv_gets(buf), strcmp(buf, "000")) {
-               if (!strncasecmp(buf, "from=", 5)) {
-                       strcpy(whatuser, &buf[5]);
-               }
-               else if (!strncasecmp(buf, "node=", 5)) {
-                       strcat(whatuser, " @ ");
-                       strcat(whatuser, &buf[5]);
-               }
-       }
-
-       sprintf(buf, "OPNA %ld|%s", msgnum, partnum);
-       serv_puts(buf);
-       serv_gets(buf);
-       if (buf[0] != '2') {
-               wDumpContent(1);
-               return;
-       }
-
-       total_len = atoi(&buf[4]);
-       serialized_vcard = malloc(total_len + 1);
-
-       read_server_binary(serialized_vcard, total_len);
-
-       serv_puts("CLOS");
-       serv_gets(buf);
-       serialized_vcard[total_len + 1] = 0;
-
-       v = vcard_load(serialized_vcard);
-       free(serialized_vcard);
-
-       /* Populate the variables for our form */
-       i = 0;
-       while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
-               value = vcard_get_prop(v, "", 0, i++, 0);
 
-               if (!strcasecmp(key, "n")) {
-                       extract_token(lastname, value, 0, ';');
-                       extract_token(firstname, value, 1, ';');
-                       extract_token(middlename, value, 2, ';');
-                       extract_token(prefix, value, 3, ';');
-                       extract_token(suffix, value, 4, ';');
+       if (msgnum >= 0) {
+               sprintf(buf, "MSG0 %ld|1", msgnum);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (buf[0] != '1') {
+                       wDumpContent(1);
+                       return;
                }
-
-               else if (!strcasecmp(key, "adr")) {
-                       extract_token(pobox, value, 0, ';');
-                       extract_token(extadr, value, 1, ';');
-                       extract_token(street, value, 2, ';');
-                       extract_token(city, value, 3, ';');
-                       extract_token(state, value, 4, ';');
-                       extract_token(zipcode, value, 5, ';');
-                       extract_token(country, value, 6, ';');
-               }
-
-               else if (!strcasecmp(key, "tel;home")) {
-                       extract_token(hometel, value, 0, ';');
+               while (serv_gets(buf), strcmp(buf, "000")) {
+                       if (!strncasecmp(buf, "from=", 5)) {
+                               strcpy(whatuser, &buf[5]);
+                       }
+                       else if (!strncasecmp(buf, "node=", 5)) {
+                               strcat(whatuser, " @ ");
+                               strcat(whatuser, &buf[5]);
+                       }
                }
-
-               else if (!strcasecmp(key, "tel;work")) {
-                       extract_token(worktel, value, 0, ';');
+       
+               sprintf(buf, "OPNA %ld|%s", msgnum, partnum);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (buf[0] != '2') {
+                       wDumpContent(1);
+                       return;
                }
-
-               else if (!strcasecmp(key, "email;internet")) {
-                       if (inetemail[0] != 0) {
-                               strcat(inetemail, "\n");
+       
+               total_len = atoi(&buf[4]);
+               serialized_vcard = malloc(total_len + 1);
+       
+               read_server_binary(serialized_vcard, total_len);
+       
+               serv_puts("CLOS");
+               serv_gets(buf);
+               serialized_vcard[total_len + 1] = 0;
+       
+               v = vcard_load(serialized_vcard);
+               free(serialized_vcard);
+       
+               /* Populate the variables for our form */
+               i = 0;
+               while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
+                       value = vcard_get_prop(v, "", 0, i++, 0);
+       
+                       if (!strcasecmp(key, "n")) {
+                               extract_token(lastname, value, 0, ';');
+                               extract_token(firstname, value, 1, ';');
+                               extract_token(middlename, value, 2, ';');
+                               extract_token(prefix, value, 3, ';');
+                               extract_token(suffix, value, 4, ';');
                        }
-                       strcat(inetemail, value);
-               }
-
-               else {
-                       strcat(extrafields, key);
-                       strcat(extrafields, ":");
-                       strcat(extrafields, value);
-                       strcat(extrafields, "\n");
+       
+                       else if (!strcasecmp(key, "adr")) {
+                               extract_token(pobox, value, 0, ';');
+                               extract_token(extadr, value, 1, ';');
+                               extract_token(street, value, 2, ';');
+                               extract_token(city, value, 3, ';');
+                               extract_token(state, value, 4, ';');
+                               extract_token(zipcode, value, 5, ';');
+                               extract_token(country, value, 6, ';');
+                       }
+       
+                       else if (!strcasecmp(key, "tel;home")) {
+                               extract_token(hometel, value, 0, ';');
+                       }
+       
+                       else if (!strcasecmp(key, "tel;work")) {
+                               extract_token(worktel, value, 0, ';');
+                       }
+       
+                       else if (!strcasecmp(key, "email;internet")) {
+                               if (primary_inetemail[0] == 0) {
+                                       strcpy(primary_inetemail, value);
+                               }
+                               else {
+                                       if (other_inetemail[0] != 0) {
+                                               strcat(other_inetemail, "\n");
+                                       }
+                                       strcat(other_inetemail, value);
+                               }
+                       }
+       
+                       else {
+                               strcat(extrafields, key);
+                               strcat(extrafields, ":");
+                               strcat(extrafields, value);
+                               strcat(extrafields, "\n");
+                       }
+       
                }
-
-       }
        
-       vcard_free(v);
+               vcard_free(v);
+       }
 
        /* Display the form */
        do_template("beginbox_nt");
@@ -230,13 +243,17 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
                "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR></TABLE>\n",
                worktel);
 
-       wprintf("<TABLE border=0><TR><TD>Internet e-mail addresses:<BR>"
-               "<FONT size=-2>For addresses in the Citadel directory, "
-               "the topmost address will be used in outgoing mail."
-               "</FONT></TD><TD>"
-               "<TEXTAREA NAME=\"inetemail\" ROWS=5 COLS=40 WIDTH=40>");
-       escputs(inetemail);
-       wprintf("</TEXTAREA></TD></TR></TABLE><BR>\n");
+       wprintf("<br /><TABLE border=0><TR>"
+               "<TD VALIGN=TOP>Primary Internet e-mail address<br />"
+               "<INPUT TYPE=\"text\" NAME=\"primary_inetemail\" "
+               "SIZE=40 MAXLENGTH=40 VALUE=\"");
+       escputs(primary_inetemail);
+       wprintf("\"><br />"
+               "</TD><TD VALIGN=TOP>"
+               "Other Internet e-mail addresses<br />"
+               "<TEXTAREA NAME=\"other_inetemail\" ROWS=5 COLS=40 WIDTH=40>");
+       escputs(other_inetemail);
+       wprintf("</TEXTAREA></TD></TR></TABLE><br />\n");
 
        wprintf("<INPUT TYPE=\"hidden\" NAME=\"extrafields\" VALUE=\"");
        escputs(extrafields);
@@ -307,9 +324,10 @@ void submit_vcard(void) {
                bstr("country") );
        serv_printf("tel;home:%s", bstr("hometel") );
        serv_printf("tel;work:%s", bstr("worktel") );
-       
-       for (i=0; i<num_tokens(bstr("inetemail"), '\n'); ++i) {
-               extract_token(buf, bstr("inetemail"), i, '\n');
+
+       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');
                if (strlen(buf) > 0) {
                        serv_printf("email;internet:%s", buf);
                }