inserted local account without SMTP server
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sat, 28 Apr 2001 10:21:21 +0000 (10:21 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sat, 28 Apr 2001 10:21:21 +0000 (10:21 +0000)
mail can be send with the mail command or using sendmail command

src/folderview.c
src/inc.c
src/prefs_account.c
src/prefs_account.h
src/send.c

index bccd0f41c5974c02eeec94f10f54af46737a22e2..6c250b526f693a77c085b4e7e4ae18b6ebe8ffed 100644 (file)
@@ -53,6 +53,7 @@
 #include "prefs_account.h"
 #include "account.h"
 #include "folder.h"
+#include "grouplist_dialog.h"
 
 #include "pixmaps/inbox.xpm"
 #include "pixmaps/outbox.xpm"
index 57d2a3fda5334d49ae1c4e657c77eef87d05a42d..cbcfe0552ce92add90a01aa70bd243854695757a 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -110,6 +110,7 @@ static gint inc_spool                       (void);
 static gint get_spool                  (FolderItem     *dest,
                                         const gchar    *mbox);
 
+static void inc_all_spool(void);
 
 static void inc_finished(MainWindow *mainwin)
 {
@@ -155,8 +156,10 @@ void inc_mail(MainWindow *mainwin)
                waitpid(pid, NULL, 0);
 
                if (prefs_common.inc_local) inc_spool();
+               inc_all_spool();
        } else {
                if (prefs_common.inc_local) inc_spool();
+               inc_all_spool();
 
                inc_account_mail(cur_account, mainwin);
        }
@@ -829,11 +832,45 @@ static gint inc_spool(void)
        return msgs;
 }
 
+static void inc_spool_account(PrefsAccount *account)
+{
+       FolderItem *inbox;
+       FolderItem *dropfolder;
+       gint val;
+
+       if (account->inbox) {
+               inbox = folder_find_item_from_path(account->inbox);
+               if (!inbox)
+                       inbox = folder_get_default_inbox();
+       } else
+               inbox = folder_get_default_inbox();
+
+       get_spool(inbox, account->local_mbox);
+}
+
+static void inc_all_spool(void)
+{
+       GList *list = NULL;
+
+       list = account_get_list();
+       if (!list) return;
+
+       for (; list != NULL; list = list->next) {
+               IncSession *session;
+               PrefsAccount *account = list->data;
+
+               if ((account->protocol == A_LOCAL)
+                   || (account->protocol == A_LOCAL_CMD)) {
+                       inc_spool_account(account);
+               }
+       }
+}
+
 static gint get_spool(FolderItem *dest, const gchar *mbox)
 {
        gint msgs, size;
        gint lockfd;
-       gchar *tmp_mbox = "/tmp/tmpmbox";
+       gchar tmp_mbox[256] = "/tmp/tmpmboxXXXXXX";
        GHashTable *folder_table = NULL;
 
        g_return_val_if_fail(dest != NULL, -1);
@@ -848,6 +885,9 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
        if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
                return -1;
 
+       if (mktemp(tmp_mbox) == NULL)
+               return -1;
+
        if (copy_mbox(mbox, tmp_mbox) < 0)
                return -1;
 
@@ -872,4 +912,4 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
        }
 
        return msgs;
