move more stuff to the lua bindings.
[apps/madmutt.git] / lib-lua / madmutt.cpkg
1 /*
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.
6  *
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.
11  *
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,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2007 Pierre Habouzit
18  */
19
20 #include <lib-lib/lib-lib.h>
21 #include <lib-lua/lib-lua.h>
22
23 #include <sys/types.h>
24 #include <pwd.h>
25
26 #include "../mutt.h"
27 @import "base.cpkg"
28
29 static char *madmutt_init_shell(void)
30 {
31     struct passwd *pw = getpwuid(getuid());
32     return m_strdup(pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh"));
33 }
34
35 static char *madmutt_init_username(void)
36 {
37     struct passwd *pw = getpwuid(getuid());
38     return m_strdup(pw ? pw->pw_name : (getenv("USER") ?: "john_doe"));
39 }
40
41 static char *madmutt_init_homedir(void)
42 {
43     struct passwd *pw = getpwuid(getuid());
44     return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/"));
45 }
46
47 #if defined(HAVE_QDBM)
48 #  define HCACHE_BACKEND  "qdbm"
49 #elif defined(HAVE_GDBM)
50 #  define HCACHE_BACKEND  "gdbm"
51 #elif defined(HAVE_DB4)
52 #  define HCACHE_BACKEND  "db4"
53 #else
54 #  define HCACHE_BACKEND  NULL
55 #endif
56
57 @package MCore {
58     /*
59      ** .pp
60      ** \fIThis is a read-only system property and specifies madmutt's
61      ** version string.\fP
62      */
63     const string_t version    = VERSION;
64     /*
65      ** .pp
66      ** \fIThis is a read-only system property and specifies madmutt's
67      ** subversion revision string.\fP
68      */
69     const string_t sysconfdir = SYSCONFDIR;
70     /*
71      ** .pp
72      ** \fIThis is a read-only system property and specifies the
73      ** directory containing the madmutt binary.\fP
74      */
75     const string_t bindir     = BINDIR;
76     /*
77      ** .pp
78      ** \fIThis is a read-only system property and specifies the
79      ** directory containing the madmutt documentation.\fP
80      */
81     const string_t docdir     = PKGDOCDIR;
82     /*
83      ** .pp
84      ** \fIThis is a read-only system property and specifies the
85      ** header chaching's database backend.\fP
86      */
87     const string_t hcache_backend = HCACHE_BACKEND;
88
89     /*
90      ** .pp
91      ** Contains the path of the \fTmadmutt_dotlock(1)\fP binary to be used by
92      ** Madmutt.
93      */
94     path_t dotlock        = m_strdup(BINDIR "/mutt_dotlock");
95     /*
96      ** .pp
97      ** This variable specifies which editor is used by Madmutt.
98      ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment
99      ** variable, or to the string "\fTvi\fP" if neither of those are set.
100      */
101     path_t editor         = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
102     /*
103      ** .pp
104      ** Command to use when spawning a subshell.  By default, the user's login
105      ** shell from \fT/etc/passwd\fP is used.
106      */
107     path_t shell          = madmutt_init_shell();
108
109     /* TODO: document */
110     path_t username       = madmutt_init_username();
111
112     /* TODO: document */
113     path_t homedir        = madmutt_init_homedir();
114
115     /*
116      ** .pp
117      ** This variable allows you to specify where Madmutt will place its
118      ** temporary files needed for displaying and composing messages.  If
119      ** this variable is not set, the environment variable \fT$$$TMPDIR\fP is
120      ** used.  If \fT$$$TMPDIR\fP is not set then "\fT/tmp\fP" is used.
121      */
122     path_t tmpdir         = m_strdup(getenv("TMPDIR") ?: "/tmp");
123     /*
124      ** .pp
125      ** A regular expression used by Madmutt to parse the GECOS field of a password
126      ** entry when expanding the alias.  By default the regular expression is set
127      ** to ``\fT^[^,]*\fP'' which will return the string up to the first ``\fT,\fP'' encountered.
128      ** If the GECOS field contains a string like "lastname, firstname" then you
129      ** should do: \fTset gecos_mask=".*"\fP.
130      ** .pp
131      ** This can be useful if you see the following behavior: you address a e-mail
132      ** to user ID stevef whose full name is Steve Franklin.  If Madmutt expands
133      ** stevef to ``Franklin'' stevef@foo.bar then you should set the gecos_mask to
134      ** a regular expression that will match the whole name so Madmutt will expand
135      ** ``Franklin'' to ``Franklin, Steve''.
136      */
137     rx_t   gecos_mask     = luaM_rxnew("^[^,]*");
138
139     /*
140      ** .pp
141      ** This variable controls whether ``quit'' and ``exit'' actually quit
142      ** from Madmutt.  If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
143      ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
144      ** prompted for confirmation when you try to quit.
145      */
146     quadopt_t quit        = M_YES;
147     /*
148      ** .pp
149      ** When this variable is \fIset\fP, Madmutt will beep when an error occurs.
150      */
151     bool      beep        = 1;
152     /*
153      ** .pp
154      ** When this variable is \fIset\fP, Madmutt will beep whenever it prints a message
155      ** notifying you of new mail.  This is independent of the setting of the
156      ** ``$$beep'' variable.
157      */
158     bool      beep_new    = 0;
159
160     /*
161      ** .pp
162      ** When \fIset\fP, Madmutt will qualify all local addresses (ones without the
163      ** @host portion) with the value of ``$$hostname''.  If \fIunset\fP, no
164      ** addresses will be qualified.
165      */
166     bool      use_domain  = 1;
167
168     /*
169      ** .pp
170      ** \fIThis is a read-only system property and, at runtime,
171      ** specifies the current working directory of the madmutt
172      ** binary.\fP
173      */
174     const string_t pwd(void) {
175         char path[_POSIX_PATH_MAX];
176         getcwd(path, sizeof(path));
177         RETURN(path);
178     };
179
180     /*
181      ** .pp
182      ** \fIThis is a read-only system property and, at runtime,
183      ** specifies the full path or URI of the folder currently
184      ** open (if any).\fP
185      */
186     const string_t folder_path(void) {
187         RETURN(CurrentFolder);
188     };
189
190     /*
191      ** .pp
192      ** \fIThis is a read-only system property and, at runtime,
193      ** specifies the actual name of the folder as far as it could
194      ** be detected.\fP
195      ** .pp
196      ** For detection, $$$folder is first taken into account
197      ** and simply stripped to form the result when a match is found. For
198      ** example, with $$$folder being \fTimap://host\fP and the folder is
199      ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
200      ** \fTINBOX/foo\fP.)
201      ** .pp
202      ** Second, if the initial portion of a name is not $$$folder,
203      ** the result will be everything after the last ``/''.
204      ** .pp
205      ** Third and last, the result will be just the name if neither
206      ** $$$folder nor a ``/'' were found in the name.
207      */
208     const string_t folder_name(void) {
209         const char *p;
210
211         if (!m_strisempty(Maildir)
212         &&  m_strstart(CurrentFolder, Maildir, &p) && *p) {
213             while (*p == '/')
214                 p++;
215             RETURN(p);
216         } else {
217             p = strchr(CurrentFolder ?: "", '/');
218             RETURN(p ? p + 1 : (CurrentFolder ?: ""));
219         }
220     };
221 };
222
223 @package MTransport {
224     /*
225      ** .pp
226      ** Specifies the program and arguments used to deliver mail sent by Madmutt.
227      ** Madmutt expects that the specified program interprets additional
228      ** arguments as recipient addresses.
229      */
230     path_t   sendmail = m_strdup(SENDMAIL " -eom -oi");
231
232     /*
233      ** .pp
234      ** \fBNote:\fP you should not enable this unless you are using Sendmail
235      ** 8.8.x or greater or in connection with the SMTP support via libESMTP.
236      ** .pp
237      ** This variable sets the request for when notification is returned.  The
238      ** string consists of a comma separated list (no spaces!) of one or more
239      ** of the following: \fInever\fP, to never request notification,
240      ** \fIfailure\fP, to request notification on transmission failure,
241      ** \fIdelay\fP, to be notified of message delays, \fIsuccess\fP, to be
242      ** notified of successful transmission.
243      ** .pp
244      ** Example: \fTset dsn_notify="failure,delay"\fP
245      */
246     /* TODO: check it's NULL, hdrs or full */
247     string_t dsn_notify = NULL;
248
249     /*
250      ** .pp
251      ** \fBNote:\fP you should not enable this unless you are using Sendmail
252      ** 8.8.x or greater or in connection with the SMTP support via libESMTP.
253      ** .pp
254      ** This variable controls how much of your message is returned in DSN
255      ** messages.  It may be set to either \fIhdrs\fP to return just the
256      ** message header, or \fIfull\fP to return the full message.
257      ** .pp
258      ** Example: \fTset dsn_return=hdrs\fP
259      */
260     /* TODO: check it's never, delay, failure, success with ',' */
261     string_t dsn_return = NULL;
262
263     /*
264      ** .pp
265      ** Specifies the number of seconds to wait for the ``$$sendmail'' process
266      ** to finish before giving up and putting delivery in the background.
267      ** .pp
268      ** Madmutt interprets the value of this variable as follows:
269      ** .dl
270      ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing
271      ** .dt 0  .dd wait forever for sendmail to finish
272      ** .dt <0 .dd always put sendmail in the background without waiting
273      ** .de
274      ** .pp
275      ** Note that if you specify a value other than 0, the output of the child
276      ** process will be put in a temporary file.  If there is some error, you
277      ** will be informed as to where to find the output.
278      */
279     int sendmail_wait = 0;
280     /*
281      ** .pp
282      ** \fBWarning:\fP do not set this variable unless you are using a version
283      ** of sendmail which supports the \fT-B8BITMIME\fP flag (such as sendmail
284      ** 8.8.x) or in connection with the SMTP support via libESMTP.
285      ** Otherwise you may not be able to send mail.
286      ** .pp
287      ** When \fIset\fP, Madmutt will either invoke ``$$sendmail'' with the \fT-B8BITMIME\fP
288      ** flag when sending 8-bit messages to enable ESMTP negotiation or tell
289      ** libESMTP to do so.
290      */
291     bool use_8bitmime = 0;
292
293     /*
294      ** .pp
295      ** When \fIset\fP, Madmutt will use ``$$envelope_from_address'' as the
296      ** \fIenvelope\fP sender if that is set, otherwise it will attempt to
297      ** derive it from the "From:" header.
298      **
299      ** .pp
300      ** \fBNote:\fP This information is passed
301      ** to sendmail command using the "-f" command line switch and
302      ** passed to the SMTP server for libESMTP (if support is compiled in).
303      */
304     bool use_envelope_from = 0;
305
306     /*
307      ** .pp
308      ** Manually sets the \fIenvelope\fP sender for outgoing messages.
309      ** This value is ignored if ``$$use_envelope_from'' is unset.
310      */
311     address_t envelope_from_address = NULL;
312 };
313
314 /* vim:set ft=c: */