- if (!s) return 0;
-
- for (; l; l = l->next)
- {
- if (regexec (l->rx->rx, s, (size_t) 0, (regmatch_t *) 0, (int) 0) == 0)
- {
- dprint (5, (debugfile, "mutt_match_rx_list: %s matches %s\n", s, l->rx->pattern));
+ static regmatch_t *pmatch = NULL;
+ static int nmatch = 0;
+ int i, n, tlen;
+ char *p;
+
+ if (!s)
+ return 0;
+
+ tlen = 0;
+
+ for (; l; l = l->next) {
+ /* If this pattern needs more matches, expand pmatch. */
+ if (l->nmatch > nmatch) {
+ safe_realloc (&pmatch, l->nmatch * sizeof (regmatch_t));
+ nmatch = l->nmatch;
+ }
+
+ /* Does this pattern match? */
+ if (regexec
+ (l->rx->rx, s, (size_t) l->nmatch, (regmatch_t *) pmatch,
+ (int) 0) == 0) {
+ dprint (5,
+ (debugfile, "mutt_match_spam_list: %s matches %s\n", s,
+ l->rx->pattern));
+ dprint (5,
+ (debugfile, "mutt_match_spam_list: %d subs\n",
+ l->rx->rx->re_nsub));
+
+ /* Copy template into text, with substitutions. */
+ for (p = l->template; *p;) {
+ if (*p == '%') {
+ n = atoi (++p); /* find pmatch index */
+ while (isdigit (*p))
+ ++p; /* skip subst token */
+ for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
+ text[tlen++] = s[i];
+ }
+ else {
+ text[tlen++] = *p++;
+ }
+ }
+ text[tlen] = '\0';
+ dprint (5, (debugfile, "mutt_match_spam_list: \"%s\"\n", text));