From: Jaakko Heinonen Date: Mon, 29 Sep 2003 13:08:27 +0000 (+0000) Subject: mutt import filter changes X-Git-Tag: upstream/0.6.1~2^2~245 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=c4d2f4ab3d5166b75f8fc1bf9e2be776014d391d;p=pkg%2Fabook.git mutt import filter changes --- diff --git a/BUGS b/BUGS index f583e90..7b4c3be 100644 --- a/BUGS +++ b/BUGS @@ -16,3 +16,4 @@ misc: * Cursor disappears in some cases with abook_readline() on Solaris. If you have problems it is recommended to use ncurses library * fseek in ldif import filter should be eliminated +* mutt import filter imports only first e-mail address diff --git a/ChangeLog b/ChangeLog index 9c9d071..b48c953 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.5.1 - minor filter fixes + - tried to fix \" quotation problem with mutt import filter + - removed obsolete filesel_sort option from abookrc manual page - added bbdb2xx translator source to contrib 0.5.0 diff --git a/configure b/configure index 3f52608..6111671 100755 --- a/configure +++ b/configure @@ -1527,7 +1527,7 @@ fi # Define the identity of the package. PACKAGE=abook - VERSION=0.5.0 + VERSION=0.5.1pre cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index fd01f99..a278a3f 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl abook configure.in AC_INIT(abook.c) -AM_INIT_AUTOMAKE(abook, 0.5.0) +AM_INIT_AUTOMAKE(abook, 0.5.1pre) AM_CONFIG_HEADER(config.h) AC_DEFINE(HAVE_SNPRINTF, 0, [Define if snprintf is available.]) diff --git a/database.c b/database.c index 70e5a1c..c17adae 100644 --- a/database.c +++ b/database.c @@ -351,21 +351,53 @@ surnamecmp(const void *i1, const void *i2) return ret; } +static int sort_field = -1; + static int namecmp(const void *i1, const void *i2) { list_item a, b; + assert(sort_field >= 0 && sort_field <= LAST_FIELD); + itemcpy(a, i1); itemcpy(b, i2); - return safe_strcoll( a[NAME], b[NAME] ); + return safe_strcoll( a[sort_field], b[sort_field] ); +} + +static int +name2field(char *name) +{ + int i, ret = -1; + + for(i = 0; i < ITEM_FIELDS; i++) { + if(!strcasecmp(name, abook_fields[i].key)) { + ret = i; + break; + } + } + + return ret; } void -sort_database() +sort_by_field(int field) { select_none(); + + assert(field <= LAST_FIELD); + + if(field < 0) { + field = name2field(opt_get_str(STR_SORT_FIELD)); + if(field < 0) { + statusline_msg("Not valid field value defined " + "in configuration"); + return; + } + } + + sort_field = field; qsort((void *)database, items, sizeof(list_item), namecmp); diff --git a/database.h b/database.h index 10b31f8..43b7338 100644 --- a/database.h +++ b/database.h @@ -55,7 +55,7 @@ int add_item2database(list_item item); void free_list_item(list_item item); void remove_selected_items(); void sort_surname(); -void sort_database(); +void sort_by_field(int field); char *get_surname(char *s); int find_item(char *str, int start, int search_fields[]); int is_selected(int item); diff --git a/filter.c b/filter.c index 880213a..9a18975 100644 --- a/filter.c +++ b/filter.c @@ -657,14 +657,38 @@ mutt_read_line(FILE *in, char **alias, char **rest) return 0; } +static void +mutt_fix_quoting(char *p) +{ + char *escape = 0; + + for(; *p; p++) { + switch(*p) { + case '\"': + if(escape) + *escape = ' '; + break; + case '\\': + escape = p; + break; + default: + escape = 0; + } + } +} + static void mutt_parse_email(list_item item) { char *line = item[NAME]; - char *start = line, *tmp; + char *tmp; char *name, *email; +#if 0 + char *start = line; int i = 0; +#endif + mutt_fix_quoting(line); tmp = strconcat("From: ", line, NULL); getname(tmp, &name, &email); free(tmp); @@ -678,6 +702,10 @@ mutt_parse_email(list_item item) else return; + /* + * this is completely broken + */ +#if 0 while( (start = strchr(start, ',')) && i++ < MAX_EMAILS - 1) { tmp = strconcat("From: ", ++start, NULL); getname(tmp, &name, &email); @@ -693,6 +721,7 @@ mutt_parse_email(list_item item) } } } +#endif } static int diff --git a/help.h b/help.h index abb040e..f9058bb 100644 --- a/help.h +++ b/help.h @@ -32,6 +32,7 @@ static char *mainhelp[] = { "\n", " s sort database\n", " S \"surname sort\"\n", +" F sort by field (defined in configuration file)\n", "\n", " / find\n", " \\ find next\n", diff --git a/options.c b/options.c index e9885a9..fe75878 100644 --- a/options.c +++ b/options.c @@ -65,6 +65,7 @@ static struct option abook_vars[] = { { "use_ascii_only", OT_BOOL, BOOL_USE_ASCII_ONLY, FALSE }, { "add_email_prevent_duplicates", OT_BOOL, BOOL_ADD_EMAIL_PREVENT_DUPLICATES, FALSE }, + { "sort_field", OT_STR, STR_SORT_FIELD, UL "nick" }, { NULL } }; diff --git a/options.h b/options.h index 5d83f98..cfdaa6c 100644 --- a/options.h +++ b/options.h @@ -42,6 +42,7 @@ enum str_opts { STR_PRINT_COMMAND, STR_WWW_COMMAND, STR_ADDRESS_STYLE, + STR_SORT_FIELD, STR_MAX }; diff --git a/sample.abookrc b/sample.abookrc index a5359df..a8fb452 100644 --- a/sample.abookrc +++ b/sample.abookrc @@ -48,3 +48,5 @@ set address_style=eu set use_ascii_only=false set add_email_prevent_duplicates=false + +set sort_field=nick diff --git a/ui.c b/ui.c index 4d4150e..023f206 100644 --- a/ui.c +++ b/ui.c @@ -420,8 +420,9 @@ get_commands() case 'o': ui_open_datafile(); break; - case 's': sort_database(); break; + case 's': sort_by_field(NAME); break; case 'S': sort_surname(); break; + case 'F': sort_by_field(-1); break; case '/': ui_find(0); break; case '\\': ui_find(1); break;