-}
\ No newline at end of file
+}
index 07e32e892b6ea584c763e4a2ecb478d28bcf85b4..73f3f5a14bb64ff34506195357d9a0a90f5eca5f 100644 (file)
@@ -66,9 +66,13 @@ static struct Basic {
        GtkWidget *recvserv_label;
        GtkWidget *smtpserv_label;
        GtkWidget *nntpserv_label;
+       GtkWidget *localmbox_label;
+       GtkWidget *mailcmd_label;
        GtkWidget *recvserv_entry;
        GtkWidget *smtpserv_entry;
        GtkWidget *nntpserv_entry;
+       GtkWidget *localmbox_entry;
+       GtkWidget *mailcmd_entry;
        GtkWidget *uid_label;
        GtkWidget *pass_label;
        GtkWidget *uid_entry;
@@ -162,6 +166,12 @@ static PrefParam param[] = {
        {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
         &basic.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
 
+       {"local_mbox", NULL, &tmp_ac_prefs.local_mbox, P_STRING,
+        &basic.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
+
+       {"mail_command", "mail", &tmp_ac_prefs.mail_command, P_STRING,
+        &basic.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
+
        {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
         NULL, NULL, NULL},
 
@@ -531,9 +541,13 @@ static void prefs_account_basic_create(void)
        GtkWidget *recvserv_label;
        GtkWidget *smtpserv_label;
        GtkWidget *nntpserv_label;
+       GtkWidget *localmbox_label;
+       GtkWidget *mailcmd_label;
        GtkWidget *recvserv_entry;
        GtkWidget *smtpserv_entry;
        GtkWidget *nntpserv_entry;
+       GtkWidget *localmbox_entry;
+       GtkWidget *mailcmd_entry;
        GtkWidget *uid_label;
        GtkWidget *pass_label;
        GtkWidget *uid_entry;
@@ -635,7 +649,9 @@ static void prefs_account_basic_create(void)
        SET_ACTIVATE (menuitem);
        MENUITEM_ADD (optmenu_menu, menuitem, _("News (NNTP)"), A_NNTP);
        SET_ACTIVATE (menuitem);
-       MENUITEM_ADD (optmenu_menu, menuitem, _("None (local)"), A_LOCAL);
+       MENUITEM_ADD (optmenu_menu, menuitem, _("Local (with SMTP server)"), A_LOCAL);
+       SET_ACTIVATE (menuitem);
+       MENUITEM_ADD (optmenu_menu, menuitem, _("Local (without SMTP server)"), A_LOCAL_CMD);
        SET_ACTIVATE (menuitem);
 
        gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
@@ -649,7 +665,7 @@ static void prefs_account_basic_create(void)
        gtk_widget_set_usize (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
        gtk_box_pack_start (GTK_BOX (hbox), inbox_entry, TRUE, TRUE, 0);
 
-       serv_table = gtk_table_new (5, 4, FALSE);
+       serv_table = gtk_table_new (7, 4, FALSE);
        gtk_widget_show (serv_table);
        gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
        gtk_table_set_row_spacings (GTK_TABLE (serv_table), VSPACING_NARROW);
@@ -674,17 +690,29 @@ static void prefs_account_basic_create(void)
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
 
+       localmbox_entry = gtk_entry_new ();
+       gtk_widget_show (localmbox_entry);
+       gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 3, 4,
+                         GTK_EXPAND | GTK_SHRINK | GTK_FILL,
+                         GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
+
+       mailcmd_entry = gtk_entry_new ();
+       gtk_widget_show (mailcmd_entry);
+       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 4, 5,
+                         GTK_EXPAND | GTK_SHRINK | GTK_FILL,
+                         GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
+
        uid_entry = gtk_entry_new ();
        gtk_widget_show (uid_entry);
        gtk_widget_set_usize (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
-       gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 4, 5,
+       gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 5, 6,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
 
        pass_entry = gtk_entry_new ();
        gtk_widget_show (pass_entry);
        gtk_widget_set_usize (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
-       gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 4, 5,
+       gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 5, 6,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                          GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
        gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
@@ -708,15 +736,29 @@ static void prefs_account_basic_create(void)
        gtk_misc_set_alignment (GTK_MISC (smtpserv_label), 1, 0.5);
        gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0);
 
+       localmbox_label = gtk_label_new (_("mailbox of the user"));
+       gtk_widget_show (localmbox_label);
+       gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 3, 4,
+                         GTK_FILL, 0, 0, 0);
+       gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
+       gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0);
+
+       mailcmd_label = gtk_label_new (_("command to send mails"));
+       gtk_widget_show (mailcmd_label);
+       gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 4, 5,
+                         GTK_FILL, 0, 0, 0);
+       gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
+       gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0);
+
        uid_label = gtk_label_new (_("User ID"));
        gtk_widget_show (uid_label);
-       gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 4, 5,
+       gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 5, 6,
                          GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
 
        pass_label = gtk_label_new (_("Password"));
        gtk_widget_show (pass_label);
-       gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 4, 5,
+       gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 5, 6,
                          0, 0, 0, 0);
 
        basic.acname_entry   = acname_entry;
@@ -737,6 +779,10 @@ static void prefs_account_basic_create(void)
        basic.smtpserv_entry   = smtpserv_entry;
        basic.nntpserv_label   = nntpserv_label;
        basic.nntpserv_entry   = nntpserv_entry;
+       basic.localmbox_label   = localmbox_label;
+       basic.localmbox_entry   = localmbox_entry;
+       basic.mailcmd_label   = mailcmd_label;
+       basic.mailcmd_entry   = mailcmd_entry;
        basic.uid_label        = uid_label;
        basic.pass_label       = pass_label;
        basic.uid_entry        = uid_entry;
@@ -1140,6 +1186,12 @@ static gint prefs_account_apply(void)
                return -1;
        }
 
+       if (protocol == A_LOCAL_CMD &&
+           *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
+               alertpanel_error(_("local mailbox filename is not entered."));
+               return -1;
+       }
+
        prefs_set_data_from_dialog(param);
        return 0;
 }
