X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lua%2Fmadmutt.cpkg;h=b47a867f39f879e5110fb1210a65df2b3c183d73;hp=d083405b8bbaacd2400ac636efec04da9303b9cf;hb=90f0c4dfb0480b5ce043c54f001d53ba6efc531b;hpb=b6980caf7b13994c57957872876cdecc21e54a82 diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index d083405..b47a867 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -24,6 +24,7 @@ #include #include +#include #include #include "../mutt.h" @@ -54,10 +55,16 @@ static char *madmutt_init_shorthost(void) /* some systems report the FQDN instead of just the hostname */ uname(&utsname); - p = strchrnul(utsname.nodename, '.'); + p = m_strchrnul(utsname.nodename, '.'); return p_dupstr(utsname.nodename, p - utsname.nodename); } +static char *madmutt_init_os(void) +{ + struct utsname un; + return m_strdup(uname(&un) < 0 ? "Unix" : un.sysname); +} + static char *madmutt_init_hostname(void) { char buffer[STRING]; @@ -66,16 +73,49 @@ static char *madmutt_init_hostname(void) return m_strdup("@"); if (*buffer != '@') { - int len = m_strlen(buffer) + m_strlen(MCore.shorthost) + 2; + int len = m_strlen(buffer) + m_strlen(mod_core.shorthost) + 2; char *res = p_new(char, len); - snprintf(res, len, "%s.%s", NONULL(MCore.shorthost), buffer); + snprintf(res, len, "%s.%s", NONULL(mod_core.shorthost), buffer); return res; } - return m_strdup(NONULL(MCore.shorthost)); + return m_strdup(NONULL(mod_core.shorthost)); +} + +static void madmutt_update_cachedir(const char *dir) +{ + static char *cachedir = NULL; + char path[_POSIX_PATH_MAX]; + char buf[HUGE_STRING]; + struct stat st; + + _mutt_expand_path(path, sizeof(path), dir, 0); + if (lstat(path, &st) || !S_ISDIR(st.st_mode)) { + snprintf(buf, sizeof(buf), _("Directory %s not exist. Create it?"), + dir); + if (mutt_yesorno(buf, M_YES) == M_YES) + mkdir(path, 0750); + } + + if (lstat(path, &st) || !S_ISDIR(st.st_mode)) { + mutt_error(_("Cache directory not created!")); + return; + } + if (st.st_mode & 0027) { + snprintf(buf, sizeof(buf), + _("Directory %s is unsafe, do you want to use it ?"), dir); + if (mutt_yesorno(buf, M_YES) != M_YES) + return; + } + + m_strreplace(&cachedir, path); + mod_core.cachedir = cachedir; } -#if defined(HAVE_QDBM) + +#if defined(HAVE_TOKYOCABINET) +# define HCACHE_BACKEND "tokyocabinet" +#elif defined(HAVE_QDBM) # define HCACHE_BACKEND "qdbm" #elif defined(HAVE_GDBM) # define HCACHE_BACKEND "gdbm" @@ -85,7 +125,13 @@ static char *madmutt_init_hostname(void) # define HCACHE_BACKEND NULL #endif -@package MCore { +static void mod_core_init2(void) +{ + madmutt_update_cachedir("~/.cache/madmutt"); +} +#define mod_core_init() do { (mod_core_init)(); mod_core_init2(); } while (0) + +@package mod_core { /* ** .pp ** \fIThis is a read-only system property and specifies madmutt's @@ -117,12 +163,6 @@ static char *madmutt_init_hostname(void) */ const string_t hcache_backend = HCACHE_BACKEND; - /* - ** .pp - ** Contains the path of the \fTmadmutt_dotlock(1)\fP binary to be used by - ** Madmutt. - */ - path_t dotlock = m_strdup(BINDIR "/mutt_dotlock"); /* ** .pp ** This variable specifies which editor is used by Madmutt. @@ -137,6 +177,16 @@ static char *madmutt_init_hostname(void) */ path_t shell = madmutt_init_shell(); + /* + ** .pp + ** This specifies the operating system name for the \fTUser-Agent:\fP header field. If + ** this is \fIunset\fP, it will be set to the operating system name that \fTuname(2)\fP + ** returns. If \fTuname(2)\fP fails, ``UNIX'' will be used. + ** .pp + ** It may, for example, look as: ``\fTMadmutt 1.5.9i (Linux)\fP''. + */ + string_t operating_system = madmutt_init_os(); + path_t username = madmutt_init_username(); path_t homedir = madmutt_init_homedir(); @@ -148,8 +198,8 @@ static char *madmutt_init_hostname(void) ** Please be sure to really know what you are doing when changing this variable ** to configure a custom domain part of Message-IDs. */ - string_t hostname = madmutt_init_hostname(); string_t shorthost = madmutt_init_shorthost(); + string_t hostname = madmutt_init_hostname(); /* ** .pp @@ -257,6 +307,13 @@ static char *madmutt_init_hostname(void) RETURN(p ? p + 1 : (CurrentFolder ?: "")); } }; + + + const string_t cachedir = NULL; + void setcachedir(const string_t path) { + madmutt_update_cachedir(path); + RETURN(); + }; }; @package MTransport { @@ -271,7 +328,7 @@ static char *madmutt_init_hostname(void) /* ** .pp ** \fBNote:\fP you should not enable this unless you are using Sendmail - ** 8.8.x or greater or in connection with the SMTP support via libESMTP. + ** 8.8.x or greater. ** .pp ** This variable sets the request for when notification is returned. The ** string consists of a comma separated list (no spaces!) of one or more @@ -288,7 +345,7 @@ static char *madmutt_init_hostname(void) /* ** .pp ** \fBNote:\fP you should not enable this unless you are using Sendmail - ** 8.8.x or greater or in connection with the SMTP support via libESMTP. + ** 8.8.x or greater. ** .pp ** This variable controls how much of your message is returned in DSN ** messages. It may be set to either \fIhdrs\fP to return just the @@ -320,12 +377,11 @@ static char *madmutt_init_hostname(void) ** .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. + ** 8.8.x). ** 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. + ** flag when sending 8-bit messages to enable ESMTP negotiation. */ bool use_8bitmime = 0; @@ -336,9 +392,8 @@ static char *madmutt_init_hostname(void) ** 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). + ** \fBNote:\fP This information is passed to sendmail command using the + ** "-f" command line switch. */ bool use_envelope_from = 0;