From: Gerfried Fuchs Date: Thu, 22 Jul 2010 20:29:18 +0000 (+0000) Subject: export all email addresses to mutt aliases file. Idea and original X-Git-Tag: upstream/0.6.1~2^2~74 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=b281ff74163f08f1a665108b55ce25ee0cdca32a;p=pkg%2Fabook.git export all email addresses to mutt aliases file. Idea and original approach done by Markus Schnalke, adapted and tweaked for 0.6 by myself. --- diff --git a/edit.c b/edit.c index 6ed553e..d2cba62 100644 --- a/edit.c +++ b/edit.c @@ -100,7 +100,7 @@ get_first_email(char *str, int item) /* This only rolls emails from the 'email' field, not emails from any * field of type FIELD_EMAILS. * TODO: expand to ask for which field to roll if several are present? */ -static void +void roll_emails(int item, enum rotate_dir dir) { abook_list *emails = csv_to_abook_list(db_fget(item, EMAIL)); diff --git a/edit.h b/edit.h index 8f1ada5..3beed65 100644 --- a/edit.h +++ b/edit.h @@ -1,8 +1,12 @@ #ifndef _EDIT_H #define _EDIT_H +#include "misc.h" /* for rotate_dir enum definition */ + + void edit_item(int item); void get_first_email(char *str, int item); +void roll_emails(int item, enum rotate_dir dir); void add_item(); int parse_date_string(char *s, int *day, int *month, int *year); diff --git a/filter.c b/filter.c index 0bdc4b9..6946f9a 100644 --- a/filter.c +++ b/filter.c @@ -1627,15 +1627,46 @@ mutt_alias_export(FILE *out, struct db_enumerator e) { char email[MAX_EMAIL_LEN]; char *alias = NULL; + int email_addresses; + char *ptr; db_enumerate_items(e) { alias = mutt_alias_genalias(e.item); get_first_email(email, e.item); - fprintf(out, *email ? "alias %s %s <%s>\n": "alias %s %s%s\n", - alias, - db_name_get(e.item), - email); - xfree(alias); + + /* do not output contacts without email address */ + /* cause this does not make sense in mutt aliases */ + if (*email) { + + /* output first email address */ + fprintf(out, "alias %s %s <%s>\n", + alias, + db_name_get(e.item), + email); + + /* number of email addresses */ + email_addresses = 1; + ptr = db_email_get(e.item); + while (*ptr != '\0') { + if (*ptr == ',') { + email_addresses++; + } + ptr++; + } + + /* output other email addresses */ + while (email_addresses-- > 1) { + roll_emails(e.item, ROTATE_RIGHT); + get_first_email(email, e.item); + fprintf(out, "alias %s__%s %s <%s>\n", + alias, + email, + db_name_get(e.item), + email); + } + roll_emails(e.item, ROTATE_RIGHT); + xfree(alias); + } } return 0;