Commit 83d23534 83d23534b9fedef803af8e06aa9fc19d504d65f3 by Sergey Poznyakoff

mail: use mailvar_is_true to test boolean values

1 parent 7e05a160
......@@ -148,7 +148,7 @@ alias_expand (const char *name)
mu_list_t al;
mu_list_t list;
if (mailvar_get (NULL, "recursivealiases", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("recursivealiases"))
{
char *s;
mu_list_t origlist;
......
......@@ -281,14 +281,13 @@ display_submessage (struct mime_descend_closure *closure, void *data)
/* If `metamail' is set to true, enable internal mailcap
support */
if (mailvar_get (NULL, "metamail", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("metamail"))
{
char *no_ask = NULL;
int debug = 0;
mailvar_get (&no_ask, "mimenoask", mailvar_type_string, 0);
if (mailvar_get (&debug, "verbose", mailvar_type_boolean, 0) == 0
&& debug)
if (mailvar_is_true ("verbose"))
debug = 9;
builtin_display = display_stream_mailcap (NULL, stream, hdr, no_ask,
......
......@@ -38,7 +38,7 @@ mail_delete (int argc, char **argv)
int rc = util_foreach_msg (argc, argv, MSG_NODELETED|MSG_SILENT,
mail_delete_msg, NULL);
if (mailvar_get (NULL, "autoprint", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("autoprint"))
util_do_command("print");
return rc;
......
......@@ -273,7 +273,7 @@ escape_run_editor (char *ed, int argc, char **argv, compose_env_t *env)
}
mu_stream_seek (env->compstr, 0, MU_SEEK_SET, NULL);
if (!mailvar_get (NULL, "editheaders", mailvar_type_boolean, 0))
if (mailvar_is_true ("editheaders"))
{
dump_headers (tempstream, env);
......
......@@ -116,7 +116,7 @@ mail_file (int argc, char **argv)
mbox = newbox;
mu_mailbox_messages_count (mbox, &total);
set_cursor (1);
if (mailvar_get (NULL, "header", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("header"))
{
util_do_command ("summary");
util_do_command ("headers");
......
......@@ -193,7 +193,7 @@ hdr_date (struct header_call_args *args, void *data)
mu_message_get_header (args->msg, &hdr);
date[0] = 0;
if (mailvar_get (NULL, "datefield", mailvar_type_boolean, 0) == 0
if (mailvar_is_true ("datefield")
&& mu_header_get_value (hdr, MU_HEADER_DATE,
date, sizeof (date), NULL) == 0)
{
......@@ -225,7 +225,7 @@ hdr_from (struct header_call_args *args, void *data)
{
char *from = NULL;
if (mailvar_get (NULL, "fromfield", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("fromfield"))
{
mu_header_t hdr;
......@@ -240,9 +240,7 @@ hdr_from (struct header_call_args *args, void *data)
if (mu_address_sget_email (address, 1, &email) == 0)
{
if (mailvar_get (NULL, "showto",
mailvar_type_boolean, 0) == 0
&& mail_is_my_name (email))
if (mailvar_is_true ("showto") && mail_is_my_name (email))
{
char *tmp;
......
......@@ -318,8 +318,7 @@ mail_cmdline (void *closure, int cont MU_ARG_UNUSED)
while (1)
{
if (mailvar_get (NULL, "autoinc", mailvar_type_boolean, 0) == 0
&& !mu_mailbox_is_updated (mbox))
if (mailvar_is_true ("autoinc") && !mu_mailbox_is_updated (mbox))
{
mu_mailbox_messages_count (mbox, &total);
page_invalidate (0);
......@@ -334,7 +333,7 @@ mail_cmdline (void *closure, int cont MU_ARG_UNUSED)
continue;
}
if (!rc && mailvar_get (NULL, "ignoreeof", mailvar_type_boolean, 0) == 0)
if (!rc && mailvar_is_true ("ignoreeof"))
{
mu_error (_("Use \"quit\" to quit."));
continue;
......@@ -536,7 +535,7 @@ main (int argc, char **argv)
/* read system-wide mail.rc and user's .mailrc */
if (mailvar_get (NULL, "rc", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("rc"))
util_do_command ("source %s", SITE_MAIL_RC);
if ((p = getenv ("MAILRC")) && *p)
util_do_command ("source %s", getenv ("MAILRC"));
......@@ -581,7 +580,7 @@ main (int argc, char **argv)
mu_argcv_string (argc, argv, &buf);
rc = util_do_command ("mail %s", buf);
return mailvar_get (NULL, "mailx", mailvar_type_boolean, 0) ? rc : 0;
return mailvar_is_true ("mailx") ? 0 : rc;
}
/* Or acting as a normal reader */
else
......@@ -637,8 +636,7 @@ main (int argc, char **argv)
}
if (total == 0
&& (strcmp (mode, "read")
|| mailvar_get (NULL, "emptystart", mailvar_type_boolean, 0)))
&& (strcmp (mode, "read") || !mailvar_is_true ("emptystart")))
{
if (file)
mu_printf (_("%s: 0 messages\n"), file);
......@@ -648,7 +646,7 @@ main (int argc, char **argv)
}
/* initial commands */
if (mailvar_get (NULL, "header", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("header"))
{
util_do_command ("summary");
util_do_command ("headers");
......
......@@ -33,7 +33,7 @@ sig_handler (int signo)
switch (signo)
{
case SIGINT:
if (mailvar_get (NULL, "quit", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("quit"))
exit (0);
_interrupted++;
break;
......
......@@ -501,8 +501,7 @@ mailvar_set (const char *variable, void *value, enum mailvar_type type,
enum mailvar_cmd cmd =
(flags & MOPTF_UNSET) ? mailvar_cmd_unset : mailvar_cmd_set;
if (!(flags & MOPTF_QUIET)
&& mailvar_get (NULL, "variable-strict", mailvar_type_boolean, 0) == 0)
if (!(flags & MOPTF_QUIET) && mailvar_is_true ("variable-strict"))
{
if (!sym)
mu_diag_output (MU_DIAG_WARNING, _("setting unknown variable %s"),
......@@ -843,8 +842,7 @@ mailvar_print (int set)
varlist = mailvar_list_copy (set);
mu_list_count (varlist, &count);
clos.out = open_pager (count);
clos.prettyprint = mailvar_get (NULL, "variable-pretty-print",
mailvar_type_boolean, 0) == 0;
clos.prettyprint = mailvar_is_true ("variable-pretty-print");
clos.width = util_screen_columns ();
mu_list_foreach (varlist, mailvar_printer, &clos);
......
......@@ -55,7 +55,7 @@ mail_pipe (int argc, char **argv)
mu_message_get_streamref (msg, &stream);
mu_stream_copy (outstr, stream, 0, NULL);
mu_stream_destroy (&stream);
if (mailvar_get (NULL, "page", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("page"))
mu_stream_write (outstr, "\f\n", 2, NULL);
}
util_mark_read (msg);
......
......@@ -36,7 +36,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
int status;
mu_message_lines (mesg, &lines);
if (mailvar_get (NULL, "showenvelope", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("showenvelope"))
lines++;
/* If it is POP or IMAP the lines number is not known, so try
......@@ -57,7 +57,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
out = open_pager (lines);
if (mailvar_get (NULL, "showenvelope", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("showenvelope"))
print_envelope (mspec, mesg, "From");
if (*(int *) data) /* print was called with a lowercase 'p' */
......
......@@ -39,7 +39,7 @@ mail_mbox_close ()
if (!mbox)
return 0;
if (mailvar_get (NULL, "readonly", mailvar_type_boolean, 0))
if (!mailvar_is_true ("readonly"))
{
if (mail_mbox_commit ())
return 1;
......@@ -67,8 +67,8 @@ mail_mbox_commit ()
int saved_count = 0;
mu_message_t msg;
mu_attribute_t attr;
int keepsave = mailvar_get (NULL, "keepsave", mailvar_type_boolean, 0) == 0;
int hold = mailvar_get (NULL, "hold", mailvar_type_boolean, 0) == 0;
int keepsave = mailvar_is_true ("keepsave");
int hold = mailvar_is_true ("hold");
mu_url_t url;
int is_user_mbox;
......
......@@ -83,8 +83,7 @@ reply0 (msgset_t *mspec, mu_message_t msg, void *data)
const char *email;
if (mu_address_sget_email (addr, i, &email) || email == NULL)
continue;
if ((mailvar_get (NULL, "metoo", mailvar_type_boolean, 0) == 0)
|| !mail_is_my_name (email))
if (mailvar_is_true ("metoo") || !mail_is_my_name (email))
compose_header_set (&env, MU_HEADER_TO,
email,
COMPOSE_SINGLE_LINE);
......@@ -121,9 +120,7 @@ reply0 (msgset_t *mspec, mu_message_t msg, void *data)
make_in_reply_to (&env, msg);
make_references (&env, msg);
status = mail_send0 (&env,
mailvar_get (NULL, "byname", mailvar_type_boolean, 0)
== 0);
status = mail_send0 (&env, mailvar_is_true ("byname"));
compose_destroy (&env);
return status;
......@@ -133,7 +130,7 @@ int
mail_reply (int argc, char **argv)
{
int lower = mu_islower (argv[0][0]);
if (mailvar_get (NULL, "flipr", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("flipr"))
lower = !lower;
return util_foreach_msg (argc, argv, MSG_NODELETED, reply0, &lower);
}
......
......@@ -619,10 +619,10 @@ add_attachments (compose_env_t *env, mu_message_t *pmsg)
static void
read_cc_bcc (compose_env_t *env)
{
if (mailvar_get (NULL, "askcc", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("askcc"))
compose_header_set (env, MU_HEADER_CC,
ml_readline_with_intr ("Cc: "), COMPOSE_REPLACE);
if (mailvar_get (NULL, "askbcc", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("askbcc"))
compose_header_set (env, MU_HEADER_BCC,
ml_readline_with_intr ("Bcc: "), COMPOSE_REPLACE);
}
......@@ -655,7 +655,7 @@ mail_send (int argc, char **argv)
if (interactive)
compose_header_set (&env, MU_HEADER_TO, ml_readline_with_intr ("To: "),
COMPOSE_REPLACE);
else if (!mailvar_get (NULL, "editheaders", mailvar_type_boolean, 0))
else if (mailvar_is_true ("editheaders"))
{
if (parse_headers (mu_strin, &env) != parse_headers_ok)
{
......@@ -710,10 +710,10 @@ mail_send (int argc, char **argv)
if (interactive)
{
if (mailvar_get (NULL, "mailx", mailvar_type_boolean, 0))
if (!mailvar_is_true ("mailx"))
read_cc_bcc (&env);
if (mailvar_get (NULL, "asksub", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("asksub"))
compose_header_set (&env, MU_HEADER_SUBJECT,
ml_readline_with_intr ("Subject: "),
COMPOSE_REPLACE);
......@@ -859,8 +859,7 @@ compose_header_set (compose_env_t *env, const char *name,
switch (mode)
{
case COMPOSE_REPLACE:
if (is_address_field (name)
&& mailvar_get (NULL, "inplacealiases", mailvar_type_boolean, 0) == 0)
if (is_address_field (name) && mailvar_is_true ("inplacealiases"))
{
char *exp = alias_expand (value);
status = mu_header_set_value (env->header, name, exp ? exp : value, 1);
......@@ -871,8 +870,7 @@ compose_header_set (compose_env_t *env, const char *name,
break;
case COMPOSE_APPEND:
if (is_address_field (name)
&& mailvar_get (NULL, "inplacealiases", mailvar_type_boolean, 0) == 0)
if (is_address_field (name) && mailvar_is_true ("inplacealiases"))
{
char *exp = alias_expand (value);
status = mu_header_append (env->header, name, exp ? exp : value);
......@@ -886,8 +884,7 @@ compose_header_set (compose_env_t *env, const char *name,
if (mu_header_aget_value (env->header, name, &old_value) == 0
&& old_value[0])
{
if (is_address_field (name)
&& mailvar_get (NULL, "inplacealiases", mailvar_type_boolean, 0) == 0)
if (is_address_field (name) && mailvar_is_true ("inplacealiases"))
{
char *exp = alias_expand (value);
status = util_merge_addresses (&old_value, exp ? exp : value);
......@@ -971,7 +968,7 @@ fill_body (mu_message_t msg, mu_stream_t instr)
if (n == 0)
{
if (mailvar_get (NULL, "nullbody", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("nullbody"))
{
char *str;
if (mailvar_get (&str, "nullbodymsg", mailvar_type_string, 0) == 0)
......@@ -987,7 +984,7 @@ fill_body (mu_message_t msg, mu_stream_t instr)
static int
save_dead_message_env (compose_env_t *env)
{
if (mailvar_get (NULL, "save", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("save"))
{
mu_stream_t dead_letter, str;
int rc;
......@@ -1005,8 +1002,7 @@ save_dead_message_env (compose_env_t *env)
mu_error (_("Cannot open file %s: %s"), name, strerror (rc));
return 1;
}
if (mailvar_get (NULL, "appenddeadletter",
mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("appenddeadletter"))
mu_stream_seek (dead_letter, 0, MU_SEEK_END, NULL);
else
mu_stream_truncate (dead_letter, 0);
......@@ -1039,7 +1035,7 @@ save_dead_message_env (compose_env_t *env)
static int
save_dead_message (mu_message_t msg)
{
if (mailvar_get (NULL, "save", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("save"))
{
mu_stream_t dead_letter, str;
int rc;
......@@ -1057,8 +1053,7 @@ save_dead_message (mu_message_t msg)
mu_error (_("Cannot open file %s: %s"), name, strerror (rc));
return 1;
}
if (mailvar_get (NULL, "appenddeadletter",
mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("appenddeadletter"))
mu_stream_seek (dead_letter, 0, MU_SEEK_END, NULL);
else
mu_stream_truncate (dead_letter, 0);
......@@ -1117,7 +1112,7 @@ send_message (mu_message_t msg)
}
}
if (mailvar_get (NULL, "verbose", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("verbose"))
{
mu_debug_set_category_level (MU_DEBCAT_MAILER,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
......@@ -1188,7 +1183,7 @@ mail_send0 (compose_env_t *env, int save_to)
if (ml_got_interrupt ())
{
if (mailvar_get (NULL, "ignore", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("ignore"))
{
mu_printf ("@\n");
}
......@@ -1205,12 +1200,11 @@ mail_send0 (compose_env_t *env, int save_to)
if (!buf)
{
if (interactive
&& mailvar_get (NULL, "ignoreeof", mailvar_type_boolean, 0) == 0)
if (interactive && mailvar_is_true ("ignoreeof"))
{
mu_error (mailvar_get (NULL, "dot", mailvar_type_boolean, 0) == 0 ?
_("Use \".\" to terminate letter.") :
_("Use \"~.\" to terminate letter."));
mu_error (mailvar_is_true ("dot")
? _("Use \".\" to terminate letter.")
: _("Use \"~.\" to terminate letter."));
continue;
}
else
......@@ -1219,8 +1213,7 @@ mail_send0 (compose_env_t *env, int save_to)
int_cnt = 0;
if (strcmp (buf, ".") == 0
&& mailvar_get (NULL, "dot", mailvar_type_boolean, 0) == 0)
if (strcmp (buf, ".") == 0 && mailvar_is_true ("dot"))
done = 1;
else if (mailvar_get (&escape, "escape", mailvar_type_string, 0) == 0
&& buf[0] == escape[0])
......@@ -1276,13 +1269,12 @@ mail_send0 (compose_env_t *env, int save_to)
/* In mailx compatibility mode, ask for Cc and Bcc after editing
the body of the message */
if (mailvar_get (NULL, "mailx", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("mailx"))
read_cc_bcc (env);
/* Prepare the header */
if (mailvar_get (NULL, "xmailer", mailvar_type_boolean, 0) == 0)
mu_header_set_value (env->header, MU_HEADER_X_MAILER,
program_version, 1);
if (mailvar_is_true ("xmailer"))
mu_header_set_value (env->header, MU_HEADER_X_MAILER, program_version, 1);
if (util_header_expand (&env->header) == 0)
{
......
......@@ -78,7 +78,7 @@ mail_execute (int shell, char *progname, int argc, char **argv)
xargv = mu_calloc (xargc + 1, sizeof (xargv[0]));
/* Expand arguments if required */
if (mailvar_get (NULL, "bang", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("bang"))
{
int i;
char *last = NULL;
......
......@@ -403,7 +403,7 @@ util_get_crt ()
if (mailvar_get (&lines, "crt", mailvar_type_number, 0) == 0)
return lines;
else if (mailvar_get (NULL, "crt", mailvar_type_boolean, 0) == 0)
else if (mailvar_is_true ("crt"))
return util_getlines ();
return 0;
}
......@@ -931,12 +931,11 @@ util_header_expand (mu_header_t *phdr)
mu_address_t new_addr;
char *p = ws.ws_wordv[j];
/* If inplacealiases was set, the value was already expanded */
if (mailvar_get (NULL, "inplacealiases",
mailvar_type_boolean, 0))
exp = alias_expand (p);
else
if (mailvar_is_true ("inplacealiases"))
/* If inplacealiases was set, the value was already expanded */
exp = p;
else
exp = alias_expand (p);
rc = mu_address_create (&new_addr, p);
if (rc)
{
......@@ -1072,7 +1071,7 @@ util_rfc2047_decode (char **value)
rc = mu_rfc2047_decode (charset, *value, &tmp);
if (rc)
{
if (mailvar_get (NULL, "verbose", mailvar_type_boolean, 0) == 0)
if (mailvar_is_true ("verbose"))
mu_error (_("Cannot decode line `%s': %s"), *value, mu_strerror (rc));
}
else
......