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>
21 #include "lib-lua_priv.h"
25 static int madmutt_pwd(lua_State *L)
27 char path[_POSIX_PATH_MAX];
28 getcwd(path, sizeof(path));
29 lua_pushstring(L, path);
33 static int madmutt_folder_path(lua_State *L)
35 lua_pushstring(L, CurrentFolder ?: "");
39 static int madmutt_folder_name(lua_State *L)
43 if (!m_strisempty(Maildir)
44 && m_strstart(CurrentFolder, Maildir, &p) && *p) {
49 p = strchr(CurrentFolder ?: "", '/');
50 lua_pushstring(L, p ? p + 1 : (CurrentFolder ?: ""));
55 static const struct luaL_Reg madmutt_module_funcs[] = {
59 ** \fIThis is a read-only system property and, at runtime,
60 ** specifies the current working directory of the madmutt
63 {"folder_path", madmutt_folder_path},
66 ** \fIThis is a read-only system property and, at runtime,
67 ** specifies the full path or URI of the folder currently
70 {"folder_name", madmutt_folder_name},
73 ** \fIThis is a read-only system property and, at runtime,
74 ** specifies the actual name of the folder as far as it could
77 ** For detection, $$$folder is first taken into account
78 ** and simply stripped to form the result when a match is found. For
79 ** example, with $$$folder being \fTimap://host\fP and the folder is
80 ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
83 ** Second, if the initial portion of a name is not $$$folder,
84 ** the result will be everything after the last ``/''.
86 ** Third and last, the result will be just the name if neither
87 ** $$$folder nor a ``/'' were found in the name.
95 } madmutt_module_vars[] = {
96 { "version", VERSION },
99 ** \fIThis is a read-only system property and specifies madmutt's
100 ** version string.\fP
102 { "sysconfdir", SYSCONFDIR },
105 ** \fIThis is a read-only system property and specifies madmutt's
106 ** subversion revision string.\fP
108 { "bindir", BINDIR },
111 ** \fIThis is a read-only system property and specifies the
112 ** directory containing the madmutt binary.\fP
114 { "docdir", PKGDOCDIR },
117 ** \fIThis is a read-only system property and specifies the
118 ** directory containing the madmutt documentation.\fP
121 #if defined(HAVE_QDBM)
122 {"hcache_backend", "qdbm" },
123 #elif defined(HAVE_GDBM)
124 {"hcache_backend", "gdbm" },
125 #elif defined(HAVE_DB4)
126 {"hcache_backend", "db4" },
128 {"hcache_backend", "unknown" },
132 ** \fIThis is a read-only system property and specifies the
133 ** header chaching's database backend.\fP
138 int luaopen_madmutt(lua_State *L)
141 luaL_register(L, LUA_MADMUTT, madmutt_module_funcs);
143 for (i = 0; i < countof(madmutt_module_vars); i++) {
144 lua_pushstring(L, madmutt_module_vars[i].value);
145 lua_setfield(L, -2, madmutt_module_vars[i].key);