From 9a4192468557a6d53cafff937cffd7f06157a47f Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 28 Mar 2007 00:02:21 +0200 Subject: [PATCH] move more stuff to the lua bindings. Signed-off-by: Pierre Habouzit --- globals.h | 2 -- init.h | 51 -------------------------------------------- lib-lua/base.cpkg | 14 ++++++++++++ lib-lua/lib-lua.h | 4 +++- lib-lua/lua-token.sh | 4 ++++ lib-lua/madmutt.cpkg | 50 +++++++++++++++++++++++++++++++++++++++++++ lib-lua/runtime.c | 19 +++++++++++------ mutt.h | 2 -- mutt_libesmtp.c | 6 +++--- sendlib.c | 32 +++++++++++++-------------- 10 files changed, 102 insertions(+), 82 deletions(-) diff --git a/globals.h b/globals.h index 5e4aa18..81e2952 100644 --- a/globals.h +++ b/globals.h @@ -21,7 +21,6 @@ WHERE char AttachmentMarker[STRING]; WHERE char Quotebuf[STRING]; -WHERE address_t *EnvFrom; 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 SendmailWait; 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 --- a/init.h +++ b/init.h @@ -558,25 +558,6 @@ struct option_t MuttVars[] = { ** you must take care of space-stuffing 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" }, /* @@ -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. */ - {"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 diff --git a/lib-lua/base.cpkg b/lib-lua/base.cpkg index 221e2a0..e7b91e4 100644 --- a/lib-lua/base.cpkg +++ b/lib-lua/base.cpkg @@ -4,6 +4,12 @@ .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, $$); @@ -30,4 +36,12 @@ .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: */ diff --git a/lib-lua/lib-lua.h b/lib-lua/lib-lua.h index 569e77e..3adc746 100644 --- a/lib-lua/lib-lua.h +++ b/lib-lua/lib-lua.h @@ -28,6 +28,7 @@ #include #include +#include #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); -char *luaM_pathnew(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" diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index a7d9916..6adcef3 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -122,16 +122,20 @@ exit 0 ## dsn_notify ## dsn_return ## editor +## envelope_from_address ## gecos_mask ## hcache_backend ## homedir ## no ## quit ## sendmail +## sendmail_wait ## shell ## sysconfdir ## tmpdir +## use_8bitmime ## use_domain +## use_envelope_from ## username ## version ## yes diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index 65ad756..daa101f 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -259,6 +259,56 @@ static char *madmutt_init_homedir(void) */ /* 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: */ diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 923222b..b96db43 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -122,6 +122,14 @@ const char *luaM_checkrx(lua_State *Ls, int narg) 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]; @@ -129,11 +137,10 @@ char *luaM_pathnew(const char *val) 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 --- a/mutt.h +++ b/mutt.h @@ -237,7 +237,6 @@ enum { OPTDUPTHREADS, OPTEDITHDRS, OPTENCODEFROM, - OPTENVFROM, OPTFASTREPLY, OPTFCCATTACH, OPTFCCCLEAR, @@ -329,7 +328,6 @@ enum { OPTTHREADRECEIVED, OPTTILDE, OPTUNCOLLAPSEJUMP, - OPTUSE8BITMIME, OPTUSEFROM, OPTUSEGPGAGENT, #ifdef HAVE_LIBIDN diff --git a/mutt_libesmtp.c b/mutt_libesmtp.c index e8786d9..c77d4d2 100644 --- a/mutt_libesmtp.c +++ b/mutt_libesmtp.c @@ -355,8 +355,8 @@ int mutt_libesmtp_invoke (address_t * from, /* the 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"); @@ -365,7 +365,7 @@ int mutt_libesmtp_invoke (address_t * from, /* the sender */ 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) diff --git a/sendlib.c b/sendlib.c index 666ccba..838b850 100644 --- 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); - if (SendmailWait >= 0) { + if (MTransport.sendmail_wait >= 0) { 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); - 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) @@ -1744,11 +1744,11 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile) _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 @@ -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); - 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; - if (SendmailWait && st == (0xff & EX_OK)) { + if (MTransport.sendmail_wait && st == (0xff & EX_OK)) { 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); } @@ -1876,14 +1876,12 @@ static int mutt_invoke_sendmail (address_t * from, /* the sender */ #ifdef USE_NNTP if (!option (OPTNEWSSEND)) { #endif - if (eightbit && option (OPTUSE8BITMIME)) + if (eightbit && MTransport.use_8bitmime) 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"); -- 2.20.1