move more stuff to the lua bindings.
authorPierre Habouzit <madcoder@debian.org>
Tue, 27 Mar 2007 22:02:21 +0000 (00:02 +0200)
committerPierre Habouzit <madcoder@debian.org>
Tue, 27 Mar 2007 22:02:21 +0000 (00:02 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
globals.h
init.h
lib-lua/base.cpkg
lib-lua/lib-lua.h
lib-lua/lua-token.sh
lib-lua/madmutt.cpkg
lib-lua/runtime.c
mutt.h
mutt_libesmtp.c
sendlib.c

index 5e4aa18..81e2952 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -21,7 +21,6 @@ WHERE char AttachmentMarker[STRING];
 
 WHERE char Quotebuf[STRING];
 
 
 WHERE char Quotebuf[STRING];
 
-WHERE address_t *EnvFrom;
 WHERE address_t *From;
 
 WHERE char *AssumedCharset;
 WHERE address_t *From;
 
 WHERE char *AssumedCharset;
@@ -199,7 +198,6 @@ WHERE short MenuContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
-WHERE short SendmailWait;
 WHERE short SleepTime INITVAL (1);
 WHERE short Timeout;
 WHERE short Umask INITVAL (0077);
 WHERE short SleepTime INITVAL (1);
 WHERE short Timeout;
 WHERE short Umask INITVAL (0077);
diff --git a/init.h b/init.h
index e6ae39c..15ca874 100644 (file)
--- a/init.h
+++ b/init.h
@@ -558,25 +558,6 @@ struct option_t MuttVars[] = {
    ** you must take care of space-stuffing <tt/From / lines (with a trailing
    ** space) yourself.
    */
    ** you must take care of space-stuffing <tt/From / lines (with a trailing
    ** space) yourself.
    */
-  {"envelope_from", DT_SYN, R_NONE, UL "use_envelope_from", 0 },
-  {"use_envelope_from", DT_BOOL, R_NONE, OPTENVFROM, "no" },
-  /*
-   ** .pp
-   ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
-   ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
-   ** derive it from the "From:" header.
-   **
-   ** .pp
-   ** \fBNote:\fP This information is passed
-   ** to sendmail command using the "-f" command line switch and
-   ** passed to the SMTP server for libESMTP (if support is compiled in).
-   */
-  {"envelope_from_address", DT_ADDR, R_NONE, UL &EnvFrom, "" },
-  /*
-  ** .pp
-  ** Manually sets the \fIenvelope\fP sender for outgoing messages.
-  ** This value is ignored if ``$$use_envelope_from'' is unset.
-  */
   {"fast_reply", DT_BOOL, R_NONE, OPTFASTREPLY, "no" },
   /*
    ** .pp
   {"fast_reply", DT_BOOL, R_NONE, OPTFASTREPLY, "no" },
   /*
    ** .pp
@@ -2254,7 +2235,6 @@ struct option_t MuttVars[] = {
    ** (S/MIME only)
    */
 #if defined(USE_LIBESMTP)
    ** (S/MIME only)
    */
 #if defined(USE_LIBESMTP)
-  {"smtp_auth_username", DT_SYN, R_NONE, UL "smtp_user", 0},
   {"smtp_user", DT_STR, R_NONE, UL &SmtpAuthUser, "" },
   /*
    ** .pp
   {"smtp_user", DT_STR, R_NONE, UL &SmtpAuthUser, "" },
   /*
    ** .pp
@@ -2264,7 +2244,6 @@ struct option_t MuttVars[] = {
    ** Defines the username to use with SMTP AUTH.  Setting this variable will
    ** cause Madmutt to attempt to use SMTP AUTH when sending.
    */
    ** Defines the username to use with SMTP AUTH.  Setting this variable will
    ** cause Madmutt to attempt to use SMTP AUTH when sending.
    */
-  {"smtp_auth_password", DT_SYN, R_NONE, UL "smtp_pass", 0},
   {"smtp_pass", DT_STR, R_NONE, UL &SmtpAuthPass, "" },
   /*
    ** .pp
   {"smtp_pass", DT_STR, R_NONE, UL &SmtpAuthPass, "" },
   /*
    ** .pp
@@ -2279,7 +2258,6 @@ struct option_t MuttVars[] = {
    ** presents a security risk since the superuser of your machine may read it
    ** regardless of the file's permissions.
    */
    ** presents a security risk since the superuser of your machine may read it
    ** regardless of the file's permissions.
    */
-  {"smtp_envelope", DT_SYN, R_NONE, UL "envelope_from_address", 0 },
   {"smtp_host", DT_STR, R_NONE, UL &SmtpHost, "" },
   /*
    ** .pp
   {"smtp_host", DT_STR, R_NONE, UL &SmtpHost, "" },
   /*
    ** .pp
@@ -2860,23 +2838,6 @@ struct option_t MuttVars[] = {
    ** \fTiso-8859-2\fP, \fTkoi8-r\fP or \fTiso-2022-jp\fP) either
    ** instead of or after \fTiso-8859-1\fP.
    */
    ** \fTiso-8859-2\fP, \fTkoi8-r\fP or \fTiso-2022-jp\fP) either
    ** instead of or after \fTiso-8859-1\fP.
    */
-  {"sendmail_wait", DT_NUM, R_NONE, UL &SendmailWait, "0" },
-  /*
-   ** .pp
-   ** Specifies the number of seconds to wait for the ``$$sendmail'' process
-   ** to finish before giving up and putting delivery in the background.
-   ** .pp
-   ** Madmutt interprets the value of this variable as follows:
-   ** .dl
-   ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
-   ** .dt 0  .dd wait forever for sendmail to finish
-   ** .dt <0 .dd always put sendmail in the background without waiting
-   ** .de
-   ** .pp
-   ** Note that if you specify a value other than 0, the output of the child
-   ** process will be put in a temporary file.  If there is some error, you
-   ** will be informed as to where to find the output.
-   */
 #ifdef USE_NNTP
   {"nntp_save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, "no" },
   /*
 #ifdef USE_NNTP
   {"nntp_save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, "no" },
   /*
@@ -3310,18 +3271,6 @@ struct option_t MuttVars[] = {
    ** This sets the umask that will be used by Madmutt when creating all
    ** kinds of files. If \fIunset\fP, the default value is \fT077\fP.
    */
    ** This sets the umask that will be used by Madmutt when creating all
    ** kinds of files. If \fIunset\fP, the default value is \fT077\fP.
    */
-  {"use_8bitmime", DT_BOOL, R_NONE, OPTUSE8BITMIME, "no" },
-  /*
-   ** .pp
-   ** \fBWarning:\fP do not set this variable unless you are using a version
-   ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
-   ** 8.8.x) or in connection with the SMTP support via libESMTP.
-   ** Otherwise you may not be able to send mail.
-   ** .pp
-   ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
-   ** flag when sending 8-bit messages to enable ESMTP negotiation or tell
-   ** libESMTP to do so.
-   */
   {"use_from", DT_BOOL, R_NONE, OPTUSEFROM, "yes" },
   /*
    ** .pp
   {"use_from", DT_BOOL, R_NONE, OPTUSEFROM, "yes" },
   /*
    ** .pp
index 221e2a0..e7b91e4 100644 (file)
@@ -4,6 +4,12 @@
     .push  = lua_pushboolean($L, $$);
 };
 
     .push  = lua_pushboolean($L, $$);
 };
 
+@type int {
+    .ctype = int;
+    .check = luaL_checkinteger($L, $$);
+    .push  = lua_pushinteger($L, $$);
+};
+
 @type quadopt_t {
     .ctype = unsigned : 2;
     .check = luaM_checkquadopt($L, $$);
 @type quadopt_t {
     .ctype = unsigned : 2;
     .check = luaM_checkquadopt($L, $$);
     .dtor  = rx_delete($$);
 };
 
     .dtor  = rx_delete($$);
 };
 
+@type address_t {
+    .ctype = address_t *;
+    .check = luaL_checkstring($L, $$);
+    .push  = luaM_pushaddr($L, $$);
+    .ctor  = rfc822_parse_adrlist(NULL, $$);
+    .dtor  = address_list_wipe($$);
+};
+
 /* vim:set ft=c: */
 /* vim:set ft=c: */
index 569e77e..3adc746 100644 (file)
@@ -28,6 +28,7 @@
 #include <lualib.h>
 #include <lauxlib.h>
 
 #include <lualib.h>
 #include <lauxlib.h>
 
+#include <lib-mime/mime-types.h>
 #include "lua-token.h"
 
 /* possible arguments to set_quadoption() */
 #include "lua-token.h"
 
 /* possible arguments to set_quadoption() */
@@ -50,8 +51,9 @@ quadopt_t luaM_checkquadopt(lua_State *L, int narg);
 void luaM_pushquadopt(lua_State *Ls, int val);
 
 const char *luaM_checkrx(lua_State *Ls, int narg);
 void luaM_pushquadopt(lua_State *Ls, int val);
 
 const char *luaM_checkrx(lua_State *Ls, int narg);
-char *luaM_pathnew(const char *val);
 rx_t *luaM_rxnew(const char* val);
 rx_t *luaM_rxnew(const char* val);
+char *luaM_pathnew(const char *val);
+void luaM_pushaddr(lua_State *Ls, address_t *addr);
 
 #include "madmutt.li"
 
 
 #include "madmutt.li"
 
index a7d9916..6adcef3 100644 (file)
@@ -122,16 +122,20 @@ exit 0
 ## dsn_notify
 ## dsn_return
 ## editor
 ## dsn_notify
 ## dsn_return
 ## editor
+## envelope_from_address
 ## gecos_mask
 ## hcache_backend
 ## homedir
 ## no
 ## quit
 ## sendmail
 ## gecos_mask
 ## hcache_backend
 ## homedir
 ## no
 ## quit
 ## sendmail
+## sendmail_wait
 ## shell
 ## sysconfdir
 ## tmpdir
 ## shell
 ## sysconfdir
 ## tmpdir
+## use_8bitmime
 ## use_domain
 ## use_domain
+## use_envelope_from
 ## username
 ## version
 ## yes
 ## username
 ## version
 ## yes
index 65ad756..daa101f 100644 (file)
@@ -259,6 +259,56 @@ static char *madmutt_init_homedir(void)
      */
     /* TODO: check it's never, delay, failure, success with ',' */
     string_t dsn_return = NULL;
      */
     /* TODO: check it's never, delay, failure, success with ',' */
     string_t dsn_return = NULL;
+
+    /*
+     ** .pp
+     ** Specifies the number of seconds to wait for the ``$$sendmail'' process
+     ** to finish before giving up and putting delivery in the background.
+     ** .pp
+     ** Madmutt interprets the value of this variable as follows:
+     ** .dl
+     ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
+     ** .dt 0  .dd wait forever for sendmail to finish
+     ** .dt <0 .dd always put sendmail in the background without waiting
+     ** .de
+     ** .pp
+     ** Note that if you specify a value other than 0, the output of the child
+     ** process will be put in a temporary file.  If there is some error, you
+     ** will be informed as to where to find the output.
+     */
+    int sendmail_wait = 0;
+    /*
+     ** .pp
+     ** \fBWarning:\fP do not set this variable unless you are using a version
+     ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
+     ** 8.8.x) or in connection with the SMTP support via libESMTP.
+     ** Otherwise you may not be able to send mail.
+     ** .pp
+     ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
+     ** flag when sending 8-bit messages to enable ESMTP negotiation or tell
+     ** libESMTP to do so.
+     */
+    bool use_8bitmime = 0;
+
+    /*
+     ** .pp
+     ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
+     ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
+     ** derive it from the "From:" header.
+     **
+     ** .pp
+     ** \fBNote:\fP This information is passed
+     ** to sendmail command using the "-f" command line switch and
+     ** passed to the SMTP server for libESMTP (if support is compiled in).
+     */
+    bool use_envelope_from = 0;
+
+    /*
+     ** .pp
+     ** Manually sets the \fIenvelope\fP sender for outgoing messages.
+     ** This value is ignored if ``$$use_envelope_from'' is unset.
+     */
+    address_t envelope_from_address = NULL;
 };
 
 /* vim:set ft=c: */
 };
 
 /* vim:set ft=c: */
