aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-10 17:48:33 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-10 17:48:33 +0200
commitb4df49565fad59748e05bda5cd186d8cc1792ffa (patch)
tree0b090fb70a9894f06d7be5a35780436ba31dc2b3
parent2c0ace3d828a0df7360845dce4c8967f7f9dae37 (diff)
downloadmblaze-b4df49565fad59748e05bda5cd186d8cc1792ffa.tar.gz
mscan: add %S for stripped subject
-rw-r--r--man/mscan.16
-rw-r--r--mscan.c27
2 files changed, 30 insertions, 3 deletions
diff --git a/man/mscan.1 b/man/mscan.1
index 1ac55c6..622499d 100644
--- a/man/mscan.1
+++ b/man/mscan.1
@@ -123,6 +123,12 @@ if the message is from us).
spaces per indentation depth in the thread tree.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "s"
The subject of the message (defaults to remaining width).
+.It Cm "%" Ns Oo Ar wd Oc Ns Cm "S"
+The subject of the message (defaults to remaining width),
+with leading
+.Sq Li Re: ,
+.Sq Li Fwd:
+etc. stripped.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "b"
Human-readable size of the message (in kilobytes).
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "F"
diff --git a/mscan.c b/mscan.c
index b2b5cb2..684faae 100644
--- a/mscan.c
+++ b/mscan.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
@@ -151,7 +152,7 @@ fmt_date(struct message *msg, int w, int iso)
}
static char *
-fmt_subject(struct message *msg, char *file)
+fmt_subject(struct message *msg, char *file, int strip)
{
static char subjdec[100];
char *subj = "(no subject)";
@@ -167,6 +168,25 @@ fmt_subject(struct message *msg, char *file)
blaze822_decode_rfc2047(subjdec, subj, sizeof subjdec - 1, "UTF-8");
+ if (strip) {
+ size_t i;
+ for (i = 0; subjdec[i]; ) {
+ if (subjdec[i] == ' ') {
+ i++;
+ continue;
+ } else if (strncasecmp("re:", subjdec+i, 3) == 0 ||
+ strncasecmp("aw:", subjdec+i, 3) == 0) {
+ i += 3;
+ continue;
+ } else if (strncasecmp("fwd:", subjdec+i, 4) == 0) {
+ i += 4;
+ continue;
+ }
+ break;
+ }
+ return subjdec + i;
+ }
+
return subjdec;
}
@@ -382,12 +402,13 @@ oneline(char *file)
}
break;
case 's':
+ case 'S':
if (w)
wleft -= u8putstr(stdout,
- fmt_subject(msg, file), w, 1);
+ fmt_subject(msg, file, *f == 'S'), w, 1);
else
wleft -= u8putstr(stdout,
- fmt_subject(msg, file), wleft, 0);
+ fmt_subject(msg, file, *f == 'S'), wleft, 0);
break;
case 'b':
{