]> git.deb.at Git - pkg/abook.git/blobdiff - abook.c
quit and print command added
[pkg/abook.git] / abook.c
diff --git a/abook.c b/abook.c
index e01eb427b4a399e78dda5f616191ae5b8a310240..de333180c757a91bfe6f2bc0b8165aa6400b6f1f 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * by JH <jheinonen@bigfoot.com>
+ * by JH <jheinonen@users.sourceforge.net>
  *
  * Copyright (C) Jaakko Heinonen
  */
@@ -204,7 +204,6 @@ show_usage()
 }
 
 extern list_item *database;
-extern int items;
 
 static void
 muttq_print_item(int item)
@@ -274,43 +273,89 @@ quit_mutt_query(int status)
 }
 
 
+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)
+{
+       char *mailstr = NULL;
+
+       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);
+               }
+       }
+
+    fprintf(stderr, "%s", mailstr);
+
+#ifdef DEBUG
+       fprintf(stderr, "mailstr: %s\n", mailstr);
+#endif
+
+       free(mailstr);
+
+}
+
 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
@@ -332,6 +377,11 @@ launch_wwwbrowser(int item)
                system(cmd);
 
        free(cmd);
+
+       /*
+        * we need to make sure that curses settings are correct
+        */
+       ui_init_curses();
 }
 
 void *
@@ -396,11 +446,13 @@ convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile)
        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();