about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile8
-rw-r--r--blaze822_priv.h6
-rwxr-xr-xcontrib/mgpg2
-rw-r--r--man/mblaze-profile.517
-rw-r--r--man/mblaze.73
-rw-r--r--man/mdirs.122
-rw-r--r--man/minc.13
-rwxr-xr-xmcolor6
-rwxr-xr-xmcom20
-rw-r--r--mdirs.c41
-rw-r--r--minc.c13
-rw-r--r--mscan.c10
-rw-r--r--rfc2047.c3
-rwxr-xr-xt/1100-mhdr.t26
-rw-r--r--t/9000-minc.t8
15 files changed, 150 insertions, 38 deletions
diff --git a/GNUmakefile b/GNUmakefile
index c90e938..d3c081e 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -26,10 +26,10 @@ SCRIPT = mcolor mcom mless mmkdir mquote museragent
 all: $(ALL) museragent
 
 $(ALL) : % : %.o
-maddr magrep mdeliver mexport mflag mflow mgenmid mhdr mpick mscan msed mshow \
-  msort mthread : blaze822.o mymemmem.o mytimegm.o
-maddr magrep mdeliver mexport mflag mgenmid mhdr mlist mpick mscan msed mseq \
-  mshow msort mthread : seq.o slurp.o mystrverscmp.o
+maddr magrep mdeliver mdirs mexport mflag mflow mgenmid mhdr mpick mscan msed \
+  mshow msort mthread : blaze822.o mymemmem.o mytimegm.o
+maddr magrep mdeliver mdirs mexport mflag mgenmid mhdr minc mlist mpick mscan \
+  msed mseq mshow msort mthread : seq.o slurp.o mystrverscmp.o
 maddr magrep mflow mhdr mpick mscan mshow : rfc2047.o
 magrep mflow mhdr mshow : rfc2045.o
 mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
