+/*
+ * Edit a user's Internet email addresses
+ */
+void edit_user_internet_email_addresses(CtdlIPC *ipc, char *who)
+{
+ char buf[256];
+ char *resp = NULL;
+ int num_recs = 0;
+ char **recs = NULL;
+ char ch;
+ int i, j;
+ int quitting = 0;
+ int modified = 0;
+ int r;
+ char emailaddrs[512];
+
+ r = CtdlIPCAideGetEmailAddresses(ipc, who, emailaddrs, buf);
+ if (r / 100 == 1) {
+ while (!IsEmptyStr(emailaddrs)) {
+ extract_token(buf, emailaddrs, 0, '\n', sizeof buf);
+ remove_token(emailaddrs, 0, '\n');
+
+ ++num_recs;
+ if (num_recs == 1) recs = malloc(sizeof(char *));
+ else recs = realloc(recs, (sizeof(char *)) * num_recs);
+ recs[num_recs-1] = malloc(strlen(buf) + 1);
+ strcpy(recs[num_recs-1], buf);
+ }
+ }
+
+ do {
+ scr_printf("\n");
+ color(BRIGHT_WHITE);
+ scr_printf(" Internet email addresses for %s\n", who);
+ color(DIM_WHITE);
+ scr_printf("--- --------------------------------------------------\n");
+ for (i=0; i<num_recs; ++i) {
+ color(DIM_WHITE);
+ scr_printf("%3d ", i+1);
+ color(BRIGHT_CYAN);
+ scr_printf("%s\n", recs[i]);
+ color(DIM_WHITE);
+ }
+
+ ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
+ switch(ch) {
+ case 'a':
+ newprompt("Enter new email address: ", buf, 50);
+ striplt(buf);
+ if (!IsEmptyStr(buf)) {
+ // FIXME validate the email address (format, our own domain, addr does not belong to another user)
+ ++num_recs;
+ if (num_recs == 1) {
+ recs = malloc(sizeof(char *));
+ }
+ else {
+ recs = realloc(recs, (sizeof(char *)) * num_recs);
+ }
+ recs[num_recs-1] = strdup(buf);
+ }
+ modified = 1;
+ break;
+ case 'd':
+ i = intprompt("Delete which address", 1, 1, num_recs) - 1;
+ free(recs[i]);
+ --num_recs;
+ for (j=i; j<num_recs; ++j) {
+ recs[j] = recs[j+1];
+ }
+ modified = 1;
+ break;
+ case 's':
+ r = 1;
+ for (i = 0; i < num_recs; i++)
+ r += 1 + strlen(recs[i]);
+ resp = (char *)calloc(1, r);
+ if (!resp) {
+ scr_printf("Can't save config - out of memory!\n");
+ logoff(ipc, 1);
+ }
+ if (num_recs) for (i = 0; i < num_recs; i++) {
+ strcat(resp, recs[i]);
+ strcat(resp, "\n");
+ }
+
+ //r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
+ //if (r / 100 != 4) {
+ //scr_printf("%s\n", buf);
+ //} else {
+ //scr_printf("Wrote %d records.\n", num_recs);
+ //modified = 0;
+ //}
+ scr_printf("<%s>\n", resp);
+
+
+
+ free(resp);
+ break;
+ case 'q':
+ quitting = !modified || boolprompt("Quit without saving", 0);
+ break;
+ default:
+ break;
+ }
+ } while (!quitting);
+
+ if (recs != NULL) {
+ for (i=0; i<num_recs; ++i) free(recs[i]);
+ free(recs);
+ }
+}
+
+