Package: abook
Version: 0.5.6-3
Severity: wishlist

The following command

abook --convert --infile ~/.abook/addressbook --informat abook
        --outfile mutt.aliases_test --outformat mutt

does only export the first (primary) email address of each contact.
All further (secondary) email addresses are simply ignored.
If you want to generate mutt.aliases from abook, you have to create
multiple entries for one person in abook - for every email address
one.


Also, contacts without email addresses at all, are exported. This
leads to entries in the aliases file that are useless.


The attached patch is an example solution for both "problems".


meillo



-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-5-686
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages abook depends on:
ii  debconf [debconf-2.0]  1.5.11            Debian configuration management sy
ii  libc6                  2.3.6.ds1-13etch2 GNU C Library: Shared libraries
ii  libncursesw5           5.5-5             Shared libraries for terminal hand
ii  libreadline5           5.2-2             GNU readline and history libraries

abook recommends no packages.

-- debconf information:
  abook/muttrc.d: true
diff -u abook-0.5.6/edit.c abook_meillo/edit.c
--- abook-0.5.6/edit.c	2005-10-20 15:59:30.000000000 +0200
+++ abook_meillo/edit.c	2008-01-09 16:36:06.000000000 +0100
@@ -96,7 +96,7 @@
 		str[MAX_EMAIL_LEN-1] = 0;
 }
 
-static void
+void
 roll_emails(int item)
 {
 	char tmp[MAX_EMAILSTR_LEN];
diff -u abook-0.5.6/edit.h abook_meillo/edit.h
--- abook-0.5.6/edit.h	2005-09-17 12:10:26.000000000 +0200
+++ abook_meillo/edit.h	2008-01-09 16:35:56.000000000 +0100
@@ -3,6 +3,7 @@
 
 void		edit_item(int item);
 void		get_first_email(char *str, int item);
+void		roll_emails(int item);
 void		add_item();
 
 #define EDITW_COLS	(COLS - 6)
diff -u abook-0.5.6/filter.c abook_meillo/filter.c
--- abook-0.5.6/filter.c	2006-04-10 18:02:10.000000000 +0200
+++ abook_meillo/filter.c	2008-01-09 17:15:42.000000000 +0100
@@ -1600,15 +1600,47 @@
 {
 	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",
+
+		/* do not output contacts without email address */
+		/* cause this does not make sense in mutt aliases */
+		if (! *email) {
+			return 0;
+		}
+
+		/* output first email address */
+		fprintf(out, "alias %s %s <%s>\n",
 				alias,
 				database[e.item][NAME],
 				email);
+
+		/* number of email addresses */
+		email_addresses = 1;
+		ptr = database[e.item][EMAIL];
+		while (*ptr != '\0') {
+			if (*ptr == ',') {
+				email_addresses++;
+			}
+			ptr++;
+		}
+
+		/* output other email addresses */
+		while (email_addresses-- > 1) {
+			roll_emails(e.item);
+			get_first_email(email, e.item);
+			fprintf(out, "alias %s__%s %s <%s>\n",
+					alias,
+					email,
+					database[e.item][NAME],
+					email);
+		}
+		roll_emails(e.item);
 		xfree(alias);
 	}

Reply via email to