summaryrefslogtreecommitdiffstats
path: root/hdrline.c
diff options
context:
space:
mode:
authorDavid Champion <dgc@bikeshed.us>2017-01-23 19:01:50 -0800
committerDavid Champion <dgc@bikeshed.us>2017-01-23 19:01:50 -0800
commit0663272c47d0a858a4fc3bc14d3e67959292f6ad (patch)
treeafd513bfe4225f9057815888ecbe506cc42b32fb /hdrline.c
parent149ed356ffaad6ebf3a0d2d55c96e3414398b9eb (diff)
Add subjectrx command to replace matching subjects with something else.
This lets you define regular expressions-replacement pairs for subject display. When a Subject: matches the regular expression, the replacement value will be displayed instead in the message index. Backreferences are supported. This is especially nice for simplifying subjects that are overly wordy, such as mailing list posts (with [Listname] tags, etc), mail from ticketing systems or bug trackers, etc. It lets you reduce clutter in your mutt display without altering the messages themselves.
Diffstat (limited to 'hdrline.c')
-rw-r--r--hdrline.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/hdrline.c b/hdrline.c
index 10248469..ba118bf5 100644
--- a/hdrline.c
+++ b/hdrline.c
@@ -199,6 +199,22 @@ int mutt_user_is_recipient (HEADER *h)
return h->recipient;
}
+static char *apply_subject_mods (ENVELOPE *env)
+{
+ if (env == NULL)
+ return NULL;
+
+ if (SubjectRxList == NULL)
+ return env->subject;
+
+ if (env->subject == NULL || *env->subject == '\0')
+ return env->disp_subj = NULL;
+
+ env->disp_subj = mutt_apply_replace(NULL, 0, env->subject, SubjectRxList);
+ return env->disp_subj;
+}
+
+
/* %a = address of author
* %A = reply-to address (if present; otherwise: address of author
* %b = filename of the originating folder
@@ -566,20 +582,28 @@ hdr_format_str (char *dest,
break;
case 's':
-
- if (flags & MUTT_FORMAT_TREE && !hdr->collapsed)
{
- if (flags & MUTT_FORMAT_FORCESUBJ)
+ char *subj;
+ if (hdr->env->disp_subj)
+ subj = hdr->env->disp_subj;
+ else if (SubjectRxList)
+ subj = apply_subject_mods(hdr->env);
+ else
+ subj = hdr->env->subject;
+ if (flags & MUTT_FORMAT_TREE && !hdr->collapsed)
{
- mutt_format_s (dest, destlen, "", NONULL (hdr->env->subject));
- snprintf (buf2, sizeof (buf2), "%s%s", hdr->tree, dest);
- mutt_format_s_tree (dest, destlen, prefix, buf2);
+ if (flags & MUTT_FORMAT_FORCESUBJ)
+ {
+ mutt_format_s (dest, destlen, "", NONULL (subj));
+ snprintf (buf2, sizeof (buf2), "%s%s", hdr->tree, dest);
+ mutt_format_s_tree (dest, destlen, prefix, buf2);
+ }
+ else
+ mutt_format_s_tree (dest, destlen, prefix, hdr->tree);
}
else
- mutt_format_s_tree (dest, destlen, prefix, hdr->tree);
+ mutt_format_s (dest, destlen, prefix, NONULL (subj));
}
- else
- mutt_format_s (dest, destlen, prefix, NONULL (hdr->env->subject));
break;
case 'S':