-
- /* not reached */
-}
-
-static void add_to_list (string_list_t ** list, const char *str)
-{
- string_list_t *t, *last = NULL;
-
- /* don't add a NULL or empty string to the list */
- if (!str || *str == '\0')
- return;
-
- /* check to make sure the item is not already on this list */
- for (last = *list; last; last = last->next) {
- if (ascii_strcasecmp (str, last->data) == 0) {
- /* already on the list, so just ignore it */
- last = NULL;
- break;
- }
- if (!last->next)
- break;
- }
-
- if (!*list || last) {
- t = p_new(string_list_t, 1);
- t->data = m_strdup(str);
- if (last) {
- last->next = t;
- last = last->next;
- }
- else
- *list = last = t;
- }
-}
-
-static int
-add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err)
-{
- rx_t* rx;
-
- if (m_strisempty(s))
- return 0;
-
- if (rx_lookup(list, s))
- return 0;
-
- rx = rx_compile(s, flags);
- if (!rx) {
- snprintf(err->data, err->dsize, "Bad regexp: %s\n", s);
- return -1;
- }
-
- rx_list_append(list, rx);
- return 0;
-}
-
-static int add_to_spam_list(rx_t **list, const char *pat,
- const char *templ, BUFFER * err)
-{
- rx_t **last, *rx;
-
- if (m_strisempty(pat) || !templ)
- return 0;
-
- if (!(rx = rx_compile (pat, REG_ICASE))) {
- snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
- return -1;
- }
-
- /* check to make sure the item is not already on this list */
- for (last = list; *last; last = &(*last)->next) {
- if (!ascii_strcasecmp(rx->pattern, (*last)->pattern) == 0) {
- rx_t *tmp = rx_list_pop(last);
- rx_delete(&tmp);
- last = rx_list_last(last);
- break;
- }
- }
-
- *last = rx;
- rx_set_template(rx, templ);
- return 0;
-}
-
-static int remove_from_spam_list (rx_t ** list, const char *pat)
-{
- int nremoved = 0;
-
- while (*list) {
- if (!m_strcmp((*list)->pattern, pat)) {
- rx_t *spam = rx_list_pop(list);
- rx_delete(&spam);
- nremoved++;
- } else {
- list = &(*list)->next;
- }
- }
-
- return nremoved;
-}
-
-
-static void remove_from_list (string_list_t ** l, const char *str)
-{
- string_list_t *p, *last = NULL;
-
- if (m_strcmp("*", str) == 0)
- string_list_wipe(l); /* ``unCMD *'' means delete all current entries */
- else {
- p = *l;
- last = NULL;
- while (p) {
- if (ascii_strcasecmp (str, p->data) == 0) {
- p_delete(&p->data);
- if (last)
- last->next = p->next;
- else
- (*l) = p->next;
- p_delete(&p);
- }
- else {
- last = p;
- p = p->next;
- }
- }
- }
-}
-
-static int remove_from_rx_list(rx_t **l, const char *str)
-{
- if (m_strcmp("*", str) == 0) {
- rx_list_wipe(l);
- return 0;
- }
-
- l = rx_lookup(l, str);
- if (l) {
- rx_t *r = rx_list_pop(l);
- rx_delete(&r);
- return 0;
- }
-
- return -1;
-}
-
-static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
- BUFFER * err)
-{
- int i, j;
- unsigned long res = 0;
- BUFFER token;
- struct option_t* option = NULL;
-
- p_clear(&token, 1);
- mutt_extract_token (tmp, s, 0);
-
- /* is the item defined as a variable or a function? */
- if ((option = hash_find (ConfigOptions, tmp->data)) != NULL)
- res = 1;
- else {
- for (i = 0; !res && i < MENU_MAX; i++) {
- struct binding_t *b = km_get_table (Menus[i].value);
-
- if (!b)
- continue;
-
- for (j = 0; b[j].name; j++)
- if (!ascii_strncasecmp (tmp->data, b[j].name, m_strlen(tmp->data))
- && (m_strlen(b[j].name) == m_strlen(tmp->data))) {
- res = 1;
- break;
- }
- }
- }
- /* check for feature_* */
- if (!res && ascii_strncasecmp (tmp->data, "feature_", 8) == 0 &&
- (j = m_strlen(tmp->data)) > 8) {
- i = 0;
- while (Features[i]) {
- if (m_strlen(Features[i]) == j-8 &&
- ascii_strncasecmp (Features[i], tmp->data+8, j-8) == 0) {
- res = 1;
- break;
- }
- i++;
- }
- }
-
- if (!MoreArgs (s)) {
- if (data)
- snprintf (err->data, err->dsize, _("ifdef: too few arguments"));
- else
- snprintf (err->data, err->dsize, _("ifndef: too few arguments"));
- return (-1);
- }
-
- mutt_extract_token (tmp, s, M_TOKEN_SPACE);
-
- if (data == res) {
- if (mutt_parse_rc_line (tmp->data, &token, err) == -1) {
- mutt_error ("Error: %s", err->data);
- p_delete(&token.data);
- return (-1);
- }
- p_delete(&token.data);
- }
- return 0;
-}
-
-static int parse_unignore (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- do {
- mutt_extract_token (buf, s, 0);
-
- /* don't add "*" to the unignore list */
- if (strcmp (buf->data, "*"))
- add_to_list (&UnIgnore, buf->data);
-
- remove_from_list (&Ignore, buf->data);
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static int parse_ignore (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- do {
- mutt_extract_token (buf, s, 0);
- remove_from_list (&UnIgnore, buf->data);
- add_to_list (&Ignore, buf->data);
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static int parse_list (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- do {
- mutt_extract_token (buf, s, 0);
- add_to_list ((string_list_t **) data, buf->data);
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static void _alternates_clean (void)
-{
- int i;
-
- if (Context && Context->msgcount) {
- for (i = 0; i < Context->msgcount; i++)
- Context->hdrs[i]->recip_valid = 0;
- }
-}
-
-static int parse_alternates (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- _alternates_clean ();
- do {
- mutt_extract_token (buf, s, 0);
- remove_from_rx_list (&UnAlternates, buf->data);
-
- if (add_to_rx_list (&Alternates, buf->data, REG_ICASE, err) != 0)
- return -1;
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static int parse_unalternates (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- _alternates_clean ();
- do {
- mutt_extract_token (buf, s, 0);
- remove_from_rx_list (&Alternates, buf->data);
-
- if (m_strcmp(buf->data, "*") &&
- add_to_rx_list (&UnAlternates, buf->data, REG_ICASE, err) != 0)
- return -1;
-
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data,
- BUFFER * err)
-{
- BUFFER templ;
-
- p_clear(&templ, 1);
-
- /* Insist on at least one parameter */
- if (!MoreArgs (s)) {
- if (data == M_SPAM)
- m_strcpy(err->data, err->dsize, _("spam: no matching pattern"));
- else
- m_strcpy(err->data, err->dsize, _("nospam: no matching pattern"));
- return -1;
- }
-
- /* Extract the first token, a regexp */
- mutt_extract_token (buf, s, 0);
-
- /* data should be either M_SPAM or M_NOSPAM. M_SPAM is for spam commands. */
- if (data == M_SPAM) {
- /* If there's a second parameter, it's a template for the spam tag. */
- if (MoreArgs (s)) {
- mutt_extract_token (&templ, s, 0);
-
- /* Add to the spam list. */
- if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) {
- p_delete(&templ.data);
- return -1;
- }
- p_delete(&templ.data);
- }
-
- /* If not, try to remove from the nospam list. */
- else {
- remove_from_rx_list (&NoSpamList, buf->data);
- }
-
- return 0;
- }
-
- /* M_NOSPAM is for nospam commands. */
- else if (data == M_NOSPAM) {
- /* nospam only ever has one parameter. */
-
- /* "*" is a special case. */
- if (!m_strcmp(buf->data, "*")) {
- rx_list_wipe(&SpamList);
- rx_list_wipe(&NoSpamList);
- return 0;
- }
-
- /* If it's on the spam list, just remove it. */
- if (remove_from_spam_list (&SpamList, buf->data) != 0)
- return 0;
-
- /* Otherwise, add it to the nospam list. */
- if (add_to_rx_list (&NoSpamList, buf->data, REG_ICASE, err) != 0)
- return -1;
-
- return 0;
- }
-
- /* This should not happen. */
- m_strcpy(err->data, err->dsize, "This is no good at all.");
- return -1;