Patch for mbox support in the SendMail conduit.



This patch adds support for mbox files in the SendMail conduit.  It is
against current cvs.

Is this ok to commit?

Later,
-dave
? gpilotd-visor.diff
? capplet-visor.diff
? full-visor-patch.diff
? gnome-pilot-mbox.patch
? gpilotd/gnome-pilot-client-private.h
Index: conduits/email/email-conduit-control-applet.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/email/email-conduit-control-applet.c,v
retrieving revision 1.17
diff -u -r1.17 email-conduit-control-applet.c
--- conduits/email/email-conduit-control-applet.c	2000/03/12 07:28:45	1.17
+++ conduits/email/email-conduit-control-applet.c	2000/08/04 04:46:09
@@ -70,6 +70,7 @@
 	(*c)->fromAddr = gnome_config_get_string( "from_address" );
 	(*c)->sendAction = gnome_config_get_string( "send_action=file");
 	(*c)->mhDirectory = gnome_config_get_string( "mh_directory" );
+        (*c)->mboxFile = gnome_config_get_string ("mbox_file");
 	(*c)->receiveAction = gnome_config_get_string( "receive_action=file" );
 	gnome_config_pop_prefix();
 
@@ -91,6 +92,7 @@
 	gnome_config_set_string("from_address", c->fromAddr);
 	gnome_config_set_string("send_action", c->sendAction);
 	gnome_config_set_string("mh_directory", c->mhDirectory);
+        gnome_config_set_string("mbox_file", c->mboxFile);
 	gnome_config_set_string("receive_action", c->receiveAction);
 	gnome_config_pop_prefix();
 
@@ -108,6 +110,7 @@
 	retval->fromAddr = g_strdup(c->fromAddr);
 	retval->sendAction = g_strdup(c->sendAction);
 	retval->mhDirectory = g_strdup(c->mhDirectory);
+        retval->mboxFile = g_strdup (c->mboxFile);
 	retval->receiveAction = g_strdup(c->receiveAction);
 	retval->pilotId = c->pilotId;
 	return retval;
@@ -123,6 +126,7 @@
 	g_free( (*c)->fromAddr );
 	g_free( (*c)->sendAction );
 	g_free( (*c)->mhDirectory );
+        g_free( (*c)->mboxFile );
 	g_free( (*c)->receiveAction );
 	g_free(*c);
 	*c = NULL;
@@ -312,7 +316,7 @@
 
 	vbox = gtk_vbox_new(FALSE, GNOME_PAD);
 
-	table = gtk_table_new(2, 4, FALSE);
+	table = gtk_table_new(6, 3, FALSE);
 	gtk_table_set_row_spacings(GTK_TABLE(table), 4);
 	gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 	gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, GNOME_PAD);
@@ -349,6 +353,17 @@
   	gtk_signal_connect(GTK_OBJECT(entry), "insert_text",
   			   GTK_SIGNAL_FUNC(insert_callback),
   			   NULL);
+        /* Get the mbox file */
+	label = gtk_label_new(_("mbox file"));
+	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
+
+	entry = gtk_entry_new_with_max_length(256);
+	gtk_object_set_data(GTK_OBJECT(vbox), "mboxFile", entry);
+	gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 2, 3);
+        /* no spaces in the fields */
+  	gtk_signal_connect(GTK_OBJECT(entry), "insert_text",
+  			   GTK_SIGNAL_FUNC(insert_callback),
+  			   NULL);
 
         /* change the state of the capplet on delete chars as well */
   	gtk_signal_connect(GTK_OBJECT(entry), "delete_text",
@@ -361,11 +376,11 @@
 
         /* Get sendmail location */
 	label = gtk_label_new(_("Mailer location"));
-	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
+	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
 
 	entry = gtk_entry_new_with_max_length(256);
 	gtk_object_set_data(GTK_OBJECT(vbox), "SendmailLoc", entry);
-	gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 2, 3);
+	gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 3, 4);
 
         /* change the state of the capplet on delete chars as well */
   	gtk_signal_connect(GTK_OBJECT(entry), "delete_text",
@@ -378,7 +393,7 @@
         
         /* what to do with mail sent from the pilot */
         label = gtk_label_new(_("Mail sent from pilot"));
-        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
+        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
 
         menu = GTK_MENU(gtk_menu_new());
         for (i = 0; i < ACTION_OPTIONS_COUNT; i++) {
@@ -397,12 +412,12 @@
                            GTK_SIGNAL_FUNC(statechange_cb),
                            NULL);
 
-        gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 3, 4);
+        gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 4, 5);
 	gtk_object_set_data(GTK_OBJECT(vbox), "SendAction", optionMenu);
 
         /* is the mail on the host computer archived? */
         label = gtk_label_new(_("Mail on Host"));