diff --git a/blaze822_priv.h b/blaze822_priv.h
index a84c963..e5f4a09 100644
--- a/blaze822_priv.h
+++ b/blaze822_priv.h
@@ -12,9 +12,9 @@ struct message {
 
 #define isfws(c)  (((unsigned char)(c) == ' ' || (unsigned char)(c) == '\t' || (unsigned char)(c) == '\n' || (unsigned char)(c) == '\r'))
 
-// ASCII lowercase/uppercase without alpha check (wrong for "@[\]^_")
-#define lc(c) ((c) | 0x20)
-#define uc(c) ((c) & 0xdf)
+// 7bit-ASCII only lowercase/uppercase
+#define lc(c) (((unsigned)(c)-'A') < 26 ? ((c) | 0x20) : (c))
+#define uc(c) (((unsigned)(c)-'a') < 26 ? ((c) & 0xdf) : (c))
 
 // dirent type that can be a mail/dir (following symlinks)
 #if defined(DT_REG) && defined(DT_LNK) && defined(DT_UNKNOWN)
diff --git a/contrib/mgpg b/contrib/mgpg
index 4a46701..4190501 100755
--- a/contrib/mgpg
+++ b/contrib/mgpg
@@ -20,7 +20,7 @@ n=$(mshow -t "$tmp" | awk -F: '
 	/: application\/octet-stream/ {if (supported) print $1}')
 
 if [ "$n" ]; then
-	mshow -O "$tmp" "$n" | $GPG -d 2>&1 || exit 0
+	mshow -O "$tmp" "$n" | $GPG --quiet -d 2>&1 || exit 0
 	exit 64
 fi
 exit 63
diff --git a/man/mblaze-profile.5 b/man/mblaze-profile.5
index 65d1b3d..d0594f3 100644
--- a/man/mblaze-profile.5
+++ b/man/mblaze-profile.5
@@ -1,4 +1,4 @@
-.Dd June 18, 2021
+.Dd January 27, 2024
 .Dt MBLAZE-PROFILE 5
 .Os
 .Sh NAME
@@ -49,15 +49,24 @@ The fully qualified domain name used for
 .Li Message\&-Id\&:
 generation in
 .Xr mgenmid 1 .
+.It Li Maildir\&:
+If set,
+.Xr mdirs 1
+will use this maildir when no directories are supplied.
 .It Li Outbox\&:
 If set,
 .Xr mcom 1
-will create draft messages in this maildir,
-and save messages there after sending.
+will save messages in this maildir after sending.
+.It Li Drafts\&:
+If set,
+.Xr mcom 1
+will create draft messages in this maildir (defaults to Outbox).
 .It Li Reply-From\&:
-A comma-separated list of display name and mail address pairs, formatted like this:
+A comma-separated list of display name and mail address pairs,
+formatted like this:
 .Dl Li Primary Name <myname1@domain1>, Name v.2 <myname2@domain2>, \[dq]Name, My Third\[dq] <myname3@domain3>, ...
 The first of these that appears in the
+.Li Delivered-To\&: ,
 .Li To\&: ,
 .Li Cc\&: ,
 or
diff --git a/man/mblaze.7 b/man/mblaze.7
index 328bcef..da2aebf 100644
--- a/man/mblaze.7
+++ b/man/mblaze.7
@@ -163,6 +163,9 @@ thread it and look at it interactively:
 Or you could list the attachments of the 20 largest messages in your INBOX:
 .Dl mlist ~/Maildir/INBOX | msort -S | tail -20 | mshow -t
 .Pp
+Or delete messages beyond a certain age:
+.Dl mlist ~/Maildir/INBOX | mpick -t 'mtime < \&"-365d\&"' | xargs rm
+.Pp
 Or apply the patches from the current message:
 .Dl mshow -O . '*.diff' | patch
 .Pp
diff --git a/man/mdirs.1 b/man/mdirs.1
index 44ffae4..f564803 100644
--- a/man/mdirs.1
+++ b/man/mdirs.1
@@ -1,4 +1,4 @@
-.Dd January 22, 2020
+.Dd July 25, 2023
 .Dt MDIRS 1
 .Os
 .Sh NAME
@@ -17,6 +17,14 @@ for maildir
 folders and prints them,
 separated by newlines.
 .Pp
+If
+.Ar dirs
+is not present then use
+.Sq Li Maildir\&:
+from
+.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
+.Pq if set .
+.Pp
 To
 .Nm ,
 a maildir folder is a directory containing
@@ -36,10 +44,20 @@ Print folders separated by a NUL character.
 .It Fl a
 Traverse into all subfolders, without considering the maildir++ name conventions.
 .El
+.Sh ENVIRONMENT
+.Bl -tag -width Ds
+.It Ev MBLAZE
+Directory containing mblaze configuration.
+.Po
+Default:
+.Pa $HOME/.mblaze
+.Pc
+.El
 .Sh EXIT STATUS
 .Ex -std
 .Sh SEE ALSO
-.Xr find 1
+.Xr find 1 ,
+.Xr mblaze-profile 5
 .Sh AUTHORS
 .An Leah Neukirchen Aq Mt leah@vuxu.org
 .Sh LICENSE
diff --git a/man/minc.1 b/man/minc.1
index cb71c85..6b7f96c 100644
--- a/man/minc.1
+++ b/man/minc.1
@@ -17,6 +17,9 @@ by moving them from
 to
 .Pa cur ,
 and adjusting the filenames.
+If used non-interactively with no specified folders,
+.Nm
+reads directory names from the standard input.
 .Pp
 By default, the new filenames are printed,
 separated by newlines.
diff --git a/mcolor b/mcolor
index ba2c42c..6e3417f 100755
--- a/mcolor
+++ b/mcolor
@@ -8,14 +8,18 @@ BEGIN { hdr = 1; if ("NO_COLOR" in ENVIRON || match(ENVIRON["TERM"], "^(dumb|net
 no_color { print; next }
 /\r$/ { sub(/\r$/, "") }
 /^\014$/ { nextmail = 1; print(fg(co("FF",232), $0)); next }
-/^$/ { hdr = 0 }
+/^$/ { hdr = 0; diff = 0 }
 /^-- $/ { ftr = 1 }
+/^diff -/ { diff = 1 }
 /^--- .* ---/ { print fg(co("SEP",242), $0); ftr = 0; sig = 0; next }
 /^-----BEGIN .* SIGNATURE-----/ { sig = 1 }
 nextmail && /^From:/ { hdr = 1 }
 hdr && /^From:/ { print so(fg(co("FROM",119), $0)); next }
 hdr { print fg(co("HEADER",120), $0); next }
 ftr { print fg(co("FOOTER",244), $0); next }
+diff && /^-/ { print fg(co("DIFF_D",160), $0); next }
+diff && /^\+/ { print fg(co("DIFF_I",40), $0); next }
+diff && /^@/ { print fg(co("DIFF_R",226), $0); next }
 /^-----BEGIN .* MESSAGE-----/ ||
 /^-----END .* SIGNATURE-----/ { print fg(co("SIG",244), $0); sig = 0; next }
 sig { print fg(co("SIG",244), $0); next }
diff --git a/mcom b/mcom
index fb48401..4e834c6 100755
--- a/mcom
+++ b/mcom
@@ -236,7 +236,9 @@ esac
 hdrs="$(printf '%s\n' "${hdrs#$NL}" | mhdr -)"
 
 outbox=$(mhdr -h outbox "$MBLAZE/profile" | sed "s:^~/:$HOME/:")
-if [ -z "$outbox" ]; then
+draftbox=$(mhdr -h drafts "$MBLAZE/profile" | sed "s:^~/:$HOME/:")
+draftbox="${draftbox:-$outbox}"
+if [ -z "$draftbox" ]; then
 	if [ -z "$resume" ]; then
 		i=0
 		while [ -f "snd.$i" ]; do
@@ -249,13 +251,13 @@ if [ -z "$outbox" ]; then
 	draftmime="$draft.mime"
 else
 	if [ -z "$resume" ]; then
-		draft="$(true | mdeliver -v -c -XD "$outbox")"
+		draft="$(true | mdeliver -v -c -XD "$draftbox")"
 		if [ -z "$draft" ]; then
-			printf '%s\n' "$0: failed to create draft in outbox $outbox." 1>&2
+			printf '%s\n' "$0: failed to create draft in outbox $draftbox." 1>&2
 			exit 1
 		fi
 	elif [ -z "$draft" ]; then
-		draft=$(mlist -D "$outbox" | msort -r -M | sed 1q)
+		draft=$(mlist -D "$draftbox" | msort -r -M | sed 1q)
 	fi
 	draftmime="$(printf '%s\n' "$draft" | sed 's,\(.*\)/cur/,\1/tmp/mime-,')"
 fi
@@ -323,7 +325,7 @@ fi
 	*mbnc*)
 		old_ifs="$IFS"
 		IFS=$NL
-		set -- $(mseq -- "$@")
+		set -- $(mseq -r -- "$@")
 		IFS="$old_ifs"
 		if [ "$#" -ne 1 ]; then
 			printf 'mbnc: needs exactly one mail to bounce\n' 1>&2
@@ -343,13 +345,13 @@ fi
 		printf 'Resent-Date: %s\n' "$(mdate)"
 		(
 			IFS=$NL
-			cat $(mseq -- "$@")
+			cat $(mseq -r -- "$@")
 		)
 		;;
 	*mrep*)
 		old_ifs="$IFS"
 		IFS=$NL
-		set -- $(mseq -- "$@")
+		set -- $(mseq -r -- "$@")
 		IFS="$old_ifs"
 		if [ "$#" -ne 1 ]; then
 			printf 'mrep: needs exactly one mail to reply to\n' 1>&2
@@ -446,7 +448,7 @@ while :; do
 				if $sendmail <"$draftmime"; then
 					if [ "$outbox" ]; then
 						mv "$draftmime" "$draft"
-						mflag -d -S "$draft"
+						mrefile "$(mflag -d -S "$draft")" "$outbox"
 					else
 						rm "$draft" "$draftmime"
 					fi
@@ -464,7 +466,7 @@ while :; do
 				stampdate "$draft"
 				if $sendmail <"$draft"; then
 					if [ "$outbox" ]; then
-						mflag -d -S "$draft"
+						mrefile "$(mflag -d -S "$draft")" "$outbox"
 					else
 						rm "$draft"
 					fi
diff --git a/mdirs.c b/mdirs.c
index 5f49906..89ebab5 100644
--- a/mdirs.c
+++ b/mdirs.c
@@ -3,8 +3,10 @@
 
 #include <dirent.h>
 #include <limits.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "blaze822.h"
@@ -72,6 +74,33 @@ mdirs(char *fpath)
 	closedir(dir);
 }
 
+char *
+profile_maildir()
+{
+	char *f = blaze822_home_file("profile");
+	struct message *config = blaze822(f);
+	char *maildir;
+	static char path[PATH_MAX];
+
+	if (!config)
+		return 0;
+
+	if (!(maildir = blaze822_hdr(config, "maildir")))
+		return 0;
+
+	if (strncmp(maildir, "~/", 2) == 0) {
+		const char *home = getenv("HOME");
+		if (!home) {
+			struct passwd *pw = getpwuid(getuid());
+			home = pw ? pw->pw_dir : "/dev/null/homeless";
+		}
+		snprintf(path, sizeof path, "%s/%s", home, maildir+2);
+		maildir = path;
+	}
+
+	return maildir;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -86,11 +115,17 @@ usage:
 			exit(1);
 		}
 
-	if (argc == optind)
-		goto usage;
-
 	xpledge("stdio rpath", "");
 
+	if (argc == optind) {
+		char *maildir = profile_maildir();
+		if (maildir) {
+			mdirs(maildir);
+			return 0;
+		}
+		goto usage;
+	}
+
 	char toplevel[PATH_MAX];
 	if (!getcwd(toplevel, sizeof toplevel)) {
 		perror("mdirs: getcwd");
diff --git a/minc.c b/minc.c
index c1d28fd..2811646 100644
--- a/minc.c
+++ b/minc.c
@@ -74,14 +74,17 @@ usage:
 			exit(1);
 		}
 
-	if (optind == argc)
-		goto usage;
-
 	xpledge("stdio rpath cpath", "");
 
 	status = 0;
-	for (i = optind; i < argc; i++)
-		inc(argv[i]);
+	if (optind == argc) {
+		if (isatty(0))
+			goto usage;
+		blaze822_loop(0, 0, inc);
+	} else {
+		for (i = optind; i < argc; i++)
+			inc(argv[i]);
+	}
 
 	return status;
 }
diff --git a/mscan.c b/mscan.c
index 0494409..4052f1f 100644
--- a/mscan.c
+++ b/mscan.c
@@ -575,9 +575,13 @@ main(int argc, char *argv[])
 
 	struct winsize w;
 	int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY);
-	if (ttyfd >= 0 && ioctl(ttyfd, TIOCGWINSZ, &w) == 0) {
-		cols = w.ws_col;
+	if (ttyfd >= 0) {
+		if (ioctl(ttyfd, TIOCGWINSZ, &w) == 0)
+			cols = w.ws_col;
+		close(ttyfd);
+	}
 
+	if (isatty(1)) {
 		char *pg;
 		pg = getenv("MBLAZE_PAGER");
 		if (!pg)
@@ -590,8 +594,6 @@ main(int argc, char *argv[])
 				    pg, strerror(errno));
 		}
 	}
