5 * by JH <jheinonen@users.sourceforge.net>
7 * Copyright (C) Jaakko Heinonen
16 #include <sys/types.h>
17 #include "abook_curses.h"
28 extern list_item *database;
29 extern struct abook_field abook_fields[];
32 * function declarations
36 * import filter prototypes
39 static int ldif_parse_file(FILE *handle);
40 static int mutt_parse_file(FILE *in);
41 static int pine_parse_file(FILE *in);
42 static int csv_parse_file(FILE *in);
45 * export filter prototypes
48 static int ldif_export_database(FILE *out, struct db_enumerator e);
49 static int html_export_database(FILE *out, struct db_enumerator e);
50 static int pine_export_database(FILE *out, struct db_enumerator e);
51 static int csv_export_database(FILE *out, struct db_enumerator e);
52 static int palm_export_database(FILE *out, struct db_enumerator e);
53 static int gcrd_export_database(FILE *out, struct db_enumerator e);
54 static int mutt_alias_export(FILE *out, struct db_enumerator e);
55 static int elm_alias_export(FILE *out, struct db_enumerator e);
56 static int text_export_database(FILE *out, struct db_enumerator e);
57 static int spruce_export_database(FILE *out, struct db_enumerator e);
60 * end of function declarations
63 struct abook_input_filter i_filters[] = {
64 { "abook", "abook native format", parse_database },
65 { "ldif", "ldif / Netscape addressbook", ldif_parse_file },
66 { "mutt", "mutt alias", mutt_parse_file },
67 { "pine", "pine addressbook", pine_parse_file },
68 { "csv", "comma separated values", csv_parse_file },
72 struct abook_output_filter e_filters[] = {
73 { "abook", "abook native format", write_database },
74 { "ldif", "ldif / Netscape addressbook (.4ld)", ldif_export_database },
75 { "mutt", "mutt alias", mutt_alias_export },
76 { "html", "html document", html_export_database },
77 { "pine", "pine addressbook", pine_export_database },
78 { "gcrd", "GnomeCard (VCard) addressbook", gcrd_export_database },
79 { "csv", "comma separated values", csv_export_database },
80 { "palmcsv", "Palm comma separated values", palm_export_database},
81 { "elm", "elm alias", elm_alias_export },
82 { "text", "plain text", text_export_database },
83 { "spruce", "Spruce address book", spruce_export_database },
97 for(i=0; *i_filters[i].filtname ; i++)
98 printf("\t%s\t%s\n", i_filters[i].filtname,
104 for(i=0; *e_filters[i].filtname ; i++)
105 printf("\t%s\t%s\n", e_filters[i].filtname,
112 number_of_output_filters()
116 for(i=0; *e_filters[i].filtname ; i++)
123 number_of_input_filters()
127 for(i=0; *i_filters[i].filtname ; i++)
136 char *username = getenv("USER");
137 struct passwd *pwent;
141 pwent = getpwnam(username);
143 if((tmp = strdup(pwent->pw_gecos)) == NULL)
144 return strdup(username);
146 rtn = sscanf(pwent->pw_gecos, "%[^,]", tmp);
147 if (rtn == EOF || rtn == 0) {
149 return strdup(username);
158 static int i_read_file(char *filename, int (*func) (FILE *in));
167 refresh_statusline();
168 headerline("import database");
170 mvaddstr(3, 1, "please select a filter");
173 for(i=0; *i_filters[i].filtname ; i++)
174 mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
175 i_filters[i].filtname,
178 mvprintw(6 + i, 6, "x -\tcancel");
190 filter = getch() - 'a';
191 if(filter == 'x' - 'a' ||
192 filter >= number_of_input_filters() || filter < 0) {
197 mvaddstr(5+filter, 2, "->");
199 filename = ask_filename("Filename: ");
205 if( i_read_file(filename, i_filters[filter].func ) )
206 statusline_msg("Error occured while opening the file");
207 else if( tmp == items )
208 statusline_msg("Hmm.., file seems not to be a valid file");
219 i_read_file(char *filename, int (*func) (FILE *in))
224 if( ( in = abook_fopen( filename, "r" ) ) == NULL )
235 import_file(char filtname[FILTNAME_LEN], char *filename)
242 if( ! strncasecmp(i_filters[i].filtname, filtname,
245 if( ! *i_filters[i].filtname ) {
254 if( !strcmp(filename, "-") ) {
256 if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode))
259 ret = (*i_filters[i].func) (stdin);
261 ret = i_read_file(filename, i_filters[i].func);
273 static int e_write_file(char *filename,
274 int (*func) (FILE *in, struct db_enumerator e), int mode);
284 refresh_statusline();
285 headerline("export database");
287 mvaddstr(3, 1, "please select a filter");
290 for(i=0; *e_filters[i].filtname ; i++)
291 mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
292 e_filters[i].filtname,
295 mvprintw(6 + i, 6, "x -\tcancel");
302 int enum_mode = ENUM_ALL;
307 filter = getch() - 'a';
308 if(filter == 'x' - 'a' ||
309 filter >= number_of_output_filters() || filter < 0) {
314 mvaddstr(5+filter, 2, "->");
316 if( selected_items() ) {
317 statusline_addstr("Export All/Selected/Cancel (A/s/c)");
318 switch( tolower(getch()) ) {
320 enum_mode = ENUM_SELECTED;
329 filename = ask_filename("Filename: ");
335 if( e_write_file(filename, e_filters[filter].func, enum_mode ) )
336 statusline_msg("Error occured while exporting");
345 e_write_file(char *filename, int (*func) (FILE *in, struct db_enumerator e),
350 struct db_enumerator enumerator = init_db_enumerator(mode);
352 if( (out = fopen(filename, "a")) == NULL )
358 ret = (*func) (out, enumerator);
366 fexport(char filtname[FILTNAME_LEN], FILE *handle, int enum_mode)
369 struct db_enumerator e = init_db_enumerator(enum_mode);
372 if( ! strncasecmp(e_filters[i].filtname, filtname,
375 if( ! *e_filters[i].filtname ) {
381 return (e_filters[i].func) (handle, e);
387 export_file(char filtname[FILTNAME_LEN], char *filename)
389 const int mode = ENUM_ALL;
392 struct db_enumerator e = init_db_enumerator(mode);
395 if( ! strncasecmp(e_filters[i].filtname, filtname,
398 if( ! *e_filters[i].filtname ) {
407 if( !strcmp(filename, "-") )
408 ret = (e_filters[i].func) (stdout, e);
410 ret = e_write_file(filename, e_filters[i].func, mode);
416 * end of common functions
425 static void ldif_fix_string(char *str);
427 #define LDIF_ITEM_FIELDS 16
429 typedef char* ldif_item[LDIF_ITEM_FIELDS];
431 static ldif_item ldif_field_names = {
443 "facsimiletelephonenumber",
447 "objectclass", /* this must be the last entry */
450 static int ldif_conv_table[LDIF_ITEM_FIELDS] = {
453 ADDRESS, /* "streetaddress" */
454 ADDRESS2, /* "streetaddress2" */
455 CITY, /* "locality" */
457 ZIP, /* "postalcode" */
458 COUNTRY, /* "countryname" */
459 PHONE, /* "homephone" */
460 NOTES, /* "description" */
462 FAX, /* "facsimiletelephonenumber" */
463 MOBILEPHONE, /* "cellphone" */
464 WORKPHONE, /* "xmozillaanyphone" */
465 NICK, /* "xmozillanickname" */
466 -1, /* "objectclass" */ /* this must be the last entry */
471 ldif_read_line(FILE *in)
484 if( feof(in) || !line )
493 fseek(in, pos, SEEK_SET); /* fixme ! */
503 buf = strconcat(buf, ptr, NULL);
508 if(buf && *buf == '#' ) {
517 ldif_add_item(ldif_item ldif_item)
519 list_item abook_item;
522 memset(abook_item, 0, sizeof(abook_item));
524 if( !ldif_item[LDIF_ITEM_FIELDS -1] )
528 for(i=0; i < LDIF_ITEM_FIELDS; i++) {
529 if(ldif_conv_table[i] >= 0 && ldif_item[i] && *ldif_item[i] )
530 abook_item[ldif_conv_table[i]] = strdup(ldif_item[i]);
533 add_item2database(abook_item);
536 for(i=0; i < LDIF_ITEM_FIELDS; i++)
537 my_free(ldif_item[i]);
542 ldif_convert(ldif_item item, char *type, char *value)
546 if( !strcmp(type, "dn") ) {
551 for(i=0; i < LDIF_ITEM_FIELDS; i++) {
552 if( !safe_strcmp(ldif_field_names[i], type) && *value ) {
553 if( i == LDIF_ITEM_FIELDS -1) /* this is a dirty hack */
554 if( safe_strcmp("person", value))
558 item[i] = strdup(value);
564 ldif_parse_file(FILE *handle)
571 memset(item, 0, sizeof(item));
574 if( ! (line = ldif_read_line(handle)) )
577 if( -1 == ( str_parse_line(line, &type, &value, &vlen)) ) {
579 continue; /* just skip the errors */
582 ldif_fix_string(value);
584 ldif_convert(item, type, value);
587 } while ( !feof(handle) );
589 ldif_convert(item, "dn", "");
595 ldif_fix_string(char *str)
599 for( i = 0, j = 0; j < (int)strlen(str); i++, j++)
600 str[i] = ( str[j] == (char)0xc3 ?
601 (char) str[++j] + (char) 0x40 :
612 * mutt alias import filter
618 mutt_read_line(FILE *in, char **alias, char **rest)
620 char *line, *ptr, *tmp;
622 if( !(line = ptr = getaline(in)) )
623 return 1; /* error / EOF */
625 while( ISSPACE(*ptr) )
628 if( strncmp("alias", ptr, 5) ) {
635 while( ISSPACE(*ptr) )
640 while( ! ISSPACE(*ptr) )
643 if( (*alias = (char *)malloc(ptr - tmp)) == NULL) {
648 strncpy(*alias, tmp, ptr - tmp - 1);
649 *(*alias + (ptr - tmp)) = 0;
661 mutt_fix_quoting(char *p)
681 mutt_parse_email(list_item item)
683 char *line = item[NAME];
691 mutt_fix_quoting(line);
692 tmp = strconcat("From: ", line, NULL);
693 getname(tmp, &name, &email);
706 * this is completely broken
709 while( (start = strchr(start, ',')) && i++ < MAX_EMAILS - 1) {
710 tmp = strconcat("From: ", ++start, NULL);
711 getname(tmp, &name, &email);
716 tmp = strconcat(item[EMAIL], ",", email, NULL);
728 mutt_parse_file(FILE *in)
733 memset(item, 0, sizeof(item));
735 if( !mutt_read_line(in, &item[NICK],
737 mutt_parse_email(item);
740 free_list_item(item);
744 add_item2database(item);
751 * end of mutt alias import filter
760 ldif_fput_type_and_value(FILE *out,char *type, char *value )
764 tmp = ldif_type_and_value(type, value, strlen(value));
772 ldif_export_database(FILE *out, struct db_enumerator e)
774 char email[MAX_EMAILSTR_LEN];
776 fprintf(out, "version: 1\n");
778 db_enumerate_items(e) {
781 get_first_email(email, e.item);
783 tmp = mkstr("cn=%s,mail=%s", database[e.item][NAME], email);
784 ldif_fput_type_and_value(out, "dn", tmp);
787 for(j=0; j < LDIF_ITEM_FIELDS; j++) {
788 if(ldif_conv_table[j] >= 0) {
789 if(ldif_conv_table[j] == EMAIL)
790 ldif_fput_type_and_value(out,
791 ldif_field_names[j], email);
792 else if(database[e.item][ldif_conv_table[j]])
793 ldif_fput_type_and_value(out,
795 database[e.item][ldif_conv_table[j]]);
799 fprintf(out, "objectclass: top\n"
800 "objectclass: person\n\n");
807 * end of ldif export filter
814 static void html_export_write_head(FILE *out, int extra_column);
815 static void html_export_write_tail(FILE *out);
817 extern int extra_column;
820 html_export_database(FILE *out, struct db_enumerator e)
822 char tmp[MAX_EMAILSTR_LEN];
827 extra_column = (extra_column > 2 && extra_column < ITEM_FIELDS) ?
828 extra_column : PHONE;
830 html_export_write_head(out, extra_column);
832 db_enumerate_items(e) {
833 get_first_email(tmp, e.item);
835 fprintf(out, "<tr>\n<td><a href=\"mailto:%s\">%s</a>\n",
837 database[e.item][NAME] );
839 fprintf(out, "<tr>\n<td>%s\n",
840 database[e.item][NAME] );
842 fprintf(out, "<td>%s\n<td>%s\n",
843 database[e.item][EMAIL],
844 safe_str(database[e.item][extra_column]) );
845 fprintf(out, "</tr>\n\n");
848 html_export_write_tail(out);
855 html_export_write_head(FILE *out, int extra_column)
857 char *realname = get_real_name();
859 fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
860 fprintf(out, "<html>\n<head>\n <title>%s's addressbook</title>", realname );
861 fprintf(out, "\n</head>\n<body>\n");
862 fprintf(out, "\n<h2>%s's addressbook</h2>\n", realname );
863 fprintf(out, "<br><br>\n\n");
865 fprintf(out, "<table border=\"1\" align=\"center\">\n");
866 fprintf(out, "\n<tr><th>Name<th>E-mail address(es)<th>%s</tr>\n\n",
867 abook_fields[extra_column].name);
873 html_export_write_tail(FILE *out)
875 fprintf(out, "\n</table>\n");
876 fprintf(out, "\n</body>\n</html>\n");
880 * end of html export filter
885 * pine addressbook import filter
888 #define PINE_BUF_SIZE 2048
891 pine_fixbuf(char *buf)
895 for(i=0,j=0; j < (int)strlen(buf); i++, j++)
896 buf[i] = buf[j] == '\n' ? buf[++j] : buf[j];
900 pine_convert_emails(char *s)
905 if( s == NULL || *s != '(' )
911 if( ( tmp = strchr(s,')')) )
914 for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s=tmp+1 )
915 if( i > MAX_EMAILS - 1 ) {
923 pine_parse_buf(char *buf)
928 char tmp[PINE_BUF_SIZE];
930 int pine_conv_table[]= {NICK, NAME, EMAIL, -1, NOTES};
932 memset(&item, 0, sizeof(item) );
934 for(i=0, last=0; !last ; i++) {
935 if( ! (end = strchr(start, '\t')) )
938 len = last ? strlen(start) : (int) (end-start);
939 len = min(len, PINE_BUF_SIZE - 1);
941 if(i < (int)(sizeof(pine_conv_table) / sizeof(*pine_conv_table))
942 && pine_conv_table[i] >= 0) {
943 strncpy(tmp, start, len);
946 item[pine_conv_table[i]] = strdup(tmp);
951 pine_convert_emails(item[EMAIL]);
952 add_item2database(item);
956 #define LINESIZE 1024
959 pine_parse_file(FILE *in)
966 fgets(line, LINESIZE, in);
970 buf = (char *) realloc(buf, i*LINESIZE);
973 fgets(line, LINESIZE, in);
975 if(*ptr != ' ' || feof(in) )
998 * end of pine addressbook import filter
1003 * pine addressbook export filter
1005 * filter doesn't wrap the lines as it should but Pine seems to handle
1006 * created files without problems - JH
1010 pine_export_database(FILE *out, struct db_enumerator e)
1012 db_enumerate_items(e) {
1013 fprintf(out, have_multiple_emails(e.item) ?
1014 "%s\t%s\t(%s)\t\t%s\n" : "%s\t%s\t%s\t\t%s\n",
1015 safe_str(database[e.item][NICK]),
1016 safe_str(database[e.item][NAME]),
1017 safe_str(database[e.item][EMAIL]),
1018 safe_str(database[e.item][NOTES])
1026 * end of pine addressbook export filter
1035 * these files should be parsed according to a certain
1036 * lay out, or the default if layout is not given, at
1037 * the moment only default is done...
1040 #define CSV_COMMENT_CHAR '#'
1042 static int csv_conv_table[] = {
1051 csv_convert_emails(char *s)
1059 for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s = tmp + 1 )
1060 if( i > MAX_EMAILS - 1 ) {
1068 csv_remove_quotes(char *s)
1070 char *copy, *trimmed;
1073 copy = trimmed = strdup(s);
1076 len = strlen(trimmed);
1077 if(trimmed[len - 1] == '\"' && *trimmed == '\"') {
1082 trimmed[len - 1] = 0;
1084 trimmed = strdup(trimmed);
1094 csv_store_field(list_item item, char *s, int field)
1096 char *newstr = NULL;
1101 if( !(newstr = csv_remove_quotes(s)) )
1104 if(field < (int)(sizeof(csv_conv_table) / sizeof(*csv_conv_table))
1105 && csv_conv_table[field] >= 0) {
1106 item[csv_conv_table[field]] = newstr;
1113 csv_is_valid_quote_end(char *p)
1121 else if(!ISSPACE(*p))
1129 csv_is_valid_quote_start(char *p)
1134 else if(!ISSPACE(*p))
1142 csv_parse_line(char *line)
1146 bool in_quote = FALSE;
1149 memset(item, 0, sizeof(item));
1151 for(p = start = line, field = 0; *p; p++) {
1153 if(csv_is_valid_quote_end(p))
1156 if ( (((p - start) / sizeof (char)) < 2 ) &&
1157 csv_is_valid_quote_start(p) )
1161 if( *p == ',' && !in_quote) {
1163 csv_store_field(item, start, field);
1171 csv_store_field(item, start, field);
1173 csv_convert_emails(item[EMAIL]);
1174 add_item2database(item);
1179 csv_parse_file(FILE *in)
1184 line = getaline(in);
1186 if(line && *line && *line != CSV_COMMENT_CHAR)
1187 csv_parse_line(line);
1196 * end of csv import filter
1200 * csv addressbook export filters
1203 #define CSV_LAST (-1)
1204 #define CSV_UNDEFINED (-2)
1205 #define CSV_SPECIAL(X) (-3 - (X))
1206 #define CSV_IS_SPECIAL(X) ((X) <= -3)
1209 csv_export_common(FILE *out, struct db_enumerator e,
1210 int fields[], void (*special_func)(FILE *, int, int))
1214 db_enumerate_items(e) {
1215 for(i = 0; fields[i] != CSV_LAST; i++) {
1216 if(fields[i] == CSV_UNDEFINED)
1217 fprintf(out, "\"\"");
1218 else if(CSV_IS_SPECIAL(fields[i])) {
1220 (*special_func)(out, e.item, fields[i]);
1223 strchr(safe_str(database[e.item][fields[i]]), ',') ||
1224 strchr(safe_str(database[e.item][fields[i]]), '\"')) ?
1226 safe_str(database[e.item][fields[i]])
1228 fprintf(out, "\"%s\"",
1229 safe_str(database[e.item][fields[i]]));
1231 if(fields[i + 1] != CSV_LAST)
1241 csv_export_database(FILE *out, struct db_enumerator e)
1243 int csv_export_fields[] = {
1252 csv_export_common(out, e, csv_export_fields, NULL);
1261 #define PALM_CSV_NAME CSV_SPECIAL(0)
1262 #define PALM_CSV_END CSV_SPECIAL(1)
1263 #define PALM_CSV_CAT CSV_SPECIAL(2)
1266 palm_split_and_write_name(FILE *out, char *name)
1272 if ( (p = strchr(name, ' ')) ) {
1276 fprintf(out, "\"%s\",\"" , p + 1);
1277 fwrite((void *)name, p - name, sizeof(char), out);
1280 fprintf(out, "\"%s\"", safe_str(name));
1285 palm_csv_handle_specials(FILE *out, int item, int field)
1289 palm_split_and_write_name(out, database[item][NAME]);
1292 fprintf(out, "\"abook\"");
1295 fprintf(out, "\"0\"");
1303 palm_export_database(FILE *out, struct db_enumerator e)
1305 int palm_export_fields[] = {
1306 PALM_CSV_NAME, /* LASTNAME, FIRSTNAME */
1307 CSV_UNDEFINED, /* TITLE */
1308 CSV_UNDEFINED, /* COMPANY */
1309 WORKPHONE, /* WORK PHONE */
1310 PHONE, /* HOME PHONE */
1312 MOBILEPHONE, /* OTHER */
1314 ADDRESS, /* ADDRESS */
1318 COUNTRY, /* COUNTRY */
1319 NICK, /* DEFINED 1 */
1320 URL, /* DEFINED 2 */
1321 CSV_UNDEFINED, /* DEFINED 3 */
1322 CSV_UNDEFINED, /* DEFINED 4 */
1324 PALM_CSV_END, /* "0" */
1325 PALM_CSV_CAT, /* CATEGORY */
1329 csv_export_common(out, e, palm_export_fields, palm_csv_handle_specials);
1335 * end of csv export filters
1339 * GnomeCard (VCard) addressbook export filter
1343 gcrd_export_database(FILE *out, struct db_enumerator e)
1345 char emails[MAX_EMAILS][MAX_EMAIL_LEN];
1349 db_enumerate_items(e) {
1350 fprintf(out, "BEGIN:VCARD\nFN:%s\n",
1351 safe_str(database[e.item][NAME]));
1353 name = get_surname(database[e.item][NAME]);
1354 for( j = strlen(database[e.item][NAME]) - 1; j >= 0; j-- ) {
1355 if(database[e.item][NAME][j] == ' ')
1358 fprintf(out, "N:%s;%.*s\n",
1361 safe_str(database[e.item][NAME])
1366 if ( database[e.item][ADDRESS] )
1367 fprintf(out, "ADR:;;%s;%s;%s;%s;%s;%s\n",
1368 safe_str(database[e.item][ADDRESS]),
1369 safe_str(database[e.item][ADDRESS2]),
1370 safe_str(database[e.item][CITY]),
1371 safe_str(database[e.item][STATE]),
1372 safe_str(database[e.item][ZIP]),
1373 safe_str(database[e.item][COUNTRY])
1376 if (database[e.item][PHONE])
1377 fprintf(out, "TEL;HOME:%s\n", database[e.item][PHONE]);
1378 if (database[e.item][WORKPHONE])
1379 fprintf(out, "TEL;WORK:%s\n", database[e.item][WORKPHONE]);
1380 if (database[e.item][FAX])
1381 fprintf(out, "TEL;FAX:%s\n", database[e.item][FAX]);
1382 if (database[e.item][MOBILEPHONE])
1383 fprintf(out, "TEL;CELL:%s\n", database[e.item][MOBILEPHONE]);
1385 if ( database[e.item][EMAIL] ) {
1386 split_emailstr(e.item, emails);
1387 for(j=0; j < MAX_EMAILS ; j++) {
1389 fprintf(out, "EMAIL;INTERNET:%s\n",
1394 if ( database[e.item][NOTES] )
1395 fprintf(out, "NOTE:%s\n", database[e.item][NOTES]);
1396 if (database[e.item][URL])
1397 fprintf(out, "URL:%s\n", database[e.item][URL]);
1399 fprintf(out, "END:VCARD\n\n");
1407 * end of GnomeCard export filter
1412 * mutt alias export filter
1416 mutt_alias_genalias(int i)
1420 if(database[i][NICK])
1421 return strdup(database[i][NICK]);
1423 tmp = strdup(database[i][NAME]);
1425 if( ( pos = strchr(tmp, ' ') ) )
1434 mutt_alias_export(FILE *out, struct db_enumerator e)
1436 char email[MAX_EMAIL_LEN];
1439 db_enumerate_items(e) {
1440 alias = mutt_alias_genalias(e.item);
1442 get_first_email(email, e.item);
1443 fprintf(out, *email ? "alias %s %s <%s>\n": "alias %s %s%s\n",
1445 database[e.item][NAME],
1454 * end of mutt alias export filter
1459 * printable export filter
1464 text_write_address_us(FILE *out, int i) {
1465 fprintf(out, "\n%s", database[i][ADDRESS]);
1467 if (database[i][ADDRESS2])
1468 fprintf(out, "\n%s", database[i][ADDRESS2]);
1470 if (database[i][CITY])
1471 fprintf(out, "\n%s", database[i][CITY]);
1473 if (database[i][STATE] || database[i][ZIP]) {
1476 if(database[i][STATE]) {
1477 fprintf(out, "%s", database[i][STATE]);
1478 if(database[i][ZIP])
1482 if(database[i][ZIP])
1483 fprintf(out, "%s", database[i][ZIP]);
1486 if (database[i][COUNTRY])
1487 fprintf(out, "\n%s", database[i][COUNTRY]);
1492 text_write_address_uk(FILE *out, int i) {
1495 for (j = ADDRESS; j <= COUNTRY; j++)
1497 fprintf(out, "\n%s", database[i][j]);
1501 text_write_address_eu(FILE *out, int i) {
1502 fprintf(out, "\n%s", database[i][ADDRESS]);
1504 if (database[i][ADDRESS2])
1505 fprintf(out, "\n%s", database[i][ADDRESS2]);
1507 if (database[i][ZIP] || database[i][CITY]) {
1510 if(database[i][ZIP]) {
1511 fprintf(out, "%s", database[i][ZIP]);
1512 if(database[i][CITY])
1516 if(database[i][CITY])
1517 fprintf(out, "%s", database[i][CITY]);
1520 if (database[i][STATE])
1521 fprintf(out, "\n%s", database[i][STATE]);
1523 if (database[i][COUNTRY])
1524 fprintf(out, "\n%s", database[i][COUNTRY]);
1528 text_export_database(FILE * out, struct db_enumerator e)
1530 char emails[MAX_EMAILS][MAX_EMAIL_LEN];
1532 char *realname = get_real_name();
1533 char *style = opt_get_str(STR_ADDRESS_STYLE);
1536 "-----------------------------------------\n%s's address book\n"
1537 "-----------------------------------------\n\n\n",
1541 db_enumerate_items(e) {
1543 "-----------------------------------------\n\n");
1544 fprintf(out, "%s", database[e.item][NAME]);
1545 if (database[e.item][NICK] && *database[e.item][NICK])
1546 fprintf(out, "\n(%s)", database[e.item][NICK]);
1549 if (*database[e.item][EMAIL]) {
1551 split_emailstr(e.item, emails);
1552 for (j = 0; j < MAX_EMAILS; j++)
1554 fprintf(out, "%s\n", emails[j]);
1557 if (database[e.item][ADDRESS]) {
1558 if (!safe_strcmp(style, "us")) /* US like */
1559 text_write_address_us(out, e.item);
1560 else if (!safe_strcmp(style, "uk")) /* UK like */
1561 text_write_address_uk(out, e.item);
1563 text_write_address_eu(out, e.item);
1568 if ((database[e.item][PHONE]) ||
1569 (database[e.item][WORKPHONE]) ||
1570 (database[e.item][FAX]) ||
1571 (database[e.item][MOBILEPHONE])) {
1573 for (j = PHONE; j <= MOBILEPHONE; j++)
1574 if (database[e.item][j])
1575 fprintf(out, "%s: %s\n",
1576 abook_fields[j].name,
1577 database[e.item][j]);
1580 if (database[e.item][URL])
1581 fprintf(out, "\n%s\n", database[e.item][URL]);
1582 if (database[e.item][NOTES])
1583 fprintf(out, "\n%s\n", database[e.item][NOTES]);
1588 fprintf(out, "-----------------------------------------\n");
1594 * end of printable export filter
1598 * elm alias export filter
1602 elm_alias_export(FILE *out, struct db_enumerator e)
1604 char email[MAX_EMAIL_LEN];
1607 db_enumerate_items(e) {
1608 alias = mutt_alias_genalias(e.item);
1609 get_first_email(email, e.item);
1610 fprintf(out, "%s = %s = %s\n",
1612 database[e.item][NAME],
1621 * end of elm alias export filter
1626 * Spruce export filter
1630 spruce_export_database (FILE *out, struct db_enumerator e)
1632 char email[MAX_EMAIL_LEN];
1634 fprintf (out, "# This is a generated file made by abook for the Spruce e-mail client.\n\n");
1636 db_enumerate_items(e) {
1637 if(strcmp (safe_str(database[e.item][EMAIL]), "")) {
1638 get_first_email(email, e.item);
1639 fprintf(out, "# Address %d\nName: %s\nEmail: %s\nMemo: %s\n\n",
1641 database[e.item][NAME],
1643 safe_str(database[e.item][NOTES])
1648 fprintf (out, "# End of address book file.\n");
1654 * end of Spruce export filter