Re: Storing Addresses





On Sat, 27 May 2000, Matthew Guenther wrote:

> On Sat, 27 May 2000, FITZSIMMONS THOMAS wrote:
> > 
> > Is there any way to store an address in the address book without typing it
> > in through GnomeCard?
> > 
> > Thanks,
> > 
> 
> Not at the moment, though this has been requested in the past... so it may
> get added at some point (probably pretty easy to do, just a matter of taking
> the time).
> 
> <obligatory request>
> 
> 	Patches always welcome. :)

I have a patch ready.

I've added a "Store Address" item to the pop-up menu that comes up when
you right click on a message in the index. 

Right now, you can only store one address at a time.

The address is stored as a VCARD entry in the .gnome/GnomeCard.gcrd file.
I use message->from->personal as the FN: field (making sure that there is 
not already an entry with FN:message->from->personal) and then store
message->from->mailbox in the EMAIL;INTERNET: field. The VCARD entry is
placed at the end of the .gcrd file.

This works for now, but it would probably be better if the "Store Address"
menu item opened a gnome card window with the personal name and the e-mail
address as defaults. Any ideas on how to do this?

Anyway, to install the patch, put the patchfile 'balsa-address-storage' in
balsa-0.8.0/src/ and, in that directory, type

	patch <balsa-address-storage
 
> 
> </obligatory request>
> 
> MBG
> 
> -- 
> Matthew Guenther                     "I came to kick ass and chew gum...
> mguenthe@engr.uvic.ca                and I'm all out of gum"
> http://www.netcom.ca/~mguenthe/
> 
> 
> _______________________________________________
> balsa-list mailing list
> balsa-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/balsa-list
> 
*** balsa-index-page.h	Fri Mar 24 04:28:53 2000
--- balsa-index-page.h.new	Sat May 27 17:11:17 2000
***************
*** 66,71 ****
--- 66,72 ----
  void balsa_message_previous (GtkWidget * widget, gpointer index);
  void balsa_message_delete (GtkWidget * widget, gpointer index);
  void balsa_message_undelete (GtkWidget * widget, gpointer index);
+ void balsa_message_store_address (GtkWidget * widget, gpointer index);
  
  void balsa_index_page_reset(BalsaIndexPage *page);
  gint balsa_find_notebook_page_num(Mailbox *mailbox);
*** balsa-index-page.c	Wed May  3 20:58:41 2000
--- balsa-index-page.c.new	Sat May 27 22:46:56 2000
***************
*** 20,25 ****
--- 20,26 ----
  #include "config.h"
  
  #include <gnome.h>
+ #include <errno.h>
  #include "balsa-app.h"
  #include "balsa-index.h"
  #include "balsa-message.h"
***************
*** 631,636 ****
--- 632,645 ----
    gtk_menu_append (GTK_MENU (menu), menuitem);
    gtk_widget_show (menuitem);
  
+   menuitem = gnome_stock_menu_item (GNOME_STOCK_MENU_BOOK_RED, _ ("Store Address"));
+   gtk_signal_connect (GTK_OBJECT (menuitem),
+ 		      "activate",
+ 		      (GtkSignalFunc) balsa_message_store_address,
+ 		      bindex);
+   gtk_menu_append (GTK_MENU (menu), menuitem);
+   gtk_widget_show (menuitem);
+ 
    menuitem = gtk_menu_item_new_with_label (_ ("Transfer"));
    submenu = gtk_menu_new ();
    smenuitem = gtk_menu_item_new ();
***************
*** 979,982 ****
--- 988,1105 ----
      list = list->next;
    }
    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;
+   }
+     
+   message = gtk_clist_get_row_data(GTK_CLIST(index), GPOINTER_TO_INT(list->data));
+   
+   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;
  }


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