-        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
+        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 5, 6);
         menu = GTK_MENU(gtk_menu_new());
         for (i = 0; i < ACTION_OPTIONS_COUNT; i++) {
                 action_options[i] = _(action_options[i]);
@@ -419,7 +434,7 @@
                            GTK_SIGNAL_FUNC(statechange_cb),
                            NULL);
 
-        gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 4, 5);
+        gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 5, 6);
 	gtk_object_set_data(GTK_OBJECT(vbox), "RecvAction", optionMenu);
 
 	return vbox;
@@ -428,17 +443,19 @@
 static void
 setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
 {
-	GtkWidget *fromAddress, *mailDir, *sendmailLoc, *sendAct, *recvAct;
+	GtkWidget *fromAddress, *mailDir, *mboxFile, *sendmailLoc, *sendAct, *recvAct;
         int i;
 
 	fromAddress = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FromAddress");
 	mailDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "MailDir");
+        mboxFile = gtk_object_get_data(GTK_OBJECT(pilotcfg), "mboxFile");
         sendmailLoc = gtk_object_get_data(GTK_OBJECT(pilotcfg), "SendmailLoc");
         sendAct = gtk_object_get_data(GTK_OBJECT(pilotcfg), "SendAction");
         recvAct = gtk_object_get_data(GTK_OBJECT(pilotcfg), "RecvAction");
 
 	g_assert(fromAddress != NULL);
 	g_assert(mailDir != NULL);
+        g_assert(mboxFile != NULL);
 	g_assert(sendmailLoc != NULL);
   	g_assert(sendAct != NULL); 
   	g_assert(recvAct != NULL);
@@ -447,6 +464,7 @@
 
 	gtk_entry_set_text(GTK_ENTRY(fromAddress), state->fromAddr);
 	gtk_entry_set_text(GTK_ENTRY(mailDir), state->mhDirectory);
+        gtk_entry_set_text(GTK_ENTRY(mboxFile), state->mboxFile);
 	gtk_entry_set_text(GTK_ENTRY(sendmailLoc), state->sendmail);
 
         /* find the entry in the option menu. if not found, 
@@ -463,14 +481,16 @@
 static void
 readOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
 {
-	GtkWidget *fromAddress, *mailDir, *sendmailLoc;
+	GtkWidget *fromAddress, *mailDir, *mboxFile, *sendmailLoc;
 
 	fromAddress = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FromAddress");
 	mailDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "MailDir");
+        mboxFile = gtk_object_get_data(GTK_OBJECT(pilotcfg), "mboxFile");
 	sendmailLoc = gtk_object_get_data(GTK_OBJECT(pilotcfg), "SendmailLoc");
 
 	state->fromAddr = g_strdup(gtk_entry_get_text(GTK_ENTRY(fromAddress)));
 	state->mhDirectory = g_strdup(gtk_entry_get_text(GTK_ENTRY(mailDir)));
+        state->mboxFile = g_strdup(gtk_entry_get_text(GTK_ENTRY(mboxFile)));
 	state->sendmail = g_strdup(gtk_entry_get_text(GTK_ENTRY(sendmailLoc)));
         /* the sendAction and receiveAction were already updated in the cb */
 }