@@ -1233,6 +1285,9 @@ static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
        case A_LOCAL:
                gtk_option_menu_set_history(optmenu, 4);
                break;
+       case A_LOCAL_CMD:
+               gtk_option_menu_set_history(optmenu, 5);
+               break;
        default:
        }
 
@@ -1258,6 +1313,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_hide(basic.recvserv_entry);
                gtk_widget_hide(basic.smtpserv_label);
                gtk_widget_hide(basic.smtpserv_entry);
+               gtk_widget_hide(basic.localmbox_label);
+               gtk_widget_hide(basic.localmbox_entry);
+               gtk_widget_hide(basic.mailcmd_label);
+               gtk_widget_hide(basic.mailcmd_entry);
                gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table), 3, 0);
                gtk_widget_set_sensitive(basic.uid_label,  TRUE);
                gtk_widget_set_sensitive(basic.pass_label, TRUE);
@@ -1272,10 +1331,37 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_hide(basic.nntpserv_entry);
                gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
                gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
-               gtk_widget_show(basic.recvserv_label);
-               gtk_widget_show(basic.recvserv_entry);
+               gtk_widget_hide(basic.recvserv_label);
+               gtk_widget_hide(basic.recvserv_entry);
                gtk_widget_show(basic.smtpserv_label);
                gtk_widget_show(basic.smtpserv_entry);
+               gtk_widget_show(basic.localmbox_label);
+               gtk_widget_show(basic.localmbox_entry);
+               gtk_widget_hide(basic.mailcmd_label);
+               gtk_widget_hide(basic.mailcmd_entry);
+               gtk_table_set_row_spacing
+                       (GTK_TABLE (basic.serv_table), 3, VSPACING_NARROW);
+               gtk_widget_set_sensitive(basic.uid_label,  FALSE);
+               gtk_widget_set_sensitive(basic.pass_label, FALSE);
+               gtk_widget_set_sensitive(basic.uid_entry,  FALSE);
+               gtk_widget_set_sensitive(basic.pass_entry, FALSE);
+               gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
+               break;
+       case A_LOCAL_CMD:
+               gtk_widget_set_sensitive(basic.inbox_label, TRUE);
+               gtk_widget_set_sensitive(basic.inbox_entry, TRUE);
+               gtk_widget_hide(basic.nntpserv_label);
+               gtk_widget_hide(basic.nntpserv_entry);
+               gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
+               gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
+               gtk_widget_hide(basic.recvserv_label);
+               gtk_widget_hide(basic.recvserv_entry);
+               gtk_widget_hide(basic.smtpserv_label);
+               gtk_widget_hide(basic.smtpserv_entry);
+               gtk_widget_show(basic.localmbox_label);
+               gtk_widget_show(basic.localmbox_entry);
+               gtk_widget_show(basic.mailcmd_label);
+               gtk_widget_show(basic.mailcmd_entry);
                gtk_table_set_row_spacing
                        (GTK_TABLE (basic.serv_table), 3, VSPACING_NARROW);
                gtk_widget_set_sensitive(basic.uid_label,  FALSE);
@@ -1295,6 +1381,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_show(basic.recvserv_entry);
                gtk_widget_show(basic.smtpserv_label);
                gtk_widget_show(basic.smtpserv_entry);
+               gtk_widget_hide(basic.localmbox_label);
+               gtk_widget_hide(basic.localmbox_entry);
+               gtk_widget_hide(basic.mailcmd_label);
+               gtk_widget_hide(basic.mailcmd_entry);
                gtk_table_set_row_spacing
                        (GTK_TABLE (basic.serv_table), 3, VSPACING_NARROW);
                gtk_widget_set_sensitive(basic.uid_label,  TRUE);
@@ -1314,6 +1404,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_show(basic.recvserv_entry);
                gtk_widget_show(basic.smtpserv_label);
                gtk_widget_show(basic.smtpserv_entry);
