+ atexit(close_database);
+
+ signal(SIGINT, quit_add_email);
+}
+
+static int
+add_email_add_item(int quiet, char *name, char *email)
+{
+ list_item item;
+
+ if(!quiet) {
+ FILE *in = fopen("/dev/tty", "r");
+ char c;
+ if(!in) {
+ fprintf(stderr, "cannot open /dev/tty\n"
+ "you may want to use --add-email-force\n");
+ exit(1);
+ }
+ printf("Add ``%s <%s>'' to %s ? (y/n)\n",
+ name,
+ email,
+ datafile
+ );
+ do {
+ c = fgetc(in);
+ if(c == 'n' || c == 'N') {
+ fclose(in);
+ return 0;
+ }
+ } while(c != 'y' && c != 'Y');
+ fclose(in);
+ }
+
+ memset(item, 0, sizeof(item));
+ item[NAME] = strdup(name);
+ item[EMAIL] = strdup(email);
+ add_item2database(item);
+
+ return 1;
+}
+
+static void
+add_email(int quiet)
+{
+ char *line;
+ char *name = NULL, *email = NULL;
+
+ init_add_email();
+
+ do {
+ line = getaline(stdin);
+ if(line && !strncasecmp("From:", line, 5) ) {
+ getname(line, &name, &email);
+ my_free(line);
+ add_email_count += add_email_add_item(quiet,
+ name, email);
+ my_free(name);
+ my_free(email);
+ }
+ my_free(line);
+ } while( !feof(stdin) );
+
+ quit_add_email();
+}
+
+/*
+ * end of --add-email handling
+ */