/*
* $Id$
*
- * by JH <jheinonen@bigfoot.com>
+ * by JH <jheinonen@users.sourceforge.net>
*
* Copyright (C) Jaakko Heinonen
*/
}
extern list_item *database;
-extern int items;
static void
-muttq_print_item(int item)
+muttq_print_item(FILE *file, int item)
{
char emails[MAX_EMAILS][MAX_EMAIL_LEN];
int i;
for(i = 0; i < (options_get_int("mutt_return_all_emails") ?
MAX_EMAILS : 1) ; i++)
if( *emails[i] )
- printf("%s\t%s\t%s\n", emails[i],
+ fprintf(file, "%s\t%s\t%s\n", emails[i],
database[item][NAME],
database[item][NOTES] == NULL ? " " :
database[item][NOTES]
struct db_enumerator e = init_db_enumerator(ENUM_ALL);
printf("All items\n");
db_enumerate_items(e)
- muttq_print_item(e.item);
+ muttq_print_item(stdout, e.item);
} else {
int search_fields[] = {NAME, EMAIL, NICK, -1};
int i;
}
putchar('\n');
while(i >= 0) {
- muttq_print_item(i);
+ muttq_print_item(stdout, i);
i = find_item(str, i+1, search_fields);
}
}
}
+static char *
+make_mailstr(int item)
+{
+ char email[MAX_EMAIL_LEN];
+ char *ret;
+ char *name = mkstr("\"%s\"", database[item][NAME]);
+
+ get_first_email(email, item);
+
+ ret = *database[item][EMAIL] ?
+ mkstr("%s <%s>", name, email) :
+ strdup(name);
+
+ free(name);
+
+ return ret;
+}
+
+void
+print_stderr(int item)
+{
+ fprintf (stderr, "%c", '\n');
+
+ if( is_valid_item(item) )
+ muttq_print_item(stderr, item);
+ else {
+ struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+ db_enumerate_items(e) {
+ muttq_print_item(stderr, e.item);
+ }
+ }
+
+}
+
void
launch_mutt(int item)
{
- int i;
- char email[MAX_EMAIL_LEN];
- char *cmd;
- char *tmp = options_get_str("mutt_command");
+ char *cmd = NULL, *mailstr = NULL;
+ char *mutt_command = options_get_str("mutt_command");
- if( !is_valid_item(item) )
+ if(mutt_command == NULL || !*mutt_command)
return;
- cmd = strconcat(tmp, " '", NULL );
-
- for(i=0; i < items; i++) {
- if( ! is_selected(i) && i != list_current_item() )
- continue;
- get_first_email(email, i);
- tmp = mkstr("%s \"%s\"", cmd, database[i][NAME]);
- my_free(cmd);
- if( *database[i][EMAIL] ) {
- cmd = mkstr("%s <%s>", tmp, email);
+ if( is_valid_item(item) )
+ mailstr = make_mailstr(item);
+ else {
+ struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+ char *tmp = NULL;
+ db_enumerate_items(e) {
+ tmp = mailstr;
+ mailstr = tmp ?
+ strconcat(tmp, ",", make_mailstr(e.item), NULL):
+ strconcat(make_mailstr(e.item), NULL);
free(tmp);
- tmp = cmd;
}
- cmd = strconcat(tmp, " ", NULL);
- free(tmp);
}
- tmp = mkstr("%s%c", cmd, '\'');
- free(cmd);
- cmd = tmp;
+ cmd = strconcat(mutt_command, " \'", mailstr,
+ "\'", NULL);
+ free(mailstr);
#ifdef DEBUG
fprintf(stderr, "cmd: %s\n", cmd);
#endif
system(cmd);
-
free(cmd);
+
+ /*
+ * we need to make sure that curses settings are correct
+ */
+ ui_init_curses();
}
void
system(cmd);
free(cmd);
+
+ /*
+ * we need to make sure that curses settings are correct
+ */
+ ui_init_curses();
}
void *
strlower(srcformat);
strlower(dstformat);
+#ifndef DEBUG
if( !strcmp(srcformat, dstformat) ) {
printf( "input and output formats are the same\n"
"exiting...\n");
exit(1);
}
+#endif
set_filenames();
init_options();
exit(ret);
}
-