]> git.deb.at Git - pkg/abook.git/blobdiff - abook.c
added option add_email_prevent_duplicates
[pkg/abook.git] / abook.c
diff --git a/abook.c b/abook.c
index 101dd69d6b41fe787c2cce462e844163a8f612d9..d4de3ec5679d71620fa311c790998618ec03072e 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -605,17 +605,18 @@ FILE *
 abook_fopen (const char *path, const char *mode)
 {      
        struct stat s;
+       bool stat_ok;
 
-       if((stat(path, &s)) == -1)
-               return NULL;
+       stat_ok = (stat(path, &s) != -1);
        
        if(strchr(mode, 'r'))
-               return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL;
+               return (stat_ok && S_ISREG(s.st_mode)) ?
+                       fopen(path, mode) : NULL;
        else
-               return S_ISDIR(s.st_mode) ? NULL : fopen(path, mode);
+               return (stat_ok && S_ISDIR(s.st_mode)) ?
+                       NULL : fopen(path, mode);
 }
 
-
 static void
 convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile)
 {
@@ -722,6 +723,16 @@ add_email_add_item(int quiet, char *name, char *email)
 {
        list_item item;
 
+       if(opt_get_bool(BOOL_ADD_EMAIL_PREVENT_DUPLICATES)) {
+               int search_fields[] = { EMAIL, -1 };
+               if(find_item(email, 0, search_fields) >= 0) {
+                       if(!quiet)
+                               printf("Address %s already in addressbook\n",
+                                               email);
+                       return 0;
+               }
+       }
+                                       
        if(!quiet) {
                FILE *in = fopen("/dev/tty", "r");
                char c;