/* 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));
#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);
{
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;