X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=755dae6fc9472e566b55d8d2d218bf58b7b7988c;hb=d120028b4c45f3c26d05186c8ba488fd2feef13f;hp=58047f7b8c85d937e10f889194751fee14c22dc3;hpb=25085ec2cf0f8a5d34cfb8906e43e2df18d0e0ed;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 58047f7b8..755dae6fc 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -1,62 +1,46 @@ /* - * vcard_edit.c + * $Id$ * - * Handles editing of vCard objects. + * Handles on-screen editing of vCard objects. * - * $Id$ */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "webcit.h" #include "vcard.h" - - -void edit_vcard(void) { +/* 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 whatuser[SIZ]; - - char lastname[SIZ]; - char firstname[SIZ]; - char middlename[SIZ]; - char prefix[SIZ]; - char suffix[SIZ]; - char pobox[SIZ]; - char extadr[SIZ]; - char street[SIZ]; - char city[SIZ]; - char state[SIZ]; - char zipcode[SIZ]; - char country[SIZ]; - char hometel[SIZ]; - char worktel[SIZ]; - char inetemail[SIZ]; + char whatuser[256]; + + char lastname[256]; + char firstname[256]; + char middlename[256]; + char prefix[256]; + char suffix[256]; + char pobox[256]; + char extadr[256]; + char street[256]; + char city[256]; + char state[256]; + char zipcode[256]; + char country[256]; + char hometel[256]; + char worktel[256]; + char primary_inetemail[256]; + char other_inetemail[SIZ]; char extrafields[SIZ]; + char fullname[256]; + char title[256]; + char org[256]; lastname[0] = 0; firstname[0] = 0; @@ -72,129 +56,145 @@ void edit_vcard(void) { country[0] = 0; hometel[0] = 0; worktel[0] = 0; - inetemail[0] = 0; + primary_inetemail[0] = 0; + other_inetemail[0] = 0; + title[0] = 0; + org[0] = 0; extrafields[0] = 0; - output_headers(1); - - strcpy(whatuser, ""); - sprintf(buf, "MSG0 %s|1", bstr("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]); - + safestrncpy(whatuser, "", sizeof whatuser); - sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("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
\n", &buf[4]); + serv_getln(buf, sizeof buf); + if (buf[0] != '1') { + convenience_page("770000", _("Error"), &buf[4]); + return; } - } - - 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, ';'); - } - - else if (!strcasecmp(key, "tel;home")) { - extract_token(hometel, value, 0, ';'); + 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 (!strcasecmp(key, "tel;work")) { - extract_token(worktel, value, 0, ';'); + + sprintf(buf, "OPNA %ld|%s", msgnum, partnum); + serv_puts(buf); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + convenience_page("770000", "Error", &buf[4]); + return; } + + total_len = atoi(&buf[4]); + 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; + + 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, ';', sizeof lastname); + extract_token(firstname, value, 1, ';', sizeof firstname); + extract_token(middlename, value, 2, ';', sizeof middlename); + extract_token(prefix, value, 3, ';', sizeof prefix); + extract_token(suffix, value, 4, ';', sizeof suffix); + } - else if (!strcasecmp(key, "email;internet")) { - if (inetemail[0] != 0) { - strcat(inetemail, "\n"); + else if (!strcasecmp(key, "fn")) { + safestrncpy(fullname, value, sizeof fullname); } - strcat(inetemail, value); - } - else { - strcat(extrafields, key); - strcat(extrafields, ":"); - strcat(extrafields, value); - strcat(extrafields, "\n"); + else if (!strcasecmp(key, "title")) { + safestrncpy(title, value, sizeof title); + } + + else if (!strcasecmp(key, "org")) { + safestrncpy(org, value, sizeof org); + } + + else if (!strcasecmp(key, "adr")) { + extract_token(pobox, value, 0, ';', sizeof pobox); + extract_token(extadr, value, 1, ';', sizeof extadr); + extract_token(street, value, 2, ';', sizeof street); + extract_token(city, value, 3, ';', sizeof city); + extract_token(state, value, 4, ';', sizeof state); + extract_token(zipcode, value, 5, ';', sizeof zipcode); + extract_token(country, value, 6, ';', sizeof country); + } + + else if (!strcasecmp(key, "tel;home")) { + extract_token(hometel, value, 0, ';', sizeof hometel); + } + + else if (!strcasecmp(key, "tel;work")) { + extract_token(worktel, value, 0, ';', sizeof worktel); + } + + else if (!strcasecmp(key, "email;internet")) { + if (primary_inetemail[0] == 0) { + safestrncpy(primary_inetemail, value, sizeof primary_inetemail); + } + 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 */ - wprintf("
\n"); - wprintf("