+               gtk_widget_hide(basic.localmbox_label);
+               gtk_widget_hide(basic.localmbox_entry);
+               gtk_widget_hide(basic.mailcmd_label);
+               gtk_widget_hide(basic.mailcmd_entry);
                gtk_table_set_row_spacing
                        (GTK_TABLE (basic.serv_table), 3, VSPACING_NARROW);
                gtk_widget_set_sensitive(basic.uid_label,  TRUE);
index a58a883b932e12206eeab43253254497f5470293..e08ff1dbc890daaa5d8d4bff5575c74b011cdb1d 100644 (file)
@@ -36,7 +36,8 @@ typedef enum {
        A_RPOP,
        A_IMAP4,
        A_NNTP,
-       A_LOCAL
+       A_LOCAL,
+       A_LOCAL_CMD
 } RecvProtocol;
 
 #if USE_GPGME
@@ -66,6 +67,9 @@ struct _PrefsAccount
        gchar *userid;
        gchar *passwd;
 
+       gchar * local_mbox;
+       gchar * mail_command;
+
        /* Temporarily preserved password */
        gchar *tmp_pass;
 
index 37c185d8cd84daedebc25de55739d22d00b03e68..09aa4593bef65469faa957ddf75023b33e9744e8 100644 (file)
@@ -47,6 +47,8 @@ static gint send_message_smtp (GSList *to_list, const gchar *from,
                                 FILE *fp);
 static SockInfo *send_smtp_open        (const gchar *server, gushort port,
                                 const gchar *domain, gboolean use_smtp_auth);
+static gint send_message_with_command(GSList *to_list, gchar * mailcmd,
+                                     FILE * fp);
 
 #define SEND_EXIT_IF_ERROR(f, s) \
 { \
@@ -86,13 +88,25 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return -1;
        }
 
-       port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
-       domain = ac_prefs->set_domain ? ac_prefs->domain : NULL;
-
-       val = send_message_smtp(to_list, ac_prefs->address,
-                               ac_prefs->smtp_server, port, domain,
-                               ac_prefs->userid, ac_prefs->passwd,
-                               ac_prefs->use_smtp_auth, fp);
+       if (ac_prefs->protocol == A_LOCAL_CMD)
+               {
+                       val = send_message_with_command(to_list,
+                                                       ac_prefs->mail_command,
+                                                       fp);
+               }
+       else
+               {
+                       port = ac_prefs->set_smtpport
+                               ? ac_prefs->smtpport : SMTP_PORT;
+                       domain = ac_prefs->set_domain
+                               ? ac_prefs->domain : NULL;
+                       
+                       val = send_message_smtp(to_list, ac_prefs->address,
+                                               ac_prefs->smtp_server, port,
+                                               domain, ac_prefs->userid,
+                                               ac_prefs->passwd,
+                                               ac_prefs->use_smtp_auth, fp);
+               }
 
        fclose(fp);
        return val;
@@ -105,6 +119,51 @@ enum
        Q_RECIPIENTS = 2
 };
 
+static gint send_message_with_command(GSList *to_list, gchar * mailcmd,
+                                     FILE * fp)
+{
+       FILE * p;
+       int len;
+       gchar * cmdline;
+       GSList *cur;
+       gchar buf[BUFFSIZE];
+
+       len = strlen(mailcmd);
+       for (cur = to_list; cur != NULL; cur = cur->next)
+               len += strlen((gchar *)cur->data) + 1;
+
+       cmdline = g_new(gchar, len + 1);
+       strcpy(cmdline, mailcmd);
+
+       for (cur = to_list; cur != NULL; cur = cur->next)
+               {
+                       cmdline = strncat(cmdline, " ", len);
+                       cmdline = strncat(cmdline, (gchar *)cur->data, len);
+               }
+
+       log_message(_("Using command to send mail: %s ...\n"), cmdline);
+
+       p = popen(cmdline, "w");
+       if (p != NULL)
+               {
+                       while (fgets(buf, sizeof(buf), fp) != NULL) {
+                               strretchomp(buf);
+                               
+                               /* escape when a dot appears on the top */
+                               if (buf[0] == '.')
+                                       fputs(".", p);
+                               
+                               fputs(buf, p);
+                               fputs("\n", p);
+                       }
+               }
+       pclose(p);
+
+       log_message(_("Mail sent successfully ...\n"));
+
+       return 0;
+}
+
 gint send_message_queue(const gchar *file)
 {
        static HeaderEntry qentry[] = {{"S:",   NULL, FALSE},