</sect1>
+<sect1 id="setenv">
+<title>Managing the Environment</title>
+
+<para>
+You can alter the environment that Mutt passes on to its child processes
+using the <quote>setenv</quote> and <quote>unsetenv</quote> operators.
+(N.B. These follow Mutt-style syntax, not shell-style!) You can also
+query current environment values by prefixing a <quote>?</quote> character.
+</para>
+
+<screen>
+setenv TERM vt100
+setenv ORGANIZATION "The Mutt Development Team"
+unsetenv DISPLAY
+setenv ?LESS
+</screen>
+</sect1>
+
<sect1 id="query">
<title>External Address Queries</title>
</cmdsynopsis>
</listitem>
+<listitem>
+ <cmdsynopsis>
+ <command><link linkend="setenv">setenv</link></command>
+ <arg choice="plain">
+ <replaceable class="parameter">[?]variable</replaceable>
+ </arg>
+ <arg choice="opt">
+ <replaceable class="parameter">value</replaceable>
+ </arg>
+
+ <command><link linkend="setenv">unsetenv</link></command>
+ <arg choice="plain">
+ <replaceable class="parameter">variable</replaceable>
+ </arg>
+ </cmdsynopsis>
+</listitem>
+
<listitem>
<cmdsynopsis>
<command><link linkend="sidebar-whitelist">sidebar_whitelist</link></command>
#endif
+extern char **envlist;
+
static void toggle_quadoption (int opt)
{
int n = opt/4;
return rc;
}
+static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
+{
+ int query, unset, len;
+ char work[LONG_STRING];
+ char **save, **envp = envlist;
+ int count = 0;
+
+ query = 0;
+ unset = data & MUTT_SET_UNSET;
+
+ if (!MoreArgs (s))
+ {
+ strfcpy (err->data, _("too few arguments"), err->dsize);
+ return -1;
+ }
+
+ if (*s->dptr == '?')
+ {
+ query = 1;
+ s->dptr++;
+ }
+
+ /* get variable name */
+ mutt_extract_token (tmp, s, MUTT_TOKEN_EQUAL);
+ len = strlen (tmp->data);
+
+ if (query)
+ {
+ int found = 0;
+ while (envp && *envp)
+ {
+ if (!mutt_strncmp (tmp->data, *envp, len))
+ {
+ if (!found)
+ {
+ mutt_endwin (NULL);
+ found = 1;
+ }
+ puts (*envp);
+ }
+ envp++;
+ }
+
+ if (found)
+ {
+ set_option (OPTFORCEREDRAWINDEX);
+ set_option (OPTFORCEREDRAWPAGER);
+ mutt_any_key_to_continue (NULL);
+ return 0;
+ }
+
+ snprintf (err->data, err->dsize, _("%s is unset"), tmp->data);
+ return -1;
+ }
+
+ if (unset)
+ {
+ count = 0;
+ while (envp && *envp)
+ {
+ if (!mutt_strncmp (tmp->data, *envp, len) && (*envp)[len] == '=')
+ {
+ /* shuffle down */
+ save = envp++;
+ while (*envp)
+ {
+ *save++ = *envp++;
+ count++;
+ }
+ *save = NULL;
+ safe_realloc (&envlist, sizeof(char *) * (count+1));
+ return 0;
+ }
+ envp++;
+ count++;
+ }
+ return -1;
+ }
+
+ if (*s->dptr == '=')
+ {
+ s->dptr++;
+ SKIPWS (s->dptr);
+ }
+
+ if (!MoreArgs (s))
+ {
+ strfcpy (err->data, _("too few arguments"), err->dsize);
+ return -1;
+ }
+
+ /* Look for current slot to overwrite */
+ count = 0;
+ while (envp && *envp)
+ {
+ if (!mutt_strncmp (tmp->data, *envp, len) && (*envp)[len] == '=')
+ {
+ FREE (envp); /* __FREE_CHECKED__ */
+ break;
+ }
+ envp++;
+ count++;
+ }
+
+ /* Format var=value string */
+ strfcpy (work, tmp->data, sizeof(work));
+ len = strlen (work);
+ work[len++] = '=';
+ mutt_extract_token (tmp, s, 0);
+ strfcpy (&work[len], tmp->data, sizeof(work)-len);
+
+ /* If slot found, overwrite */
+ if (*envp)
+ *envp = safe_strdup (work);
+
+ /* If not found, add new slot */
+ else
+ {
+ *envp = safe_strdup (work);
+ count++;
+ safe_realloc (&envlist, sizeof(char *) * (count + 1));
+ envlist[count] = NULL;
+ }
+
+ return 0;
+}
+
static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
{
int query, unset, inv, reset, r = 0;
static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_set (BUFFER *, BUFFER *, unsigned long, BUFFER *);
+static int parse_setenv (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_my_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_unmy_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *);
static int parse_subscribe (BUFFER *, BUFFER *, unsigned long, BUFFER *);
{ "send-hook", mutt_parse_hook, MUTT_SENDHOOK },
{ "send2-hook", mutt_parse_hook, MUTT_SEND2HOOK },
{ "set", parse_set, 0 },
+ { "setenv", parse_setenv, 0 },
#ifdef USE_SIDEBAR
{ "sidebar_whitelist",parse_list, UL &SidebarWhitelist },
{ "unsidebar_whitelist",parse_unlist, UL &SidebarWhitelist },
{ "unmy_hdr", parse_unmy_hdr, 0 },
{ "unscore", mutt_parse_unscore, 0 },
{ "unset", parse_set, MUTT_SET_UNSET },
+ { "unsetenv", parse_setenv, MUTT_SET_UNSET },
{ "unsubscribe", parse_unsubscribe, 0 },
{ NULL, NULL, 0 }
};
#include "nntp.h"
#endif
+char **envlist;
+
void mutt_exit (int code)
{
mutt_endwin (NULL);
#define MUTT_NEWS (1<<5) /* -g and -G */
#endif
-int main (int argc, char **argv)
+int main (int argc, char **argv, char **environ)
{
char folder[_POSIX_PATH_MAX] = "";
char *subject = NULL;
memset (Options, 0, sizeof (Options));
memset (QuadOptions, 0, sizeof (QuadOptions));
+ /* Init envlist */
+ {
+ char **srcp, **dstp;
+ int count = 0;
+ for (srcp = environ; srcp && *srcp; srcp++)
+ count++;
+ envlist = safe_calloc(count+1, sizeof(char *));
+ for (srcp = environ, dstp = envlist; srcp && *srcp; srcp++, dstp++)
+ *dstp = safe_strdup(*srcp);
+ }
+
for (optind = 1; optind < double_dash; )
{
/* We're getopt'ing POSIXLY, so we'll be here every time getopt()
#include <sys/wait.h>
#include <unistd.h>
+extern char **envlist;
+
int _mutt_system (const char *cmd, int flags)
{
int rc = -1;
sigaction (SIGTSTP, &act, NULL);
sigaction (SIGCONT, &act, NULL);
- execl (EXECSHELL, "sh", "-c", cmd, NULL);
+ execle (EXECSHELL, "sh", "-c", cmd, NULL, envlist);
_exit (127); /* execl error */
}
else if (thepid != -1)