]> git.deb.at Git - pkg/abook.git/blobdiff - filter.c
export all email addresses to mutt aliases file. Idea and original
[pkg/abook.git] / filter.c
index 70ec2d4e8aa5e054b2227311399b8f8ee13c6976..6946f9a5da0fbe6ac685bb411562530a9ecb99f2 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -61,6 +61,7 @@ static int    elm_alias_export(FILE *out, struct db_enumerator e);
 static int     text_export_database(FILE *out, struct db_enumerator e);
 static int     spruce_export_database(FILE *out, struct db_enumerator e);
 static int     wl_export_database(FILE *out, struct db_enumerator e);
+static int     bsdcal_export_database(FILE *out, struct db_enumerator e);
 
 /*
  * end of function declarations
@@ -91,6 +92,7 @@ struct abook_output_filter e_filters[] = {
        { "text", N_("plain text"), text_export_database },
        { "wl", N_("Wanderlust address book"), wl_export_database },
        { "spruce", N_("Spruce address book"), spruce_export_database },
+       { "bsdcal", N_("BSD calendar"), bsdcal_export_database },
        { "\0", NULL, NULL }
 };
 
@@ -1625,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;
@@ -1876,3 +1909,34 @@ wl_export_database(FILE *out, struct db_enumerator e)
  * end of wanderlust addressbook export filter
  */
 
+/*
+ * BSD calendar export filter
+ */
+
+static int
+bsdcal_export_database(FILE *out, struct db_enumerator e)
+{
+       db_enumerate_items(e) {
+               int year, month = 0, day = 0;
+               char *anniversary = db_fget(e.item, ANNIVERSARY);
+
+               if(anniversary) {
+                       if(!parse_date_string(anniversary, &day, &month, &year))
+                               continue;
+
+                       fprintf(out,
+                               _("%02d/%02d\tAnniversary of %s\n"),
+                               month,
+                               day,
+                               safe_str(db_name_get(e.item))
+                       );
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * end of BSD calendar export filter
+ */
+