-	if (ttyfd >= 0)
-		close(ttyfd);
 
 	xpledge("stdio rpath", "");
 
diff --git a/rfc2047.c b/rfc2047.c
index 3074b4d..5aec546 100644
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -201,7 +201,8 @@ blaze822_decode_rfc2047(char *dst, char *src, size_t dlen, char *tgtenc)
 		if (ic == (iconv_t)-1)
 			goto nocode;
 
-		char enc = lc(*e++);
+		char enc = lc(*e);
+		e++;
 		if (*e++ != '?')
 			goto nocode;
 		char *start = e;
diff --git a/t/1100-mhdr.t b/t/1100-mhdr.t
new file mode 100755
index 0000000..9937041
--- /dev/null
+++ b/t/1100-mhdr.t
@@ -0,0 +1,26 @@
+#!/bin/sh -e
+cd ${0%/*}
+. ./lib.sh
+
+plan 9
+
+cat <<EOF >tmp
+Header: foo
+Header2: bar
+Header-Three: quux
+Header_Four: ding
+
+Body
+EOF
+
+check_same 'Header' 'mhdr -h Header ./tmp' 'echo foo'
+check_same 'Header2' 'mhdr -h Header2 ./tmp' 'echo bar'
+check_same 'Header-Three' 'mhdr -h Header-Three ./tmp' 'echo quux'
+check_same 'Header_Four' 'mhdr -h Header_Four ./tmp' 'echo ding'
+
+check_same 'header' 'mhdr -h header ./tmp' 'echo foo'
+check_same 'header2' 'mhdr -h header2 ./tmp' 'echo bar'
+check_same 'header-Three' 'mhdr -h header-Three ./tmp' 'echo quux'
+check_same 'header_Four' 'mhdr -h header_Four ./tmp' 'echo ding'
+
+check 'issue 235' 'mhdr ./tmp |grep -i header_four'
diff --git a/t/9000-minc.t b/t/9000-minc.t
index 3d5b789..9b29194 100644
--- a/t/9000-minc.t
+++ b/t/9000-minc.t
@@ -1,7 +1,7 @@
 #!/bin/sh -e
 cd ${0%/*}
 . ./lib.sh
-plan 1
+plan 2
 
 rm -rf test.dir
 mkdir test.dir
@@ -16,4 +16,10 @@ inbox/new/2
 
 check_test 'minc' -eq 2 'minc inbox | wc -l'
 
+while read f; do touch "$f"; done <<!
+inbox/new/3:2,
+inbox/new/4
+!
+
+check_test 'minc stdin' -eq 2 'echo inbox | minc | wc -l'
 )