#include <errno.h>
#include <fcntl.h>
+#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "options.h"
#include "getname.h"
#include "getopt.h"
+#include "views.h"
#include "xmalloc.h"
static void init_abook();
bool alternative_datafile = FALSE;
bool alternative_rcfile = FALSE;
+
static int
datafile_writeable()
{
printf(_("Press enter to continue...\n"));
fgetc(stdin);
}
+ init_default_views();
signal(SIGTERM, quit_abook_sig);
umask(DEFAULT_UMASK);
if(!datafile_writeable()) {
- char *s = mkstr(_("File %s is not writeable"), datafile);
+ char *s = strdup_printf(_("File %s is not writeable"), datafile);
refresh_screen();
statusline_msg(s);
free(s);
xmalloc_set_error_handler(xmalloc_error_handler);
+ prepare_database_internals();
+
parse_command_line(argc, argv);
init_abook();
}
}
- if (optind < argc) {
+ if(optind < argc) {
fprintf(stderr, _("%s: unrecognized arguments on command line\n"),
argv[0]);
exit(EXIT_FAILURE);
"add the sender to the addressbook"));
puts (_(" --add-email-quiet "
"same as --add-email but doesn't\n"
- " confirm adding"));
+ " require to confirm adding"));
putchar('\n');
puts (_(" --convert convert address book files"));
puts (_(" options to use with --convert:"));
* end of CLI
*/
-extern list_item *database;
static void
quit_mutt_query(int status)
static void
muttq_print_item(FILE *file, int item)
{
- char emails[MAX_EMAILS][MAX_EMAIL_LEN];
- int i;
-
- split_emailstr(item, emails);
-
- for(i = 0; i < (opt_get_bool(BOOL_MUTT_RETURN_ALL_EMAILS) ?
- MAX_EMAILS : 1) ; i++)
- if( *emails[i] )
- fprintf(file, "%s\t%s\t%s\n", emails[i],
- database[item][NAME],
- database[item][NOTES] == NULL ? " " :
- database[item][NOTES]
+ abook_list *emails, *e;
+
+ emails = csv_to_abook_list(db_email_get(item));
+
+ for(e = emails; e; e = e->next) {
+ fprintf(file, "%s\t%s\t%s\n", e->data, db_name_get(item),
+ !db_fget(item, NOTES) ?" " :db_fget(item, NOTES)
);
+ if(!opt_get_bool(BOOL_MUTT_RETURN_ALL_EMAILS))
+ break;
+ }
+ abook_list_free(&emails);
}
static void
{
char email[MAX_EMAIL_LEN];
char *ret;
- char *name = mkstr("\"%s\"", database[item][NAME]);
+ char *name = strdup_printf("\"%s\"", db_name_get(item));
get_first_email(email, item);
- ret = *database[item][EMAIL] ?
- mkstr("%s <%s>", name, email) :
+ ret = *db_email_get(item) ?
+ strdup_printf("%s <%s>", name, email) :
xstrdup(name);
free(name);
if( !is_valid_item(item) )
return;
- if( database[item][URL] )
- cmd = mkstr("%s '%s'",
+ if(db_fget(item, URL))
+ cmd = strdup_printf("%s '%s'",
opt_get_str(STR_WWW_COMMAND),
- safe_str(database[item][URL]));
+ safe_str(db_fget(item, URL)));
else
return;
int ret=0;
if( !srcformat || !srcfile || !dstformat || !dstfile ) {
- fprintf(stderr, _("too few argumets to make conversion\n"));
+ fprintf(stderr, _("too few arguments to make conversion\n"));
fprintf(stderr, _("try --help\n"));
}
set_filenames();
init_opts();
load_opts(rcfile);
+ init_standard_fields();
switch(import_file(srcformat, srcfile)) {
case -1:
}
do {
- /* TODO gettext: handle translated keypresses? */
- printf(_("Add ``%s <%s>'' to %s ? (y/n)\n"),
+ printf(_("Add \"%s <%s>\" to %s? (%c/%c)\n"),
name,
email,
- datafile);
- c = getc(in);
- if(c == 'n' || c == 'N') {
+ datafile,
+ *S_("keybinding for yes|y"),
+ *S_("keybinding for no|n"));
+ c = tolower(getc(in));
+ if(c == *S_("keybinding for no|n")) {
fclose(in);
return 0;
}
- } while(c != 'y' && c != 'Y');
+ } while(c != *S_("keybinding for yes|y"));
fclose(in);
}
- memset(item, 0, sizeof(item));
- item[NAME] = xstrdup(name);
- item[EMAIL] = xstrdup(email);
+ item = item_create();
+ item_fput(item, NAME, xstrdup(name));
+ item_fput(item, EMAIL, xstrdup(email));
add_item2database(item);
+ item_free(&item);
return 1;
}