Index: conduits/email/email_conduit.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/email/email_conduit.c,v
retrieving revision 1.12
diff -u -r1.12 email_conduit.c
--- conduits/email/email_conduit.c	2000/02/27 12:03:56	1.12
+++ conduits/email/email_conduit.c	2000/08/04 04:46:10
@@ -50,6 +50,7 @@
 	(*c)->fromAddr = gnome_config_get_string( "from_address" );
 	(*c)->sendAction = gnome_config_get_string( "send_action=file");
 	(*c)->mhDirectory = gnome_config_get_string( "mh_directory" );
+	(*c)->mboxFile = gnome_config_get_string ( "mbox_file" );
 	(*c)->receiveAction = gnome_config_get_string( "receive_action=file" );
 	gnome_config_pop_prefix();
 
@@ -67,6 +68,7 @@
 	g_free( (*c)->fromAddr );
 	g_free( (*c)->sendAction );
 	g_free( (*c)->mhDirectory );
+	g_free( (*c)->mboxFile );
 	g_free( (*c)->receiveAction );
 	g_free(*c);
 	*c = NULL;
@@ -146,6 +148,67 @@
     }
 }
 
+static gboolean
+write_message_to_pilot (GnomePilotConduit *c, GnomePilotDBInfo *dbi, 
+			int dbHandle, char *buffer, int msg_num)
+{
+    char *msg;
+    int h;
+    struct Mail t;
+    int len;
+    
+    t.to = NULL;
+    t.from = NULL;
+    t.cc = NULL;
+    t.bcc = NULL;
+    t.subject = NULL;
+    t.replyTo = NULL;
+    t.sentTo = NULL;
+    t.body = NULL;
+    t.dated = 0;
+
+    msg = (char *)buffer;
+    h = 1;
+    
+    while ( h == 1 ) {
+	markline( msg );
+	
+	if ( ( msg[0] == 0 ) && ( msg[1] == 0 ) ) {
+	    break;
+	}
+	
+	if ( msg[0] == 0 ) {
+	    h = 0;
+	    header( &t, 0 );
+	} else {
+	    header( &t, msg );
+	}
+	msg += strlen(msg)+1;
+    }
+    
+    if ( (*msg) == 0 ) {
+	h = 1;
+    }
+    
+    if ( h ) {
+	fprintf( stderr, "Incomplete message %d\n", msg_num );
+	free_Mail( &t );
+	return FALSE;
+    }
+    
+    t.body = strdup( msg );
+    
+    len = pack_Mail( &t, buffer, 0xffff );
+    
+    if ( dlp_WriteRecord( dbi->pilot_socket, dbHandle, 0, 0, 0, buffer,
+			  len, 0 ) > 0 ) {
+	return TRUE;
+    } else {
+	fprintf( stderr, "Error writing message to Pilot\n" );
+	return FALSE;
+    }
+}
+
 static gint synchronize( GnomePilotConduit *c, GnomePilotDBInfo *dbi ) 
 {
     int dbHandle;
@@ -312,8 +375,6 @@
         for( i = 1; ; i++ ) {
             int len;
             int l;
-            char *msg;
-            int h;
             struct Mail t;
             int mhmsg;
             
@@ -326,7 +387,7 @@
             t.sentTo = NULL;
             t.body = NULL;
             t.dated = 0;
-            
+	    
             if ( ( mhmsg = openmhmsg( GET_CONFIG(c)->mhDirectory, i ) ) < 0 ) {
                 break;
             }
@@ -346,44 +407,10 @@
             if ( l < 0 ) {
                 fprintf( stderr, "Error processing message %d\n", i );
                 break;
-            }
-            
-            msg = (char *)buffer;
-            h = 1;
-            
-            while ( h == 1 ) {
-                markline( msg );
-                
-                if ( ( msg[0] == 0 ) && ( msg[1] == 0 ) ) {
-                    break;
-                }
-                
-                if ( msg[0] == 0 ) {
-                    h = 0;
-                    header( &t, 0 );
-                } else {
-                    header( &t, msg );
-                }
-                msg += strlen(msg)+1;
-            }
-            
-            if ( (*msg) == 0 ) {
-                h = 1;
-            }
-            
-            if ( h ) {
-                fprintf( stderr, "Incomplete message %d\n", i );
-                free_Mail( &t );
-                continue;
-            }
-            
-            t.body = strdup( msg );
-            
-            len = pack_Mail( &t, buffer, 0xffff );
-            
-            if ( dlp_WriteRecord( dbi->pilot_socket, dbHandle, 0, 0, 0, buffer,
-                                  len, 0 ) > 0 ) {
-                rec++;
+            } 
+		
+	    if (write_message_to_pilot (c, dbi, dbHandle, buffer, i)) {
+		rec++;
                 if ( strcmp( GET_CONFIG(c)->receiveAction, "delete" ) == 0 ) {
                     char filename[1000];
                     sprintf( filename, "%s/%d", GET_CONFIG(c)->mhDirectory, 
@@ -397,14 +424,63 @@
                 } else {
                     dupe++;
                 }
-            } else {
-                fprintf( stderr, "Error writing message to Pilot\n" );
-            }
-            
-            free_Mail( &t );
-            
+	    }
+
             close( mhmsg );
         }
+    }
+    
+    if ( GET_CONFIG(c)->mboxFile ) {
+	FILE *f;
+#ifdef EC_DEBUG
+        fprintf( stderr, "Reading inbound mail from %s\n",
+                 GET_CONFIG(c)->mboxFile );
+#endif
+        f = fopen (GET_CONFIG (c)->mboxFile, "r");
+	
+
+	if (f) {	
+	    fgets (buffer, sizeof (buffer) - 1, f);
+	    while (!feof (f) && strncmp (buffer, "From ", 5)) {
+		fgets (buffer, sizeof (buffer) - 1, f);
+	    }
+	    for( i = 1; !feof (f); i++ ) {
+		int len;
+		int l;
+		char *p;
+           
+#ifdef EC_DEBUG 
+		fprintf( stderr, "Processing message %d", i );
+#endif
+		len = 0;
+		while ( ( len < sizeof(buffer) ) &&
+			( ( p = fgets ( (char *)(buffer+len),
+					sizeof(buffer)-len, f ) ) != 0 ) ) {
+		    if (!strncmp (p, "From ", 5)) {
+			break;
+		    } else {
+			len += strlen (p);
+		    }
+		}
+		
+		buffer[len] = 0;
+		len = 0;
+		
+		if ( l < 0 ) {
+		    fprintf( stderr, "Error processing message %d\n", i );
+		    break;
+		}
+		
+		write_message_to_pilot (c, dbi, dbHandle, buffer, i);
+	    }
+	    fclose (f);
+	    if ( strcmp( GET_CONFIG(c)->receiveAction, "delete" ) == 0 ) {
+		if ( unlink( GET_CONFIG(c)->mboxFile ) ) {
+		    fprintf( stderr, "Error deleting mbox file %s\n", 
+			     GET_CONFIG(c)->mboxFile);
+		}
+	    }
+	}   
     }
 
     free_MailAppInfo( &tai );
Index: conduits/email/email_conduit.h
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/email/email_conduit.h,v
retrieving revision 1.10
diff -u -r1.10 email_conduit.h
--- conduits/email/email_conduit.h	2000/02/26 08:12:20	1.10
+++ conduits/email/email_conduit.h	2000/08/04 04:46:11
@@ -8,6 +8,7 @@
   gchar *fromAddr;
   gchar *sendAction;
   gchar *mhDirectory;
+  gchar *mboxFile;
   gchar *receiveAction;
   guint32 pilotId;
   pid_t child;



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