aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/backend')
-rw-r--r--addressbook/backend/ebook/load-pine-addressbook.c70
1 files changed, 50 insertions, 20 deletions
diff --git a/addressbook/backend/ebook/load-pine-addressbook.c b/addressbook/backend/ebook/load-pine-addressbook.c
index 7d74fe20a4..073c35c915 100644
--- a/addressbook/backend/ebook/load-pine-addressbook.c
+++ b/addressbook/backend/ebook/load-pine-addressbook.c
@@ -27,27 +27,16 @@ add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
}
static void
-book_open_cb (EBook *book, EBookStatus status, gpointer closure)
+parse_line (EBook *book, char *line)
{
- FILE *fp = fopen (".addressbook", "r");
- char line[1024];
-
- if (!fp) {
- g_warning ("Can't find .addressbook");
- return;
- }
-
- while(fgets(line, 1024, fp)) {
- int length = strlen(line);
- char **strings;
- ECardName *name;
- ECard *card;
- EList *list;
- if (line[length - 1] == '\n')
- line[--length] = 0;
-
- card = e_card_new("");
- strings = g_strsplit(line, "\t", 3);
+ char **strings;
+ ECardName *name;
+ ECard *card;
+ EList *list;
+
+ card = e_card_new("");
+ strings = g_strsplit(line, "\t", 3);
+ if (strings[0] && strings[1] && strings[2]) {
name = e_card_name_from_string(strings[1]);
gtk_object_set(GTK_OBJECT(card),
"nickname", strings[0],
@@ -63,6 +52,47 @@ book_open_cb (EBook *book, EBookStatus status, gpointer closure)
}
}
+static void
+book_open_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ FILE *fp = fopen (".addressbook", "r");
+ char line[2 * 1024];
+ int which = 0;
+ char *lastline = NULL;
+
+ if (!fp) {
+ g_warning ("Can't find .addressbook");
+ return;
+ }
+
+ while(fgets(line + which * 1024, 1024, fp)) {
+ int length;
+ char *thisline = line + which * 1024;
+ length = strlen(thisline);
+ if (thisline[length - 1] == '\n')
+ line[--length] = 0;
+ if (lastline && *thisline && isspace(*thisline)) {
+ char *temp;
+ while(*thisline && isspace(*thisline))
+ thisline ++;
+ temp = lastline;
+ lastline = g_strdup_printf("%s%s", lastline, thisline);
+ g_free(temp);
+ continue;
+ }
+ if (lastline) {
+ parse_line (book, lastline);
+ g_free(lastline);
+ }
+ lastline = g_strdup(thisline);
+ }
+
+ if (lastline) {
+ parse_line (book, lastline);
+ g_free(lastline);
+ }
+}
+
static guint
ebook_create (void)
{