X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=init.c;h=1f5d36570e6f9a3fbc86812db62126a497ba2d0d;hp=76bb0851db9685033c52b2b880acaf5fdcbc83a8;hb=fa54675b6ceb98bce1a8931b7cc5b70ecedf4225;hpb=bbc4fd52516a8afefbd14c77e34f8389d6f0a6ed diff --git a/init.c b/init.c index 76bb085..1f5d365 100644 --- a/init.c +++ b/init.c @@ -27,6 +27,10 @@ #include "mutt_ssl.h" #endif +#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS)) +#include "mutt_libesmtp.h" +#endif + #include "mx.h" #include "init.h" @@ -54,11 +58,28 @@ typedef struct { } syn_t; /* for synonym warning reports: list of synonyms found */ -list2_t* Synonyms; +static list2_t* Synonyms; /* for synonym warning reports: current rc file */ -char* CurRCFile = NULL; +static const char* CurRCFile = NULL; /* for synonym warning reports: current rc line */ -int CurRCLine = 0; +static int CurRCLine = 0; + +/* prototypes for checking for special vars */ +static int check_dsn_return (const char*); +static int check_dsn_notify (const char*); + +static struct { + const char* name; + int (*check) (const char*); +} SpecialVars[] = { + { "dsn_notify", check_dsn_notify }, + { "dsn_return", check_dsn_return }, +#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS)) + { "smtp_use_tls", mutt_libesmtp_check_usetls }, +#endif + /* last */ + { NULL, NULL } +}; /* for synonym warning reports: adds synonym to end of list */ static void syn_add (int n, int o) { @@ -976,6 +997,47 @@ static void mutt_restore_default (struct option_t *p) set_option (OPTREDRAWTREE); } +/* check whether value for $dsn_return would be valid */ +static int check_dsn_return (const char* val) { + if (val && *val && str_ncmp (val, "hdrs", 4) != 0 && + str_ncmp (val, "full", 4) != 0) + return (0); + return (1); +} + +/* check whether value for $dsn_notify would be valid */ +static int check_dsn_notify (const char* val) { + list2_t* list = NULL; + int i = 0, rc = 1; + + if (!val || !*val) + return (1); + list = list_from_str (val, ","); + if (list_empty (list)) + return (1); + + for (i = 0; i < list->length; i++) + if (str_ncmp (list->data[i], "never", 5) != 0 && + str_ncmp (list->data[i], "failure", 7) != 0 && + str_ncmp (list->data[i], "delay", 5) != 0 && + str_ncmp (list->data[i], "success", 7) != 0) { + rc = 0; + break; + } + list_del (&list, (list_del_t*) _mem_free); + return (rc); +} + +static int check_special (const char* name, const char* val) { + int i = 0; + + for (i = 0; SpecialVars[i].name; i++) { + if (str_cmp (SpecialVars[i].name, name) == 0) + return (SpecialVars[i].check (val)); + } + return (1); +} + static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, BUFFER * err) { @@ -1110,9 +1172,17 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, *((char **) MuttVars[idx].data) = str_dup (scratch); } else if (DTYPE (MuttVars[idx].type) == DT_STR) { - *((char **) MuttVars[idx].data) = str_dup (tmp->data); - if (str_cmp (MuttVars[idx].option, "charset") == 0) - mutt_set_charset (Charset); + /* see if the value may only be a certain value... */ + if (check_special (MuttVars[idx].option, tmp->data)) { + *((char **) MuttVars[idx].data) = str_dup (tmp->data); + if (str_cmp (MuttVars[idx].option, "charset") == 0) + mutt_set_charset (Charset); + } else { + /* ... and abort if it fails */ + snprintf (err->data, err->dsize, "'%s' is invalid for $%s", + tmp->data, MuttVars[idx].option); + return (-1); + } } else { *((ADDRESS **) MuttVars[idx].data) = @@ -1391,8 +1461,6 @@ static int source_rc (const char *rcfile, BUFFER * err) pid_t pid; debug_print (2, ("reading configuration file '%s'.\n", rcfile)); - str_replace (&CurRCFile, rcfile); - CurRCLine = 0; if ((f = mutt_open_read (rcfile, &pid)) == NULL) { snprintf (err->data, err->dsize, "%s: %s", rcfile, strerror (errno)); @@ -1401,7 +1469,6 @@ static int source_rc (const char *rcfile, BUFFER * err) memset (&token, 0, sizeof (token)); while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) { - CurRCLine++; conv = ConfigCharset && (*ConfigCharset) && Charset; if (conv) { currentline = str_dup (linebuf); @@ -1412,6 +1479,9 @@ static int source_rc (const char *rcfile, BUFFER * err) else currentline = linebuf; + CurRCLine = line; + CurRCFile = rcfile; + if (mutt_parse_rc_line (currentline, &token, err) == -1) { mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data); if (--rc < -MAXERRS) { @@ -2080,14 +2150,18 @@ void mutt_init (int skip_sys_rc, LIST * commands) if (!Muttrc) { +#if 0 snprintf (buffer, sizeof (buffer), "%s/.muttngrc-%s", NONULL (Homedir), MUTT_VERSION); if (access (buffer, F_OK) == -1) +#endif snprintf (buffer, sizeof (buffer), "%s/.muttngrc", NONULL (Homedir)); if (access (buffer, F_OK) == -1) +#if 0 snprintf (buffer, sizeof (buffer), "%s/.muttng/muttngrc-%s", NONULL (Homedir), MUTT_VERSION); if (access (buffer, F_OK) == -1) +#endif snprintf (buffer, sizeof (buffer), "%s/.muttng/muttngrc", NONULL (Homedir)); @@ -2154,12 +2228,10 @@ void mutt_init (int skip_sys_rc, LIST * commands) MuttVars[((syn_t*) Synonyms->data[i])->n].option, NONULL(((syn_t*) Synonyms->data[i])->f), ((syn_t*) Synonyms->data[i])->l); - fprintf (stderr, _("Warning: Synonym variables are scheduled for removal.\n")); + fprintf (stderr, _("Warning: synonym variables are scheduled for removal.\n")); list_del (&Synonyms, syn_del); need_pause = 1; } - /* this is not needed during runtime */ - mem_free(&CurRCFile); if (need_pause && !option (OPTNOCURSES)) { if (mutt_any_key_to_continue (NULL) == -1) @@ -2215,7 +2287,7 @@ int mutt_dump_variables (void) { snprintf (command, sizeof (command), "set ?%s\n", ((struct option_t*) tmp->data[i])->option); if (mutt_parse_rc_line (command, &token, &err) == -1) { - fprintf (stderr, "%s\n", err.data); + printf ("%s\n", err.data); mem_free (&token.data); list_del (&tmp, NULL); return 1;