/*
- * vcard_edit.c
+ * $Id$
*
* Handles editing of vCard objects.
*
- * $Id$
*/
#include <ctype.h>
#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;
size_t total_len = 0;
- size_t bytes = 0;
- size_t thisblock = 0;
struct vCard *v;
int i;
char *key, *value;
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;
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]);
- }
- }
-
- total_len = atoi(&buf[4]);
-
-
- 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);
- while (bytes < total_len) {
- thisblock = 4000;
- if ((total_len - bytes) < thisblock) thisblock = total_len - bytes;
- sprintf(buf, "READ %d|%d", bytes, thisblock);
+ if (msgnum >= 0) {
+ sprintf(buf, "MSG0 %ld|1", msgnum);
serv_puts(buf);
serv_gets(buf);
- if (buf[0] == '6') {
- thisblock = atoi(&buf[4]);
- serv_read(&serialized_vcard[bytes], thisblock);
- bytes += thisblock;
- }
- else {
- wprintf("Error: %s<BR>\n", &buf[4]);
- }
- }
-
- 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, ';');
- }
-
- 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, ';');
+ if (buf[0] != '1') {
+ wDumpContent(1);
+ return;
}
-
- 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");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/submit_vcard\">\n");
wprintf("<H2><IMG ALIGN=CENTER SRC=\"/static/vcard.gif\">"
"Contact information for ");
"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);
urlescputs(return_to);
wprintf("\">\n");
- wprintf("<CENTER>\n");
- wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
- wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
- wprintf("</CENTER></FORM>\n");
-
-
+ wprintf("<CENTER>\n"
+ "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">"
+ " "
+ "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">"
+ "</CENTER></FORM>\n"
+ );
+
+ do_template("endbox");
wDumpContent(1);
}
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);
}
if (!strcmp(bstr("return_to"), "/select_user_to_edit")) {
select_user_to_edit(NULL, NULL);
}
+ else if (!strcmp(bstr("return_to"), "/do_welcome")) {
+ do_welcome();
+ }
else {
readloop("readnew");
}