Commit d45791ef d45791efa25233eed9c2837593f4e9428253cab3 by Sergey Poznyakoff

Use util_getenv()

1 parent 92d14adf
......@@ -77,7 +77,7 @@ mail_set_my_name (char *name)
int
mail_is_my_name (char *name)
{
if (util_find_env("metoo")->set)
if (util_getenv (NULL, "metoo", Mail_env_boolean, 0) == 0)
return 0;
if (strchr(name, '@') == NULL && strcasecmp (name, my_name) == 0)
return 1;
......
......@@ -62,7 +62,8 @@ display_message (message_t mesg, msgset_t *msgset, void *arg)
return 1;
message_lines (mesg, &lines);
if ((util_find_env("crt"))->set && (int)lines > util_getlines ())
if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0
&& (int)lines > util_getlines ())
out = popen (getenv("PAGER"), "w");
else
out = ofile;
......
......@@ -64,7 +64,7 @@ mail_delete (int argc, char **argv)
cursor = realcursor;
}
if (util_find_env("autoprint")->set)
if (util_getenv (NULL, "autoprint", Mail_env_boolean, 0) == 0)
util_do_command("print");
return rc;
......
......@@ -25,17 +25,12 @@ int
mail_folders (int argc, char **argv)
{
char *path;
struct mail_env_entry *env = util_find_env ("folder");
(void)argc; (void)argv;
if (!env->set)
{
util_error ("No value set for \"folder\"");
return 1;
}
if (util_getenv (&path, "folder", Mail_env_string, 1))
return 1;
path = env->value;
if (path[0] != '/' && path[0] != '~')
{
char *tmp = alloca (strlen (path) + 3);
......
......@@ -80,7 +80,7 @@ _cond_pop()
int
mail_if (int argc, char **argv)
{
struct mail_env_entry *mode;
char *mode;
int cond;
if (argc != 2)
......@@ -95,11 +95,8 @@ mail_if (int argc, char **argv)
return 1;
}
mode = util_find_env("mode");
if (!mode)
{
exit (EXIT_FAILURE);
}
if (util_getenv (&mode, "mode", Mail_env_string, 1))
exit (EXIT_FAILURE);
if (if_cond() == 0)
/* Propagate negative condition */
......@@ -109,10 +106,10 @@ mail_if (int argc, char **argv)
switch (argv[1][0])
{
case 's': /* Send mode */
cond = strcmp(mode->value, "send") == 0;
cond = strcmp(mode, "send") == 0;
break;
case 'r': /* Read mode */
cond = strcmp(mode->value, "send") != 0;
cond = strcmp(mode, "send") != 0;
break;
case 't': /* Reading from a terminal */
cond = interactive;
......
......@@ -504,7 +504,7 @@ select_header (message_t msg, void *closure)
message_get_header (msg, &hdr);
if (header_aget_value (hdr, header, &contents) == 0)
{
if (!(util_find_env ("noregex"))->set)
if (util_getenv (NULL, "regex", Mail_env_boolean, 0) == 0)
{
/* Match string against the extended regular expression(ignoring
case) in pattern, treating errors as no match.
......@@ -542,7 +542,7 @@ int
select_body (message_t msg, void *closure)
{
char *expr = closure;
int noregex = util_find_env ("noregex")->set;
int noregex = util_getenv (NULL, "regex", Mail_env_boolean, 0);
regex_t re;
int status;
body_t body = NULL;
......
......@@ -36,9 +36,7 @@ mail_pipe (int argc, char **argv)
if (argc > 1)
cmd = argv[--argc];
else if ((util_find_env ("cmd"))->set)
cmd = (util_find_env ("cmd"))->value;
else
else if (util_getenv (&cmd, "cmd", Mail_env_boolean, 1))
return 1;
if (msgset_parse (argc, argv, &list))
......@@ -59,7 +57,7 @@ mail_pipe (int argc, char **argv)
fprintf (tube, "%s", buffer);
off += n;
}
if ((util_find_env("page"))->set && mp->next)
if (util_getenv (NULL, "page", Mail_env_boolean, 0) == 0)
fprintf (tube, "\f\n");
}
}
......
......@@ -52,7 +52,7 @@ mail_print (int argc, char **argv)
to be smart about it. */
if (lines == 0)
{
if ((util_find_env("crt"))->set)
if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0)
{
size_t col = (size_t)util_getcols ();
if (col)
......@@ -64,8 +64,9 @@ mail_print (int argc, char **argv)
}
}
if ((util_find_env("crt"))->set && lines > (size_t)util_getlines ())
out = popen (getenv("PAGER"), "w");
if (util_getenv (NULL, "crt", Mail_env_boolean, 0) == 0
&& lines > (size_t)util_getlines ())
out = popen (getenv ("PAGER"), "w");
if (islower (argv[0][0]))
{
......
......@@ -37,7 +37,7 @@ mail_mbox_close ()
url_t url = NULL;
size_t held_count;
if (!util_find_env ("readonly")->set)
if (util_getenv (NULL, "readonly", Mail_env_boolean, 0))
{
if (mail_mbox_commit ())
return 1;
......@@ -62,8 +62,8 @@ mail_mbox_commit ()
int saved_count = 0;
message_t msg;
attribute_t attr;
int keepsave = util_find_env("keepsave")->set;
int hold = util_find_env ("hold")->set;
int keepsave = util_getenv (NULL, "keepsave", Mail_env_boolean, 0) == 0;
int hold = util_getenv (NULL, "hold", Mail_env_boolean, 0) == 0;
url_t url;
int is_user_mbox;
......
......@@ -74,15 +74,18 @@ mail_send (int argc, char **argv)
}
}
if ((util_find_env ("askcc"))->set)
if (util_getenv (NULL, "askcc", Mail_env_boolean, 0) == 0)
env.cc = ml_readline ((char *)"Cc: ");
if ((util_find_env ("askbcc"))->set)
if (util_getenv (NULL, "askbcc", Mail_env_boolean, 0) == 0)
env.bcc = ml_readline ((char *)"Bcc: ");
if ((util_find_env ("asksub"))->set)
if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0)
env.subj = ml_readline ((char *)"Subject: ");
else
env.subj = (util_find_env ("subject"))->value;
{
env.subj = NULL;
util_getenv (&env.subj, "subject", Mail_env_string, 0);
}
status = mail_send0 (&env, isupper(argv[0][0]));
free_env_headers (&env);
......@@ -135,6 +138,7 @@ mail_send0 (struct send_environ *env, int save_to)
FILE *file;
char *savefile = NULL;
int int_cnt;
char *escape;
fd = mu_tempfile (NULL, &filename);
......@@ -159,7 +163,7 @@ mail_send0 (struct send_environ *env, int save_to)
if (ml_got_interrupt ())
{
if (util_find_env ("ignore")->set)
if (util_getenv (NULL, "ignore", Mail_env_boolean, 0) == 0)
{
fprintf (stdout, "@\n");
}
......@@ -176,9 +180,9 @@ mail_send0 (struct send_environ *env, int save_to)
if (!buf)
{
if (util_find_env ("ignoreeof")->set)
if (util_getenv (NULL, "ignore", Mail_env_boolean, 0) == 0)
{
util_error (util_find_env ("dot")->set ?
util_error (util_getenv (NULL, "dot", Mail_env_boolean, 0) == 0 ?
"Use \".\" to terminate letter." :
"Use \"~.\" to terminate letter.");
continue;
......@@ -189,9 +193,10 @@ mail_send0 (struct send_environ *env, int save_to)
int_cnt = 0;
if (buf[0] == '.' && util_find_env ("dot")->set)
if (buf[0] == '.' && util_getenv (NULL, "dot", Mail_env_boolean, 0) == 0)
done = 1;
else if (buf[0] == (util_find_env ("escape"))->value[0])
else if (util_getenv (&escape, "escape", Mail_env_string, 0) == 0
&& buf[0] == escape[0])
{
if (buf[1] == buf[0])
fprintf (env->file, "%s\n", buf+1);
......@@ -240,10 +245,11 @@ mail_send0 (struct send_environ *env, int save_to)
/* If interrupted dumpt the file to dead.letter. */
if (int_cnt)
{
if (util_find_env ("save")->set)
if (util_getenv (NULL, "save", Mail_env_boolean, 0) == 0)
{
FILE *fp = fopen (getenv ("DEAD"),
util_find_env ("appenddeadletter")->set ?
util_getenv (NULL, "appenddeadletter",
Mail_env_boolean, 0) == 0 ?
"a" : "w");
if (!fp)
......@@ -369,13 +375,13 @@ mail_send0 (struct send_environ *env, int save_to)
|| (env->cc && *env->cc != '\0')
|| (env->bcc && *env->bcc != '\0'))
{
if (util_find_env ("sendmail")->set)
char *sendmail;
if (util_getenv (&sendmail, "sendmail", Mail_env_string, 0) == 0)
{
char *sendmail = util_find_env ("sendmail")->value;
int status = mailer_create (&mailer, sendmail);
if (status == 0)
{
if (util_find_env ("verbose")->set)
if (util_getenv (NULL, "verbose", Mail_env_boolean, 0) == 0)
{
mu_debug_t debug = NULL;
mailer_get_debug (mailer, &debug);
......
......@@ -33,9 +33,10 @@ mail_top (int argc, char **argv)
char buf[512];
size_t n;
off_t off;
int lines = strtol ((util_find_env("toplines"))->value, NULL, 10);
int lines;
if (lines < 0)
if (util_getenv (&lines, "toplines", Mail_env_number, 1)
|| lines < 0)
return 1;
if (mailbox_get_message (mbox, cursor, &msg) != 0)
......
......@@ -30,8 +30,9 @@ static int var_check_args (int argc, char **argv)
{
if (argc == 1)
{
util_error ("%c%s requires an argument",
util_find_env ("escape")->value[0], argv[0]);
char *escape = "~";
util_getenv (&escape, "escape", Mail_env_string, 0);
util_error ("%c%s requires an argument", escape[0], argv[0]);
return 1;
}
return 0;
......@@ -102,19 +103,16 @@ var_help(int argc, char **argv, struct send_environ *env)
int
var_sign(int argc, char **argv, struct send_environ *env)
{
struct mail_env_entry *p;
char *p;
(void)argc; (void)env;
if (isupper(argv[0][0]))
p = util_find_env("Sign");
else
p = util_find_env("sign");
if (p->set)
if (util_getenv (&p, isupper (argv[0][0]) ? "Sign" : "sign",
Mail_env_string, 1) == 0)
{
if (isupper(argv[0][0]))
if (isupper (argv[0][0]))
{
char *name = util_fullpath(p->value);
char *name = util_fullpath (p);
FILE *fp = fopen(name, "r");
char *buf = NULL;
size_t n = 0;
......@@ -134,11 +132,9 @@ var_sign(int argc, char **argv, struct send_environ *env)
free(name);
}
else
fprintf(ofile, "%s", p->value);
fprintf(ofile, "%s", p);
var_continue();
}
else
util_error("\"sign\" not set");
return 0;
}
......@@ -232,12 +228,32 @@ var_headers(int argc, char **argv, struct send_environ *env)
/* ~i[var-name] */
int
var_insert(int argc, char **argv, struct send_environ *env)
var_insert (int argc, char **argv, struct send_environ *env)
{
struct mail_env_entry *env;
(void)env;
if (var_check_args (argc, argv))
return 1;
fprintf(ofile, "%s", util_find_env(argv[1])->value);
env = util_find_env (argv[1], 0);
if (env)
switch (env->type)
{
case Mail_env_string:
fprintf (ofile, "%s", env->value.string);
break;
case Mail_env_number:
fprintf (ofile, "%d", env->value.number);
break;
case Mail_env_boolean:
fprintf (ofile, "%s", env->set ? "yes" : "no");
break;
default:
break;
}
return 0;
}
......@@ -257,13 +273,15 @@ var_quote(int argc, char **argv, struct send_environ *env)
char buffer[512];
off_t off = 0;
size_t n = 0;
char *prefix = util_find_env("indentprefix")->value;
char *prefix = "\t";
if (mailbox_get_message(mbox, cursor, &mesg) != 0)
return 1;
fprintf(stdout, "Interpolating: %d\n", cursor);
util_getenv(&prefix, "indentprefix", Mail_env_string, 0);
if (islower(argv[0][0]))
{
size_t i, num = 0;
......