2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2007 Pierre Habouzit
20 #include <lib-lib/lib-lib.h>
22 #include <sys/utsname.h>
23 #include <sys/types.h>
26 #include <lib-lua/lib-lua.h>
27 #include <lib-ui/lib-ui.h>
28 #include <lib-sys/unix.h>
33 static char *madmutt_init_shell(void)
35 struct passwd *pw = getpwuid(getuid());
36 return m_strdup(pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh"));
39 static char *madmutt_init_username(void)
41 struct passwd *pw = getpwuid(getuid());
42 return m_strdup(pw ? pw->pw_name : (getenv("USER") ?: "john_doe"));
45 static char *madmutt_init_homedir(void)
47 struct passwd *pw = getpwuid(getuid());
48 return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/"));
51 static char *madmutt_init_shorthost(void)
53 struct utsname utsname;
56 /* some systems report the FQDN instead of just the hostname */
58 p = m_strchrnul(utsname.nodename, '.');
59 return p_dupstr(utsname.nodename, p - utsname.nodename);
62 static char *madmutt_init_os(void)
65 return m_strdup(uname(&un) < 0 ? "Unix" : un.sysname);
68 static char *madmutt_init_hostname(void)
72 if (getdnsdomainname(buffer, sizeof(buffer)) < 0)
76 int len = m_strlen(buffer) + m_strlen(mod_core.shorthost) + 2;
77 char *res = p_new(char, len);
78 snprintf(res, len, "%s.%s", NONULL(mod_core.shorthost), buffer);
82 return m_strdup(NONULL(mod_core.shorthost));
85 static void madmutt_update_cachedir(const char *dir)
87 static char *cachedir = NULL;
88 char path[_POSIX_PATH_MAX];
89 char buf[HUGE_STRING];
92 _mutt_expand_path(path, sizeof(path), dir, 0);
93 if (lstat(path, &st) || !S_ISDIR(st.st_mode)) {
94 snprintf(buf, sizeof(buf), _("Directory %s not exist. Create it?"),
96 if (mutt_yesorno(buf, M_YES) == M_YES)
100 if (lstat(path, &st) || !S_ISDIR(st.st_mode)) {
101 mutt_error(_("Cache directory not created!"));
104 if (st.st_mode & 0027) {
105 snprintf(buf, sizeof(buf),
106 _("Directory %s is unsafe, do you want to use it ?"), dir);
107 if (mutt_yesorno(buf, M_YES) != M_YES)
111 m_strreplace(&cachedir, path);
112 mod_core.cachedir = cachedir;
116 #if defined(HAVE_TOKYOCABINET)
117 # define HCACHE_BACKEND "tokyocabinet"
118 #elif defined(HAVE_QDBM)
119 # define HCACHE_BACKEND "qdbm"
120 #elif defined(HAVE_GDBM)
121 # define HCACHE_BACKEND "gdbm"
122 #elif defined(HAVE_DB4)
123 # define HCACHE_BACKEND "db4"
125 # define HCACHE_BACKEND NULL
128 static void mod_core_init2(void)
130 madmutt_update_cachedir("~/.cache/madmutt");
132 #define mod_core_init() do { (mod_core_init)(); mod_core_init2(); } while (0)
137 ** \fIThis is a read-only system property and specifies madmutt's
138 ** version string.\fP
140 const string_t version = VERSION;
143 ** \fIThis is a read-only system property and specifies madmutt's
144 ** subversion revision string.\fP
146 const string_t sysconfdir = SYSCONFDIR;
149 ** \fIThis is a read-only system property and specifies the
150 ** directory containing the madmutt binary.\fP
152 const string_t bindir = BINDIR;
155 ** \fIThis is a read-only system property and specifies the
156 ** directory containing the madmutt documentation.\fP
158 const string_t docdir = PKGDOCDIR;
161 ** \fIThis is a read-only system property and specifies the
162 ** header chaching's database backend.\fP
164 const string_t hcache_backend = HCACHE_BACKEND;
168 ** This variable specifies which editor is used by Madmutt.
169 ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment
170 ** variable, or to the string "\fTvi\fP" if neither of those are set.
172 path_t editor = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
175 ** Command to use when spawning a subshell. By default, the user's login
176 ** shell from \fT/etc/passwd\fP is used.
178 path_t shell = madmutt_init_shell();
182 ** This specifies the operating system name for the \fTUser-Agent:\fP header field. If
183 ** this is \fIunset\fP, it will be set to the operating system name that \fTuname(2)\fP
184 ** returns. If \fTuname(2)\fP fails, ``UNIX'' will be used.
186 ** It may, for example, look as: ``\fTMadmutt 1.5.9i (Linux)\fP''.
188 string_t operating_system = madmutt_init_os();
190 path_t username = madmutt_init_username();
191 path_t homedir = madmutt_init_homedir();
195 ** Specifies the hostname to use after the ``\fT@\fP'' in local e-mail
196 ** addresses and during generation of \fTMessage-ID:\fP headers.
198 ** Please be sure to really know what you are doing when changing this variable
199 ** to configure a custom domain part of Message-IDs.
201 string_t shorthost = madmutt_init_shorthost();
202 string_t hostname = madmutt_init_hostname();
206 ** This variable allows you to specify where Madmutt will place its
207 ** temporary files needed for displaying and composing messages. If
208 ** this variable is not set, the environment variable \fT$$$TMPDIR\fP is
209 ** used. If \fT$$$TMPDIR\fP is not set then "\fT/tmp\fP" is used.
211 path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
214 ** A regular expression used by Madmutt to parse the GECOS field of a password
215 ** entry when expanding the alias. By default the regular expression is set
216 ** to ``\fT^[^,]*\fP'' which will return the string up to the first ``\fT,\fP'' encountered.
217 ** If the GECOS field contains a string like "lastname, firstname" then you
218 ** should do: \fTset gecos_mask=".*"\fP.
220 ** This can be useful if you see the following behavior: you address a e-mail
221 ** to user ID stevef whose full name is Steve Franklin. If Madmutt expands
222 ** stevef to ``Franklin'' stevef@foo.bar then you should set the gecos_mask to
223 ** a regular expression that will match the whole name so Madmutt will expand
224 ** ``Franklin'' to ``Franklin, Steve''.
226 rx_t gecos_mask = luaM_rxnew("^[^,]*");
230 ** This variable controls whether ``quit'' and ``exit'' actually quit
231 ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
232 ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
233 ** prompted for confirmation when you try to quit.
235 quadopt_t quit = M_YES;
238 ** When this variable is \fIset\fP, Madmutt will beep when an error occurs.
243 ** When this variable is \fIset\fP, Madmutt will beep whenever it prints a message
244 ** notifying you of new mail. This is independent of the setting of the
245 ** ``$$beep'' variable.
251 ** When \fIset\fP, Madmutt will qualify all local addresses (ones without the
252 ** @host portion) with the value of ``$$hostname''. If \fIunset\fP, no
253 ** addresses will be qualified.
259 ** \fIThis is a read-only system property and, at runtime,
260 ** specifies the current working directory of the madmutt
263 const string_t pwd(void) {
264 char path[_POSIX_PATH_MAX];
265 getcwd(path, sizeof(path));
271 ** \fIThis is a read-only system property and, at runtime,
272 ** specifies the full path or URI of the folder currently
275 const string_t folder_path(void) {
276 RETURN(CurrentFolder);
281 ** \fIThis is a read-only system property and, at runtime,
282 ** specifies the actual name of the folder as far as it could
285 ** For detection, $$$folder is first taken into account
286 ** and simply stripped to form the result when a match is found. For
287 ** example, with $$$folder being \fTimap://host\fP and the folder is
288 ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
291 ** Second, if the initial portion of a name is not $$$folder,
292 ** the result will be everything after the last ``/''.
294 ** Third and last, the result will be just the name if neither
295 ** $$$folder nor a ``/'' were found in the name.
297 const string_t folder_name(void) {
300 if (!m_strisempty(Maildir)
301 && m_strstart(CurrentFolder, Maildir, &p) && *p) {
306 p = strchr(CurrentFolder ?: "", '/');
307 RETURN(p ? p + 1 : (CurrentFolder ?: ""));
312 const string_t cachedir = NULL;
313 void setcachedir(const string_t path) {
314 madmutt_update_cachedir(path);
319 @package MTransport {
322 ** Specifies the program and arguments used to deliver mail sent by Madmutt.
323 ** Madmutt expects that the specified program interprets additional
324 ** arguments as recipient addresses.
326 path_t sendmail = m_strdup(SENDMAIL " -eom -oi");
330 ** \fBNote:\fP you should not enable this unless you are using Sendmail
333 ** This variable sets the request for when notification is returned. The
334 ** string consists of a comma separated list (no spaces!) of one or more
335 ** of the following: \fInever\fP, to never request notification,
336 ** \fIfailure\fP, to request notification on transmission failure,
337 ** \fIdelay\fP, to be notified of message delays, \fIsuccess\fP, to be
338 ** notified of successful transmission.
340 ** Example: \fTset dsn_notify="failure,delay"\fP
342 /* TODO: check it's NULL, hdrs or full */
343 string_t dsn_notify = NULL;
347 ** \fBNote:\fP you should not enable this unless you are using Sendmail
350 ** This variable controls how much of your message is returned in DSN
351 ** messages. It may be set to either \fIhdrs\fP to return just the
352 ** message header, or \fIfull\fP to return the full message.
354 ** Example: \fTset dsn_return=hdrs\fP
356 /* TODO: check it's never, delay, failure, success with ',' */
357 string_t dsn_return = NULL;
361 ** Specifies the number of seconds to wait for the ``$$sendmail'' process
362 ** to finish before giving up and putting delivery in the background.
364 ** Madmutt interprets the value of this variable as follows:
366 ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
367 ** .dt 0 .dd wait forever for sendmail to finish
368 ** .dt <0 .dd always put sendmail in the background without waiting
371 ** Note that if you specify a value other than 0, the output of the child
372 ** process will be put in a temporary file. If there is some error, you
373 ** will be informed as to where to find the output.
375 int sendmail_wait = 0;
378 ** \fBWarning:\fP do not set this variable unless you are using a version
379 ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
381 ** Otherwise you may not be able to send mail.
383 ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
384 ** flag when sending 8-bit messages to enable ESMTP negotiation.
386 bool use_8bitmime = 0;
390 ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
391 ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
392 ** derive it from the "From:" header.
395 ** \fBNote:\fP This information is passed to sendmail command using the
396 ** "-f" command line switch.
398 bool use_envelope_from = 0;
402 ** Manually sets the \fIenvelope\fP sender for outgoing messages.
403 ** This value is ignored if ``$$use_envelope_from'' is unset.
405 address_t envelope_from_address = NULL;