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/curses.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_QDBM)
117 # define HCACHE_BACKEND "qdbm"
118 #elif defined(HAVE_GDBM)
119 # define HCACHE_BACKEND "gdbm"
120 #elif defined(HAVE_DB4)
121 # define HCACHE_BACKEND "db4"
123 # define HCACHE_BACKEND NULL
126 static void mod_core_init2(void)
128 madmutt_update_cachedir("~/.cache/madmutt");
130 #define mod_core_init() do { (mod_core_init)(); mod_core_init2(); } while (0)
135 ** \fIThis is a read-only system property and specifies madmutt's
136 ** version string.\fP
138 const string_t version = VERSION;
141 ** \fIThis is a read-only system property and specifies madmutt's
142 ** subversion revision string.\fP
144 const string_t sysconfdir = SYSCONFDIR;
147 ** \fIThis is a read-only system property and specifies the
148 ** directory containing the madmutt binary.\fP
150 const string_t bindir = BINDIR;
153 ** \fIThis is a read-only system property and specifies the
154 ** directory containing the madmutt documentation.\fP
156 const string_t docdir = PKGDOCDIR;
159 ** \fIThis is a read-only system property and specifies the
160 ** header chaching's database backend.\fP
162 const string_t hcache_backend = HCACHE_BACKEND;
166 ** Contains the path of the \fTmadmutt_dotlock(1)\fP binary to be used by
169 path_t dotlock = m_strdup(BINDIR "/mutt_dotlock");
172 ** This variable specifies which editor is used by Madmutt.
173 ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment
174 ** variable, or to the string "\fTvi\fP" if neither of those are set.
176 path_t editor = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
179 ** Command to use when spawning a subshell. By default, the user's login
180 ** shell from \fT/etc/passwd\fP is used.
182 path_t shell = madmutt_init_shell();
186 ** This specifies the operating system name for the \fTUser-Agent:\fP header field. If
187 ** this is \fIunset\fP, it will be set to the operating system name that \fTuname(2)\fP
188 ** returns. If \fTuname(2)\fP fails, ``UNIX'' will be used.
190 ** It may, for example, look as: ``\fTMadmutt 1.5.9i (Linux)\fP''.
192 string_t operating_system = madmutt_init_os();
194 path_t username = madmutt_init_username();
195 path_t homedir = madmutt_init_homedir();
199 ** Specifies the hostname to use after the ``\fT@\fP'' in local e-mail
200 ** addresses and during generation of \fTMessage-ID:\fP headers.
202 ** Please be sure to really know what you are doing when changing this variable
203 ** to configure a custom domain part of Message-IDs.
205 string_t shorthost = madmutt_init_shorthost();
206 string_t hostname = madmutt_init_hostname();
210 ** This variable allows you to specify where Madmutt will place its
211 ** temporary files needed for displaying and composing messages. If
212 ** this variable is not set, the environment variable \fT$$$TMPDIR\fP is
213 ** used. If \fT$$$TMPDIR\fP is not set then "\fT/tmp\fP" is used.
215 path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
218 ** A regular expression used by Madmutt to parse the GECOS field of a password
219 ** entry when expanding the alias. By default the regular expression is set
220 ** to ``\fT^[^,]*\fP'' which will return the string up to the first ``\fT,\fP'' encountered.
221 ** If the GECOS field contains a string like "lastname, firstname" then you
222 ** should do: \fTset gecos_mask=".*"\fP.
224 ** This can be useful if you see the following behavior: you address a e-mail
225 ** to user ID stevef whose full name is Steve Franklin. If Madmutt expands
226 ** stevef to ``Franklin'' stevef@foo.bar then you should set the gecos_mask to
227 ** a regular expression that will match the whole name so Madmutt will expand
228 ** ``Franklin'' to ``Franklin, Steve''.
230 rx_t gecos_mask = luaM_rxnew("^[^,]*");
234 ** This variable controls whether ``quit'' and ``exit'' actually quit
235 ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
236 ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
237 ** prompted for confirmation when you try to quit.
239 quadopt_t quit = M_YES;
242 ** When this variable is \fIset\fP, Madmutt will beep when an error occurs.
247 ** When this variable is \fIset\fP, Madmutt will beep whenever it prints a message
248 ** notifying you of new mail. This is independent of the setting of the
249 ** ``$$beep'' variable.
255 ** When \fIset\fP, Madmutt will qualify all local addresses (ones without the
256 ** @host portion) with the value of ``$$hostname''. If \fIunset\fP, no
257 ** addresses will be qualified.
263 ** \fIThis is a read-only system property and, at runtime,
264 ** specifies the current working directory of the madmutt
267 const string_t pwd(void) {
268 char path[_POSIX_PATH_MAX];
269 getcwd(path, sizeof(path));
275 ** \fIThis is a read-only system property and, at runtime,
276 ** specifies the full path or URI of the folder currently
279 const string_t folder_path(void) {
280 RETURN(CurrentFolder);
285 ** \fIThis is a read-only system property and, at runtime,
286 ** specifies the actual name of the folder as far as it could
289 ** For detection, $$$folder is first taken into account
290 ** and simply stripped to form the result when a match is found. For
291 ** example, with $$$folder being \fTimap://host\fP and the folder is
292 ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
295 ** Second, if the initial portion of a name is not $$$folder,
296 ** the result will be everything after the last ``/''.
298 ** Third and last, the result will be just the name if neither
299 ** $$$folder nor a ``/'' were found in the name.
301 const string_t folder_name(void) {
304 if (!m_strisempty(Maildir)
305 && m_strstart(CurrentFolder, Maildir, &p) && *p) {
310 p = strchr(CurrentFolder ?: "", '/');
311 RETURN(p ? p + 1 : (CurrentFolder ?: ""));
316 const string_t cachedir = NULL;
317 void setcachedir(const string_t path) {
318 madmutt_update_cachedir(path);
323 @package MTransport {
326 ** Specifies the program and arguments used to deliver mail sent by Madmutt.
327 ** Madmutt expects that the specified program interprets additional
328 ** arguments as recipient addresses.
330 path_t sendmail = m_strdup(SENDMAIL " -eom -oi");
334 ** \fBNote:\fP you should not enable this unless you are using Sendmail
337 ** This variable sets the request for when notification is returned. The
338 ** string consists of a comma separated list (no spaces!) of one or more
339 ** of the following: \fInever\fP, to never request notification,
340 ** \fIfailure\fP, to request notification on transmission failure,
341 ** \fIdelay\fP, to be notified of message delays, \fIsuccess\fP, to be
342 ** notified of successful transmission.
344 ** Example: \fTset dsn_notify="failure,delay"\fP
346 /* TODO: check it's NULL, hdrs or full */
347 string_t dsn_notify = NULL;
351 ** \fBNote:\fP you should not enable this unless you are using Sendmail
354 ** This variable controls how much of your message is returned in DSN
355 ** messages. It may be set to either \fIhdrs\fP to return just the
356 ** message header, or \fIfull\fP to return the full message.
358 ** Example: \fTset dsn_return=hdrs\fP
360 /* TODO: check it's never, delay, failure, success with ',' */
361 string_t dsn_return = NULL;
365 ** Specifies the number of seconds to wait for the ``$$sendmail'' process
366 ** to finish before giving up and putting delivery in the background.
368 ** Madmutt interprets the value of this variable as follows:
370 ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
371 ** .dt 0 .dd wait forever for sendmail to finish
372 ** .dt <0 .dd always put sendmail in the background without waiting
375 ** Note that if you specify a value other than 0, the output of the child
376 ** process will be put in a temporary file. If there is some error, you
377 ** will be informed as to where to find the output.
379 int sendmail_wait = 0;
382 ** \fBWarning:\fP do not set this variable unless you are using a version
383 ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
385 ** Otherwise you may not be able to send mail.
387 ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
388 ** flag when sending 8-bit messages to enable ESMTP negotiation.
390 bool use_8bitmime = 0;
394 ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
395 ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
396 ** derive it from the "From:" header.
399 ** \fBNote:\fP This information is passed to sendmail command using the
400 ** "-f" command line switch.
402 bool use_envelope_from = 0;
406 ** Manually sets the \fIenvelope\fP sender for outgoing messages.
407 ** This value is ignored if ``$$use_envelope_from'' is unset.
409 address_t envelope_from_address = NULL;