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-sys/unix.h>
32 static char *madmutt_init_shell(void)
34 struct passwd *pw = getpwuid(getuid());
35 return m_strdup(pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh"));
38 static char *madmutt_init_username(void)
40 struct passwd *pw = getpwuid(getuid());
41 return m_strdup(pw ? pw->pw_name : (getenv("USER") ?: "john_doe"));
44 static char *madmutt_init_homedir(void)
46 struct passwd *pw = getpwuid(getuid());
47 return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/"));
50 static char *madmutt_init_shorthost(void)
52 struct utsname utsname;
55 /* some systems report the FQDN instead of just the hostname */
57 p = strchrnul(utsname.nodename, '.');
58 return p_dupstr(utsname.nodename, p - utsname.nodename);
61 static char *madmutt_init_hostname(void)
65 if (getdnsdomainname(buffer, sizeof(buffer)) < 0)
69 int len = m_strlen(buffer) + m_strlen(MCore.shorthost) + 2;
70 char *res = p_new(char, len);
71 snprintf(res, len, "%s.%s", NONULL(MCore.shorthost), buffer);
75 return m_strdup(NONULL(MCore.shorthost));
78 #if defined(HAVE_QDBM)
79 # define HCACHE_BACKEND "qdbm"
80 #elif defined(HAVE_GDBM)
81 # define HCACHE_BACKEND "gdbm"
82 #elif defined(HAVE_DB4)
83 # define HCACHE_BACKEND "db4"
85 # define HCACHE_BACKEND NULL
91 ** \fIThis is a read-only system property and specifies madmutt's
94 const string_t version = VERSION;
97 ** \fIThis is a read-only system property and specifies madmutt's
98 ** subversion revision string.\fP
100 const string_t sysconfdir = SYSCONFDIR;
103 ** \fIThis is a read-only system property and specifies the
104 ** directory containing the madmutt binary.\fP
106 const string_t bindir = BINDIR;
109 ** \fIThis is a read-only system property and specifies the
110 ** directory containing the madmutt documentation.\fP
112 const string_t docdir = PKGDOCDIR;
115 ** \fIThis is a read-only system property and specifies the
116 ** header chaching's database backend.\fP
118 const string_t hcache_backend = HCACHE_BACKEND;
122 ** Contains the path of the \fTmadmutt_dotlock(1)\fP binary to be used by
125 path_t dotlock = m_strdup(BINDIR "/mutt_dotlock");
128 ** This variable specifies which editor is used by Madmutt.
129 ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment
130 ** variable, or to the string "\fTvi\fP" if neither of those are set.
132 path_t editor = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
135 ** Command to use when spawning a subshell. By default, the user's login
136 ** shell from \fT/etc/passwd\fP is used.
138 path_t shell = madmutt_init_shell();
140 path_t username = madmutt_init_username();
141 path_t homedir = madmutt_init_homedir();
145 ** Specifies the hostname to use after the ``\fT@\fP'' in local e-mail
146 ** addresses and during generation of \fTMessage-ID:\fP headers.
148 ** Please be sure to really know what you are doing when changing this variable
149 ** to configure a custom domain part of Message-IDs.
151 string_t hostname = madmutt_init_hostname();
152 string_t shorthost = madmutt_init_shorthost();
156 ** This variable allows you to specify where Madmutt will place its
157 ** temporary files needed for displaying and composing messages. If
158 ** this variable is not set, the environment variable \fT$$$TMPDIR\fP is
159 ** used. If \fT$$$TMPDIR\fP is not set then "\fT/tmp\fP" is used.
161 path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
164 ** A regular expression used by Madmutt to parse the GECOS field of a password
165 ** entry when expanding the alias. By default the regular expression is set
166 ** to ``\fT^[^,]*\fP'' which will return the string up to the first ``\fT,\fP'' encountered.
167 ** If the GECOS field contains a string like "lastname, firstname" then you
168 ** should do: \fTset gecos_mask=".*"\fP.
170 ** This can be useful if you see the following behavior: you address a e-mail
171 ** to user ID stevef whose full name is Steve Franklin. If Madmutt expands
172 ** stevef to ``Franklin'' stevef@foo.bar then you should set the gecos_mask to
173 ** a regular expression that will match the whole name so Madmutt will expand
174 ** ``Franklin'' to ``Franklin, Steve''.
176 rx_t gecos_mask = luaM_rxnew("^[^,]*");
180 ** This variable controls whether ``quit'' and ``exit'' actually quit
181 ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
182 ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
183 ** prompted for confirmation when you try to quit.
185 quadopt_t quit = M_YES;
188 ** When this variable is \fIset\fP, Madmutt will beep when an error occurs.
193 ** When this variable is \fIset\fP, Madmutt will beep whenever it prints a message
194 ** notifying you of new mail. This is independent of the setting of the
195 ** ``$$beep'' variable.
201 ** When \fIset\fP, Madmutt will qualify all local addresses (ones without the
202 ** @host portion) with the value of ``$$hostname''. If \fIunset\fP, no
203 ** addresses will be qualified.
209 ** \fIThis is a read-only system property and, at runtime,
210 ** specifies the current working directory of the madmutt
213 const string_t pwd(void) {
214 char path[_POSIX_PATH_MAX];
215 getcwd(path, sizeof(path));
221 ** \fIThis is a read-only system property and, at runtime,
222 ** specifies the full path or URI of the folder currently
225 const string_t folder_path(void) {
226 RETURN(CurrentFolder);
231 ** \fIThis is a read-only system property and, at runtime,
232 ** specifies the actual name of the folder as far as it could
235 ** For detection, $$$folder is first taken into account
236 ** and simply stripped to form the result when a match is found. For
237 ** example, with $$$folder being \fTimap://host\fP and the folder is
238 ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
241 ** Second, if the initial portion of a name is not $$$folder,
242 ** the result will be everything after the last ``/''.
244 ** Third and last, the result will be just the name if neither
245 ** $$$folder nor a ``/'' were found in the name.
247 const string_t folder_name(void) {
250 if (!m_strisempty(Maildir)
251 && m_strstart(CurrentFolder, Maildir, &p) && *p) {
256 p = strchr(CurrentFolder ?: "", '/');
257 RETURN(p ? p + 1 : (CurrentFolder ?: ""));
262 @package MTransport {
265 ** Specifies the program and arguments used to deliver mail sent by Madmutt.
266 ** Madmutt expects that the specified program interprets additional
267 ** arguments as recipient addresses.
269 path_t sendmail = m_strdup(SENDMAIL " -eom -oi");
273 ** \fBNote:\fP you should not enable this unless you are using Sendmail
274 ** 8.8.x or greater or in connection with the SMTP support via libESMTP.
276 ** This variable sets the request for when notification is returned. The
277 ** string consists of a comma separated list (no spaces!) of one or more
278 ** of the following: \fInever\fP, to never request notification,
279 ** \fIfailure\fP, to request notification on transmission failure,
280 ** \fIdelay\fP, to be notified of message delays, \fIsuccess\fP, to be
281 ** notified of successful transmission.
283 ** Example: \fTset dsn_notify="failure,delay"\fP
285 /* TODO: check it's NULL, hdrs or full */
286 string_t dsn_notify = NULL;
290 ** \fBNote:\fP you should not enable this unless you are using Sendmail
291 ** 8.8.x or greater or in connection with the SMTP support via libESMTP.
293 ** This variable controls how much of your message is returned in DSN
294 ** messages. It may be set to either \fIhdrs\fP to return just the
295 ** message header, or \fIfull\fP to return the full message.
297 ** Example: \fTset dsn_return=hdrs\fP
299 /* TODO: check it's never, delay, failure, success with ',' */
300 string_t dsn_return = NULL;
304 ** Specifies the number of seconds to wait for the ``$$sendmail'' process
305 ** to finish before giving up and putting delivery in the background.
307 ** Madmutt interprets the value of this variable as follows:
309 ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
310 ** .dt 0 .dd wait forever for sendmail to finish
311 ** .dt <0 .dd always put sendmail in the background without waiting
314 ** Note that if you specify a value other than 0, the output of the child
315 ** process will be put in a temporary file. If there is some error, you
316 ** will be informed as to where to find the output.
318 int sendmail_wait = 0;
321 ** \fBWarning:\fP do not set this variable unless you are using a version
322 ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
323 ** 8.8.x) or in connection with the SMTP support via libESMTP.
324 ** Otherwise you may not be able to send mail.
326 ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
327 ** flag when sending 8-bit messages to enable ESMTP negotiation or tell
328 ** libESMTP to do so.
330 bool use_8bitmime = 0;
334 ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
335 ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
336 ** derive it from the "From:" header.
339 ** \fBNote:\fP This information is passed
340 ** to sendmail command using the "-f" command line switch and
341 ** passed to the SMTP server for libESMTP (if support is compiled in).
343 bool use_envelope_from = 0;
347 ** Manually sets the \fIenvelope\fP sender for outgoing messages.
348 ** This value is ignored if ``$$use_envelope_from'' is unset.
350 address_t envelope_from_address = NULL;