" - "Contact information for "); - escputs(whatuser); - wprintf("

\n"); + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n" + "
" + "" + ""); + wprintf(_("Edit contact information")); + wprintf("" + "
\n" + "
\n
\n" + ); + + wprintf("\n"); + wprintf("
" + "
\n"); wprintf("" - "" - "" - "" - "" - "\n"); + "" + "" + "" + "" + "\n", + _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix") + ); wprintf("", + "VALUE=\"%s\" MAXLENGTH=\"5\" SIZE=\"5\">", prefix); wprintf("", @@ -206,84 +206,160 @@ void edit_vcard(void) { "VALUE=\"%s\" MAXLENGTH=\"29\">", lastname); wprintf("
PrefixFirstMiddleLastSuffix
%s%s%s%s%s
\n", + "VALUE=\"%s\" MAXLENGTH=\"10\" SIZE=\"10\">
\n", suffix); - wprintf("" - "\n", + wprintf("
PO box (optional):
"); + wprintf("\n", country); + wprintf("
"); + + wprintf(_("Display name:")); + wprintf("
" + "

\n", + fullname + ); + + wprintf(_("Title:")); + wprintf("
" + "

\n", + title + ); + + wprintf(_("Organization:")); + wprintf("
" + "

\n", + org + ); + + wprintf("
"); + + wprintf(""); + wprintf("\n", pobox); - wprintf("" - "\n", + wprintf("\n", extadr); - wprintf("" - "\n", + wprintf("\n", street); - wprintf("" - "\n", city); - wprintf(" State: " + wprintf("\n", state); - wprintf(" ZIP code: " + wprintf("\n", + "VALUE=\"%s\" MAXLENGTH=\"10\">\n", zipcode); - wprintf("" - "
"); + wprintf(_("PO box:")); + wprintf("" + "
Address line 1:
"); + wprintf(_("Address:")); + wprintf("" + "
Address line 2:
" + "
City:\n", + wprintf("
"); + wprintf(_("City:")); + wprintf("" + "
"); + wprintf(_("State:")); + wprintf("" "\n", + "VALUE=\"%s\" MAXLENGTH=\"2\">
"); + wprintf(_("ZIP code:")); + wprintf("" "
Country:
\n", + wprintf("
"); + wprintf(_("Country:")); + wprintf("" + "
\n"); + + wprintf("\n"); - wprintf("" + wprintf("
Home telephone:
" "\n", + "VALUE=\"%s\" MAXLENGTH=\"29\">\n", hometel); - wprintf("" + wprintf("" "
"); + wprintf(_("Home telephone:")); + wprintf("
Work telephone:"); + wprintf(_("Work telephone:")); + wprintf("
\n", worktel); - wprintf("
Internet e-mail addresses:
" - "For addresses in the Citadel directory, " - "the topmost address will be used in outgoing mail." - "
" - "

\n"); + wprintf(""); + wprintf("
"); + + wprintf("" + "
"); + wprintf(_("Primary Internet e-mail address")); + wprintf("
" + "
" + "
"); + wprintf(_("Internet e-mail aliases")); + wprintf("
" + "
\n"); + + wprintf("
\n"); wprintf("\n"); - wprintf("
\n"); - wprintf(""); - wprintf(""); - wprintf("
\n"); + wprintf("\n"); - + wprintf("
\n" + "" + " " + "" + "
\n", + _("Save changes"), + _("Cancel") + ); + + wprintf("
\n"); wDumpContent(1); } +void edit_vcard(void) { + long msgnum; + char *partnum; + + msgnum = atol(bstr("msgnum")); + partnum = bstr("partnum"); + do_edit_vcard(msgnum, partnum, ""); +} + + + + void submit_vcard(void) { char buf[SIZ]; int i; - if (strcmp(bstr("sc"), "OK")) { + if (strlen(bstr("ok_button")) == 0) { readloop("readnew"); return; } sprintf(buf, "ENT0 1|||4||"); - fprintf(stderr, "%s\n", buf); serv_puts(buf); - serv_gets(buf); - fprintf(stderr, "%s\n", buf); + serv_getln(buf, sizeof buf); if (buf[0] != '4') { edit_vcard(); return; @@ -298,6 +374,9 @@ void submit_vcard(void) { 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", bstr("pobox"), bstr("extadr"), @@ -308,9 +387,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 0) { serv_printf("email;internet:%s", buf); } @@ -320,5 +400,13 @@ void submit_vcard(void) { serv_puts("end:vcard"); serv_puts("000"); - readloop("readnew"); + 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"); + } }