index 923222b..b96db43 100644 (file)
@@ -122,6 +122,14 @@ const char *luaM_checkrx(lua_State *Ls, int narg)
     return s;
 }
 
     return s;
 }
 
+rx_t *luaM_rxnew(const char *val)
+{
+    if (m_strisempty(val))
+        val = ".";
+
+    return rx_compile(val, mutt_which_case(val));
+}
+
 char *luaM_pathnew(const char *val)
 {
     char path[PATH_MAX];
 char *luaM_pathnew(const char *val)
 {
     char path[PATH_MAX];
@@ -129,11 +137,10 @@ char *luaM_pathnew(const char *val)
     return m_strdup(path);
 }
 
     return m_strdup(path);
 }
 
-rx_t *luaM_rxnew(const char *val)
-{
-    if (m_strisempty(val))
-        val = ".";
 
 
-    return rx_compile(val, mutt_which_case(val));
+void luaM_pushaddr(lua_State *Ls, address_t *addr)
+{
+    char s[HUGE_STRING] = "";
+    rfc822_addrcat(s, sizeof(s), addr, 0);
+    lua_pushstring(Ls, s);
 }
 }
-
diff --git a/mutt.h b/mutt.h
index 15a9710..82ab163 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -237,7 +237,6 @@ enum {
   OPTDUPTHREADS,
   OPTEDITHDRS,
   OPTENCODEFROM,
   OPTDUPTHREADS,
   OPTEDITHDRS,
   OPTENCODEFROM,
-  OPTENVFROM,
   OPTFASTREPLY,
   OPTFCCATTACH,
   OPTFCCCLEAR,
   OPTFASTREPLY,
   OPTFCCATTACH,
   OPTFCCCLEAR,
@@ -329,7 +328,6 @@ enum {
   OPTTHREADRECEIVED,
   OPTTILDE,
   OPTUNCOLLAPSEJUMP,
   OPTTHREADRECEIVED,
   OPTTILDE,
   OPTUNCOLLAPSEJUMP,
-  OPTUSE8BITMIME,
   OPTUSEFROM,
   OPTUSEGPGAGENT,
 #ifdef HAVE_LIBIDN
   OPTUSEFROM,
   OPTUSEGPGAGENT,
 #ifdef HAVE_LIBIDN
index e8786d9..c77d4d2 100644 (file)
@@ -355,8 +355,8 @@ int mutt_libesmtp_invoke (address_t * from,       /* the sender */
     SMTPFAIL ("smtp_add_message");
 
   /*  Initialize envelope sender */
     SMTPFAIL ("smtp_add_message");
 
   /*  Initialize envelope sender */
-  if (option (OPTENVFROM) && EnvFrom)
-    envfrom = EnvFrom->mailbox;
+  if (MTransport.use_envelope_fromoption && MTransport.envelope_from_address)
+    envfrom = MTransport.envelope_from_address->mailbox;
   if (!smtp_set_reverse_path (message, envfrom))
     SMTPFAIL ("smtp_set_reverse_path");
 
   if (!smtp_set_reverse_path (message, envfrom))
     SMTPFAIL ("smtp_set_reverse_path");
 
@@ -365,7 +365,7 @@ int mutt_libesmtp_invoke (address_t * from,       /* the sender */
   do_dsn_ret (message);
 
   /* set up 8bitmime flag */
   do_dsn_ret (message);
 
   /* set up 8bitmime flag */
-  if (eightbit && option (OPTUSE8BITMIME))
+  if (eightbit && MTransport.use_8bitmime)
     smtp_8bitmime_set_body (message, E8bitmime_8BITMIME);
 
   if ((fp = fopen (msg, "r")) == NULL)
     smtp_8bitmime_set_body (message, E8bitmime_8BITMIME);
 
   if ((fp = fopen (msg, "r")) == NULL)
index 666ccba..838b850 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1689,7 +1689,7 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
   sigaddset (&set, SIGTSTP);
   sigprocmask (SIG_BLOCK, &set, NULL);
 
   sigaddset (&set, SIGTSTP);
   sigprocmask (SIG_BLOCK, &set, NULL);
 
-  if (SendmailWait >= 0) {
+  if (MTransport.sendmail_wait >= 0) {
     char tmp[_POSIX_PATH_MAX];
 
     mutt_mktemp (tmp);
     char tmp[_POSIX_PATH_MAX];
 
     mutt_mktemp (tmp);
@@ -1720,7 +1720,7 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
       }
       unlink (msg);
 
       }
       unlink (msg);
 
-      if (SendmailWait >= 0) {
+      if (MTransport.sendmail_wait >= 0) {
         /* *tempfile will be opened as stdout */
         if (open (*tempfile, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0600) <
             0)
         /* *tempfile will be opened as stdout */
         if (open (*tempfile, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0600) <
             0)
@@ -1744,11 +1744,11 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
       _exit (S_ERR);
     }
 
       _exit (S_ERR);
     }
 
-    /* SendmailWait > 0: interrupt waitpid() after SendmailWait seconds
-     * SendmailWait = 0: wait forever
-     * SendmailWait < 0: don't wait
+    /* sendmail_wait > 0: interrupt waitpid() after sendmail_wait seconds
+     * sendmail_wait = 0: wait forever
+     * sendmail_wait < 0: don't wait
      */
      */
-    if (SendmailWait > 0) {
+    if (MTransport.sendmail_wait > 0) {
       SigAlrm = 0;
       act.sa_handler = alarm_handler;
 #ifdef SA_INTERRUPT
       SigAlrm = 0;
       act.sa_handler = alarm_handler;
 #ifdef SA_INTERRUPT
@@ -1759,20 +1759,20 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
 #endif
       sigemptyset (&act.sa_mask);
       sigaction (SIGALRM, &act, &oldalrm);
 #endif
       sigemptyset (&act.sa_mask);
       sigaction (SIGALRM, &act, &oldalrm);
-      alarm (SendmailWait);
+      alarm (MTransport.sendmail_wait);
     }
     }
-    else if (SendmailWait < 0)
+    else if (MTransport.sendmail_wait < 0)
       _exit (0xff & EX_OK);
 
     if (waitpid (pid, &st, 0) > 0) {
       st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
       _exit (0xff & EX_OK);
 
     if (waitpid (pid, &st, 0) > 0) {
       st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
-      if (SendmailWait && st == (0xff & EX_OK)) {
+      if (MTransport.sendmail_wait && st == (0xff & EX_OK)) {
         unlink (*tempfile);     /* no longer needed */
         p_delete(tempfile);
       }
     } else {
         unlink (*tempfile);     /* no longer needed */
         p_delete(tempfile);
       }
     } else {
-      st = (SendmailWait > 0 && errno == EINTR && SigAlrm) ? S_BKG : S_ERR;
-      if (SendmailWait > 0) {
+      st = (MTransport.sendmail_wait > 0 && errno == EINTR && SigAlrm) ? S_BKG : S_ERR;
+      if (MTransport.sendmail_wait > 0) {
         unlink (*tempfile);
         p_delete(tempfile);
       }
         unlink (*tempfile);
         p_delete(tempfile);
       }
@@ -1876,14 +1876,12 @@ static int mutt_invoke_sendmail (address_t * from,        /* the sender */
 #ifdef USE_NNTP
   if (!option (OPTNEWSSEND)) {
 #endif
 #ifdef USE_NNTP
   if (!option (OPTNEWSSEND)) {
 #endif
-    if (eightbit && option (OPTUSE8BITMIME))
+    if (eightbit && MTransport.use_8bitmime)
       args = add_option(args, &argslen, &argsmax, "-B8BITMIME");
 
       args = add_option(args, &argslen, &argsmax, "-B8BITMIME");
 
-    if (option (OPTENVFROM)) {
-      address_t *f = EnvFrom;
-      if (EnvFrom)
-        f = EnvFrom;
-      else if (from && !from->next)
+    if (MTransport.use_envelope_from) {
+      address_t *f = MTransport.envelope_from_address;
+      if (!f && from && !from->next)
         f = from;
       if (f) {
         args = add_option (args, &argslen, &argsmax, "-f");
         f = from;
       if (f) {
         args = add_option (args, &argslen, &argsmax, "-f");