Re: Another Store Address Patch



What about using a separate Gnome card file for Balsa? Balsa will by default
look at the balsa.gcrd file and will store all addresses there. If users need to
find balsa stored address they can open the default Balsa.grcd file from within
Gnome card, and modify it there.

There will be no problems with synchronizing the Gnome card instances and it
is not terribly outrageous to have two address books. Is it?

FITZSIMMONS THOMAS wrote:

> Here is a patch that creates a popup window with Card Name, First Name,
> Last Name, Organization, and Email Address fields when the user wants to
> store an address.
>
> I also added a Store Address item on the message menu. The shortcut is
> 's'.
>
> There are still two problems:
>
> 1. When the user has GnomeCard open and is storing addresses in balsa,
> then closes GnomeCard, saving changes that GnomeCard has made will
> overwrite the vCards stored from balsa. Does anyone know a good way of
> checking whether GnomeCard is running? Are there any other Gnome programs
> that check to see if another program is running?
>
> 2. The first time the user tries to store an address in balsa, they will
> get an error if there is no GnomeCard.gcrd file. I think this needs to be
> addressed in the balsa installation druid -- the installation should not
> proceed unless there is an accessible GnomeCard.gcrd file in ~/.gnome.
>
> I applied the patches to the balsa-0.8.0 tarball, after applying my
> previous patch (now in CVS). Put src-store-contact-patches in src/ and
> libbalsa-store-contact-patches in libbalsa and run
> patch < filename
> for each one.
>
> Cheers,
>
> Thomas
>
>   ------------------------------------------------------------------------
> *** ../balsa-0.8.0/src/balsa-index-page.c       Thu Jun  8 18:33:25 2000
> --- ./src/balsa-index-page.c    Thu Jun  8 18:39:30 2000
> ***************
> *** 76,81 ****
> --- 76,83 ----
>
>   static void transfer_messages_cb (BalsaMBList *, Mailbox *, GtkCTreeNode *, GdkEventButton *, BalsaIndex *);
>
> + static void
> + store_address_dialog_button_clicked_cb(GtkWidget *widget, gint which, GtkWidget **entries);
>
>   static GtkObjectClass *parent_class = NULL;
>   #ifdef SIGNALS_USED
> ***************
> *** 820,825 ****
> --- 822,925 ----
>   }
>   #endif /*DND_USED*/
>
> + static void
> + store_address_dialog_button_clicked_cb(GtkWidget *widget, gint which, GtkWidget **entries)
> + {
> +     if(which == 0)
> +     {
> +         Contact *card = NULL;
> +         gint error_check = 0;
> +         GtkWidget *box = NULL;
> +         gchar * msg = NULL;
> +         gint cnt = 0;
> +         gint cnt2 = 0;
> +         gchar *entry_str = NULL;
> +         gint entry_str_len = 0;
> +             /* semicolons mess up how GnomeCard processes the fields, so disallow them */
> +         for(cnt = 0; cnt < NUM_FIELDS; cnt++)
> +         {
> +             entry_str = gtk_editable_get_chars(GTK_EDITABLE(entries[cnt]), 0, -1);
> +             entry_str_len = strlen(entry_str);
> +
> +             for(cnt2 = 0; cnt2 < entry_str_len; cnt2++)
> +             {
> +                 if(entry_str[cnt2] == ';')
> +                 {
> +                     msg = g_strdup( _("No ;'s!\n"));
> +                     gtk_editable_select_region(GTK_EDITABLE(entries[cnt]), 0, -1);
> +                     gtk_widget_grab_focus(GTK_WIDGET(entries[cnt]));
> +                     box = gnome_message_box_new(msg,
> +                                                 GNOME_MESSAGE_BOX_ERROR,
> +                                                 GNOME_STOCK_BUTTON_OK, NULL );
> +                     gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> +                     gnome_dialog_run_and_close( GNOME_DIALOG( box ) );
> +                     g_free(entry_str);
> +                     g_free(msg);
> +                     return;
> +                 }
> +             }
> +             g_free(entry_str);
> +         }
> +
> +         card = contact_new();
> +         card->card_name = g_strstrip(gtk_editable_get_chars(GTK_EDITABLE(entries[CARD_NAME]), 0, -1));
> +         card->first_name = g_strstrip(gtk_editable_get_chars(GTK_EDITABLE(entries[FIRST_NAME]), 0, -1));
> +         card->last_name = g_strstrip(gtk_editable_get_chars(GTK_EDITABLE(entries[LAST_NAME]), 0, -1));
> +         card->organization = g_strstrip(gtk_editable_get_chars(GTK_EDITABLE(entries[ORGANIZATION]), 0, -1));
> +         card->email_address = g_strstrip(gtk_editable_get_chars(GTK_EDITABLE(entries[EMAIL_ADDRESS]), 0, -1));
> +
> +         error_check = contact_store(card);
> +
> +         if(error_check == CONTACT_UNABLE_TO_OPEN_GNOMECARD_FILE)
> +         {
> +             msg  = g_strdup_printf(
> +                 _("Unable to open ~/.gnome/GnomeCard.gcrd for read.\n - %s\n"),
> +                 g_unix_error_string(errno));
> +         }
> +         else if(error_check == CONTACT_CARD_NAME_FIELD_EMPTY)
> +         {
> +             msg = g_strdup( _("The Card Name field must be non-empty.\n"));
> +             gtk_widget_grab_focus(GTK_WIDGET(entries[CARD_NAME]));
> +         }
> +         else if(error_check == CONTACT_CARD_NAME_EXISTS)
> +         {
> +             msg = g_strdup_printf(
> +                 _("There is already an address book entry for %s.\nRun GnomeCard if you would like to edit your address book entries.\n"),
> +                 card->card_name);
> +             gtk_editable_select_region(GTK_EDITABLE(entries[CARD_NAME]), 0, -1);
> +             gtk_widget_grab_focus(GTK_WIDGET(entries[CARD_NAME]));
> +         }
> +         else
> +         {
> +                 /* storing was successful */
> +             contact_free(card);
> +             gnome_dialog_close(GNOME_DIALOG(widget));
> +             return;
> +         }
> +
> +         box = gnome_message_box_new(msg,
> +                                     GNOME_MESSAGE_BOX_ERROR,
> +                                     GNOME_STOCK_BUTTON_OK, NULL );
> +         gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> +         gnome_dialog_run_and_close( GNOME_DIALOG( box ) );
> +         contact_free(card);
> +         g_free(msg);
> +         return;
> +     }
> +     else
> +     {
> +         gnome_dialog_close(GNOME_DIALOG(widget));
> +         return;
> +     }
> + }
> +
> + static gint
> + store_address_dialog_close(GtkWidget *widget, GtkWidget **entries)
> + {
> +     g_free(entries);
> +     return FALSE;
> + }
> +
>   /* New Stuff */
>
>   void
> ***************
> *** 990,1031 ****
>     balsa_index_select_next (index);
>   }
>
> ! /* This function edits the GnomeCard.gcrd file directly,
> !  * in order to add the address of the sender of the currently
> !  * highlighted message in the index-page to the address
> !  * book. It appends a VCARD entry for the user to the end of
> !  * GnomeCard.gcrd, using the the sender's personal name (the
> !  * one displayed in the email From: field) as the "File as"
> !  * field. If there is already an entry with the sender's
> !  * personal name as the "File as" field
> !  * balsa_message_store_address displays a dialogue
> !  * box saying so, then returns.
> !  */
> ! #define LINE_LEN 256
>   void
>   balsa_message_store_address (GtkWidget * widget, gpointer index)
>   {
> !   GList   *list;
> !   Message *message;
> !   FILE *gc;
> !   gchar string[LINE_LEN];
> !   gint in_vcard = FALSE;
> !   gchar *new_name = NULL, *new_email = NULL;
>
> !   g_return_if_fail (widget != NULL);
>     g_return_if_fail(index != NULL);
>
>     list = GTK_CLIST(index)->selection;
>
>     if(list->next)
>     {
> !      GtkWidget *box;
>        char * msg  = g_strdup( _("You may only store one address at a time.\n") );
>        box = gnome_message_box_new(msg,
> !                                  GNOME_MESSAGE_BOX_ERROR, _("OK"), NULL );
>        gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> !      gnome_dialog_run( GNOME_DIALOG( box ) );
> !      gtk_widget_destroy( GTK_WIDGET( box ) );
>        g_free(msg);
>        return;
>     }
> --- 1090,1143 ----
>     balsa_index_select_next (index);
>   }
>
> ! #define STORE_ADDRESS_DIALOG_WIDTH 375
> ! #define STORE_ADDRESS_DIALOG_HEIGHT 275
>   void
>   balsa_message_store_address (GtkWidget * widget, gpointer index)
>   {
> !   GList   *list = NULL;
> !   Message *message = NULL;
> !   GtkWidget *dialog = NULL;
> !   GtkWidget *frame = NULL;
> !   GtkWidget *table = NULL;
> !   GtkWidget *label = NULL;
> !   GtkWidget **entries = NULL;
> !   gint cnt = 0;
> !   gchar *labels[NUM_FIELDS] = { _("Card Name:"),
> !                                 _("First Name:"),
> !                                 _("Last Name:"),
> !                                 _("Organization:"),
> !                                 _("Email Address:") };
> !   gchar *new_name = NULL;
> !   gchar *new_email = NULL;
>
> !   g_return_if_fail(widget != NULL);
>     g_return_if_fail(index != NULL);
>
>     list = GTK_CLIST(index)->selection;
>
> +   if(list == NULL)
> +   {
> +      GtkWidget *box = NULL;
> +      char * msg  = g_strdup( _("In order to store an address, you must select a message.\n") );
> +      box = gnome_message_box_new(msg,
> +                                  GNOME_MESSAGE_BOX_ERROR,
> +                                  GNOME_STOCK_BUTTON_OK, NULL );
> +      gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> +      gnome_dialog_run_and_close( GNOME_DIALOG( box ) );
> +      g_free(msg);
> +      return;
> +   }
> +
>     if(list->next)
>     {
> !      GtkWidget *box = NULL;
>        char * msg  = g_strdup( _("You may only store one address at a time.\n") );
>        box = gnome_message_box_new(msg,
> !                                  GNOME_MESSAGE_BOX_ERROR,
> !                                  GNOME_STOCK_BUTTON_OK, NULL );
>        gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> !      gnome_dialog_run_and_close( GNOME_DIALOG( box ) );
>        g_free(msg);
>        return;
>     }
> ***************
> *** 1034,1105 ****
>
>     new_name = g_strdup( message->from->personal );
>     new_email = g_strdup( message->from->mailbox );
>
> !   gc = fopen(gnome_util_prepend_user_home(".gnome/GnomeCard.gcrd"), "r+");
> !   if (!gc)
> !   {
> !      GtkWidget *box;
> !      char * msg  = g_strdup_printf(
> !         _("Unable to open ~/.gnome/GnomeCard.gcrd for read.\n - %s\n"),
> !         g_unix_error_string(errno));
> !      box = gnome_message_box_new(msg,
> !                                  GNOME_MESSAGE_BOX_ERROR, _("OK"), NULL );
> !      gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> !      gnome_dialog_run( GNOME_DIALOG( box ) );
> !      gtk_widget_destroy( GTK_WIDGET( box ) );
> !      g_free(new_name);
> !      g_free(new_email);
> !      g_free(msg);
> !      return;
> !   }
> !
> !   while (fgets(string, sizeof(string), gc))
> !   {
> !      if ( g_strncasecmp(string, "BEGIN:VCARD", 11) == 0 ) {
> !         in_vcard = TRUE;
> !         continue;
> !      }
> !
> !      if ( g_strncasecmp(string, "END:VCARD", 9) == 0 ) {
> !         in_vcard = FALSE;
> !         continue;
> !      }
> !
> !      if (!in_vcard) continue;
> !
> !      g_strchomp(string);
>
> !      if ( g_strncasecmp(string, "FN:", 3) == 0 )
> !      {
> !         gchar *id = g_strdup(string+3);
> !         if( g_strcasecmp(id, new_name) == 0 )
> !         {
> !            GtkWidget *box;
> !            char * msg  =  g_strdup_printf(
> !               _("There is already an address book entry for %s.\nRun GnomeCard if you would like to edit your address book entries.\n"),
> !               new_name);
> !            box = gnome_message_box_new(msg,
> !                                        GNOME_MESSAGE_BOX_ERROR, _("OK"), NULL );
> !            gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> !            gnome_dialog_run( GNOME_DIALOG( box ) );
> !            gtk_widget_destroy( GTK_WIDGET( box ) );
> !            g_free(new_name);
> !            g_free(new_email);
> !            g_free(msg);
> !            g_free(id);
> !            fclose(gc);
> !            return;
> !         }
> !         g_free(id);
> !         continue;
> !      }
>     }
> !   fprintf(gc, g_strdup_printf( _("\nBEGIN:VCARD\n")));
> !   fprintf(gc, g_strdup_printf( _("FN:%s\n"), new_name));
> !   fprintf(gc, g_strdup_printf( _("EMAIL;INTERNET:%s\n"), new_email));
> !   fprintf(gc, g_strdup_printf( _("END:VCARD\n")));
> !   g_free(new_name);
>     g_free(new_email);
> !   fclose(gc);
> !   return;
>   }
> --- 1146,1210 ----
>
>     new_name = g_strdup( message->from->personal );
>     new_email = g_strdup( message->from->mailbox );
> +
> +   entries = g_new(GtkWidget *, 5);
>
> !   dialog = gnome_dialog_new( _("Store Address"),
> !                              GNOME_STOCK_BUTTON_OK,
> !                              GNOME_STOCK_BUTTON_CANCEL,
> !                              NULL);
> !
> !   gtk_widget_set_usize(GTK_WIDGET(dialog),
> !                        STORE_ADDRESS_DIALOG_WIDTH,
> !                        STORE_ADDRESS_DIALOG_HEIGHT);
> !
> !   frame = gtk_frame_new( _("Contact Information") );
> !
> !
> !   gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame, TRUE, TRUE, 0);
> !
> !   table = gtk_table_new(5, 2, FALSE);
> !
> !   gtk_container_add(GTK_CONTAINER(frame), table);
> !
> !   gtk_container_set_border_width( GTK_CONTAINER(table), 3 );
> !
> !   for(cnt = 0; cnt < NUM_FIELDS; cnt++)
> !   {
> !      label = gtk_label_new( labels[cnt] );
> !      entries[cnt] = gtk_entry_new();
> !
> !      gtk_table_attach(GTK_TABLE(table), label, 0, 1, cnt, cnt + 1,
> !                       GTK_FILL,
> !                       GTK_FILL,
> !                       4, 4);
> !
> !      gtk_label_set_justify(GTK_LABEL(label),
> !                            GTK_JUSTIFY_LEFT);
>
> !      gtk_table_attach(GTK_TABLE(table), entries[cnt], 1, 2, cnt, cnt + 1,
> !                       GTK_FILL | GTK_EXPAND,
> !                       GTK_FILL | GTK_EXPAND,
> !                       2, 2);
>     }
> !
> !   gtk_entry_set_text( GTK_ENTRY(entries[CARD_NAME]), new_name );
> !   gtk_entry_set_text( GTK_ENTRY(entries[EMAIL_ADDRESS]), new_email );
> !
> !   gtk_editable_select_region (GTK_EDITABLE(entries[CARD_NAME]), 0, -1);
> !
> !   gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
> !
> !   gtk_signal_connect( GTK_OBJECT(dialog),
> !                       "clicked",
> !                       GTK_SIGNAL_FUNC(store_address_dialog_button_clicked_cb),
> !                       entries);
> !   gtk_signal_connect( GTK_OBJECT(dialog),
> !                       "close",
> !                       GTK_SIGNAL_FUNC(store_address_dialog_close),
> !                       entries);
> !
> !   gtk_widget_show_all(dialog);
>     g_free(new_email);
> !   g_free(new_name);
>   }
> *** ../balsa-0.8.0/src/main-window.c    Sat May  6 13:08:43 2000
> --- ./src/main-window.c Thu Jun  8 17:39:41 2000
> ***************
> *** 133,138 ****
> --- 133,139 ----
>
>   static void delete_message_cb (GtkWidget * widget, gpointer data);
>   static void undelete_message_cb (GtkWidget * widget, gpointer data);
> + static void store_address_cb(GtkWidget * widget, gpointer data);
>   static void wrap_message_cb (GtkWidget * widget, gpointer data);
>   static void show_no_headers_cb(GtkWidget * widget, gpointer data);
>   static void show_selected_cb(GtkWidget * widget, gpointer data);
> ***************
> *** 284,290 ****
>       GNOME_STOCK_MENU_UNDELETE, 'U', 0, NULL
>     },
>     GNOMEUIINFO_SEPARATOR,
> ! #define MENU_MESSAGE_WRAP_POS 13
>     GNOMEUIINFO_TOGGLEITEM( N_ ("_Wrap"), NULL, wrap_message_cb, NULL),
>     GNOMEUIINFO_SEPARATOR,
>     GNOMEUIINFO_RADIOLIST(shown_hdrs_menu),
> --- 285,299 ----
>       GNOME_STOCK_MENU_UNDELETE, 'U', 0, NULL
>     },
>     GNOMEUIINFO_SEPARATOR,
> ! #define MENU_MESSAGE_STORE_ADDRESS_POS 13
> !       /* S */
> !   {
> !     GNOME_APP_UI_ITEM, N_ ("_Store Address"), N_("Store address of sender in addressbook"),
> !     store_address_cb, NULL, NULL, GNOME_APP_PIXMAP_STOCK,
> !     GNOME_STOCK_MENU_BOOK_RED, 'S', 0, NULL
> !   },
> !   GNOMEUIINFO_SEPARATOR,
> ! #define MENU_MESSAGE_WRAP_POS 15
>     GNOMEUIINFO_TOGGLEITEM( N_ ("_Wrap"), NULL, wrap_message_cb, NULL),
>     GNOMEUIINFO_SEPARATOR,
>     GNOMEUIINFO_RADIOLIST(shown_hdrs_menu),
> ***************
> *** 1405,1410 ****
> --- 1414,1437 ----
>   undelete_message_cb (GtkWidget * widget, gpointer data)
>   {
>     balsa_message_undelete (widget, balsa_window_find_current_index (BALSA_WINDOW (data)));
> + }
> +
> + static void
> + store_address_cb(GtkWidget * widget, gpointer data)
> + {
> +     if(balsa_window_find_current_index(BALSA_WINDOW (data)) == NULL)
> +     {
> +        GtkWidget *box;
> +        char * msg  = g_strdup( _("In order to store an address, you must open a mailbox and select a message.\n") );
> +        box = gnome_message_box_new(msg,
> +                                    GNOME_MESSAGE_BOX_ERROR,
> +                                    GNOME_STOCK_BUTTON_OK, NULL );
> +        gtk_window_set_modal( GTK_WINDOW( box ), TRUE );
> +        gnome_dialog_run_and_close( GNOME_DIALOG( box ) );
> +        g_free(msg);
> +        return;
> +     }
> +     balsa_message_store_address(widget, balsa_window_find_current_index (BALSA_WINDOW (data)));
>   }
>
>   static void
>
>   ------------------------------------------------------------------------
> diff -r -P -c ../balsa-0.8.0/libbalsa/contact.h ./libbalsa/contact.h
> *** ../balsa-0.8.0/libbalsa/contact.h   Wed Dec 31 19:00:00 1969
> --- ./libbalsa/contact.h        Thu Jun  8 18:35:04 2000
> ***************
> *** 0 ****
> --- 1,59 ----
> + /* Balsa E-Mail Client
> +  * Copyright (C) 1999 Stuart Parmenter
> +  *
> +  * This program is free software; you can redistribute it and/or modify
> +  * it under the terms of the GNU General Public License as published by
> +  * the Free Software Foundation; either version 2, or (at your option)
> +  * any later version.
> +  *
> +  * This program is distributed in the hope that it will be useful,
> +  * but WITHOUT ANY WARRANTY; without even the implied warranty of
> +  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +  * GNU General Public License for more details.
> +  *
> +  * You should have received a copy of the GNU General Public License
> +  * along with this program; if not, write to the Free Software
> +  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
> +  * 02111-1307, USA.
> +  */
> +
> + #ifndef __CONTACT_H__
> + #define __CONTACT_H__
> +
> + #include <glib.h>
> + #include "libmutt/mutt.h"
> +
> + enum
> + {
> +     CARD_NAME,
> +     FIRST_NAME,
> +     LAST_NAME,
> +     ORGANIZATION,
> +     EMAIL_ADDRESS,
> +     NUM_FIELDS
> + };
> +
> +     /* possible error values obtained while trying to store a contact vCard */
> + enum
> + {
> +     CONTACT_CARD_STORED_SUCCESSFULLY,
> +     CONTACT_UNABLE_TO_OPEN_GNOMECARD_FILE,
> +     CONTACT_CARD_NAME_FIELD_EMPTY,
> +     CONTACT_CARD_NAME_EXISTS
> + };
> +
> + struct _Contact
> + {
> +     gchar *card_name;
> +     gchar *first_name;
> +     gchar *last_name;
> +     gchar *organization;
> +     gchar *email_address;
> + };
> +
> + Contact *contact_new(void);
> + void contact_free(Contact *contact);
> + void contact_list_free(GList *contact_list);
> + gint contact_store(Contact *contact);
> +
> + #endif /* __CONTACT_H__ */
> Binary files ../balsa-0.8.0/libbalsa/files.o and ./libbalsa/files.o differ
> Binary files ../balsa-0.8.0/libbalsa/filter-error.o and ./libbalsa/filter-error.o differ
> Binary files ../balsa-0.8.0/libbalsa/filter-file.o and ./libbalsa/filter-file.o differ
> Binary files ../balsa-0.8.0/libbalsa/filter-funcs.o and ./libbalsa/filter-funcs.o differ
> Binary files ../balsa-0.8.0/libbalsa/libbalsa.a and ./libbalsa/libbalsa.a differ
> diff -r -P -c ../balsa-0.8.0/libbalsa/libbalsa.h ./libbalsa/libbalsa.h
> *** ../balsa-0.8.0/libbalsa/libbalsa.h  Tue Mar 28 22:14:45 2000
> --- ./libbalsa/libbalsa.h       Thu Jun  8 18:24:45 2000
> ***************
> *** 23,34 ****
> --- 23,36 ----
>   typedef struct _Mailbox Mailbox;
>   typedef struct _Message Message;
>   typedef struct _Address Address;
> + typedef struct _Contact Contact;
>   typedef struct _Body Body;
>   typedef struct _Server Server;
>
>   #include "mailbox.h"
>   #include "message.h"
>   #include "address.h"
> + #include "contact.h"
>   #include "body.h"
>   #include "files.h"
>
> Binary files ../balsa-0.8.0/libbalsa/libbalsa.o and ./libbalsa/libbalsa.o differ
> diff -r -P -c ../balsa-0.8.0/libbalsa/mailbox.c ./libbalsa/mailbox.c
> *** ../balsa-0.8.0/libbalsa/mailbox.c   Sat May  6 13:41:10 2000
> --- ./libbalsa/mailbox.c        Thu Jun  8 18:23:01 2000
> ***************
> *** 1498,1503 ****
> --- 1498,1609 ----
>     return addr;
>   }
>
> + /*
> +  * contacts
> +  */
> + Contact *
> + contact_new (void)
> + {
> +   Contact *contact;
> +
> +   contact = g_malloc (sizeof (Contact));
> +
> +   contact->card_name = NULL;
> +   contact->first_name = NULL;
> +   contact->last_name = NULL;
> +   contact->organization = NULL;
> +   contact->email_address = NULL;
> +
> +   return contact;
> + }
> +
> +
> + void
> + contact_free (Contact * contact)
> + {
> +
> +   if (!contact)
> +     return;
> +
> +   g_free(contact->card_name);
> +   g_free(contact->first_name);
> +   g_free(contact->last_name);
> +   g_free(contact->organization);
> +   g_free(contact->email_address);
> +
> +   g_free(contact);
> + }
> +
> + void contact_list_free(GList * contact_list)
> + {
> +   GList *list;
> +   for (list = g_list_first (contact_list); list; list = g_list_next (list))
> +     if(list->data) contact_free (list->data);
> +   g_list_free (contact_list);
> + }
> +
> + gint
> + contact_store(Contact *contact)
> + {
> +     FILE *gc;
> +     gchar string[256];
> +     gint in_vcard = FALSE;
> +
> +     if(strlen(contact->card_name) == 0)
> +         return CONTACT_CARD_NAME_FIELD_EMPTY;
> +
> +     gc = fopen(gnome_util_prepend_user_home(".gnome/GnomeCard.gcrd"), "r+");
> +
> +     if (!gc)
> +         return CONTACT_UNABLE_TO_OPEN_GNOMECARD_FILE;
> +
> +     while (fgets(string, sizeof(string), gc))
> +     {
> +         if ( g_strncasecmp(string, "BEGIN:VCARD", 11) == 0 ) {
> +             in_vcard = TRUE;
> +             continue;
> +         }
> +
> +         if ( g_strncasecmp(string, "END:VCARD", 9) == 0 ) {
> +             in_vcard = FALSE;
> +             continue;
> +         }
> +
> +         if (!in_vcard) continue;
> +
> +         g_strchomp(string);
> +
> +         if ( g_strncasecmp(string, "FN:", 3) == 0 )
> +         {
> +             gchar *id = g_strdup(string+3);
> +             if(g_strcasecmp(id, contact->card_name) == 0)
> +             {
> +                 g_free(id);
> +                 fclose(gc);
> +                 return CONTACT_CARD_NAME_EXISTS;
> +             }
> +             g_free(id);
> +             continue;
> +         }
> +     }
> +
> +     fprintf(gc, "\nBEGIN:VCARD\n");
> +     fprintf(gc, g_strdup_printf( "FN:%s\n", contact->card_name));
> +
> +     if(strlen(contact->first_name) || strlen(contact->last_name))
> +         fprintf(gc, g_strdup_printf( "N:%s;%s\n", contact->last_name, contact->first_name));
> +
> +     if(strlen(contact->organization))
> +         fprintf(gc, g_strdup_printf( "ORG:%s\n", contact->organization));
> +
> +     if(strlen(contact->email_address))
> +         fprintf(gc, g_strdup_printf( "EMAIL;INTERNET:%s\n", contact->email_address));
> +
> +     fprintf(gc, "END:VCARD\n");
> +
> +     fclose(gc);
> +     return CONTACT_CARD_STORED_SUCCESSFULLY;
> + }
>
>   /*
>    * body
> Binary files ../balsa-0.8.0/libbalsa/mailbox.o and ./libbalsa/mailbox.o differ
> Binary files ../balsa-0.8.0/libbalsa/mailbox_imap.o and ./libbalsa/mailbox_imap.o differ
> Binary files ../balsa-0.8.0/libbalsa/mailbox_local.o and ./libbalsa/mailbox_local.o differ
> Binary files ../balsa-0.8.0/libbalsa/mailbox_pop3.o and ./libbalsa/mailbox_pop3.o differ
> Binary files ../balsa-0.8.0/libbalsa/message.o and ./libbalsa/message.o differ
> Binary files ../balsa-0.8.0/libbalsa/mime.o and ./libbalsa/mime.o differ
> Binary files ../balsa-0.8.0/libbalsa/misc.o and ./libbalsa/misc.o differ
> Binary files ../balsa-0.8.0/libbalsa/send.o and ./libbalsa/send.o differ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]