]> git.deb.at Git - pkg/abook.git/commitdiff
export all email addresses to mutt aliases file. Idea and original
authorGerfried Fuchs <alfie@users.sourceforge.net>
Thu, 22 Jul 2010 20:29:18 +0000 (20:29 +0000)
committerGerfried Fuchs <alfie@users.sourceforge.net>
Thu, 22 Jul 2010 20:29:18 +0000 (20:29 +0000)
approach done by Markus Schnalke, adapted and tweaked for 0.6 by myself.

edit.c
edit.h
filter.c

diff --git a/edit.c b/edit.c
index 6ed553e0cd0134f9a8b2c705d59fa0c2902ade47..d2cba627229680b7dc7068d36bf01a6e95f033ad 100644 (file)
--- 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 8f1ada501b76df84a3c1ef78693265357ec1d515..3beed6501f7bff5ef4afb3903d9737c604d3c795 100644 (file)
--- 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);
 
index 0bdc4b94bdf736fa3bb92608b9aa0f3dc4ebc102..6946f9a5da0fbe6ac685bb411562530a9ecb99f2 100644 (file)
--- 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;