Compare commits

..

No commits in common. 'master' and 'v0.3.1' have entirely different histories.

@ -5,8 +5,8 @@ has waived all copyright and related or neighboring rights to this work.
http://creativecommons.org/publicdomain/zero/1.0/
The files mystrverscmp.c and mymemmem
The files mystrverscmp.c and mymemmem.c and mytimegm.c
are MIT-licensed and were written by Rich Felker.
mpick.c is largely based on code by Leah Neukirchen
mpick.c is largely based on code by Christian Neukirchen
and has been contributed by Duncan Overbruck <mail@duncano.de>

@ -1,6 +1,5 @@
CFLAGS?=-g -O2 -fstack-protector-strong -D_FORTIFY_SOURCE=2
override CFLAGS:=-Wall -Wno-switch -Wextra $(CFLAGS)
LDFLAGS?=-fstack-protector-strong
LDLIBS=-lrt
OS := $(shell uname)
@ -26,22 +25,22 @@ SCRIPT = mcolor mcom mless mmkdir mquote museragent
all: $(ALL) museragent
$(ALL) : % : %.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 mdeliver mexport mflag mflow mgenmid mhdr mpick mscan msed mshow \
msort mthread : blaze822.o mymemmem.o mytimegm.o
maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort \
mthread : seq.o slurp.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
mscan : pipeto.o
msort : mystrverscmp.o
mmime : slurp.o
minc mlist : squeeze_slash.o
museragent: FRC
@test -n "$$SOURCE_DATE_EPOCH" || BUILDDATE=$$(date '+ (%Y-%m-%d)'); \
printf '#!/bin/sh\nprintf "User-Agent: mblaze/%s%s\\n"\n' \
@printf '#!/bin/sh\nprintf "User-Agent: mblaze/%s (%s)\\n"\n' \
"$$({ git describe --always --dirty 2>/dev/null || cat VERSION; } | sed 's/^v//')" \
"$$BUILDDATE" >$@
"$$(date +%Y-%m-%d)" >$@
@chmod +x $@
README: man/mblaze.7
@ -51,7 +50,7 @@ clean: FRC
-rm -f $(ALL) *.o museragent
check: FRC all
PATH=$$(pwd):$$PATH prove -v </dev/null
PATH=$$(pwd):$$PATH prove -v
install: FRC all
mkdir -p $(DESTDIR)$(BINDIR) \
@ -59,22 +58,22 @@ install: FRC all
$(DESTDIR)$(MANDIR)/man5 \
$(DESTDIR)$(MANDIR)/man7
install -m0755 $(ALL) $(SCRIPT) $(DESTDIR)$(BINDIR)
ln -sf mless $(DESTDIR)$(BINDIR)/mnext
ln -sf mless $(DESTDIR)$(BINDIR)/mprev
ln -sf mcom $(DESTDIR)$(BINDIR)/mbnc
ln -sf mcom $(DESTDIR)$(BINDIR)/mfwd
ln -sf mcom $(DESTDIR)$(BINDIR)/mrep
ln -sf mdeliver $(DESTDIR)$(BINDIR)/mrefile
install -m0644 man/*.1 $(DESTDIR)$(MANDIR)/man1
install -m0644 man/*.5 $(DESTDIR)$(MANDIR)/man5
install -m0644 man/*.7 $(DESTDIR)$(MANDIR)/man7
release:
VERSION=$$(git describe --tags | sed 's/^v//;s/-[^.]*$$//') && \
[ "$$VERSION" = "$$(cat VERSION)" ] && \
git archive --prefix=mblaze-$$VERSION/ -o mblaze-$$VERSION.tar.gz HEAD
sign:
VERSION=$$(git describe --tags | sed 's/^v//;s/-[^.]*$$//') && \
gpg2 --armor --detach-sign mblaze-$$VERSION.tar.gz && \
gpg --armor --detach-sign mblaze-$$VERSION.tar.gz && \
signify -S -s ~/.signify/mblaze.sec -m mblaze-$$VERSION.tar.gz && \
sed -i '1cuntrusted comment: verify with mblaze.pub' mblaze-$$VERSION.tar.gz.sig

@ -1,101 +1,3 @@
## 1.2 (2021-12-12)
* Caution! The tools mdeliver and mexport were buggy in handling and
generation of trailing empty lines in MBOX-RD. Do not import
mbox files generated by mexport >=1.2 with mdeliver <1.2 if you
require verbatim message delivery.
* mshow: add "-A all" to render all attachments
* msed: match header names case insensitively
* mless: prefer setting LESSKEYIN and using .mlesskey
* mcom: take Delivered-To into account for choosing From address
* Many bug fixes.
## 1.1 (2021-01-14)
* mcom: allow tilde prefixed path for profile's outbox setting
* mcom: detect and report mmime errors
* add contrib/mmailto, a handler for mailto: links
* Bug fixes.
## 1.0 (2020-09-12)
* Caution! Backwards incompatible changes:
* As a message name, `-` now refers to the message on the standard input,
and not the previous message anymore. Use `.-` to refer to the previous
message in a short way.
The tools will print a warning if you use `-` and the standard input
comes from a TTY.
* mpick: use the -F flag to read script files.
* mpick: remove msglist support, use plain mmsg(7) arguments.
* Many mblaze tools now make use of pledge(2) on OpenBSD.
* add contrib/mcount, a tool to count mails
* mrep: use Reply-From configuration to find From header
* Many bug fixes.
## 0.7 (2020-05-15)
* All tools now follow symlinks to mails.
* mdirs: add -a to list all subfolders, ignoring Maildir++ convention.
* mcom: add preview alias for show command.
* mrep/mbnc: allow only one message as argument.
* maddr: add -d to only print display name.
* mthread: add -r to reverse top-level order.
* mlist: print number of matches when message selection is in place.
* mpick: many improvements.
* Many bug fixes.
## 0.6 (2020-01-18)
* mfwd: prefix Subject with "Fwd:".
* mscan: add dottime formatting.
* mlist: look at maildir/new too for messages.
* Many bug and portability fixes.
## 0.5.1 (2019-03-03)
* mdeliver: preserve mtime in mrefile
* mdirs: add -0 to separate folders by NUL characters
* Fixes for buffer-overflows, found by fuzzing.
* Fixes for memleaks.
## 0.5 (2019-02-09)
* New tool msearch to wrap several mail indexers.
* New zsh completion _mblaze.
* mnext/mprev were removed (you can call `mless +`/`mless .-`).
* The GnuPG tools in contrib/ now use gpg2.
* mshow exits with error if it could not extract all attachments
* mrep: add -noquote to disable quoting the message replied to
* mdeliver: keep permissions of messages
* mcom: aborting the editor is now more like delete than cancel
* mcom: add -send to send directly without editing
* mcom: check if mail is formatted sensibly
* mpick: new flag -v for statistics
* mscan: new flag -v for statistics
* magrep: add -h, which is like -p but doesn't print the file name
* mscan: prioritize displaying trashed mail over other markers
* mpick: fix off-by-one in expression parsing
* Many bug fixes.
## 0.4 (2018-08-15)
* New tool mrefile to move or copy messages.
* contrib/mp7m: add application/pkcs7-mime decoder
* mcom: allow setting arbitrary headers from command line
* mcom: add -body to prepopulate drafts
* mcom: mark drafts as seen after sending
* mcom: update flags after mrep/mbnc/mfwd
* mshow: add -B to decode MIME parameters in broken mails
* magrep: add -l flag
* Many bug fixes.
## 0.3.2 (2018-02-13)
* magrep: add *:REGEX to search in any header
* Fix of a buffer overflow in blaze822_multipart.
* Small bug fixes.
* Many documentation improvements by Larry Hynes.
## 0.3.1 (2018-01-30)
* mless: support $NO_COLOR

134
README

@ -1,103 +1,102 @@
MBLAZE(7) Miscellaneous Information Manual MBLAZE(7)
NAME
mblaze introduction to the mblaze message system
mblaze introduction to mblaze
DESCRIPTION
The mblaze message system is a set of Unix utilities for processing and
interacting with mail messages which are stored in maildir folders.
The mblaze message system is a set of Unix utilities to deal with mail
kept in Maildir folders.
Its design is roughly inspired by MH, the RAND Message Handling System,
but it is a complete implementation from scratch.
mblaze consists of these Unix utilities that each do one job:
maddr(1) extract mail addresses from messages
magrep(1) search messages matching a pattern
mbnc(1) bounce messages
mcom(1) compose and send messages
mdeliver(1) deliver messages or import mbox file
mdirs(1) list maildir folders, recursively
mexport(1) export messages as mbox file
mflag(1) manipulate maildir message flags
mflow(1) reflow format=flowed plain text messages
mfwd(1) forward messages
mgenmid(1) generate a Message-ID
mhdr(1) print message headers
minc(1) incorporate new messages
mless(1) conveniently read messages in less(1)
mlist(1) list and filter messages
mblaze consists of these Unix tools that each do one job:
maddr(1) extract addresses from mail
magrep(1) find mails matching a pattern
mbnc(1) bounces mail
mcom(1) compose and send mail
mdeliver(1) deliver messages or import mailboxes
mdirs(1) find Maildir folders
mexport(1) export Maildir folders as mailboxes
mflag(1) change flags (marks) of mail
mflow(1) reflow format=flowed plain text mails
mfwd(1) forward mail
mgenmid(1) generate Message-IDs
mhdr(1) extract mail headers
minc(1) incorporate new mail
mless(1) conveniently read mail in less(1)
mlist(1) list and filter mail messages
mmime(1) create MIME messages
mmkdir(1) create new maildir folders
mpick(1) advanced message filter
mrefile(1) move or copy messages between maildir folders
mrep(1) reply to messages
mscan(1) generate one-line message summaries
msed(1) manipulate message headers
mseq(1) manipulate message sequences
mshow(1) render messages and extract MIME parts
msort(1) sort messages
mthread(1) arrange messages into discussions
mmkdir(1) create new Maildir
mpick(1) advanced mail filter
mrep(1) reply to mail
mscan(1) generate one-line summaries of mail
msed(1) manipulate mail headers
mseq(1) manipulate mail sequences
mshow(1) render mail and extract attachments
msort(1) sort mail
mthread(1) arrange mail into discussions
PRINCIPLES
mblaze is a classic command line MUA and has no features for receiving or
transferring messages; you can operate on messages in a local maildir
spool, or fetch your messages using fdm(1), getmail(1), offlineimap(1),
or similar utilities, and send it using dma(8), msmtp(1), sendmail(8), as
provided by OpenSMTPD, Postfix, or similar.
mblaze operates directly on maildir folders and doesn't use its own
caches or databases. There is no setup needed for many uses. All
utilities have been written with performance in mind. Enumeration of all
messages in a maildir is avoided unless necessary, and then optimized to
limit syscalls. Parsing message metadata is optimized to limit I/O
requests. Initial operations on a large maildir may feel slow, but as
soon as they are in the file system cache, everything is blazingly fast.
The utilities are written to be memory efficient (i.e. not wasteful), but
whole messages are assumed to fit into RAM easily (one at a time).
mblaze has been written from scratch and is now well tested, but it is
not 100% RFC-conforming (which is neither worth it, nor desirable).
There may be issues with very old, nonconforming, messages.
transferring mail; you are expected to fetch your mail using fdm(1),
getmail(1) offlineimap(1), procmail(1), or similar , and send it using
dma(8), msmtp(1), sendmail(8), as provided by OpenSMTPD, Postfix, or
similar. mblaze expects your mail to reside in Maildir folders.
mblaze operates directly on Maildir folders and doesn't use its own
caches or databases. There is no setup needed for many uses. All tools
have been written with performance in mind. Enumeration of all mails in
a Maildir is avoided unless necessary, and then optimized to limit
syscalls. Parsing mail metadata is optimized to limit I/O requests.
Initial operations on a large Maildir may feel slow, but as soon as they
are in the file system cache, everything is blazingly fast. The tools
are written to be memory efficient (i.e. not wasteful), but whole
messages are assumed to fit into RAM easily (one at a time).
mblaze has been written from scratch and tested on a large corpus of
personal mail, but is not actually 100% RFC-conforming (which is neither
worth it nor desirable). There may be issues with very old,
nonconforming, messages.
mblaze is written in portable C, using only POSIX functions (apart from a
tiny Linux-only optimization), and has no external dependencies. It
supports MIME and more than 7-bit messages (everything the host iconv(3)
can decode). It assumes you work in a UTF-8 environment. mblaze works
well with other Unix utilities such as mairix(1), mu(1), or
well together with other Unix mail tools such as mairix(1), mu(1), or
offlineimap(1).
EXAMPLES
mblaze utilities are designed to be composed together in a pipe. They
are suitable for interactive use and for scripting, and integrate well
into a Unix workflow.
mblaze tools are designed to be composed together in a pipe. They are
suitable for interactive use and for scripting, and integrate well into a
Unix workflow.
For example, you could decide you want to look at all unseen messages in
your INBOX, oldest first.
For example, you could decide you want to look at all unseen mail in your
INBOX, oldest first.
mlist -s ~/Maildir/INBOX | msort -d | mscan
To operate on a set of messages in multiple steps, you can save it as a
To operate on a set of mails in multiple steps, you can save it as a
sequence, e.g. add a call to mseq -S to the above command:
mlist -s ~/Maildir/INBOX | msort -d | mseq -S | mscan
Now mscan will show message numbers and you could look at the first five
messages at once, for example:
mails at once, for example:
mshow 1:5
Likewise, you could decide to incorporate (by moving from new to cur) all
new messages in all folders, thread it and look at it interactively:
new mail in all folders, thread it and look at it interactively:
mdirs ~/Maildir | xargs minc | mthread | mless
Or you could list the attachments of the 20 largest messages in your
INBOX:
Or you could list the attachments of the 20 largest mails in your INBOX:
mlist ~/Maildir/INBOX | msort -S | tail -20 | mshow -t
Or apply the patches from the current message:
Or apply the patches from the current mail:
mshow -O. '*.diff' | patch
As usual with pipes, the sky is the limit.
CONCEPTS
mblaze deals with messages (which are files), folders (which are maildir
mblaze deals with messages (which are files), folders (which are Maildir
folders), sequences (which are newline-separated lists of messages,
possibly saved on disk in ${MBLAZE:-$HOME/.mblaze}/seq), and the current
message (kept as a symlink in ${MBLAZE:-$HOME/.mblaze}/cur).
@ -118,10 +117,9 @@ AUTHORS
Leah Neukirchen <leah@vuxu.org>
There is a mailing list available at mblaze@googlegroups.com (to
subscribe, send a message to mblaze+subscribe@googlegroups.com); archives
are available at https://inbox.vuxu.org/mblaze/. There also is an IRC
channel #vuxu on irc.libera.chat. Please report security-related bugs
directly to the author.
subscribe, send a mail to mblaze+subscribe@googlegroups.com. Please
report security-related bugs directly to the author), as well as an IRC
channel #vuxu on irc.freenode.net.
LICENSE
mblaze is in the public domain.
@ -129,6 +127,6 @@ LICENSE
To the extent possible under law, the creator of this work has waived all
copyright and related or neighboring rights to this work.
http://creativecommons.org/publicdomain/zero/1.0/
http://creativecommons.org/publicdomain/zero/1.0/
Void Linux January 18, 2020 Void Linux
Void Linux January 6, 2018 Void Linux

@ -1 +1 @@
1.2
0.2

@ -121,7 +121,7 @@ blaze822_date(char *s) {
tm.tm_isdst = -1;
time_t r = mytimegm(&tm);
time_t r = tm_to_secs(&tm);
return r;
fail:
@ -152,20 +152,14 @@ skip_comment(char *s)
// never writes more than dstmax to dst
// returns how many bytes were appended
static size_t
safe_append(char *dst, size_t dstmax, char *srcbeg, char *srcend)
safe_append(char *dst, size_t dstmax, char *strbeg, char *strend)
{
size_t srclen = srcend - srcbeg;
size_t dstlen = strnlen(dst, dstmax);
if (dstlen == dstmax)
return 0;
if (dstmax - dstlen < srclen + 1)
srclen = dstmax - dstlen - 1;
memcpy(dst + dstlen, srcbeg, srclen);
dst[dstlen + srclen] = 0;
return srclen;
size_t dstlen = strlen(dst);
if (dstmax - dstlen - 1 < strend - strbeg)
strend = strbeg + (dstmax - dstlen - 1);
memcpy(dst + dstlen, strbeg, strend - strbeg);
dst[dstlen + (strend - strbeg)] = 0;
return strend - strbeg;
}
static size_t
@ -219,9 +213,8 @@ blaze822_addr(char *s, char **dispo, char **addro)
s++;
if (*addr || *disp)
break;
} else {
s++;
}
s++;
} else if (*s == '<') {
char tok[1024] = { 0 };
char *c = tok;
@ -229,9 +222,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
s++;
while (*s && c < e && *s != '>') {
s = skip_comment(s);
if (!*s) {
break;
} else if (*s == '"') {
if (*s == '"') {
// local part may be quoted, allow all
s++;
while (*s && c < e && *s != '"') {
@ -241,7 +232,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
}
if (*s == '"')
s++;
} else if (*s == '<' || *s == ':') {
} else if (*s == '<') {
c = tok;
s++;
} else {
@ -267,7 +258,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
char *e = tok + sizeof tok;
s++;
while (*s && c < e && *s != '"') {
if (*s == '\\' && *(s+1))
if (*s == '\\')
s++;
*c++ = *s++;
}
@ -277,13 +268,13 @@ blaze822_addr(char *s, char **dispo, char **addro)
if (memchr(tok, '@', c - tok))
not_addr = 1; // @ inside "" is never an addr
*tc = 0;
if (tc != ttok)
tc += safe_append_space(ttok, sizeof ttok);
tc += safe_append(ttok, sizeof ttok, tok, c);
} else if (*s == '(') {
char *z = skip_comment(s);
if (!*disp && *addr) // user@host (name)
safe_append(disp, sizeof disp, s + 1,
*z ? z-1 : (*(z-1) == ')' ? z-1 : z));
safe_append(disp, sizeof disp, s + 1, z - 1);
else if (*disp) { // copy comment
safe_append_space(disp, sizeof disp);
safe_append(disp, sizeof disp, s, z);
@ -294,8 +285,6 @@ blaze822_addr(char *s, char **dispo, char **addro)
// in ipv6 address
if (tc < te)
*tc++ = *s++;
else
s++;
} else { // ignore group name and start over
s++;
tc = ttok;
@ -309,8 +298,6 @@ blaze822_addr(char *s, char **dispo, char **addro)
s++;
if (tc < te)
*tc++ = *s++;
else
s++;
}
}
@ -355,7 +342,7 @@ compress_hdr(char *s, char *end)
while (h < end && *h) {
if (*h == '\n') {
*t++ = ' ';
while (*h && isfws(*h) && *(h+1))
while (*h && isfws(*h))
h++;
}
*t++ = *h++;
@ -420,19 +407,10 @@ unfold_hdr(char *buf, char *end)
compress_hdr(l, end);
}
static int
is_crlf(char *s, size_t len)
{
char *firsteol = memchr(s, '\n', len);
return firsteol && firsteol > s && firsteol[-1] == '\r';
}
struct message *
blaze822(char *file)
{
int fd;
int crlf;
ssize_t rd;
char *buf;
ssize_t bufalloc;
@ -443,10 +421,7 @@ blaze822(char *file)
if (!mesg)
return 0;
if (strcmp(file, "/dev/stdin") == 0)
fd = dup(0);
else
fd = open(file, O_RDONLY);
fd = open(file, O_RDONLY);
if (fd < 0) {
free(mesg);
return 0;
@ -478,21 +453,15 @@ blaze822(char *file)
close(fd);
return 0;
}
if (used == 0) {
crlf = is_crlf(buf, rd);
}
if (crlf) {
if ((end = mymemmem(buf-overlap+used, rd+overlap, "\r\n\r\n", 4))) {
end++;
end++;
break;
}
} else {
if ((end = mymemmem(buf-overlap+used, rd+overlap, "\n\n", 2))) {
end++;
break;
}
if ((end = mymemmem(buf-overlap+used, rd+overlap, "\n\n", 2))) {
end++;
break;
}
if ((end = mymemmem(buf-overlap+used, rd+overlap, "\r\n\r\n", 4))) {
end++;
end++;
break;
}
used += rd;
@ -520,15 +489,11 @@ blaze822_mem(char *src, size_t len)
if (!mesg)
return 0;
if (is_crlf(src, len)) {
if ((end = mymemmem(src, len, "\r\n\r\n", 4)))
mesg->body = end+4;
if ((end = mymemmem(src, len, "\n\n", 2))) {
mesg->body = end+2;
} else if ((end = mymemmem(src, len, "\r\n\r\n", 4))) {
mesg->body = end+4;
} else {
if ((end = mymemmem(src, len, "\n\n", 2)))
mesg->body = end+2;
}
if (!end) {
end = src + len;
mesg->body = end;
mesg->bodyend = end;
@ -539,10 +504,8 @@ blaze822_mem(char *src, size_t len)
size_t hlen = end - src;
buf = malloc(hlen+1);
if (!buf) {
free(mesg);
if (!buf)
return 0;
}
memcpy(buf, src, hlen);
end = buf+hlen;
@ -614,11 +577,7 @@ blaze822_file(char *file)
char *buf = 0;
ssize_t rd = 0, n;
int fd;
if (strcmp(file, "/dev/stdin") == 0)
fd = dup(0);
else
fd = open(file, O_RDONLY);
int fd = open(file, O_RDONLY);
if (fd < 0)
return 0;
@ -686,6 +645,54 @@ error:
return 0;
}
struct message *
blaze822_mmap(char *file)
{
int fd = open(file, O_RDONLY);
if (fd < 0)
return 0;
struct stat st;
if (fstat(fd, &st) < 0)
goto error;
size_t len = st.st_size;
struct message *mesg = malloc(sizeof (struct message));
if (!mesg)
goto error;
char *buf = mmap(0, len+1, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (buf == MAP_FAILED) {
perror("mmap");
goto error;
}
close(fd);
char *end;
if ((end = mymemmem(buf, len, "\n\n", 2))) {
mesg->body = end+2;
} else if ((end = mymemmem(buf, len, "\r\n\r\n", 4))) {
mesg->body = end+4;
} else {
end = buf + len;
mesg->body = end;
}
unfold_hdr(buf, end);
mesg->msg = mesg->bodychunk = buf;
mesg->end = end;
mesg->bodyend = buf + len;
mesg->orig_header = 0;
return mesg;
error:
close(fd);
return 0;
}
size_t
blaze822_headerlen(struct message *mesg)
{

@ -8,23 +8,13 @@
#define PATH_MAX 4096
#endif
// maildir filename suffix: use a semicolon on winnt/ntfs, otherwise a colon
#ifdef __winnt__
#define MAILDIR_COLON ';'
#define MAILDIR_COLON_SPEC_VER ";2"
#define MAILDIR_COLON_SPEC_VER_COMMA ";2,"
#else
#define MAILDIR_COLON ':'
#define MAILDIR_COLON_SPEC_VER ":2"
#define MAILDIR_COLON_SPEC_VER_COMMA ":2,"
#endif
struct message;
// blaze822.c
struct message *blaze822(char *file); // just header
struct message *blaze822_file(char *file); // header + body (read(2))
struct message *blaze822_mmap(char *file); // header + body (mmap(2))
struct message *blaze822_mem(char *buf, size_t len); // header + body
char *blaze822_hdr_(struct message *mesg, const char *hdr, size_t len);
@ -95,7 +85,7 @@ int filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno
// mygmtime.c
time_t mytimegm(const struct tm *tm);
time_t tm_to_secs(const struct tm *tm);
// slurp.c
@ -105,7 +95,7 @@ int slurp(char *filename, char **bufo, off_t *leno);
// safe_u8putstr.c
#include <stdio.h>
void safe_u8putstr(char *s0, size_t l, int oneline, FILE *stream);
void safe_u8putstr(char *s0, size_t l, FILE *stream);
// pipeto.c

@ -12,17 +12,7 @@ struct message {
#define isfws(c) (((unsigned char)(c) == ' ' || (unsigned char)(c) == '\t' || (unsigned char)(c) == '\n' || (unsigned char)(c) == '\r'))
// 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)
#define MAIL_DT(t) (t == DT_REG || t == DT_LNK || t == DT_UNKNOWN)
#define DIR_DT(t) (t == DT_DIR || t == DT_UNKNOWN)
#else
#define MAIL_DT(t) (1)
#define DIR_DT(t) (1)
#endif
// ASCII lowercase without alpha check (wrong for "@[\]^_")
#define lc(c) ((c) | 0x20)
void *mymemmem(const void *h0, size_t k, const void *n0, size_t l);

@ -1,402 +0,0 @@
#compdef maddr magrep mbnc mcom mdeliver mdirs mexport mflag mflow mfwd mgenmid mhdr minc mless mlist mmime mmkdir mpick mrep mscan msed mseq mshow msort mthread
_mblaze_colon_separated_headers() {
_message 'headers (colon separated)'
}
_mblaze_message() {
local ret=1 expl tmp curmsg
local -a mseq mseqnums mshortcuts mshortcutdescrs
setopt localoptions extendedglob
if [[ -prefix './' ]]; then
_description files expl 'message file'
_files "$expl[@]" && ret=0
fi
curmsg=$(mseq . 2>/dev/null)
if [[ -z $curmsg || ! -f $curmsg ]]; then
_message 'no current sequence'
return $ret
fi
mseq=( ${(f)"$(mscan -f '%3n %c%u%r %10d %17f %t %2i%s' : 2>/dev/null)"} )
mseq=( ${(M)mseq:# #<->*} )
mseqnums=( ${(M)${mseq## #}##<->} )
mseq=( ${mseq//:/\\:} )
_describe -V -t mseq 'seq messages' mseq mseqnums && ret=0
mshortcuts=( '.' '+' '$' '^' '=' '_' )
mshortcutdescrs=(
' . current message'
' + next message'
# ' - previous message'
' $ last message'
' ^ parent message'
' = current thread'
' _ current subthread'
)
_describe -t mshortcuts 'shortcuts' mshortcutdescrs mshortcuts -S '' && ret=0
return $ret
}
_mblaze_message_part() {
setopt localoptions noksharrays extendedglob
local ret=1 expl tmp msgarg parts partnums
tmp=$words[(i)(-O|-x)]
if (( tmp >= $#words )); then
_message -e mparts 'message parts (parse error)'
return 1
fi
msgarg=$words[$tmp+1]
parts=( ${(f)"$(mshow -t $msgarg)"} )
parts=( ${(M)parts:# ##<->:*} )
if [[ -n $parts ]]; then
partnums=( ${${parts## #}%%:*} )
parts=( ${parts//:/\\:} )
_describe -V -t mparts 'message parts' parts partnums -l && ret=0
else
_message -e mparts 'message parts (none found)'
fi
return $ret
}
_mblaze_dirs() {
local ret=1 expl countnew countcur
local -a mailboxes mailbox_descriptions
setopt localoptions extendedglob
mailboxes=( */cur(:h) )
mailbox_descriptions=( ${(f)"$(mlist -i $mailboxes)"} )
_describe -t mailboxes "mailboxes" mailbox_descriptions mailboxes && ret=0
_description files expl 'directories'
_path_files "$expl[@]" -g "^(${(j:|:)mailboxes})(/)" && ret=0
}
_mblaze_header_regex() {
_message header\ regex
}
_mblaze_flags() {
_message flags
}
_maddr() {
local context state line expl
local -A opt_args
_arguments \
'-a[print addr-spec address without display name]' \
'-h[search only given headers]:header list:_mblaze_colon_separated_headers' \
'*:message:_mblaze_message'
}
_magrep() {
local context state line expl
local -A opt_args
_arguments \
'-a[search for regex in RFC 2822 address header parts only]' \
'-c[only print a count of matching messages]' \
'-d[decode the header according to RFC 2047 prior to searching]' \
'-i[match regex case insensitively]' \
'-m[do not show more than max matches]:max: ' \
'(-c -q -v)-o[print matches only]' \
'(-c -q -v)-p[print filename, header and matching]' \
'-q[quiet mode: do not print anything]' \
'-v[invert match]' \
'*:message:_mblaze_header_regex'
}
_mbnc() {
local context state line expl
local -A opt_args
_arguments \
':message:_mblaze_message'
}
_mcom() {
local context state line expl
local -A opt_args
_arguments \
- resume \
'-r[resume editing]:draft: ' \
- recip \
'*:recipients: '
}
_mdeliver() {
local context state line expl
local -A opt_args
_arguments \
'-c[deliver into cur/ instead of new/]' \
'-v[print message filename after delivery]' \
'-X[override flags]:flags:_mblaze_flags' \
'-M[deliver messages from mbox]' \
':dir:_mblaze_dirs'
}
_mdirs() {
_mblaze_dirs
}
_mexport() {
local context state line expl
local -A opt_args
_arguments \
'-S[add Status and X-Status headers according to flags]' \
'*:messages:_mblaze_message'
}
_mflag() {
local context state line expl
local -A opt_args
_arguments \
'(-d)-D[mark as draft]' \
'(-f)-F[mark as flagged]' \
'(-p)-P[mark as passed (resent/forwarded/bounced)]' \
'(-r)-R[mark as replied-to]' \
'(-s)-S[mark as seen]' \
'(-t)-T[mark as trashed]' \
'-X[mark with characters]:marking characters: ' \
'(-D)-d[unmark as draft]' \
'(-F)-f[unmark as flagged]' \
'(-P)-p[unmark as passed (resent/forwarded/bounced)]' \
'(-R)-r[unmark as replied-to]' \
'(-S)-s[unmark as seen]' \
'(-T)-t[unmark as trashed]' \
'-x[unmark with characters]:marked chacaters: ' \
'-v[read messages from standard input or current sequence]' \
'*:messages:_mblaze_message'
}
_mflow() {
local context state line expl
local -A opt_args
_arguments \
'-f[force wrapping of long lines]' \
'*-q[prefix lines with >]' \
'-w[set maximum line length]:width: ' \
'*:dirs:_mblaze_dirs'
}
_mfwd() {
local context state line expl
local -A opt_args
_arguments \
'-r[forward as plain text]' \
':*:message:_mblaze_message'
}
_mgenmid() {
_message 'no arguments'
}
_mhdr() {
local context state line expl
local -A opt_args
_arguments \
'-h[print specific headers only]:headers: ' \
'-p[print specific parameter from header only]:parameter: ' \
'-d[print headers decoded]' \
'-H[prefix output with filename]' \
'-M[print all occurrences, not only the first]' \
'(-D)-A[print addresses from headers]' \
'(-A)-D[print date as unix timestamp]' \
'*:message:_mblaze_message'
}
_minc() {
local context state line expl
local -A opt_args
_arguments \
'-q[quiet mode: don'\''t print filenames]' \
'*:dirs:_mblaze_dirs'
}
_mless() {
local context state line expl
local -A opt_args
_arguments \
':message:_mblaze_message'
}
_mlist() {
local context state line expl
local -A opt_args
_arguments \
'(-d)-D[only list messages marked as draft]' \
'(-f)-F[only list messages marked as flagged]' \
'(-p)-P[only list messages marked as passed (resent/forwarded/bounced)]' \
'(-r)-R[only list messages marked as replied-to]' \
'(-s)-S[only list messages marked as seen]' \
'(-t)-T[only list messages marked as trashed]' \
'-X[only list messages marked with characters]:marked characters: ' \
'(-D)-d[don'\''t list messages marked as draft]' \
'(-F)-f[don'\''t list messages marked as flagged]' \
'(-P)-p[don'\''t list messages marked as passed (resent/forwarded/bounced)]' \
'(-R)-r[don'\''t list messages marked as replied-to]' \
'(-S)-s[don'\''t list messages marked as seen]' \
'(-T)-t[don'\''t list messages marked as trashed]' \
'-x[don'\''t list messages marked with characters]:marked chacaters: ' \
'(-c -N)-C[only list messages in cur]' \
'(-n -C)-N[only list messages in new]' \
'(-C -N)-c[don'\''t list messages in cur]' \
'(-N -C)-n[don'\''t list messages in new]' \
'-i[print summaries instead of folder names]' \
'*:dirs:_mblaze_dirs'
}
_mmkdir() {
local context state line expl
local -A opt_args
_arguments \
'*:directory name: '
}
_mmime() {
local context state line expl
local -A opt_args
_arguments \
'(-r)-c[check mode (don'\''t output anything)]' \
'(-c)-r[raw mode (generate text/plain)]' \
'-t[override Content-Type of toplevel part]:Content-Type: '
}
_mpick() {
local context state line expl
local -A opt_args
_arguments \
'-T[include whole thread]' \
'-t[limit messages to test]:test: ' \
'*:message:_mblaze_message'
}
_mrep() {
local context state line expl
local -A opt_args
_arguments \
':message:_mblaze_message'
}
_mscan() {
local context state line expl
local -A opt_args
_arguments \
'-n[only print message numbers]' \
'-I[force ISO date output]' \
'-f[specify output format]:format: ' \
'*:messages:_mblaze_message'
}
_msed() {
local context state line expl
local -A opt_args
_arguments \
':sed script: ' \
'*:messages:_mblaze_message'
}
_mseq() {
local context state line expl
local -A opt_args
_arguments \
'(Cmode)-f[fix non-existing filenames]' \
'(Cmode)-r[remove leading indentation from filenames]' \
- argmode \
'-c[use current message]:message:_mblaze_message' \
'*:messages:_mblaze_message' \
- Smode \
'-S[set message sequence from stdin]' \
- Amode \
'-A[append message sequence from stdin]' \
- Cmode \
'-C[set current message]:message:_mblaze_message'
}
_mshow() {
local context state line expl
local -A opt_args
_arguments \
- regular \
'-n[only print message numbers]' \
'-h[display only given headers]:header list:_mblaze_colon_separated_headers' \
'-A[multipart/alternative preference]:mime type: ' \
'-n[don'\''t update current message link]' \
'(-r)-q[print only header]' \
'(-q)-r[print body raw]' \
'(-q)-F[don'\''t apply MIME filters]' \
'-H[print headers raw]' \
'-L[don'\''t filter headers]' \
'(-q)-N[don'\''t show MIME structure markers]' \
'*:messages:_mblaze_message' \
- xmode \
'-x[extraction mode]:message:_mblaze_message:*:part:_mblaze_message_part' \
- Omode \
'-O[extraction mode to standard output]:message:_mblaze_message:*:part:_mblaze_message_part' \
- tmode \
'-t[list mode]:*:message:_mblaze_message' \
- Rmode \
'-R[render text parts]:message:_mblaze_message'
}
_msort() {
local context state line expl
local -A opt_args
_arguments \
'-r[reverse order]' \
'*:message:_mblaze_message' \
+ '(order)' \
'-f[sort by From]' \
'-d[sort by Date]' \
'-s[sort by Subject]' \
'-F[sort by filename]' \
'-M[sort by file modification time]' \
'-S[sort by file size]' \
'-U[sort unread messages after read messages]' \
'-I[sort flagged messages before unflagged messages]'
}
_mthread() {
local context state line expl
local -A opt_args
_arguments \
'-a[don'\''t prune unresolved Message-IDs]' \
'-S[treat as optional messages]:optional message:_mblaze_message' \
'*:message:_mblaze_message'
}
_mblaze() {
local ret=1
_call_function ret _$service
return ret
}
_mblaze "$@"

@ -5,7 +5,7 @@
echo "Content-Type: $PIPE_CONTENTTYPE"
echo
cat
} | mshow -t - | awk '
} | mshow -t /dev/stdin | awk '
BEGIN { split("", ct) }
/^ [0-9]/ { ct[++n] = $2 }
function prefer(t) { for (i in ct) if (ct[i] == t) exit(64+i) }

@ -1,10 +0,0 @@
#!/bin/sh
# mcount - count mails from sequence on stdin
[ -t 1 ] && stdout=1
awk -v stdout=$stdout '
!/^ *</ { n++ }
!stdout { print }
END { fflush(); print n " mails processed" > "/dev/stderr" }
'

@ -5,26 +5,17 @@
IFS='
'
FLAGS=$(maddr -a -h from:to:cc:bcc: "$1" |sort -u |sed 's/^/--recipient=/')
FROM=$(maddr -a -h from "$1" | sed 1q)
[ "$FROM" ] && key="--default-key=$FROM"
if command -v gpg2 >/dev/null; then
GPG=gpg2
else
GPG=gpg
fi
FLAGS=$(mhdr -d -A -h from:to:cc:bcc: "$1" |sort -u |sed 's/^/--recipient=/')
TMPD=$(mktemp -d -t mencrypt.XXXXXX)
trap "rm -rf '$TMPD'" INT TERM EXIT
awk '/^$/,0' "$1" |
mmime |
$GPG "$key" --armor --encrypt --sign $FLAGS -o "$TMPD/msg.asc" ||
gpg --armor --encrypt --sign $FLAGS -o $TMPD/msg.asc ||
exit $?
printf 'Version: 1\n' >"$TMPD/version"
printf 'Version: 1\n' >$TMPD/version
{
sed '/^$/q' "$1"

@ -1,17 +1,14 @@
#!/bin/sh -e
# menter [MSG] - run subshell in temporary directory with MSG extracted
[ "$#" -eq 0 ] && set -- .
f="$(mseq "$1" | sed 1q)"
[ -z "$f" ] && printf 'No message %s.\n' "$1" 1>&2 && exit 1
[ "$#" -eq 0 ] && set -- :
dir=$(mktemp -d -t menter.XXXXXX)
cd "$dir"
mshow -t "$1"
mshow -x "$1" 2>/dev/null
ls -l
ln -s "$f" msg
ln -s "$(mseq "$1")" msg
"${SHELL:-/bin/sh}" || true
echo rm -r "$dir"
rm -r "$dir"

@ -1,11 +1,5 @@
#!/bin/sh -e
if command -v gpg2 >/dev/null; then
GPG=gpg2
else
GPG=gpg
fi
tmp=$(mktemp -t mgpg.XXXXXX)
trap "rm -f '$tmp'" INT TERM EXIT
@ -20,7 +14,7 @@ n=$(mshow -t "$tmp" | awk -F: '
/: application\/octet-stream/ {if (supported) print $1}')
if [ "$n" ]; then
mshow -O "$tmp" "$n" | $GPG --quiet -d 2>&1 || exit 0
mshow -O "$tmp" "$n" | gpg -d 2>&1
exit 64
fi
exit 63

@ -1,58 +0,0 @@
#!/bin/sh
# mmailto mailto:... - mailto: handler spawning mcom in a terminal emulator
tryterm() {
if [ -z "$TERMINAL" ] && command -v "$1" >/dev/null; then
TERMINAL="$*"
fi
}
tryterm x-terminal-emulator
tryterm urxvt
tryterm xterm
if [ -z "$TERMINAL" ]; then
echo 'No terminal emulator found, set $TERMINAL.' 1>&2
exit 1
fi
IFS='
'
exec $TERMINAL -e mcom $(
awk -v url="$1" '
function decode(s) {
hexdigits = "0123456789abcdef"
for (i = 1; i < length(s); i++) {
if (substr(s, i, 3) ~ /%[0-9a-fA-F][0-9a-fA-F]/) {
c = sprintf("%c", (index(hexdigits, tolower(substr(s, i+1, 1)))-1) * 16 + \
index(hexdigits, tolower(substr(s, i+2, 1)))-1)
if (c == "\n") c = " "
s = substr(s, 1, i-1) c substr(s, i+3)
i += 2
}
}
return s
}
BEGIN {
url = decode(url)
sub(/^mailto:/, "", url)
split(url, parts, "?")
to = parts[1]
split(parts[2], fields, "&")
args[1] = to
for (i in fields) {
split(fields[i], kv, "=")
if (kv[1] != "r") {
args[length(args)+1] = "-" kv[1]
args[length(args)+1] = kv[2]
}
}
for (i in args) {
print decode(args[i])
}
}
'
)

@ -1,4 +1,4 @@
#!/bin/sh
# mmairix QUERY - mblaze wrapper around mairix
mairix -r "$@" | sed 's,//*,/,g' | msort -rd | mless
mairix -r "$@" | sed 's,//*,/,g' | mless

@ -1,18 +0,0 @@
#!/bin/sh -e
# mopenall [MSG] - open every attachements in xdg-open
[ "$#" -eq 0 ] && set -- .
f="$(mseq "$1" | sed 1q)"
[ -z "$f" ] && printf 'No message %s.\n' "$1" 1>&2 && exit 1
dir=$(mktemp -d -t menter.XXXXXX)
cd "$dir"
mshow -t "$1"
mshow -B -x "$1" 2>/dev/null
for f in * ; do
xdg-open "$f" &
done
wait
echo rm -r "$dir"
rm -r "$dir"

@ -1,15 +0,0 @@
#!/bin/sh
# mp7m - decode S/MIME .p7m format
tmp=$(mktemp -t mp7m.XXXXXX)
trap "rm -f '$tmp'" INT TERM EXIT
cat >"$tmp"
if openssl pkcs7 -print_certs <"$tmp" |
openssl smime -verify -in "$tmp" -inform DER -noverify -signer /dev/stdin
then
exit 64
else
exit 63
fi

@ -3,4 +3,4 @@
IFS='
'
exec cat -- $(mseq "${@:-.}" | sed 's/^ *//')
exec cat -- $(mseq "${@:-.}")

@ -1,8 +1,8 @@
#!/bin/sh
# mrecode - recode stdin respecting PIPE_CHARSET into UTF-8
case "$PIPE_CHARSET" in
''|*[Uu][Nn][Kk][Nn][Oo][Ww][Nn]*) exec cat;;
*) exec iconv -f "$PIPE_CHARSET" -t UTF-8;;
esac
if [ -n "$PIPE_CHARSET" ]; then
exec iconv -f "$PIPE_CHARSET" -t UTF-8
else
exec cat
fi

@ -1,45 +0,0 @@
#!/bin/sh
MBLAZE=${MBLAZE:-$HOME/.mblaze}
engine=$(mhdr -h search-engine "$MBLAZE/profile")
while getopts nmx opt; do
case $opt in
n)
engine=notmuch
;;
m)
engine=mu
;;
x)
engine=mairix
;;
'?')
printf "Usage: %s: [-n | -m | -x] query\n" "$0" 1>&2
exit 1
;;
esac
done
shift $(($OPTIND - 1))
[ -z "$engine" ] && engine=notmuch
case $engine in
notmuch)
exec notmuch search --output=files "$@"
;;
mu)
exec mu find --fields l "$@"
;;
mairix)
if [ "$#" -eq 0 ]; then
printf "Usage: %s -x query\n" "$0" 1>&2
exit 1
fi
exec mairix -r "$@"
;;
*)
echo "Unsupported search engine: $engine"
exit 1
;;
esac

@ -1,75 +0,0 @@
.Dd September 27, 2018
.Dt MSEARCH 1
.Os
.Sh NAME
.Nm msearch
.Nd search messages
.Sh SYNOPSIS
.Nm
.Op Fl n | Fl m | Fl x
.Op Fl -
.Op Ar query
.Sh DESCRIPTION
.Nm
searches for messages matching
.Ar query ,
using an external search engine, and prints file names separated by newlines.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl n
Search using
.Xr notmuch-search 1 .
.It Fl m
Search using
.Xr mu-find 1 .
.It Fl x
Search using
.Xr mairix 1 .
.It Fl -
Stop scanning for arguments.
.It Ar query
The search query, whose interpretation is up to the search engine.
This can also contain additional arguments for them
.El
.Pp
If no search engine is specified as an argument,
.Sq Li Search-Engine\&:
from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
is used.
Valid values for this setting are
.Sq notmuch ,
.Sq mairix ,
and
.Sq mu .
If that is unset,
.Xr notmuch-search 1
is used.
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It Ev MBLAZE
Directory containing mblaze configuration files.
(Default:
.Pa $HOME/.mblaze )
.El
.Sh EXIT STATUS
.Ex -std
Note that the called programs may have their own exit values.
.Sh SEE ALSO
.Xr mairix 1 ,
.Xr mu-find 1 ,
.Xr notmuch-search 1 ,
.Xr mblaze-profile 5
.Sh AUTHORS
.An Thomas Schneider Aq Mt qsx@chaotikum.eu
.Sh LICENSE
.Nm
is in the public domain.
.Pp
To the extent possible under law,
the creator of this work
has waived all copyright and related or
neighboring rights to this work.
.Pp
.Lk http://creativecommons.org/publicdomain/zero/1.0/

@ -3,23 +3,14 @@
[ -f "$1" ] || exit 1
if command -v gpg2 >/dev/null; then
GPG=gpg2
else
GPG=gpg
fi
IFS='
'
TMPD=$(mktemp -d -t msign.XXXXXX)
trap "rm -rf '$TMPD'" INT TERM EXIT
FROM=$(maddr -a -h from "$1" | sed 1q)
[ "$FROM" ] && key="--default-key=$FROM"
awk '/^$/,0' "$1" | mmime | sed 's/$/ /' >"$TMPD"/content
$GPG $key --armor --detach-sign -o "$TMPD"/signature.asc "$TMPD"/content ||
gpg --armor --detach-sign -o "$TMPD"/signature.asc "$TMPD"/content ||
exit $?
{

@ -57,12 +57,15 @@ STDOUT.sync = true
ARGV.each { |group|
FileUtils.mkdir_p(File.join(dir, group, "cur"))
FileUtils.mkdir_p(File.join(dir, group, "new"))
FileUtils.mkdir_p(File.join(dir, group, "tmp"))
nntp.write("GROUP #{group}\r\n")
msg = nntp.gets
unless msg =~ /^211 /
STDERR.puts msg
$exit = 69
next
end
@ -75,10 +78,6 @@ ARGV.each { |group|
low = high - LIMIT + 1 if number > LIMIT - 1
low = 1 if low <= 0
FileUtils.mkdir_p(File.join(dir, group, "cur"))
FileUtils.mkdir_p(File.join(dir, group, "new"))
FileUtils.mkdir_p(File.join(dir, group, "tmp"))
have = Dir.entries(File.join(dir, group, "cur")).
map { |f| $1.to_i if f =~ /N=(\d+)/ }.compact
@ -136,5 +135,3 @@ ARGV.each { |group|
puts
}
exit $exit || 0

@ -1,13 +1,7 @@
#!/bin/sh
# mverify MSG - verify a OpenPGP or SMIME message
# Needs gpg2 (for OpenPGP) and openssl (for SMIME).
if command -v gpg2 >/dev/null; then
GPG=gpg2
else
GPG=gpg
fi
# Needs gpg (for OpenPGP) and openssl (for SMIME).
[ "$#" -eq 0 ] && set -- .
@ -20,7 +14,7 @@ signed && content && !signature && indent == si+2 { signature = 0+$1; type = $2
function q(a) { gsub("\\47", "\47\\\47\47", a); return "\47"a"\47" }
END {
if (type == "" && plain) { // guess plain text armored signature
exit(system("mshow -r " q(msg) " | '$GPG' --verify"));
exit(system("mshow -r " q(msg) " | gpg --verify"));
} else if (type == "") {
print("No signature found.")
exit(100)
@ -28,7 +22,7 @@ END {
exit(system("mshow -r -O " q(msg) " " q(content) \
" | sed $DOS2UNIX | " \
" { mshow -O " q(msg) " " q(signature) \
" | '$GPG' --verify - /dev/fd/3; } 3<&0"))
" | gpg --verify - /dev/fd/3; } 3<&0"))
} else if (type == "application/pkcs7-signature") {
exit(system("mshow -r -O " q(msg) " " q(signed) \
" | openssl smime -verify"))

@ -7,37 +7,12 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int aflag;
static int dflag;
static char defaulthflags[] = "from:sender:reply-to:to:cc:bcc:"
"resent-from:resent-sender:resent-to:resent-cc:resent-bcc:";
static char *hflag = defaulthflags;
void
print_quoted(char *s)
{
char *t;
for (t = s; *t; t++)
if ((unsigned char)*t < 32 || strchr("()<>[]:;@\\,.\"", *t))
goto quote;
printf("%s", s);
return;
quote:
putchar('"');
for (t = s; *t; t++) {
if (*t == '"' || *t == '\\')
putchar('\\');
putchar(*t);
}
putchar('"');
}
void
addr(char *file)
{
@ -57,32 +32,21 @@ addr(char *file)
v = blaze822_chdr(msg, h);
if (v) {
char *disp, *addr;
char ddec[16384];
while ((v = blaze822_addr(v, &disp, &addr))) {
if (disp) {
blaze822_decode_rfc2047(ddec, disp, sizeof ddec - 1, "UTF-8");
ddec[sizeof ddec - 1] = 0;
disp = ddec;
}
char vdec[16384];
blaze822_decode_rfc2047(vdec, v, sizeof vdec - 1, "UTF-8");
vdec[sizeof vdec - 1] = 0;
v = vdec;
while ((v = blaze822_addr(v, &disp, &addr))) {
if (disp && addr && strcmp(disp, addr) == 0)
disp = 0;
if (aflag) {
if (addr)
printf("%s\n", addr);
} else if (dflag) {
if (disp) {
print_quoted(disp);
printf("\n");
}
} else {
if (disp && addr) {
print_quoted(disp);
printf(" <%s>\n", addr);
} else if (addr) {
if (disp && addr) {
if (aflag)
printf("%s\n", addr);
}
else
printf("%s <%s>\n", disp, addr);
} else if (addr) {
printf("%s\n", addr);
}
}
}
@ -93,26 +57,22 @@ addr(char *file)
break;
}
}
blaze822_free(msg);
}
int
main(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "adh:")) != -1)
while ((c = getopt(argc, argv, "ah:")) != -1)
switch (c) {
case 'a': aflag = 1; break;
case 'd': dflag = 1; break;
case 'h': hflag = optarg; break;
default:
fprintf(stderr,
"Usage: maddr [-ad] [-h headers] [msgs...]\n");
"Usage: maddr [-a] [-h headers] [msgs...]\n");
exit(1);
}
xpledge("stdio rpath", "");
if (argc == optind && isatty(0))
blaze822_loop1(":", addr);
else

@ -7,18 +7,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int aflag;
static int cflag;
static int dflag;
static int hflag;
static int iflag;
static int lflag;
static int oflag;
static int pflag;
static int qflag;
@ -33,8 +29,8 @@ static char *curfile;
int
match(char *file, char *hdr, char *s)
{
if (oflag && !cflag && !qflag && !vflag && !lflag) {
regmatch_t pmatch = {0};
if (oflag && !cflag && !qflag && !vflag) {
regmatch_t pmatch;
int len, matched;
matched = 0;
while (*s && regexec(&pattern, s, 1, &pmatch, 0) == 0) {
@ -45,8 +41,6 @@ match(char *file, char *hdr, char *s)
}
if (pflag)
printf("%s: %s: ", file, hdr);
else if (hflag)
printf("%s: ", hdr);
printf("%.*s\n", len, s);
s += len;
matched++;
@ -57,12 +51,9 @@ match(char *file, char *hdr, char *s)
exit(0);
matches++;
if (!cflag) {
if (vflag || !hflag)
printf("%s", file);
printf("%s", file);
if (pflag && !vflag)
printf(": %s: %s", hdr, s);
else if (hflag && !vflag)
printf("%s: %s", hdr, s);
putchar('\n');
}
if (mflag && matches >= mflag)
@ -90,7 +81,7 @@ match_part(int depth, struct message *msg, char *body, size_t bodylen)
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0) {
if ((hflag || pflag) && !cflag && !oflag && !vflag) {
if (pflag && !cflag && !oflag && !vflag) {
char *s, *p;
for (p = s = body; p < body+bodylen+1; p++) {
if (*p == '\r' || *p == '\n') {
@ -125,33 +116,13 @@ match_body(char *file)
return;
blaze822_walk_mime(msg, 0, match_part);
blaze822_free(msg);
}
int
match_value(char *file, char *h, char *v)
{
if (dflag) {
char d[4096];
blaze822_decode_rfc2047(d, v, sizeof d, "UTF-8");
return match(file, h, d);
} else if (aflag) {
char *disp, *addr;
while ((v = blaze822_addr(v, &disp, &addr))) {
if (addr && match(file, h, addr))
return 1;
}
} else {
return match(file, h, v);
}
return 0;
}
void
magrep(char *file)
{
if (!*header) {
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
char *flags = strstr(file, ":2,");
if (flags)
match(file, "flags", flags+3);
return;
@ -168,21 +139,21 @@ magrep(char *file)
if (!msg)
return;
if (strcmp(header, "*") == 0) {
char *hdr = 0;
while ((hdr = blaze822_next_header(msg, hdr))) {
char *v = strchr(hdr, ':');
if (v) {
*v = 0;
if (match_value(file, hdr, v + 1 + (v[1] == ' ')) && lflag)
char *v = blaze822_chdr(msg, header);
if (v) {
if (dflag) {
char d[4096];
blaze822_decode_rfc2047(d, v, sizeof d, "UTF-8");
match(file, header, d);
} else if (aflag) {
char *disp, *addr;
while ((v = blaze822_addr(v, &disp, &addr))) {
if (addr && match(file, header, addr))
break;
*v = ':';
}
} else {
match(file, header, v);
}
} else {
char *v = blaze822_chdr(msg, header);
if (v)
(void)match_value(file, header, v);
}
blaze822_free(msg);
@ -192,14 +163,12 @@ int
main(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "acdhilm:opqv")) != -1)
while ((c = getopt(argc, argv, "acdim:opqv")) != -1)
switch (c) {
case 'a': aflag = 1; break;
case 'c': cflag = 1; break;
case 'd': dflag = 1; break;
case 'h': hflag = 1; break;
case 'i': iflag = REG_ICASE; break;
case 'l': lflag = 1; break;
case 'm': mflag = atol(optarg); break;
case 'o': oflag = 1; break;
case 'p': pflag = 1; break;
@ -208,7 +177,7 @@ main(int argc, char *argv[])
default:
usage:
fprintf(stderr,
"Usage: magrep [-c|-h|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-a|-d] header:regex [msgs...]\n");
exit(2);
}
@ -220,8 +189,6 @@ usage:
if (!rx)
goto usage;
xpledge("stdio rpath", "");
*rx++ = 0;
int r = regcomp(&pattern, rx, REG_EXTENDED | iflag);
if (r != 0) {

@ -1,4 +1,4 @@
.Dd March 30, 2020
.Dd July 22, 2016
.Dt MADDR 1
.Os
.Sh NAME
@ -6,7 +6,7 @@
.Nd extract mail addresses from messages
.Sh SYNOPSIS
.Nm
.Op Fl ad
.Op Fl a
.Op Fl h Ar headers
.Op Ar msgs\ ...
.Sh DESCRIPTION
@ -36,8 +36,6 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl a
Only print the addr-spec address, not the display name.
.It Fl d
Only print the display name.
.It Fl h Ar headers
Only search the colon-separated list of
.Ar headers

@ -1,4 +1,4 @@
.Dd September 10, 2018
.Dd February 15, 2017
.Dt MAGREP 1
.Os
.Sh NAME
@ -6,10 +6,9 @@
.Nd search messages matching a pattern
.Sh SYNOPSIS
.Nm
.Op Fl c | Fl h | Fl o | Fl p | Fl q | Fl m Ar max
.Op Fl c | Fl q | Fl m Ar max
.Op Fl v
.Op Fl i
.Op Fl l
.Op Fl a | Fl d
.Ar header Ns Cm \&: Ns Ar regex
.Op Ar msgs\ ...
@ -37,13 +36,6 @@ matches against the maildir flags of
If
.Ar header
is
.Sq Cm \&* ,
.Nm
searches for the pattern in any header.
.Pp
If
.Ar header
is
.Sq Cm \&/ ,
.Nm
searches any plain text parts of the
@ -66,25 +58,15 @@ in RFC 2822 address
.Ar header
parts only.
.It Fl c
Only print a count of matching headers.
If
.Fl v
is specified,
count non-matching headers instead.
Only print a count of matching messages.
.It Fl d
Decode the
.Ar header
according to RFC 2047 prior to searching.
.It Fl h
Like
.Fl p
but do not print the file name.
.It Fl i
Match
.Ar regex
case insensitively.
.It Fl l
Only search a message until a match has been found.
.It Fl m Ar max
Do not show more than
.Ar max
@ -129,8 +111,7 @@ and >1 if an error occurs.
.Sh SEE ALSO
.Xr grep 1 ,
.Xr mmsg 7 ,
.Xr regex 7 /
.Xr re_format 7
.Xr regex 7
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh TRIVIA

@ -1,4 +1,4 @@
.Dd January 27, 2024
.Dd February 20, 2017
.Dt MBLAZE-PROFILE 5
.Os
.Sh NAME
@ -49,34 +49,11 @@ 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 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:
.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
.Li Bcc\&:
header will be used as the
.Li From\&:
address in a reply.
If not set,
.Li Alternate\&-Mailboxes\&:
will be used as a default.
will create draft messages in this maildir,
and save messages there after sending.
.It Li Scan\&-Format\&:
The default format string for
.Xr mscan 1 .

@ -1,4 +1,4 @@
.Dd January 18, 2020
.Dd January 6, 2018
.Dt MBLAZE 7
.Os
.Sh NAME
@ -32,7 +32,7 @@ list maildir folders, recursively
.It Xr mexport 1
export messages as mbox file
.It Xr mflag 1
manipulate maildir message flags
manipulate maildir flags
.It Xr mflow 1
reflow format=flowed plain text messages
.It Xr mfwd 1
@ -54,8 +54,6 @@ create MIME messages
create new maildir folders
.It Xr mpick 1
advanced message filter
.It Xr mrefile 1
move or copy messages between maildir folders
.It Xr mrep 1
reply to messages
.It Xr mscan 1
@ -163,9 +161,6 @@ 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
@ -209,12 +204,10 @@ There is a mailing list available at
.Po
to subscribe, send a message to
.Mt mblaze+subscribe@googlegroups.com
.Pc ;
archives are available at
.Lk https://inbox.vuxu.org/mblaze/ .
There also is an IRC channel
.Pc
and an IRC channel
.Li #vuxu
on irc.libera.chat.
on irc.freenode.net.
Please report security-related bugs directly to the author.
.Sh LICENSE
.Nm

@ -1,4 +1,4 @@
.Dd April 21, 2021
.Dd January 6, 2017
.Dt MCOM 1
.Os
.Sh NAME
@ -6,46 +6,33 @@
.Nm mfwd ,
.Nm mbnc ,
.Nm mrep
.Nd compose, forward, bounce, reply, send messages
.Nd compose, forward, bounce, reply to, and send mail
.Sh SYNOPSIS
.Nm mcom
.Op Fl Ar header Ar values\ ...
.Op Ar recipients\ ...
.Nm mcom
.Fl r Op draft
.Nm mrep
.Op Fl noquote
.Op Fl Ar header Ar values\ ... Fl -
.Op Ar msg
.Nm mfwd
.Op Fl r
.Op Fl Ar header Ar values\ ... Fl -
.Op Ar msgs\ ...
.Nm mbnc
.Op Fl Ar header Ar values\ ... Fl -
.Op Ar msg
.Ar msg
.Nm mrep
.Ar msg
.Sh DESCRIPTION
.Nm mcom
creates a new draft message and opens it in an editor.
After editing, a loop is started where the user can send,
re-edit or cancel the message.
creates a new draft mail and opens it in an editor.
After editing, a loop is started where the user can re-edit,
send or cancel the mail.
Use
.Sq Nm Fl r
to resume the editing of a draft;
by default, the last modified draft will be edited.
.Pp
.Nm mrep
creates the draft such that the message will be a reply to
.Ar msg
.Po
or the current message
.Pc .
Unless
.Fl noquote
is passed, it will contain the original mail quoted.
.Pp
.Nm mfwd
creates the draft with a subject and body appropriate
behaves like
.Nm mcom
but creates the draft with a subject and body appropriate
for forwarding the message.
By default, messages are forwarded verbatim as MIME
.Sq Li message/rfc822
@ -54,68 +41,32 @@ Use
.Fl r
to forward as
.Xr mshow 1
rendered plain text, using RFC 934 message encapsulation.
rendered plain text, using RFC934 message encapsulation.
.Pp
.Nm mbnc
creates the draft from the original
behaves like
.Nm mcom
but creates the draft from the original
.Ar msg
.Po
or the current message
.Pc
including headers,
(including headers)
and adds a Resent-To header, to which the message will
be bounced directly.
.Po
.Pp
.Nm mrep
behaves like
.Nm mcom
but creates the draft such that the mail will be a reply to
.Ar msg .
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
All commands can take optional
.Ar header
flags
.Pq which consist of two or more characters
to prefill header fields,
e.g. you can use
.Sq Nm mcom Fl to No merrilyn Fl cc No elea becci Fl subject No 'Party invite'
to create a draft with the To, Cc and Subject fields already set.
The flag
.Fl body Ar file
can be used to prepopulate the draft for
.Nm mcom
and
.Nm mrep
with the contents of
.Ar file .
.Pp
Note that these flags apply to
.Em all
arguments after them
.Po e.g.
.Sq mcom Fl attach No *.c
works
.Pc ,
so you
need to use
.Sq Fl -
when you want to use this feature together with
.Nm mrep ,
.Nm mfwd ,
or
.Nm mbnc .
.Pp
If the flag
.Fl send
is passed,
the message will be sent directly using the data on
the command line, and no editor or edit loop will be run.
.Sh MENU COMMANDS
.Bl -tag -width 2n
.It Ic s
Send the message.
Send the mail.
The MIME version will be used when one has been created.
.It Ic c
Cancel sending and quit, after displaying
Cancel sending and quit after displaying
the filename of the saved draft.
.It Ic m
Run
@ -123,19 +74,14 @@ Run
on the draft, and print the result of
.Ic mshow -t .
.It Ic e
Re-edit the draft.
Re-run the editor on the draft.
.It Ic d
Delete the draft and quit.
.It Ic p
Preview the draft, using
.Xr mshow 1 .
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It Ev EDITOR , Ev VISUAL
Editor used to compose messages.
(Default:
.Xr vi 1 )
.It Ev EDITOR
Editor used to compose mail.
.It Ev MBLAZE
Directory containing mblaze configuration files.
(Default:
@ -148,7 +94,7 @@ Draft messages, kept in current directory.
This can be configured in
.Xr mblaze-profile 5 .
.It Pa ${MBLAZE:-$HOME/.mblaze}/headers
Default headers for each message.
Default headers for each mail.
.It Pa ${MBLAZE:-$HOME/.mblaze}/signature No or Pa ~/.signature
Default signature.
.El

@ -1,9 +1,9 @@
.Dd February 4, 2021
.Dd July 26, 2016
.Dt MDELIVER 1
.Os
.Sh NAME
.Nm mdeliver
.Nd deliver messages or import mbox file
.Nd deliver message or mailbox into Maildir
.Sh SYNOPSIS
.Nm
.Op Fl c
@ -22,29 +22,28 @@
.Ar mbox
.Sh DESCRIPTION
.Nm
adds a message given on the standard input
as a new message in the maildir
adds a message given on standard input
as a new message in the Maildir
.Ar dir .
.Pp
When
.Fl M
is used,
.Nm
will regard the standard input as
will regard standard input as
an MBOXRD mailbox, split it on
.Dq Li "From "
and deliver each message,
decoding it according to the MBOXRD convention.
In this case,
.Nm
will set the mtime according to the value of
.Sq Li Date\&:
and the maildir flags according to the value of
and the Maildir flags according to the value of
.Sq Li Status\&:
or
.Sq Li X-Status\&: .
.Pp
The messages are delivered in a reliable way and use the default
The messages are delivered in a reliable way and use default
.Xr umask 2 .
.Pp
Please note that no syntactical checks are performed
@ -61,7 +60,7 @@ not
.Pa new/
(the default).
.It Fl v
Print each new message filename after delivery.
Print each message filename after delivery.
.It Fl X Ar flg
Override the flags of the new message file to be
.Ar flg .
@ -70,7 +69,6 @@ Override the flags of the new message file to be
.Ex -std
.Sh SEE ALSO
.Xr mexport 1 ,
.Xr mrefile 1 ,
.Xr maildir 5 ,
.Xr mbox 5
.Pp

@ -1,63 +1,34 @@
.Dd July 25, 2023
.Dd July 22, 2016
.Dt MDIRS 1
.Os
.Sh NAME
.Nm mdirs
.Nd list maildir folders, recursively
.Nd list Maildir folders, recursively
.Sh SYNOPSIS
.Nm
.Op Fl 0a
.Ar dirs\ ...
.Sh DESCRIPTION
.Nm
recursively scans the given
.Ar dirs
for maildir
.Pq and maildir++
folders and prints them,
separated by newlines.
scans the given directories for Maildir folders and prints them,
one per line.
It understands Maildir and Maildir++ formats.
.Pp
If
.Ar dirs
is not present then use
.Sq Li Maildir\&:
from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
.Pq if set .
There are currently no options.
.Pp
To
.Nm ,
a maildir folder is a directory containing
a Maildir folder is a directory containing
the directories
.Pa cur
and
.Pa new .
By the maildir++ convention, nested maildir folder
names must begin with
By the Maildir++ convention, nested Maildir folders
need to start with
.Sq Li \&. .
.Pq This can be disabled using Fl a .
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl 0
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 mblaze-profile 5
.Xr find 1
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE

@ -10,22 +10,18 @@
.Ar msgs\ ...
.Sh DESCRIPTION
.Nm
writes the specified
.Ar msgs
to the standard output
as an MBOXRD file.
.Po
exports the specified messages as an MBOXRD file,
to the standard output.
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no
.Ar msgs
are specified,
.Nm
reads filenames from the standard input,
or uses the messages in the current sequence if used interactively.
or uses the mails in the current sequence if used interactively.
.Pp
.Nm
uses the
@ -34,7 +30,7 @@ uses the
.Sq Li X\&-Envelope\&-To\&: )
and
.Sq Li Date\&:
headers from each message for the mbox
headers from the message for the mbox
.Sq Li "From "
line.
.Pp
@ -47,7 +43,7 @@ and
.Sq Li X\&-Status\&:
headers according to the
.Ar msgs
maildir flags.
Maildir flags.
.El
.Sh EXIT STATUS
.Ex -std

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm mflag
.Nd manipulate maildir message flags
.Nd manipulate Maildir mail flags
.Sh SYNOPSIS
.Nm
.Op Fl DFPRST
@ -16,14 +16,12 @@
.Op Ar msgs\ ...
.Sh DESCRIPTION
.Nm
changes the flags of the specified maildir
changes the flags of the specified Maildir
.Ar msgs
according to the options supplied.
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
The options are as follows:
.Bl -tag -width Ds
@ -38,8 +36,7 @@ as flagged.
.It Fl P
Mark
.Ar msgs
as passed
.Pq resent/forwarded/bounced .
as passed (resent/forwarded/bounced).
.It Fl R
Mark
.Ar msgs
@ -68,8 +65,7 @@ as flagged.
.It Fl p
Unmark
.Ar msgs
as passed
.Pq resent/forwarded/bounced .
as passed (resent/forwarded/bounced).
.It Fl r
Unmark
.Ar msgs
@ -87,11 +83,12 @@ Unmark
.Ar msgs
with the characters in
.Ar str .
.Pq Remember to use uppercase characters.
(Remember to use uppercase characters.)
.It Fl v
Read messages from the standard input
.Pq or use the whole current sequence, if used interactively
Read Maildir mails from the standard input
(or use the whole current sequence, if used interactively)
and print the transformed list of filenames.
.Pp
This can be used to keep the sequence intact in the case of renames.
.El
.Pp

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm mflow
.Nd reflow format=flowed plain text messages
.Nd reflow format=flowed plain text mails
.Sh SYNOPSIS
.Nm
.Op Fl f
@ -21,9 +21,9 @@ for
.Sq text/plain
messages for
.Xr mshow 1 .
Messages not specified as
Mails not using
.Sq format=flowed
are output unchanged.
are output as is.
.Pp
Text is reflowed (where allowed) to
fit the width given in the environment variable
@ -38,7 +38,7 @@ specifies the maximum line length.
The options are as follows:
.Bl -tag -width Ds
.It Fl f
Force wrapping of long lines.
Force line wrapping of long lines.
.It Fl q
Prefix lines with
.Sq Li \&> .

@ -1,4 +1,4 @@
.Dd December 25, 2018
.Dd August 1, 2016
.Dt MGENMID 1
.Os
.Sh NAME
@ -8,27 +8,27 @@
.Nm
.Sh DESCRIPTION
.Nm
generates and prints a unique Message-ID.
The Message-ID consists of an encrypted timestamp,
generates a fresh Message-ID and prints it.
The Message-ID consists of a timestamp,
a random value,
and a fully qualified domain name.
.Pp
The fully qualified domain name is arrived at by:
The fully qualified domain name is computed by:
.Bl -enum
.It
Using
.Sq Li FQDN\&:
from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
.Pq if set .
(if set).
.It
Resolving the current hostname.
.It
Using the domain component of the mail address in
Using the host part of the address in
.Sq Li Local\&-Mailbox\&:
from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile"
.Pq if set .
(if set).
.El
.Pp
If these steps don't result in a fully qualified domain name,

@ -3,10 +3,10 @@
.Os
.Sh NAME
.Nm mhdr
.Nd print message headers
.Nd show mail headers
.Sh SYNOPSIS
.Nm
.Op Fl h Ar hdrs Op Fl p Ar parameter
.Op Fl h Ar header Op Fl p Ar parameter
.Op Fl d
.Op Fl H
.Op Fl M
@ -14,13 +14,11 @@
.Op Ar msgs\ ...
.Sh DESCRIPTION
.Nm
prints the headers of the specified
prints the mail headers of the specified
.Ar msgs .
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no
.Ar msgs
@ -28,37 +26,25 @@ are specified,
.Nm
will default to the current message.
.Pp
If no
.Ar hdrs
are specified,
.Nm
will print all headers.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl h Ar hdrs
Only print the values of headers in the colon-separated list
.Ar hdrs .
.It Fl h Ar header
Only print the values of the headers in the colon-separated list
.Ar header .
.It Fl p Ar parameter
Extract a particular RFC 2045
.Ar parameter
from the specified
.Ar hdrs .
from the specified headers.
.It Fl d
Decode the
.Ar hdrs
according to RFC 2047.
Decode the headers according to RFC 2047.
.It Fl H
Prefix output lines with the filename of the message,
followed by a tab.
.It Fl M
Search for all occurrences of the
.Ar hdrs
.Pq default: only the first .
Search for all occurrences of the headers
(default: only the first).
.It Fl A
Scan for RFC 5322 addresses in the
.Ar hdrs
and print them, one per line.
Scan for RFC 5322 addresses in the headers and print them, one per line.
.It Fl D
Assume header contains RFC 5322 date and print as Unix timestamp.
.El
@ -73,22 +59,22 @@ and >1 if an error occurs.
.Rs
.%A N. Freed
.%A N. Borenstein
.%R RFC 2045
.%D November 1996
.%R RFC 2045
.%T Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
.Re
.Rs
.%A N. Freed
.%A N. Borenstein
.%D November 1996
.%B MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text
.%R RFC 2047
.%T MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text
.%D November 1996
.Re
.Rs
.%A P. Resnick (ed.)
.%D October 2008
.%B Internet Message Format
.%R RFC 5322
.%T Internet Message Format
.%D October 2008
.Re
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org

@ -3,26 +3,23 @@
.Os
.Sh NAME
.Nm minc
.Nd incorporate new messages
.Nd incorporate new Maildir mail
.Sh SYNOPSIS
.Nm
.Op Fl q
.Ar dirs\ ...
.Sh DESCRIPTION
.Nm
incorporates new messages in the maildir folders
incorporates new mail in the specified Maildir folders
.Ar dirs
by moving them from
.Pa new
to
.Pa cur ,
.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.
By default, the new Maildir filenames
are printed, one per line
.Pp
The options are as follows:
.Bl -tag -width Ds

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm mless
.Nd conveniently read messages in less(1)
.Nd interactive wrapper around mshow
.Sh SYNOPSIS
.Nm
.Op Ar msg
@ -17,40 +17,30 @@ for the current sequence.
Display starts with the current message, or
.Ar msg
if passed.
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
When no messages are passed and the standard input is from a pipe,
When no messages are passed and standard input is from a pipe,
.Ql mseq -S
is called to set the current sequence;
will be called to set the current sequence and
.Nm
is then run on the resulting sequence.
is run on the resulting sequence.
The first "file" of the less instance will be the output of
.Xr mscan 1 .
This makes
.Nm
convenient for use at the end of a pipeline.
convenient for use at the end of a pipe.
.Pp
.Nm
will start
.Xr less 1
and display the current message, if possible.
displaying the current message if possible.
Use
.Sq Ic ":n"
and
.Sq Ic ":p"
to read the next (resp. previous) message.
.Sh FILES
.Bl -tag -width Ds
.It Pa ${MBLAZE:-$HOME/.mblaze}/mlesskey , Pa $HOME/.mlesskey
Additional keybindings loaded for convenience.
.It Pa ${MBLAZE:-$HOME/.mblaze}/mless , Pa $HOME/.mless
Additional compiled keybindings loaded for convenience.
(Only needed for less earlier than version 590.)
.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO

@ -1,9 +1,9 @@
.Dd April 30, 2020
.Dd December 13, 2016
.Dt MLIST 1
.Os
.Sh NAME
.Nm mlist
.Nd list and filter messages
.Nd list messages in Maildir folders
.Sh SYNOPSIS
.Nm
.Op Fl DFPRST
@ -18,12 +18,13 @@
.Op Ar dirs\ ...
.Sh DESCRIPTION
.Nm
lists messages in the specified maildir folders
lists all messages in the specified Maildir folders
.Ar dirs ,
separated by newlines.
If used non-interactively with no specified folders,
one per line.
If used non-interactively,
with no specified folders,
.Nm
reads directory names from the standard input.
reads directory names from standard input.
.Pp
The options are as follows:
.Bl -tag -width Ds
@ -32,8 +33,7 @@ Only list messages marked as draft.
.It Fl F
Only list messages marked as flagged.
.It Fl P
Only list messages marked as passed
.Pq resent/forwarded/bounced .
Only list messages marked as passed (resent/forwarded/bounced).
.It Fl R
Only list messages marked as replied-to.
.It Fl S
@ -48,8 +48,7 @@ Don't list messages marked as draft.
.It Fl f
Don't list messages marked as flagged.
.It Fl p
Don't list messages marked as passed
.Pq resent/forwarded/bounced .
Don't list messages marked as passed (resent/forwarded/bounced).
.It Fl r
Don't list messages marked as replied-to.
.It Fl s
@ -59,7 +58,7 @@ Don't list messages marked as trashed.
.It Fl x Ar str
Don't list messages marked with the characters in
.Ar str .
.Pq Remember to use uppercase characters.
(Remember to use uppercase characters.)
.It Fl C
Only list messages in
.Pa cur .
@ -77,10 +76,8 @@ Don't print filenames.
Instead, print a one-line summary for each folder,
showing the number of unseen, flagged and total messages,
along with the folder name.
If any of the message selection flags are used,
the number of matching messages is printed as well.
If two or more folders are specified,
a total for all folders will also be printed at the end.
.Pp
If two or more folders are specified, a total will also be printed.
.El
.Pp
Multiple options are regarded as a conjunction.

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm mmime
.Nd create MIME messages
.Nd encode MIME mails
.Sh SYNOPSIS
.Nm
.Op Fl c | Fl r
@ -14,9 +14,9 @@
.Nm
generates a
.Sq Li multipart/mixed
message from the standard input,
mail from standard input,
extending, wrapping, and encoding the header as necessary,
and replacing lines in the message body of the form
and replacing lines in the message body, of the form
.Pp
.D1 Li # Ns Ar content Ns Li / Ns Ar type Ns Oo Ns Li # Ns Ar content-disposition Oc Pa path Ns Oo Li > Ns Ar filename Oc
.Pp
@ -36,7 +36,7 @@ The options are as follows:
.It Fl c
Check mode: don't output anything,
exit with status 1 if MIME-encoding the message is required,
or else exit with status 0.
or with status 0 else.
.It Fl r
Raw mode: don't expand MIME parts in the body, generate a
.Sq Li text/plain
@ -46,14 +46,6 @@ Override Content-Type for the toplevel part.
Defaults to
.Sq Li multipart/mixed .
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It Ev MBLAZE_RELAXED_MIME
If set,
.Nm Fl c
will relax the body line length check and only consider bodies with lines
longer than 998 characters need to be MIME formatted.
.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
@ -88,9 +80,9 @@ longer than 998 characters need to be MIME formatted.
.Re
.Rs
.%A P. Resnick (ed.)
.%D October 2008
.%B Internet Message Format
.%R RFC 5322
.%T Internet Message Format
.%D October 2008
.Re
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org

@ -3,19 +3,19 @@
.Os
.Sh NAME
.Nm mmkdir
.Nd create new maildir folders
.Nd create new Maildir folders
.Sh SYNOPSIS
.Nm
.Ar dir\ ...
.Ar dirs\ ...
.Sh DESCRIPTION
.Nm
creates new maildir folders.
creates new Maildir folders.
.Pp
Parent directories are created as needed,
and attempting to create an existing
maildir is not an error.
Maildir is not an error.
.Pp
New maildir folders are created with mode 0700, i.e.
New Maildir folders are created with mode 0700, i.e.
readable and writable by the owner only.
.Sh EXIT STATUS
.Ex -std
@ -27,8 +27,8 @@ readable and writable by the owner only.
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh CAVEATS
.Nm
does not support maildir++,
you need to transform nested maildir++ folder names yourself.
does not support Maildir++,
you need to transform nested Maildir++ folder names yourself.
.Sh LICENSE
.Nm
is in the public domain.

@ -1,4 +1,4 @@
.Dd July 3, 2020
.Dd July 22, 2016
.Dt MMSG 7
.Os
.Sh NAME
@ -6,7 +6,7 @@
.Nd mblaze message argument syntax
.Sh DESCRIPTION
This document outlines the message syntax used by many
of the utilities in the
of the tools in the
.Xr mblaze 7
message system.
.Pp
@ -14,12 +14,10 @@ In general, you can always specify a filename as a message,
if it contains a
.Sq Li \&/
character.
.Po
Use
(Use
.Sq Li \&./
to prefix messages in the current directory.
.Pc
You can also specify a maildir folder, which will be expanded
to prefix messages in the current directory.)
You can also specify a Maildir folder, which will be expanded
to all messages in the
.Pa cur/
directory.
@ -70,16 +68,10 @@ and may be repeated to refer to grandparents.
.Sq Ar msg Ns Cm \&_
refers to the subthread headed by
.Ar msg
.Po
i.e. all messages below
.Ar msg ,
with more indentation
.Pc .
(i.e. all messages below, with more indentation).
.Pp
The following special shortcuts may be used:
.Bl -tag -width 4n
.It Sq Li \&-
refers to the message read directly from the standard input.
.Bl -tag -width 3n
.It Sq Li \&.
refers to the current message.
Additionally, the syntax
@ -88,41 +80,23 @@ and
.Sq Li \&.- Ns Ar N
can be used to refer to messages relative to the current message.
.It Sq Li \&+
refers to the next message
.Po
like
.Sq Li \&.+1
.Pc
.It Sq Li \&.-
refers to the previous message
.Po
like
.Sq Li \&.-1
.Pc
refers to the next message (like
.Sq Li \&.+1 ) .
.It Sq Li \&-
refers to the previous message (like
.Sq Li \&.-1 ) .
.It Sq Li \&$
refers to the last message
.Po
like
.Sq Li -1
.Pc
refers to the last message (like
.Sq Li -1 ) .
.It Sq Li \&^
refers to the current parent message
.Po
like
.Sq Li \&.^
.Pc
refers to the current parent message (like
.Sq Li \&.^ ) .
.It Sq Li \&=
refers to the current thread
.Po
like
.Sq Li \&.=
.Pc
refers to the current thread (like
.Sq Li \&.= ) .
.It Sq Li \&_
refers to the current subthread
.Po
like
.Sq Li \&._
.Pc
refers to the current subthread (like
.Sq Li \&._ ) .
.El
.Sh SEE ALSO
.Xr mblaze 7

@ -1,16 +1,14 @@
.Dd July 30, 2020
.Dd July 27, 2016
.Dt MPICK 1
.Os
.Sh NAME
.Nm mpick
.Nd advanced message filter
.Nd filter mail messages
.Sh SYNOPSIS
.Nm
.Op Fl F Ar file
.Op Fl T
.Op Fl v
.Op Fl t Ar test
.Op Ar msgs\ ...
.Op Ar msglist\ ...
.Sh DESCRIPTION
.Nm
prints all matching messages.
@ -24,11 +22,6 @@ will read filenames from the standard input.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl F Ar file
Read expression from
.Ar file
and only show matching messages, see
.Sx TESTS .
.It Fl T
Include whole thread.
.It Fl t Ar test
@ -36,31 +29,71 @@ Only show messages matching the expression
.Ar test ,
see
.Sx TESTS .
.It Fl v
Print how many messages were tested and picked to standard error.
.El
.Sh MSGLISTS
.Nm
message lists (msglist) are mostly compatible with
.Xr mailx 1 .
They are message specifications used as shortened
.Sx TESTS ,
and can include:
.Bl -tag -width Ds
.It Ar n
Message number
.Ar n .
.It Ar n Ns Cm \&: Ns Ar m , Ar n Ns Cm \&- Ns Ar m
An inclusive range of message numbers between
.Ar n
and
.Ar m .
.It Ar address
All messages from
.Ar address .
.It Cm \&/ Ns Ar string
All messages with
.Ar string
in the subject line (case ignored).
.It Cm \&: Ns Ar c
All messages of type
.Ar c ,
where
.Ar c
shall be one of:
.Bl -tag -width Ds
.It Cm D
Draft messages.
.It Cm P
Passed (resent, forwarded or bounced) messages.
.It Cm R
Replied messages.
.It Cm F
Flagged messages.
.It Cm d , Cm T
Deleted messages.
.It Cm n
New messages.
.It Cm o
Old messages.
.It Cm r , Cm S
Read messages.
.It Cm u
Unread messages.
.El
.El
.Sh TESTS
.Nm
tests are given by the following EBNF:
.Bd -literal
<expr> ::= <expr> ? <expr> : <expr> -- ternary operator
| <expr> || <expr> -- disjunction
<expr> ::= <expr> || <expr> -- disjunction
| <expr> && <expr> -- conjunction
| ! <expr> -- negation
| ( <expr> )
| <expr> "|" <str> -- pipe current mail to command
| <expr> ">>" <str> -- append current mail to file
| <expr> ">" <str> -- write current mail to file
| <flagprop>
| <timeprop> <numop> <dur>
| <numprop> <numop> <num>
| <hdrprop> <decodeop> <strop> <str>
| <strprop> <strop> <str>
| prune -- do not match further messages in thread
| print -- always true value
| skip -- always false value
| <let>
| <ident>
<flagprop> ::= child | draft | flagged | info | new | parent | passed
| replied | seen | selected | trashed
@ -91,13 +124,8 @@ tests are given by the following EBNF:
| T )? -- *1024*1024*1024*1024
| cur -- index of cur message
<hdrprop> ::= from | to | subject | <str>
<decodeop> ::= . addr -- match address parts
| . disp -- match address display parts
| -- empty matches raw headers
<strprop> ::= path
<strprop> ::= from | subject | to
| <str> -- header name
<strop> ::= == | = | != -- string (in)equality
| === | !=== -- case insensitive string (in)equality
@ -108,15 +136,6 @@ tests are given by the following EBNF:
<str> ::= " ([^"] | "")+ " -- use "" for a single " inside "
| $[A-Za-z0-9_]+ -- environment variable
-- let expressions evaluate the expression following the `in` keyword,
-- the bindings are lazily evaluated.
<let> ::= { let <ident> = <scope> } in <scope>
-- Inside the scope previously defined idents are replaced with expressions
<scope> ::= <expr>
<ident> ::= [A-Za-z_][A-Za-z0-9_]+
.Ed
.Sh EXIT STATUS
.Ex -std

@ -1,55 +0,0 @@
.Dd April 19, 2018
.Dt MREFILE 1
.Os
.Sh NAME
.Nm mrefile
.Nd move or copy messages between maildir folders
.Sh SYNOPSIS
.Nm
.Op Fl k
.Op Fl v
.Op Ar msgs\ ...
.Ar dir
.Sh DESCRIPTION
.Nm
moves the
.Ar msgs
given on the command line
.Pq or the standard input
into the maildir
.Ar dir ,
assigning new filenames but keeping any message flags.
Messages are moved directly into the
.Pa cur/
directory.
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl k
keep the messages in their respective folders,
i.e. copy into
.Ar dir .
.It Fl v
Print each resulting message filename.
.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
.Xr mdeliver 1
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE
.Nm
is in the public domain.
.Pp
To the extent possible under law,
the creator of this work
has waived all copyright and related or
neighboring rights to this work.
.Pp
.Lk http://creativecommons.org/publicdomain/zero/1.0/

@ -1,24 +1,21 @@
.Dd January 2, 2020
.Dd June 28, 2017
.Dt MSCAN 1
.Os
.Sh NAME
.Nm mscan
.Nd generate one-line message summaries
.Nd print a one line per message mail listing
.Sh SYNOPSIS
.Nm
.Op Fl I
.Op Fl n
.Op Fl v
.Op Fl f Ar format
.Op Fl I
.Ar msgs\ ...
.Sh DESCRIPTION
.Nm
prints a one line summary for each message.
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no
.Ar msgs
@ -37,18 +34,14 @@ for details on how to control this behaviour.
The default
.Ar format
is
.Pp
.Dl %c%u%r %-3n %10d %17f %t %2i%s
.Pp
.Sq Li "%c%u%r %-3n %10d %17f %t %2i%s" ;
that is, for each message,
.Nm
prints relevant flags,
the sequence number
.Pq if applicable ,
the sequence number (if applicable),
the date,
the originator,
and the subject of the message
.Pq possibly indented .
and the subject of the message (possibly indented).
A default
.Nm
format may be specified in the user's
@ -56,15 +49,13 @@ format may be specified in the user's
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl n
Only print message numbers
(or filenames, if the message is not in the current sequence).
.It Fl I
Force ISO date output,
even for
.Sq Cm "%d" .
.It Fl n
Only print message numbers
.Pq or filenames, if the message is not in the current sequence .
.It Fl v
Print how many messages were scanned to standard error.
.It Fl f Ar format
Format according to the string
.Ar format ,
@ -72,10 +63,8 @@ inspired by
.Xr printf 3 .
.Pp
The following formatting codes may be used
.Po
.Ar wd
overrides the default width
.Pc :
.Ar ( wd
overrides the default width):
.Bl -tag -width Ds
.It Cm \en
Newline.
@ -85,8 +74,7 @@ Tab.
A plain
.Sq Li \&% .
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "b"
Human-readable size of the message
.Pq in kilobytes .
Human-readable size of the message (in kilobytes).
.It Cm "%c"
A
.Sq Li >
@ -94,14 +82,8 @@ on the current message,
otherwise a blank.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "d"
Adaptive date of the message.
When
.Ar wd
is greater or equal to 19,
the timestamp is shown in dottime format
.Pq Lk https://dotti.me/ .
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "D"
ISO date of the message
.Pq year, month, day .
ISO date of the message (year, month, day).
When
.Ar wd
is greater or equal to 16,
@ -113,23 +95,21 @@ seconds will also be shown.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "f"
The
.Sq Li From\&:
.Po
or
(or
.Sq Li To\&: ,
if the message is from us
.Pc .
if the message is from us).
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "F"
The maildir folder the message resides in.
The Maildir folder the message resides in.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "i"
.Ar wd
.Pq default: 1
(default: 1)
spaces per indentation depth in the thread tree.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "I"
The
.Sq Li Message\&-ID\&:
of the message.
.It Cm "%M"
The raw maildir flags of the message.
The raw Maildir flags of the message.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "n"
The number of the message in the current sequence.
.It Cm "%r"
@ -141,11 +121,9 @@ on a forwarded message, or a blank.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "R"
The filename of the message.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "s"
The subject of the message
.Pq defaults to remaining width .
The subject of the message (defaults to remaining width).
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "S"
The subject of the message
.Pq defaults to remaining width ,
The subject of the message (defaults to remaining width),
with leading
.Sq Li Re\&: ,
.Sq Li Fwd\&:
@ -191,13 +169,13 @@ A replied-to message
.Bl -tag -width 2n -compact
.It Li \&>
You are in
.Sq Li To\&:
.Sq Li To\&: .
.It Li \&+
You are in
.Sq Li Cc\&:
.Sq Li Cc\:& .
.It Li \&:
You are in
.Sq Li Resent\&-To\&:
.Sq Li Resent\&-To\&: .
.El
.Sh ENVIRONMENT
.Bl -tag -width MBLAZE_PAGER

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm msed
.Nd manipulate message headers
.Nd stream editor for transforming mail
.Sh SYNOPSIS
.Nm
.Ar script
@ -12,13 +12,11 @@
.Nm
prints the messages
.Ar msgs
with message headers transformed by the commands in
with mail headers transformed by the commands in
.Ar script .
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
If no
.Ar msgs
are passed,
@ -28,14 +26,14 @@ will default to the current message.
.Nm
scripts are akin to a subset of
.Xr sed 1
scripts, but optimized for modifying messages.
scripts, but optimized for modifying mail.
Note that
.Nm
unfolds and normalizes message headers,
unfolds and normalizes mail headers,
so they may need to be passed through
.Xr mmime 7
to ensure RFC 5322 conformance.
The message body is not affected.
The mail body is copied as-is.
.Pp
.Nm
supports the following commands.
@ -49,7 +47,7 @@ Multiple commands can be separated by
.It Cm \&/ Ns Ar header Ns Cm \&/ Ns Ic a Ns Cm \&/ Ns Ar value Ns Cm \&/
If the header
.Sq Ar header Ns Cm \&:
is not set in the message, add it with the given
is not set in the message, add it with given
.Ar value .
.It Cm \&/ Ns Ar headers Ns Cm \&/ Ns Ic c Ns Cm \&/ Ns Ar value Ns Cm \&/
Change colon-separated headers matching the regular expression
@ -69,7 +67,7 @@ For example,
.Sq Li "/x-.*/d"
will delete all headers starting with
.Sq Li "X-"
.Pq always case insensitive ,
(always case insensitive),
and
.Sq Li "/from:to:cc/d"
will delete the headers
@ -83,7 +81,7 @@ Substitute matches of the POSIX Basic Regular Expression
in headers matching the POSIX Basic Regular Expression
.Ar headers ,
with implicit anchoring to the header name
.Pq or all headers, if omitted ,
(or all headers, if omitted),
with the string
.Ar replacement ,
expanding
@ -123,10 +121,8 @@ contains the letter
.Ex -std
.Sh SEE ALSO
.Xr sed 1 ,
.Xr mhdr 1 ,
.Xr mmsg 7 ,
.Xr regex 7 /
.Xr re_format 7
.Xr regex 7
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm mseq
.Nd manipulate message sequences
.Nd manipulate mail sequence
.Sh SYNOPSIS
.Nm
.Op Fl fr
@ -23,12 +23,10 @@
.Fl C Ar msg
.Sh DESCRIPTION
.Nm
prints, fixes and sets the message sequence.
.Po
prints, fixes and sets messages in the mail sequence.
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no
.Ar msgs
@ -43,11 +41,8 @@ With
or
.Fl A ,
.Nm
will replace
.Pq resp. append
the default sequence.
If the standard output is not a terminal,
the new sequence is also printed.
will replace (resp. append) the default sequence.
If standard output is not a terminal, the new sequence is also printed.
.Pp
The options are as follows:
.Bl -tag -width Ds
@ -57,16 +52,15 @@ Behave as if
was the current message.
.It Fl f
Fix non-existing filenames by searching for a message with the same
maildir id
.Pq but different flags .
Maildir id (but different flags).
.It Fl r
Remove leading indentation from the filenames.
.It Fl S
Set the message sequence to the filenames passed on standard input.
Set the mail sequence to the filenames passed on standard input.
.It Fl A
Like
.Fl S ,
but append to the message sequence instead of replacing it.
but append to the mail sequence instead of replacing it.
.It Fl C Ar msg
Set the current message to
.Ar msg
@ -76,29 +70,21 @@ and exit.
.Bl -tag -width Ds
.It Ev MBLAZE
Directory containing mblaze configuration.
.Po
Default:
.Pa $HOME/.mblaze
.Pc
(Default:
.Pa $HOME/.mblaze )
.It Ev MAILCUR
Symbolic link referring to the current message.
.Po
Default:
.Pa ${MBLAZE:-$HOME/.mblaze}/cur
.Pc
(Default:
.Pa ${MBLAZE:-$HOME/.mblaze}/cur )
.It Ev MAILDOT
When set to a filename, overrides the current message.
.Po
Prefer using
(Prefer using
.Fl c
instead.
.Pc
instead.)
.It Ev MAILSEQ
File were the sequence is stored.
.Po
Default:
.Pa ${MBLAZE:-$HOME/.mblaze}/seq
.Pc
(Default:
.Pa ${MBLAZE:-$HOME/.mblaze}/seq )
.El
.Sh EXIT STATUS
.Ex -std

@ -1,14 +1,14 @@
.Dd January 17, 2021
.Dd July 22, 2016
.Dt MSHOW 1
.Os
.Sh NAME
.Nm mshow
.Nd render messages and extract MIME parts
.Nd render mail and extract MIME parts
.Sh SYNOPSIS
.Nm
.Op Fl h Ar headers
.Op Fl A Ar mimetypes
.Op Fl nqrBFHLN
.Op Fl nqrFHLN
.Op Ar msgs\ ...
.Nm
.Fl x Ar msg
@ -23,18 +23,13 @@
.Fl R
.Ar msg
.Sh DESCRIPTION
By default,
.Nm
renders the specified
.Ar msgs
to the standard output, by default.
.Po
renders the specified messages to the standard output.
See
.Xr mmsg 7
for the message argument syntax.
.Pc
If used interactively and no
.Ar msgs
are specified,
If used interactively, and no messages are specified,
.Nm
displays the current message using colorization and a pager.
.Pp
@ -47,25 +42,16 @@ instead of the default headers
.Sq Li from\&:subject\&:to\&:cc\&:date\&:reply\&-to\&: .
.It Fl A Ar mimetypes
Define
.Sq Li "multipart/alternative"
.Sq Li "mixed/alternative"
preference.
.Ar mimetypes
is a colon-separated list of
MIME types which will be preferred,
in the order given,
when rendering
.Sq Li "multipart/alternative"
.Sq Li "mixed/alternative"
parts.
If no MIME type matches, the last MIME part will be rendered.
.Pp
When
.Ar mimetypes
is
.Sq Li all ,
.Nm
will render all parts of a
.Sq Li "multipart/alternative"
part.
If no MIME type matches, the first MIME part will be rendered.
.Pp
Defaults to
.Sq Li "text/plain:text/html" .
@ -76,11 +62,6 @@ Don't render the body, stop after header output.
.It Fl r
Don't render the body, print raw body.
This may be dangerous to use on a tty.
.It Fl B
Decode encoded-words also in MIME parameters in direct violation
of RFC 2047.
This is useful if the attachment names look like
.Sq Li =?UTF-8?Q?stuff?= .
.It Fl F
Don't apply filters to MIME parts.
.It Fl H
@ -100,9 +81,6 @@ into files.
can be specified by number, filename or
.Xr fnmatch 3
pattern.
If no
.Ar parts
are specified, extracts all attachments with a filename.
.It Fl O Ar msg
Like
.Fl x
@ -134,21 +112,14 @@ and re-encodes them into UTF-8 if necessary.
.Pp
Other filters can be specified in the file
.Pa ${MBLAZE:-$HOME/.mblaze}/filter
.Po
or via
.Ev MAILFILTER
.Pc ,
in the format:
.Pp
in the format
.D1 Ar type/subtype Ns Li \&: Ar command
or
.D1 Ar type Ns Li \&: Ar command
.Pp
.Nm
will then spawn a pipe to
.Ar command ,
write the MIME part
to standard input
and display the output.
The environment variable
.Ev PIPE_CHARSET
@ -166,7 +137,7 @@ The output is printed raw, without escaping.
.It 63
Behave as if the filter never ran.
.It 64
The output is an RFC 5322 message that should be rendered again.
The output is a RFC5322 message that should be rendered again.
.It 65 to 80
Render the
.Va n Ns \&- Ns 64th
@ -175,14 +146,6 @@ part of this text/multipart part.
All other exit statuses are regarded as errors.
.Sh ENVIRONMENT
.Bl -tag -width MBLAZE_NOCOLOR
.It Ev MAILFILTER
Path to an alternative
.Pa filter
file.
.It Ev MBLAZE_NOCOLOR
If non-empty,
.Nm
will not spawn a colorization filter.
.It Ev MBLAZE_PAGER
Any non-empty value of the environment variable
.Ev MBLAZE_PAGER
@ -191,6 +154,10 @@ is used instead of the standard pagination program, specified in
When empty or set to
.Sq Ic cat ,
no pager is spawned.
.It Ev MBLAZE_NOCOLOR
If non-empty,
.Nm
will not spawn a colorization filter.
.El
.Sh EXIT STATUS
.Ex -std

@ -3,7 +3,7 @@
.Os
.Sh NAME
.Nm msort
.Nd sort messages
.Nd sort mail messages
.Sh SYNOPSIS
.Nm
.Op Fl r
@ -11,13 +11,11 @@
.Op Ar msgs\ ...
.Sh DESCRIPTION
.Nm
sorts messages according to various orders,
and prints, separated by newlines, the resulting message names.
.Po
sorts mail messages according to various orders,
and prints, one per line, the sorted message names.
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no messages are specified,
.Nm

@ -1,23 +1,21 @@
.Dd May 4, 2020
.Dd July 22, 2016
.Dt MTHREAD 1
.Os
.Sh NAME
.Nm mthread
.Nd arrange messages into discussions
.Nd thread mail messages
.Sh SYNOPSIS
.Nm
.Op Fl vpr
.Op Fl v
.Op Fl S Ar msg
.Op Ar msgs\ ...
.Sh DESCRIPTION
.Nm
groups messages together in parent/child relationships, based on
which messages are replies to which others.
.Po
See
.Xr mmsg 7
for the message argument syntax.
.Pc
.Pp
If no messages are specified,
.Nm
@ -25,7 +23,7 @@ will read filenames from the standard input,
or use the default sequence if used interactively.
.Pp
.Nm
prints the threaded messages separated by newlines and
prints the threaded messages one per line,
indented according to their depth in the message tree.
Unresolved Message-IDs are printed as-is.
.Pp
@ -33,12 +31,6 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl v
Do not prune unresolved Message-IDs at the top-level.
.It Fl p
With
.Fl S ,
only add parents, not unrelated subthreads.
.It Fl r
Sort the top-level threads in reverse order (newest threads first).
.It Fl S Ar msg
Treat
.Ar msg

@ -7,19 +7,15 @@ function so(s) { return sprintf("\033[1m%s\033[0m", s) }
BEGIN { hdr = 1; if ("NO_COLOR" in ENVIRON || match(ENVIRON["TERM"], "^(dumb|network|9term)")) no_color = 1 }
no_color { print; next }
/\r$/ { sub(/\r$/, "") }
/^\014$/ { nextmail = 1; print(fg(co("FF",232), $0)); next }
/^$/ { hdr = 0; diff = 0 }
/^\014$/ { nextmail = 1; next }
/^$/ { hdr = 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 }

410
mcom

@ -1,9 +1,6 @@
#!/bin/sh
# mcom [TO] - compose mail
NL='
'
commajoin() {
awk 'NR==1 {l=$0; next}
{l=l", "$0}
@ -11,20 +8,10 @@ commajoin() {
}
notmine() {
mine="$(maddr -a -h local-mailbox:alternate-mailboxes: "$MBLAZE/profile")"
mine="$(maddr -a -h local-mailbox:alternate-mailboxes: $MBLAZE/profile)"
grep -Fv -e "$mine"
}
replyfrom() {
addrs="$(maddr -a -h reply-from: "$MBLAZE/profile")"
[ -z "$addrs" ] && addrs="$(maddr -a -h alternate-mailboxes: "$MBLAZE/profile")"
grep -F -e "$addrs"
}
ouniq() {
awk '!seen[$0]++'
}
reffmt() {
sed 's/^[^<]*//g;s/[^>]*$//g;s/>[^<]*</>\
</g' | uniq | sed 's/^/ /'
@ -46,27 +33,6 @@ stampdate() {
fi
}
checksensible() {
awk '
/^$/ {
seenheader=1
exit
}
!(/^[^ \t][^ \t]*[ \t]*:/ || /^[ \t]/) {
bad=1
print "invalid header line: "$0 >"/dev/stderr"
}
END {
if (!seenheader) {
print "warning: message does not contain an empty line between headers and body." >"/dev/stderr"
exit 1
}
if (bad)
exit 1
}
' "$1"
}
stripempty() {
tmp=$(mktemp -t mcom.XXXXXX)
msed 's/^[ \t]*$//d' "$1" >"$tmp"
@ -75,27 +41,24 @@ stripempty() {
needs_multipart() {
mhdr -h attach "$1" >/dev/null ||
grep -qE '^#[a-zA-Z]+/[a-zA-Z0-9+.;=#-]+ ' "$1"
grep -q '^#[^ ]*/[^ ]* ' "$1"
}
do_mime() {
if needs_multipart "$draft"; then
(
IFS=$NL
msed '/attach/d' "$draft"
for f in $(mhdr -M -h attach "$draft"); do
IFS='
'
msed '/attach/d' $draft
for f in $(mhdr -M -h attach $draft); do
printf '#%s %s\n' \
"$(file -Lb --mime "$f" | sed 's/ //g')" \
"$(file -Lbi $f | sed 's/ //g')" \
"$f"
done
) | mmime >"$draftmime"
) | mmime >$draftmime
else
mmime -r <"$draft" >"$draftmime"
fi
if [ $? -ne 0 ]; then
printf 'mcom: fix above errors before continuing\n' 1>&2
rm -f "$draftmime"
fi
}
MBLAZE=${MBLAZE:-$HOME/.mblaze}
@ -103,142 +66,24 @@ MBLAZE=${MBLAZE:-$HOME/.mblaze}
sendmail=$(mhdr -h sendmail "$MBLAZE/profile")
sendmail_args=$(mhdr -h sendmail-args "$MBLAZE/profile")
sendmail="${sendmail:-sendmail} ${sendmail_args:--t}"
default_from=$(mhdr -h local-mailbox "$MBLAZE/profile")
defaultc=e
hdrs=
resume=
noquote=
case "$0" in
*mcom*)
hdr=to
while [ $# -gt 0 ]; do
case "$1" in
--)
# -- is like -to, really
shift
hdr=to
;;
-r)
*mcom*)
if [ "$1" = -r ]; then
shift
resume=1
if [ "$#" -gt 0 ]; then
case "$1" in
/*|./*) draft="$1";;
*) draft="./$1";;
esac
if ! [ -f "$draft" ]; then
printf 'mcom: no such draft %s\n' \
"$draft" 1>&2
exit 1
fi
echo "using draft $draft"
echo "used draft $1"
draft="$1"
shift
fi
;;
-send)
defaultc=justsend
shift;;
-??*)
hdr=${1#-}
shift;;
[!-]*)
hdrs="$hdrs$NL$(printf '%s: %s\n' "${hdr}" "$1")"
shift;;
*)
printf 'mcom: invalid argument %s\n' "$1" 1>&2
exit 1;;
esac
done
;;
*mfwd*)
hdr=
raw=
while [ $# -gt 0 ]; do
case "$1" in
--)
shift
break;;
-r)
shift
raw=1;;
-send)
defaultc=justsend
shift;;
-??*)
hdr=${1#-}
shift;;
[!-]*)
[ -z "$hdr" ] && break
hdrs="$hdrs$NL$(printf '%s: %s\n' "${hdr}" "$1")"
shift;;
*)
printf 'mfwd: invalid argument %s\n' "$1" 1>&2
exit 1;;
esac
done
[ "$#" -eq 0 ] && set -- .
;;
*mbnc*)
hdr=
while [ $# -gt 0 ]; do
case "$1" in
--)
shift
break;;
-send)
defaultc=justsend
shift;;
-??*)
hdr=${1#-}
shift;;
[!-]*)
[ -z "$hdr" ] && break
hdrs="$hdrs$NL$(printf '%s: %s\n' "${hdr}" "$1")"
shift;;
*)
printf 'mbnc: invalid argument %s\n' "$1" 1>&2
exit 1;;
esac
done
[ "$#" -eq 0 ] && set -- .
;;
*mrep*)
hdr=
while [ $# -gt 0 ]; do
case "$1" in
--)
shift
break;;
-send)
defaultc=justsend
shift;;
-noquote)
noquote=1
shift;;
-??*)
hdr=${1#-}
shift;;
[!-]*)
[ -z "$hdr" ] && break
hdrs="$hdrs$NL$(printf '%s: %s\n' "${hdr}" "$1")"
shift;;
*)
printf 'mrep: invalid argument %s\n' "$1" 1>&2
exit 1;;
esac
done
[ "$#" -eq 0 ] && set -- .
;;
fi
;;
esac
hdrs="$(printf '%s\n' "${hdrs#$NL}" | mhdr -)"
outbox=$(mhdr -h outbox "$MBLAZE/profile" | sed "s:^~/:$HOME/:")
draftbox=$(mhdr -h drafts "$MBLAZE/profile" | sed "s:^~/:$HOME/:")
draftbox="${draftbox:-$outbox}"
if [ -z "$draftbox" ]; then
outbox=$(mhdr -h outbox "$MBLAZE/profile")
if [ -z "$outbox" ]; then
if [ -z "$resume" ]; then
i=0
while [ -f "snd.$i" ]; do
@ -248,140 +93,91 @@ if [ -z "$draftbox" ]; then
elif [ -z "$draft" ]; then
draft=$(ls -1t ./snd.*[0-9] | sed 1q)
fi
draftmime="$draft.mime"
draftmime="./snd.$i.mime"
else
if [ -z "$resume" ]; then
draft="$(true | mdeliver -v -c -XD "$draftbox")"
draft="$(true | mdeliver -v -c -XD "$outbox")"
if [ -z "$draft" ]; then
printf '%s\n' "$0: failed to create draft in outbox $draftbox." 1>&2
printf '%s\n' "$0: failed to create draft in outbox $outbox." 1>&2
exit 1
fi
elif [ -z "$draft" ]; then
draft=$(mlist -D "$draftbox" | msort -r -M | sed 1q)
draft=$(mlist -D "$outbox" | msort -r -M | sed 1q)
fi
draftmime="$(printf '%s\n' "$draft" | sed 's,\(.*\)/cur/,\1/tmp/mime-,')"
fi
if [ -n "$resume" ] && [ -z "$draft" ]; then
echo "mcom: no draft found"
exit 1
fi
[ -z "$resume" ] &&
{
case "$0" in
*mcom*)
{
printf '%s' "$hdrs" | mhdr -M -h to - |
commajoin | sed 's/^/To: /'
printf '%s' "$hdrs" | mhdr -M -h cc - |
commajoin | sed 's/^/Cc: /'
printf '%s' "$hdrs" | mhdr -M -h bcc - |
commajoin | sed 's/^/Bcc: /'
printf '%s\n' "$hdrs" | awk '{ print }' |
msed "/to/d; /cc/d; /bcc/d; /body/d" -
} | msed "/cc/a//; /bcc/a//; /subject/a//; /from/a/$default_from/" - | sed '/^$/d'
printf 'To: '
printf '%s\n' "$@" | commajoin
printf '%s: \n' Cc Bcc Subject
from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && printf 'From: %s\n' "$from"
cat "$MBLAZE/headers" 2>/dev/null
msgid
museragent
cat "$MBLAZE/headers" 2>/dev/null
printf '\n'
(
IFS=$NL
cat -- /dev/null $(printf '%s' "$hdrs" | mhdr -M -h body -)
)
printf '\n'
printf '\n\n'
;;
*mfwd*)
{
printf '%s' "$hdrs" | mhdr -M -h to - |
commajoin | sed 's/^/To: /'
printf '%s' "$hdrs" | mhdr -M -h cc - |
commajoin | sed 's/^/Cc: /'
printf '%s' "$hdrs" | mhdr -M -h bcc - |
commajoin | sed 's/^/Bcc: /'
COLUMNS=10000 mscan -f 'Subject: Fwd: [%f] %s' "$@" 2>/dev/null | sed 1q
printf '%s\n' "$hdrs" | awk '{ print }' |
msed "/to/d; /cc/d; /bcc/d" -
} | msed "/cc/a//; /bcc/a//; /from/a/$default_from/" - | sed '/^$/d'
raw=
[ "$1" = -r ] && raw=1 && shift
[ "$#" -eq 0 ] && set -- .
printf '%s: \n' To Cc Bcc
COLUMNS=10000 mscan -f 'Subject: [%f] %s' "$@" | sed 1q
from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && printf 'From: %s\n' "$from"
cat "$MBLAZE/headers" 2>/dev/null
msgid
museragent
cat "$MBLAZE/headers" 2>/dev/null
printf '\n\n'
if [ -z "$raw" ]; then
mseq -r "$@" | sed 's:^:#message/rfc822#inline :; s:$:>:'
else (
SEP=-----
IFS=$NL
IFS='
'
for f in $(mseq -r "$@"); do
printf '%s Forwarded message from %s %s\n\n' \
$SEP "$(mhdr -d -A -h from "$f")" $SEP
$SEP "$(mhdr -d -h from "$f")" $SEP
DISPLAY= mshow -n -N "$f" </dev/null |
sed 's/^-/- &/' # RFC 934
sed 's/^-/- &/' # RFC934
printf '\n%s %s %s\n\n' \
$SEP 'End forwarded message' $SEP
done
) fi
;;
*mbnc*)
old_ifs="$IFS"
IFS=$NL
set -- $(mseq -r -- "$@")
IFS="$old_ifs"
if [ "$#" -ne 1 ]; then
printf 'mbnc: needs exactly one mail to bounce\n' 1>&2
exit 1
fi
{
printf '%s' "$hdrs" | mhdr -M -h resent-to - |
commajoin | sed 's/^/Resent-To: /'
printf '%s' "$hdrs" | mhdr -M -h resent-cc - |
commajoin | sed 's/^/Resent-Cc: /'
printf '%s\n' "$hdrs" | awk '{ print }' |
msed "/resent-to/d; /resent-cc/d" -
} |
msed "/resent-to/a//; /resent-from/a/$default_from/" - | sed '/^$/d'
printf '%s: \n' Resent-To
from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && printf 'Resent-From: %s\n' "$from"
msgid | sed 's/^/Resent-/'
printf 'Resent-Date: %s\n' "$(mdate)"
(
IFS=$NL
cat $(mseq -r -- "$@")
IFS='
'
cat $(mseq "${@:-.}")
)
;;
*mrep*)
old_ifs="$IFS"
IFS=$NL
set -- $(mseq -r -- "$@")
IFS="$old_ifs"
if [ "$#" -ne 1 ]; then
printf 'mrep: needs exactly one mail to reply to\n' 1>&2
exit 1
fi
[ "$#" -eq 0 ] && set -- .
ng=$(mhdr -h newsgroups "$1")
if [ "$ng" ]; then
printf 'Newsgroups: %s\n' "$ng"
else
to=$(mhdr -d -h reply-to "$1")
[ -z "$to" ] && to=$(mhdr -d -A -h from "$1")
to=$(mhdr -h reply-to "$1")
[ -z "$to" ] && to=$(mhdr -h from "$1")
printf 'To: %s\n' "$to"
printf 'Cc: %s\n' \
"$(mhdr -d -A -h to:cc: "$1" |
notmine |grep -Fv -e "$to" |
ouniq |commajoin)"
"$(mhdr -d -A -h to:cc: "$1" |notmine |commajoin)"
printf 'Bcc: \n'
printf '%s\n' "$hdrs" | awk '{ print }' |
msed "/body/d" -
fi | sed '/^$/d'
printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")"
if ! printf '%s\n' "$hdrs" | awk '{ print }' |
mhdr -h from: - >/dev/null; then
addr=$(maddr -a -h delivered-to:to:cc:bcc: "$1" | replyfrom | head -n1)
[ -n "$addr" ] && from=$(maddr -h reply-from "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1)
[ -n "$addr" ] && [ -z "$from" ] && from=$(maddr -h alternate-mailboxes "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1)
[ -z "$from" ] && from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ -n "$from" ] && printf 'From: %s\n' "$from"
fi
printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")"
from=$(mhdr -h local-mailbox "$MBLAZE/profile")
[ "$from" ] && printf 'From: %s\n' "$from"
cat "$MBLAZE/headers" 2>/dev/null
mid=$(mhdr -h message-id "$1")
if [ "$mid" ]; then
printf 'References:'
@ -393,17 +189,9 @@ fi
fi
msgid
museragent
cat "$MBLAZE/headers" 2>/dev/null
printf '\n'
if [ -z "$noquote" ]; then
mquote "$1"
printf '\n'
fi
(
IFS=$NL
cat -- /dev/null $(printf '%s' "$hdrs" | mhdr -M -h body -)
)
mquote "$1"
printf '\n'
;;
esac
@ -422,10 +210,10 @@ fi
cat "$SIGNATURE"
fi
esac
} >"$draft"
} >$draft
automime=
c=$defaultc
c=e
while :; do
case "$c" in
s|send)
@ -442,16 +230,17 @@ while :; do
;;
esac
if [ -e "$draftmime" ]; then
if [ "$draft" -ot "$draftmime" ] || [ "$automime" = 1 ]; then
stampdate "$draftmime"
if $sendmail <"$draftmime"; then
if [ -e $draftmime ]; then
if [ $draft -ot $draftmime ] || [ "$automime" -eq 1 ]; then
stampdate $draftmime
if $sendmail <$draftmime; then
if [ "$outbox" ]; then
mv "$draftmime" "$draft"
mrefile "$(mflag -d -S "$draft")" "$outbox"
mv $draftmime $draft
mflag -d $draft
else
rm "$draft" "$draftmime"
rm $draft $draftmime
fi
exit 0
else
printf '%s\n' "mcom: $sendmail failed, kept draft $draft"
exit 2
@ -459,17 +248,17 @@ while :; do
else
printf 'mcom: re-run mmime first.\n'
c=
continue
fi
else
if mmime -c <"$draft" && ! [ "$automime" = 1 ]; then
stampdate "$draft"
if $sendmail <"$draft"; then
if mmime -c <$draft; then
stampdate $draft
if $sendmail <$draft; then
if [ "$outbox" ]; then
mrefile "$(mflag -d -S "$draft")" "$outbox"
mflag -d $draft
else
rm "$draft"
rm $draft
fi
exit 0
else
printf '%s\n' "mcom: $sendmail failed, kept draft $draft"
exit 2
@ -477,80 +266,53 @@ while :; do
else
printf '%s\n' "mcom: message needs to be MIME-encoded first."
c=
continue
fi
fi
case "$0" in
*mrep*) mflag -R -- "$1" ;;
*mbnc*) mflag -P -- "$1" ;;
*mfwd*) mflag -P -- "$@" ;;
esac
case "$0" in
*mrep*|*mbnc*|*mfwd*) mseq -f | mseq -S ;;
esac
exit 0
;;
c|cancel)
stampdate "$draft"
stampdate $draft
printf '%s\n' "mcom: cancelled draft $draft"
exit 1
;;
m|mime)
do_mime
mshow -t "$draftmime"
mshow -t $draftmime
c=
;;
e|edit)
c=
if ! ${VISUAL:-${EDITOR:-vi}} "$draft"; then
c=d
else
if checksensible "$draft"; then
stripempty "$draft"
if mmime -c <"$draft" && ! needs_multipart "$draft"; then
automime=
else
automime=1
do_mime
fi
else
printf '\n'
fi
if ! ${EDITOR:-vi} $draft; then
c=c
fi
;;
justsend)
stripempty "$draft"
if mmime -c <"$draft" && ! needs_multipart "$draft"; then
stripempty $draft
if mmime -c <$draft; then
automime=
else
automime=1
do_mime
fi
c=send
;;
d|delete)
rm -i "$draft"
if ! [ -f "$draft" ]; then
rm -f "$draftmime"
rm -i $draft
if ! [ -f $draft ]; then
rm -f $draftmime
printf '%s\n' "mcom: deleted draft $draft"
exit 0
fi
c=
;;
sign)
msign "$draft" >"$draftmime"
mshow -t "$draftmime"
msign $draft >$draftmime
mshow -t $draftmime
c=
;;
encrypt)
mencrypt "$draft" >"$draftmime"
mshow -t "$draftmime"
mencrypt $draft >$draftmime
mshow -t $draftmime
c=
;;
p|preview|show)
if [ -e "$draftmime" ]; then
show)
if [ -e $draftmime ]; then
mshow "$draftmime"
else
mshow "$draft"
@ -558,7 +320,7 @@ while :; do
c=
;;
*)
printf 'What now? (%s[s]end, [c]ancel, [d]elete, [e]dit, [m]ime, [p]review, sign, encrypt) ' "${automime:+mime and }"
printf 'What now? (%s[s]end, [c]ancel, [d]elete, [e]dit, [m]ime, sign, encrypt) ' "${automime:+mime and }"
read -r c
;;
esac

@ -1,17 +1,11 @@
#include <time.h>
#include <unistd.h>
#include "xpledge.h"
int
main()
{
char buf[64];
time_t now;
xpledge("stdio", "");
now = time(0);
time_t now = time(0);
ssize_t l = strftime(buf, sizeof buf,
"%a, %d %b %Y %T %z\n", localtime(&now));

@ -1,4 +1,3 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
@ -10,11 +9,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
/*
design rationale:
@ -26,15 +23,12 @@ design rationale:
*/
static int cflag;
static int kflag;
static int Mflag;
static int vflag;
static char *Xflag;
char *targetdir;
long delivery;
int preserve_mtime;
int try_rename;
char host[64];
void
@ -50,10 +44,9 @@ gethost() {
}
int
deliver(char *infilename)
deliver(FILE *infile)
{
int outfd;
FILE *infile;
FILE *outfile;
char dst[PATH_MAX];
char tmp[PATH_MAX];
@ -63,22 +56,6 @@ deliver(char *infilename)
char *line = 0;
size_t linelen = 0;
if (infilename) {
if (try_rename) {
infile = 0;
} else {
infile = fopen(infilename, "r");
if (!infile) {
fprintf(stderr, "mrefile: %s: %s\n",
infilename, strerror(errno));
return -1;
}
}
} else {
// mdeliver
infile = stdin;
}
if (Mflag) {
// skip to first "From " line
while (1) {
@ -86,8 +63,9 @@ deliver(char *infilename)
ssize_t rd = getdelim(&line, &linelen, '\n', infile);
if (rd == -1) {
if (errno == 0)
errno = EINVAL; // invalid mbox file
goto fail;
// invalid mbox file
errno = EINVAL;
return -1;
}
if (strncmp("From ", line, 5) == 0)
@ -95,9 +73,9 @@ deliver(char *infilename)
}
}
do {
while (!feof(infile)) {
delivery++;
try_again:
tryagain:
gettimeofday(&tv, 0);
snprintf(id, sizeof id, "%ld.M%06ldP%ldQ%ld.%s",
@ -106,39 +84,11 @@ try_again:
snprintf(tmp, sizeof tmp, "%s/tmp/%s", targetdir, id);
if (try_rename) {
snprintf(dst, sizeof dst, "%s/%s/%s"MAILDIR_COLON_SPEC_VER_COMMA"%s",
targetdir, cflag ? "cur" : "new", id, Xflag);
if (rename(infilename, dst) == 0)
goto success;
/* rename failed, open file and try copying */
infile = fopen(infilename, "r");
if (!infile) {
fprintf(stderr, "mrefile: %s: %s\n",
infilename, strerror(errno));
return -1;
}
}
struct stat st;
if (fstat(fileno(infile), &st) < 0)
st.st_mode = 0600;
if (S_ISFIFO(st.st_mode))
st.st_mode = 0600;
outfd = open(tmp, O_CREAT | O_WRONLY | O_EXCL,
st.st_mode & 07777);
outfd = open(tmp, O_CREAT | O_WRONLY | O_EXCL, 0666);
if (outfd < 0) {
if (errno == EEXIST)
goto try_again;
if (errno == ENOENT)
fprintf(stderr, "mrefile: %s/tmp: %s\n",
targetdir, strerror(errno));
else
fprintf(stderr, "mrefile: %s: %s\n",
tmp, strerror(errno));
goto fail;
goto tryagain;
return -1;
}
outfile = fdopen(outfd, "w");
@ -147,40 +97,32 @@ try_again:
int in_header = 1;
int is_old = 0;
int prev_line_empty = 0;
int this_line_empty = 0; // only for mbox parsing
while (1) {
errno = 0;
ssize_t rd = getdelim(&line, &linelen, '\n', infile);
if (rd == -1) {
if (errno != 0)
goto fail;
return -1;
break;
}
char *line_start = line;
if (line[0] == '\n' && (!line[1] ||
(line[1] == '\r' && !line[2]))) {
this_line_empty = Mflag ? 1 : 0;
if (line[0] == '\n' && !line[1])
in_header = 0;
} else {
this_line_empty = 0;
}
if (Mflag && strncmp("From ", line, 5) == 0)
break;
if (Mflag && in_header &&
(strncasecmp("status:", line, 7) == 0 ||
strncasecmp("x-status:", line, 9) == 0)) {
(strncasecmp("status:", line, 6) == 0 ||
strncasecmp("x-status:", line, 8) == 0)) {
char *v = strchr(line, ':');
if (v) {
if (strchr(v, 'F')) statusflags[0] = 'F';
if (strchr(v, 'A')) statusflags[1] = 'R';
if (strchr(v, 'R')) statusflags[2] = 'S';
if (strchr(v, 'D')) statusflags[3] = 'T';
if (strchr(v, 'O')) is_old = 1;
}
if (strchr(v, 'F')) statusflags[0] = 'F';
if (strchr(v, 'A')) statusflags[1] = 'R';
if (strchr(v, 'R')) statusflags[2] = 'S';
if (strchr(v, 'D')) statusflags[3] = 'T';
if (strchr(v, 'O')) is_old = 1;
continue; // drop header
}
@ -195,22 +137,15 @@ try_again:
}
}
// print delayed empty line
if (prev_line_empty)
if (fputc('\n', outfile) == EOF)
goto fail;
if (!this_line_empty)
if (fwrite(line_start, 1, rd, outfile) != (size_t)rd)
goto fail;
prev_line_empty = this_line_empty;
if (fwrite(line_start, 1, rd, outfile) != (size_t)rd)
return -1;
}
if (fflush(outfile) == EOF)
goto fail;
return -1;
if (fsync(outfd) < 0)
goto fail;
return -1;
if (fclose(outfile) == EOF)
goto fail;
return -1;
// compress flags
int i, j;
@ -234,108 +169,23 @@ try_again:
utimes(tmp, times);
}
}
blaze822_free(msg);
}
if (preserve_mtime) {
#if defined(AT_FDCWD) && defined(UTIME_NOW) && defined(UTIME_OMIT)
const struct timespec times[2] = {
{ tv.tv_sec, tv.tv_usec * 1000L },
#if (defined(__APPLE__) && defined(__MACH__))
st.st_mtimespec
#else /* POSIX.1-2008 */
st.st_mtim
#endif
};
utimensat(AT_FDCWD, tmp, times, 0);
#else
const struct timeval times[2] = {
tv,
{ st.st_mtime, 0 }
};
utimes(tmp, times);
#endif
}
snprintf(dst, sizeof dst, "%s/%s/%s"MAILDIR_COLON_SPEC_VER_COMMA"%s",
snprintf(dst, sizeof dst, "%s/%s/%s:2,%s",
targetdir, (cflag || is_old) ? "cur" : "new", id,
Xflag ? Xflag : statusflags);
if (rename(tmp, dst) != 0)
goto fail;
return -1;
success:
if (vflag)
printf("%s\n", dst);
} while (Mflag && !feof(infile));
if (infile)
fclose(infile);
return 0;
fail:
if (infile)
fclose(infile);
return -1;
}
void
refile(char *file)
{
while (*file == ' ' || *file == '\t')
file++;
// keep flags
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (flags)
Xflag = flags + 3;
else
Xflag = "";
if (deliver(file) < 0) {
perror("mrefile");
return;
}
if (!kflag && !try_rename)
unlink(file);
return 0;
}
int
main(int argc, char *argv[])
{
if (strchr(argv[0], 'f')) {
// mrefile(1)
cflag = 1; // use cur/
preserve_mtime = 1;
try_rename = 1;
int c;
while ((c = getopt(argc, argv, "kv")) != -1)
switch (c) {
case 'k': kflag = 1; try_rename = 0; break;
case 'v': vflag = 1; break;
default:
usage:
fprintf(stderr,
"Usage: mrefile [-kv] [msgs...] maildir\n");
exit(1);
}
if (argc == optind)
goto usage;
targetdir = argv[argc - 1];
gethost();
if (argc == optind + 1 && isatty(0))
goto usage;
else
blaze822_loop(argc - 1 - optind, argv + optind, refile);
return 0;
}
int c;
while ((c = getopt(argc, argv, "cMvX:")) != -1)
switch (c) {
@ -344,7 +194,6 @@ usage:
case 'v': vflag = 1; break;
case 'X': Xflag = optarg; break;
default:
usage2:
fprintf(stderr,
"Usage: mdeliver [-c] [-v] [-X flags] dir < message\n"
" mdeliver -M [-c] [-v] [-X flags] dir < mbox\n"
@ -352,20 +201,16 @@ usage2:
exit(1);
}
if (argc != optind+1)
goto usage2;
xpledge("stdio rpath wpath cpath fattr", "");
if (!preserve_mtime && !Mflag) {
/* drop fattr */
xpledge("stdio rpath wpath cpath", "");
if (argc != optind+1) {
fprintf(stderr, "usage: mdeliver DIR\n");
return 1;
}
targetdir = argv[optind];
gethost();
if (deliver(0) < 0) {
if (deliver(stdin) < 0) {
perror("mdeliver");
return 2;
}

@ -3,25 +3,18 @@
#include <dirent.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "blaze822.h"
#include "blaze822_priv.h"
#include "xpledge.h"
static char sep = '\n';
int aflag;
void
pwd()
{
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof cwd))
printf("%s%c", cwd, sep);
puts(cwd);
}
void
@ -51,9 +44,10 @@ mdirs(char *fpath)
}
while ((d = readdir(dir))) {
if (!DIR_DT(d->d_type))
#if defined(DT_DIR) && defined(DT_UNKNOWN)
if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN)
continue;
#endif
if (d->d_name[0] == '.' &&
d->d_name[1] == 0)
continue;
@ -62,7 +56,7 @@ mdirs(char *fpath)
d->d_name[2] == 0)
continue;
if (!aflag && dotonly && d->d_name[0] != '.')
if (dotonly && d->d_name[0] != '.')
continue;
mdirs(d->d_name);
@ -74,71 +68,23 @@ 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[])
{
int c, i;
while ((c = getopt(argc, argv, "0a")) != -1)
while ((c = getopt(argc, argv, "")) != -1)
switch (c) {
case '0': sep = '\0'; break;
case 'a': aflag = 1; break;
default:
usage:
fprintf(stderr, "Usage: mdirs [-0a] dirs...\n");
fprintf(stderr, "Usage: mdirs dirs...\n");
exit(1);
}
xpledge("stdio rpath", "");
if (argc == optind) {
char *maildir = profile_maildir();
if (maildir) {
mdirs(maildir);
return 0;
}
if (argc == optind)
goto usage;
}
char toplevel[PATH_MAX];
if (!getcwd(toplevel, sizeof toplevel)) {
perror("mdirs: getcwd");
exit(-1);
}
for (i = 0; i < argc; i++) {
for (i = 0; i < argc; i++)
mdirs(argv[i]);
if (chdir(toplevel) < 0) {
perror("mdirs: chdir");
exit(-1);
}
}
return 0;
}

@ -10,7 +10,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int Sflag;
@ -33,7 +32,7 @@ export(char *file)
}
char from[1024] = "nobody";
time_t date = 0;
time_t date = -1;
if (fseek(infile, 0L, SEEK_SET) && errno == ESPIPE) {
date = time(0);
@ -68,7 +67,7 @@ export(char *file)
char *line = 0;
size_t linelen = 0;
printf("From %s %s", from, asctime(gmtime(&date)));
printf("From %s %s", from, ctime(&date));
int in_header = 1;
int final_nl = 0;
@ -87,7 +86,7 @@ export(char *file)
if (in_header && line[0] == '\n' && !line[1]) {
if (Sflag) {
char *flags = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
char *flags = strstr(file, ":2,");
if (!flags)
flags = "";
@ -125,9 +124,6 @@ export(char *file)
if (!final_nl)
putchar('\n');
// ensure empty line at end of message
putchar('\n');
fclose(infile);
}
@ -145,8 +141,6 @@ main(int argc, char *argv[])
status = 0;
xpledge("stdio rpath", "");
if (argc == optind && isatty(0))
blaze822_loop1(":", export);
else

@ -12,8 +12,8 @@
#include <unistd.h>
#include "blaze822.h"
#include "blaze822_priv.h"
#include "xpledge.h"
#define uc(c) ((c) & 0xdf)
static int8_t flags[255];
static int vflag = 0;
@ -47,7 +47,7 @@ flag(char *file)
while (file[indent] == ' ' || file[indent] == '\t')
indent++;
char *f = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
char *f = strstr(file, ":2,");
if (!f)
goto skip;
@ -135,8 +135,6 @@ main(int argc, char *argv[])
exit(1);
}
xpledge("stdio rpath cpath", "");
curfile = blaze822_seq_cur();
if (vflag) {
@ -145,7 +143,7 @@ main(int argc, char *argv[])
return 0;
}
args = calloc(argsalloc, sizeof (char *));
args = calloc(sizeof (char *), argsalloc);
if (!args)
exit(-1);

@ -1,7 +1,3 @@
#ifdef __sun
#define __EXTENSIONS__ /* to get TIOCGWINSZ */
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
@ -11,12 +7,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <termios.h>
#include "blaze822.h"
#include "xpledge.h"
int column = 0;
int maxcolumn = 80;
@ -34,6 +27,28 @@ chgquote(int quotes)
}
}
void
fixed(int quotes, char *line, size_t linelen)
{
chgquote(quotes);
if (column && linelen > (size_t)(maxcolumn - column)) {
putchar('\n');
column = 0;
}
if (column == 0) {
for (; column < quotes; column++)
putchar('>');
if (quotes)
putchar(' ');
}
fwrite(line, 1, linelen, stdout);
putchar('\n');
column = 0;
}
void
flowed(int quotes, char *line, ssize_t linelen)
{
@ -45,7 +60,7 @@ flowed(int quotes, char *line, ssize_t linelen)
for (; column < quotes; column++)
putchar('>');
column++;
if (quotes && *line != ' ')
if (quotes)
putchar(' ');
}
@ -79,15 +94,6 @@ flowed(int quotes, char *line, ssize_t linelen)
}
}
void
fixed(int quotes, char *line, size_t linelen)
{
flowed(quotes, line, linelen);
putchar('\n');
column = 0;
}
int
main(int argc, char *argv[])
{
@ -101,8 +107,6 @@ main(int argc, char *argv[])
int force = 0;
int delsp = 0;
xpledge("stdio rpath tty", "");
char *ct = getenv("PIPE_CONTENTTYPE");
if (ct) {
char *s, *se;
@ -126,8 +130,6 @@ main(int argc, char *argv[])
}
}
xpledge("stdio", "");
char *maxcols = getenv("MAXCOLUMNS");
if (maxcols && isdigit(*maxcols)) {
int m = atoi(maxcols);
@ -192,11 +194,6 @@ main(int argc, char *argv[])
if (delsp)
line[--rd] = 0;
flowed(quotes, line, rd);
} else if (rd == 0) { // empty line is fixed
if (column > 0)
putchar('\n');
putchar('\n');
column = 0;
} else {
if (force && rd > maxcolumn) {
flowed(quotes, line, rd);

@ -13,7 +13,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
void
printb36(uint64_t x)
@ -37,8 +36,6 @@ int main()
char *f = blaze822_home_file("profile");
struct message *config = blaze822(f);
xpledge("stdio rpath dns", "");
if (config) // try FQDN: first
host = blaze822_hdr(config, "fqdn");
@ -88,35 +85,30 @@ int main()
struct timeval tp;
gettimeofday(&tp, (struct timezone *)0);
uint64_t rnd1, rnd2;
uint64_t rnd;
int rndfd = open("/dev/urandom", O_RDONLY);
if (rndfd >= 0) {
unsigned char rndb[16];
unsigned char rndb[8];
if (read(rndfd, rndb, sizeof rndb) != sizeof rndb)
goto fallback;
close(rndfd);
int i;
for (i = 0, rnd1 = 0; i < 8; i++)
rnd1 = rnd1*256 + rndb[i];
for (i = 0, rnd2 = 0; i < 8; i++)
rnd2 = rnd2*256 + rndb[i+8];
for (i = 0, rnd = 0; i < 8; i++)
rnd = rnd*256 + rndb[i];
} else {
fallback:
srand48(tp.tv_sec ^ tp.tv_usec ^ getpid());
rnd1 = ((uint64_t)lrand48() << 32) + lrand48();
rnd2 = ((uint64_t)lrand48() << 32) + lrand48();
rnd = ((uint64_t)lrand48() << 32) + lrand48();
}
rnd1 ^= ((uint64_t)tp.tv_sec * 1000000LL + tp.tv_usec);
rnd1 |= (1ULL << 63); // set highest bit to force full width
rnd2 |= (1ULL << 63); // set highest bit to force full width
rnd |= (1ULL << 63); // set highest bit to force full width
putchar('<');
printb36(rnd1);
printb36(((uint64_t)tp.tv_sec * 1000000LL + tp.tv_usec));
putchar('.');
printb36(rnd2);
printb36(rnd);
putchar('@');
fputs(host, stdout);
putchar('>');

@ -7,11 +7,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static char *hflag;
static char *pflag;
@ -60,51 +58,26 @@ headerall(struct message *msg)
blaze822_free(msg);
}
void
print_quoted(char *s)
{
char *t;
for (t = s; *t; t++)
if ((unsigned char)*t < 32 || strchr("()<>[]:;@\\,.\"", *t))
goto quote;
printf("%s", s);
return;
quote:
putchar('"');
for (t = s; *t; t++) {
if (*t == '"' || *t == '\\')
putchar('\\');
putchar(*t);
}
putchar('"');
}
void
print_addresses(char *s)
{
char *disp, *addr;
char ddec[4096];
char sdec[4096];
if (dflag) {
blaze822_decode_rfc2047(sdec, s, sizeof sdec, "UTF-8");
sdec[sizeof sdec - 1] = 0;
s = sdec;
}
while ((s = blaze822_addr(s, &disp, &addr))) {
if (Hflag && addr)
printf("%s\t", curfile);
if (disp && addr) {
if (dflag) {
blaze822_decode_rfc2047(ddec, disp, sizeof ddec, "UTF-8");
ddec[sizeof ddec - 1] = 0;
disp = ddec;
}
print_quoted(disp);
printf(" <%s>\n", addr);
} else if (addr) {
if (disp && addr)
printf("%s <%s>\n", disp, addr);
else if (addr)
printf("%s\n", addr);
}
}
}
@ -165,7 +138,7 @@ headermany(struct message *msg)
*n = 0;
size_t l = strlen(h);
if (strncasecmp(hdr, h, l) == 0 && hdr[l] == ':') {
if (strncmp(hdr, h, l) == 0 && hdr[l] == ':') {
hdr += l + 1;
while (*hdr == ' ' || *hdr == '\t')
hdr++;
@ -247,8 +220,6 @@ main(int argc, char *argv[])
status = 1;
xpledge("stdio rpath", "");
if (argc == optind && isatty(0))
blaze822_loop1(".", header);
else

@ -11,8 +11,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "blaze822_priv.h"
#include "xpledge.h"
static int qflag;
static int status;
@ -37,17 +35,17 @@ inc(char *dir)
}
while ((d = readdir(fd))) {
if (!MAIL_DT(d->d_type))
#if defined(DT_REG) && defined(DT_UNKNOWN)
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
continue;
#endif
if (d->d_name[0] == '.')
continue;
snprintf(src, sizeof src, "%s/new/%s",
dir, d->d_name);
snprintf(dst, sizeof dst, "%s/cur/%s%s",
dir, d->d_name,
strstr(d->d_name, MAILDIR_COLON_SPEC_VER_COMMA) ? "" : MAILDIR_COLON_SPEC_VER_COMMA);
dir, d->d_name, strstr(d->d_name, ":2,") ? "" : ":2,");
if (rename(src, dst) < 0) {
fprintf(stderr, "minc: can't rename '%s' to '%s': %s\n",
src, dst, strerror(errno));
@ -75,17 +73,12 @@ usage:
exit(1);
}
xpledge("stdio rpath cpath", "");
if (optind == argc)
goto usage;
status = 0;
if (optind == argc) {
if (isatty(0))
goto usage;
blaze822_loop(0, 0, inc);
} else {
for (i = optind; i < argc; i++)
inc(argv[i]);
}
for (i = optind; i < argc; i++)
inc(argv[i]);
return status;
}

41
mless

@ -22,16 +22,7 @@ if [ "$1" = --filter ]; then
fi
mseq -C "$2"
total=$(mscan -n -- -1)
case $2 in
1) mscan .-0:.+5 ;;
2) mscan .-1:.+4 ;;
$((total - 2))) mscan .-3:.+2 ;;
$((total - 1))) mscan .-4:.+1 ;;
$total) mscan .-5:.+0 ;;
*) mscan .-2:.+3 ;;
esac 2>/dev/null | colorscan
mscan .-2:.+3 2>/dev/null | colorscan
echo
if ! [ -f "$(mseq -r "$2")" ]; then
@ -46,9 +37,9 @@ if [ "$1" = --filter ]; then
mshow "$2"
fi | mcolor
else
mseq -r "$2"
mseq -r $2
echo
cat "$(mseq -r "$2")"
cat "$(mseq -r $2)"
fi
exit $?
fi
@ -62,7 +53,11 @@ if ! [ -t 1 ]; then
exec mseq :
fi
[ "$#" -eq 1 ] && set -- ${1:-.}
case "$0" in
*mnext) set -- +;;
*mprev) set -- -;;
*) [ "$#" -eq 1 ] && set -- ${1:-.};;
esac
if [ "$#" -ge 1 ]; then
mseq -C "$1"
@ -72,20 +67,14 @@ nl="
"
export MLESS_RAW=0
export MLESS_HTML=0
if [ -f "$MBLAZE/mlesskey" ]; then
export LESSKEYIN="$MBLAZE/mlesskey"
elif [ -f "$HOME/.mblaze/mlesskey" ]; then
export LESSKEYIN="$HOME/.mblaze/mlesskey"
elif [ -f "$HOME/.mlesskey" ]; then
export LESSKEYIN="$HOME/.mlesskey"
elif [ -f "$MBLAZE/mless" ]; then
export LESSKEY="$MBLAZE/mless"
elif [ -f "$HOME/.mblaze/mless" ]; then
export LESSKEY="$HOME/.mblaze/mless"
elif [ -f "$HOME/.mless" ]; then
export LESSKEY="$HOME/.mless"
fi
while :; do
if [ -f $MBLAZE/mless ]; then
export LESSKEY=$MBLAZE/mless
elif [ -f $HOME/.mblaze/mless ]; then
export LESSKEY=$HOME/.mblaze/mless
elif [ -f $HOME/.mless ]; then
export LESSKEY=$HOME/.mless
fi
LESSOPEN="|$0 --filter %s" \
less -Ps"mless %f?m (message %i of %m).." -R \
"+:e $(mscan -n .)$nl" //scan $(mscan -n :)

@ -1,7 +1,5 @@
# mless(1) keybindings
# When using less <590:
# compile with lesskey -o .mless mlesskey and install as ~/.mless
# When using less >=590: copy this file to ~/.mlesskey
# to update: lesskey -o ~/.mless ~/.mlesskey
Q quit \1
:cq quit \1
[ prev-file

@ -12,8 +12,9 @@
#include <unistd.h>
#include "blaze822.h"
#include "blaze822_priv.h"
#include "xpledge.h"
#define lc(c) ((c) | 0x20)
#define uc(c) ((c) & 0xdf)
/*
@ -48,47 +49,34 @@ static long tdirs;
static long tunseen;
static long tflagged;
static long tcount;
static long tmatched;
void
list(char *prefix, char *file)
{
char *f = 0;
if (flagset || iflag) {
size_t prefixlen;
f = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA);
if (!f &&
prefix &&
(prefixlen = strlen(prefix)) &&
prefixlen >= 4 &&
strcmp(prefix + prefixlen - 4, "/new") == 0)
f = MAILDIR_COLON_SPEC_VER_COMMA;
}
if (flagset) {
int sum = 0;
char *f = strstr(file, ":2,");
if (!f)
return;
icount++;
tcount++;
char *g;
for (g = f + 3; *g; g++)
if (flags[(unsigned int)*g] == -1)
f += 3;
while (*f) {
if (flags[(unsigned int)*f] == -1)
return;
else if (flags[(unsigned int)*g] == 1)
if (flags[(unsigned int)*f] == 1)
sum++;
f++;
}
if (sum != flagsum)
return;
}
if (iflag) {
char *f = strstr(file, ":2,");
if (!f)
return;
imatched++;
tmatched++;
if (!flagset)
icount++, tcount++;
if (!strchr(f, 'S'))
@ -111,8 +99,8 @@ list(char *prefix, char *file)
#include <sys/syscall.h>
struct linux_dirent64 {
uint64_t d_ino; /* 64-bit inode number */
int64_t d_off; /* 64-bit offset to next structure */
ino64_t d_ino; /* 64-bit inode number */
off64_t d_off; /* 64-bit offset to next structure */
unsigned short d_reclen; /* Size of this dirent */
unsigned char d_type; /* File type */
char d_name[]; /* Filename (null-terminated) */
@ -146,7 +134,7 @@ listdir(char *dir)
for (bpos = 0; bpos < nread; bpos += d->d_reclen) {
d = (struct linux_dirent64 *)(buf + bpos);
if (!MAIL_DT(d->d_type))
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
continue;
if (d->d_name[0] == '.')
continue;
@ -167,7 +155,7 @@ listdir(char *dir)
if (!fd)
return;
while ((d = readdir(fd))) {
if (!MAIL_DT(d->d_type))
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
continue;
if (d->d_name[0] == '.')
continue;
@ -218,12 +206,8 @@ listarg(char *arg)
if (iflag && (imatched || (maildir && !flagset))) {
tdirs++;
if (flagset && imatched)
printf("%6ld matched %6ld unseen %3ld flagged %6ld msg %s\n",
imatched, iunseen, iflagged, icount, arg);
else
printf("%6ld unseen %3ld flagged %6ld msg %s\n",
iunseen, iflagged, icount, arg);
printf("%6ld unseen %3ld flagged %6ld msg %s\n",
iunseen, iflagged, icount, arg);
}
icount = gcount;
@ -273,8 +257,6 @@ usage:
int i;
xpledge("stdio rpath", "");
for (i = 0, flagsum = 0, flagset = 0; (size_t)i < sizeof flags; i++) {
if (flags[i] != 0)
flagset++;
@ -291,14 +273,9 @@ usage:
listarg(argv[i]);
}
if (iflag && tdirs > 1) {
if (flagset)
printf("%6ld matched %6ld unseen %3ld flagged %6ld msg\n",
tmatched, tunseen, tflagged, tcount);
else
printf("%6ld unseen %3ld flagged %6ld msg\n",
tunseen, tflagged, tcount);
}
if (iflag && tdirs > 1)
printf("%6ld unseen %3ld flagged %6ld msg\n",
tunseen, tflagged, tcount);
return 0;
}

@ -1,7 +1,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@ -12,12 +11,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int cflag;
static int rflag;
@ -60,11 +57,6 @@ int gen_b64(uint8_t *s, off_t size)
return 0;
}
#define qphrasevalid(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || \
(c >= 'a' && c <= 'z') || \
c == '!' || c == '*' || c == '+' || c == '-' || \
c == '/')
size_t
gen_qp(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen)
{
@ -129,10 +121,6 @@ gen_qp(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen)
putc_unlocked('\n', stdout);
linelen = 0;
prev = 0;
} else if (header && !qphrasevalid(s[i])) {
printf("=%02X", s[i]);
linelen += 3;
prev = '_';
} else {
putc_unlocked(s[i], stdout);
linelen++;
@ -258,7 +246,7 @@ gen_file(char *file, char *ct)
}
if (bitlow == 0 && bithigh == 0 &&
maxlinelen <= 78) {
maxlinelen <= 78 && content[size-1] == '\n') {
if (!ct)
ct = "text/plain";
printf("Content-Type: %s\n", ct);
@ -294,9 +282,6 @@ print_header(char *line) {
char *s, *e;
size_t l = strlen(line);
if (l == 0)
return;
if (line[l-1] == '\n')
line[l-1] = 0;
@ -313,41 +298,23 @@ print_header(char *line) {
}
int prevq = 0; // was the previous word encoded as qp?
char prevqs = 0; // was the previous word a quoted-string?
ssize_t linelen = s - line;
size_t linelen = s - line;
while (*s) {
size_t highbit = 0;
int qs = 0;
e = s;
while (*e && *e == ' ')
e++;
if (*e == '"') { // scan quoted-string, encode at once
s = e;
for (e++; *e && *e != '"'; e++) {
if (*e == '\\')
e++;
if ((uint8_t)*e >= 127)
highbit++;
}
if (*e == '"')
e++;
qs = 1;
} else { // scan word
while (*e && *e == ' ')
e++;
for (; *e && *e != ' '; e++) {
if ((uint8_t)*e >= 127)
highbit++;
}
for (; *e && *e != ' '; e++) {
if ((uint8_t)*e >= 127)
highbit++;
}
if (!highbit) {
if (e-s >= 998)
goto force_qp;
if (e-s >= 78 - linelen && linelen > 0) {
if (e-s >= 78 - linelen) {
// wrap in advance before long word
printf("\n");
linelen = 0;
@ -356,7 +323,7 @@ print_header(char *line) {
// space at beginning of line
goto force_qp;
}
if (*s != ' ' && !(prevqs && !prevq && *(s-1) != ' ')) {
if (*s != ' ') {
printf(" ");
linelen++;
}
@ -367,12 +334,6 @@ print_header(char *line) {
force_qp:
if (!prevq && *s == ' ')
s++;
if (qs && *s == '"')
s++;
if (qs && e > s && *(e-1) == '"')
e--;
if (linelen >= 78 - 13 - 4 ||
(e-s < (78 - 13)/3 &&
e-s >= (78 - linelen - 13)/3)) {
@ -386,33 +347,12 @@ force_qp:
printf("?=");
linelen += 2;
prevq = 1;
if (qs && *e == '"')
e++;
}
prevqs = qs;
s = e;
}
printf("\n");
}
static int
valid_content_type(char *s)
{
int slash = 0;
for (; *s; s++)
if (*s == '/')
slash++;
else if (isalnum(*s) || *s == '-' || *s == '+' || *s == '.' ||
*s == ';' || *s == '=' || *s == '#')
; /* ok */
else
return 0;
return slash == 1;
}
int
gen_build()
{
@ -424,45 +364,30 @@ gen_build()
size_t linelen = 0;
int inheader = 1;
int intext = 0;
int emptybody = 1;
int ret = 0;
char *contenttype = 0;
char *contenttransferenc = 0;
while (1) {
ssize_t read = getdelim(&line, &linelen, '\n', stdin);
if (read == -1) {
if (feof(stdin)) {
if (!emptybody)
break;
line = strdup(inheader ? "\n" : "");
} else { // errored
if (feof(stdin))
break;
else
exit(1);
}
}
if (inheader) {
if (line[0] == '\n') {
inheader = 0;
printf("MIME-Version: 1.0\n");
if (rflag) {
printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=UTF-8\n");
printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " quoted-printable\n");
printf("\n");
printf("Content-Type: text/plain; charset=UTF-8\n");
printf("Content-Transfer-Encoding: quoted-printable\n\n");
} else {
printf("Content-Type: %s; boundary=\"%s\"\n", tflag, sep);
printf("\n");
printf("This is a multipart message in MIME format.\n");
}
} else {
if (strncasecmp(line, "Content-Type:", 13) == 0) {
free(contenttype);
contenttype = strdup(line+13);
} else if (strncasecmp(line, "Content-Transfer-Encoding:", 26) == 0) {
free(contenttransferenc);
contenttransferenc = strdup(line+26);
} else {
print_header(line);
}
print_header(line);
}
continue;
}
@ -472,14 +397,12 @@ gen_build()
if (f) {
char of = *f;
*f = 0;
if (valid_content_type(line+1)) {
if (strchr(line, '/')) {
printf("\n--%s\n", sep);
if (line[read-1] == '\n')
line[read-1] = 0;
if (gen_file(f+1, line+1) != 0)
ret = 1;
gen_file(f+1, (char *)line+1);
intext = 0;
emptybody = 0;
continue;
}
*f = of;
@ -488,26 +411,20 @@ gen_build()
if (!rflag && !intext) {
printf("\n--%s\n", sep);
printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=UTF-8\n");
printf("Content-Type: text/plain; charset=UTF-8\n");
printf("Content-Disposition: inline\n");
printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " quoted-printable\n");
printf("\n");
printf("Content-Transfer-Encoding: quoted-printable\n\n");
intext = 1;
}
if (contenttransferenc)
printf("%s", line);
else
gen_qp((uint8_t *)line, strlen(line), 78, 0);
emptybody = 0;
gen_qp((uint8_t *)line, strlen(line), 78, 0);
}
if (!rflag && !inheader)
printf("\n--%s--\n", sep);
free(line);
return ret;
return 0;
}
int
@ -518,7 +435,6 @@ check()
off_t linelen = 0;
off_t maxheadlinelen = 0;
off_t maxbodylinelen = 0;
off_t bodylinelenlimit = getenv("MBLAZE_RELAXED_MIME") ? 998 : 78;
int c;
int l = -1;
@ -556,7 +472,7 @@ check()
}
if (bitlow == 0 && bithigh == 0 &&
maxheadlinelen < 998 && maxbodylinelen <= bodylinelenlimit &&
maxheadlinelen < 998 && maxbodylinelen <= 78 &&
l == '\n')
return 0;
else
@ -584,8 +500,6 @@ usage:
if (argc != optind)
goto usage;
xpledge("stdio rpath", "");
if (cflag)
return check();

@ -1,11 +1,9 @@
#!/bin/sh
# mmkdir DIRS... - create new maildirs
umask 077
r=0
for dir; do
mkdir -p "$dir"/tmp "$dir"/new "$dir"/cur || r=1
mkdir -p -m 0700 $dir/cur $dir/new $dir/tmp || r=1
done
exit $r

@ -0,0 +1 @@
mless

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
mless

@ -1,17 +1,11 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
#ifdef __sun
#define __EXTENSIONS__ /* to get TIOCGWINSZ */
#endif
#include "xpledge.h"
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
@ -22,7 +16,6 @@
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <termios.h>
#include "blaze822.h"
#include "u8decode.h"
@ -36,7 +29,6 @@ static int alias_idx;
static int Iflag;
static int nflag;
static int vflag;
static int curyear;
static time_t now;
static char default_fflag[] = "%c%u%r %-3n %10d %17f %t %2i%s";
@ -60,13 +52,9 @@ u8putstr(FILE *out, char *s, ssize_t l, int pad)
int r = u8decode(s, &c);
if (r < 0) {
r = 1;
l--;
fprintf(out, "%lc", (wint_t)replacement);
} else {
int w = wcwidth((wchar_t)c);
if (w < 0)
w = 2; /* assume worst width */
l -= w;
l -= wcwidth((wchar_t)c);
if (l >= 0)
fwrite(s, 1, r, out);
}
@ -145,33 +133,6 @@ fmt_date(struct message *msg, int w, int iso)
strftime(date, sizeof date, "%Y-%m-%d %H:%M", tm);
else
strftime(date, sizeof date, "%Y-%m-%d", tm);
} else if (w >= 19) {
// https://dotti.me/
tm = gmtime(&t);
strftime(date, sizeof date, "%Y-%m-%dT%H\xc2\xb7%M", tm);
char *d = date + strlen(date);
char *e = v + strlen(v);
while (e > v && (*e != '+' && *e != '-'))
e--;
if (isdigit(e[1]) && isdigit(e[2]) && isdigit(e[3]) && isdigit(e[4])) {
*d++ = e[0];
*d++ = e[1];
*d++ = e[2];
if (e[3] != '0' || e[4] != '0') {
*d++ = ':';
*d++ = e[3];
*d++ = e[4];
}
*d = 0;
} else {
*d++ = '+';
*d++ = '0';
*d++ = '0';
*d = 0;
}
} else if (w < 10) {
if (tm->tm_year != curyear)
strftime(date, sizeof date, "%b%y", tm);
@ -322,7 +283,7 @@ oneline(char *file)
}
struct message *msg = blaze822(file);
char *flags = msg ? strstr(file, MAILDIR_COLON_SPEC_VER_COMMA) : 0;
char *flags = msg ? strstr(file, ":2,") : 0;
if (!flags)
flags = "";
else
@ -377,12 +338,12 @@ oneline(char *file)
wleft--;
break;
case 'u': // unseen
if (strchr(flags, 'T'))
putchar('x');
else if (strchr(flags, 'F'))
if (strchr(flags, 'F'))
putchar('*');
else if (msg && !strchr(flags, 'S'))
putchar('.');
else if (strchr(flags, 'T'))
putchar('x');
else
putchar(' ');
wleft--;
@ -471,21 +432,13 @@ oneline(char *file)
case 'F':
{
char *e = file + strlen(file);
if (!msg)
goto empty;
while (file < e && *e != '/')
e--;
if (file == e)
goto empty;
e--;
while (file < e && *e != '/')
e--;
while (file < e && *e == '/')
e--;
if (file == e)
goto empty;
char *b = e;
e++;
while (file < b && *b != '/')
@ -494,11 +447,6 @@ oneline(char *file)
b++;
if (*b == '.')
b++;
if (0) {
empty:
b = e = "";
}
if (w) {
if (w < 0)
w = -w;
@ -541,22 +489,19 @@ empty:
int
main(int argc, char *argv[])
{
pid_t pager_pid = -1;
pid_t pid1 = -1;
int c;
while ((c = getopt(argc, argv, "If:nv")) != -1)
while ((c = getopt(argc, argv, "If:n")) != -1)
switch (c) {
case 'I': Iflag++; break;
case 'f': fflag = optarg; break;
case 'n': nflag = 1; break;
case 'v': vflag = 1; break;
default:
fprintf(stderr, "Usage: mscan [-Inv] [-f format] [msgs...]\n");
fprintf(stderr, "Usage: mscan [-n] [-f format] [-I] [msgs...]\n");
exit(1);
}
xpledge("stdio rpath tty proc exec", NULL);
if (nflag) {
if (argc == optind && isatty(0))
blaze822_loop1(":", numline);
@ -575,28 +520,23 @@ main(int argc, char *argv[])
struct winsize w;
int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY);
if (ttyfd >= 0) {
if (ioctl(ttyfd, TIOCGWINSZ, &w) == 0)
cols = w.ws_col;
close(ttyfd);
}
if (ttyfd >= 0 && ioctl(ttyfd, TIOCGWINSZ, &w) == 0) {
cols = w.ws_col;
if (isatty(1)) {
char *pg;
pg = getenv("MBLAZE_PAGER");
if (!pg)
pg = getenv("PAGER");
if (pg && *pg && strcmp(pg, "cat") != 0) {
pager_pid = pipeto(pg);
if (pager_pid < 0)
pid1 = pipeto(pg);
if (pid1 < 0)
fprintf(stderr,
"mscan: spawning pager '%s': %s\n",
pg, strerror(errno));
}
}
xpledge("stdio rpath", "");
if (ttyfd >= 0)
close(ttyfd);
if (getenv("COLUMNS"))
cols = atoi(getenv("COLUMNS"));
if (cols <= 40)
@ -627,12 +567,10 @@ main(int argc, char *argv[])
i = blaze822_loop1(":", oneline);
else
i = blaze822_loop(argc-optind, argv+optind, oneline);
fprintf(stderr, "%ld mails scanned\n", i);
if (pager_pid > 0)
pipeclose(pager_pid);
if (vflag)
fprintf(stderr, "%ld mails scanned\n", i);
if (pid1 > 0)
pipeclose(pid1);
return 0;
}

@ -11,7 +11,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static char *expr;
@ -29,7 +28,7 @@ subst(char *str, char *srch, char *repl, char *flags)
#define APPC(c) do { if (b >= bufe) return str; *b++ = c; } while (0)
regex_t srchrx;
regmatch_t pmatch[10] = {{0}};
regmatch_t pmatch[10];
if (regcomp(&srchrx, srch, iflag ? REG_ICASE : 0) != 0)
return str;
@ -138,7 +137,7 @@ sed(char *file)
if (*s == ':')
*s = '|';
int rv;
if ((rv = regcomp(&headerrx, headersel, REG_EXTENDED | REG_ICASE)) != 0) {
if ((rv = regcomp(&headerrx, headersel, REG_EXTENDED)) != 0) {
char buf[100];
regerror(rv, &headerrx, buf, sizeof buf);
fprintf(stderr, "msed: %s\n", buf);
@ -218,8 +217,6 @@ sed(char *file)
free(to);
free(flags);
break;
case '\0':
break;
default:
fprintf(stderr, "msed: unknown command: '%c'\n", *e);
@ -324,8 +321,6 @@ main(int argc, char *argv[])
exit(1);
}
xpledge("stdio rpath", "");
expr = argv[optind];
optind++;

@ -12,8 +12,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "blaze822_priv.h"
#include "xpledge.h"
static int fflag;
static int rflag;
@ -60,9 +58,10 @@ namescan(char *dir)
if (!fd)
return;
while ((d = readdir(fd))) {
if (!MAIL_DT(d->d_type))
#if defined(DT_REG) && defined(DT_UNKNOWN)
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
continue;
#endif
if (d->d_name[0] == '.')
continue;
@ -70,7 +69,7 @@ namescan(char *dir)
snprintf(file, sizeof file, "%s/%s", dir, d->d_name);
char *e;
if ((e = strstr(d->d_name, MAILDIR_COLON_SPEC_VER_COMMA)))
if ((e = strstr(d->d_name, ":2,")))
*e = 0;
struct name *c = malloc(sizeof (struct name));
@ -101,7 +100,7 @@ search(char *file)
if (!namefind(dir))
namescan(dir);
if ((e = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA)))
if ((e = strstr(file, ":2,")))
*e = 0;
return namefind(file);
@ -131,11 +130,11 @@ fix(FILE *out, char *file)
char *e;
char *sep;
if ((e = strstr(file, MAILDIR_COLON_SPEC_VER_COMMA))) {
if ((e = strstr(file, ":2,"))) {
sep = "";
e[3] = 0;
} else {
sep = MAILDIR_COLON_SPEC_VER_COMMA;
sep = ":2,";
}
snprintf(buf, sizeof buf, "%s%s", file, sep);
if (access(buf, F_OK) == 0) goto ok;
@ -299,8 +298,6 @@ usage:
exit(1);
}
xpledge("stdio rpath wpath cpath", "");
if (cflag)
blaze822_loop1(cflag, overridecur);
@ -317,10 +314,14 @@ usage:
if (optind == argc && !isatty(0))
return stdinmode();
char *seq = blaze822_seq_open(0);
if (!seq)
return 1;
int i;
char *f;
char *a;
char *seq = 0;
struct blaze822_seq_iter iter = { 0 };
if (optind == argc) {
a = ":";
@ -334,14 +335,6 @@ hack:
printf("%s\n", a);
continue;
}
if (!seq) {
seq = blaze822_seq_open(0);
if (!seq)
return 1;
}
struct blaze822_seq_iter iter = { 0 };
while ((f = blaze822_seq_next(seq, a, &iter))) {
char *s = f;
if (rflag)

@ -14,9 +14,7 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int Bflag;
static int rflag;
static int Rflag;
static int qflag;
@ -36,7 +34,6 @@ static char fallback_ct[] = "text/plain";
struct message *filters;
static int mimecount;
static int extractcount;
static int safe_output;
static int reply_found;
@ -51,10 +48,10 @@ printable(int c)
}
size_t
print_ascii(char *body, size_t bodylen, int oneline)
print_ascii(char *body, size_t bodylen)
{
if (safe_output) {
safe_u8putstr(body, bodylen, oneline, stdout);
safe_u8putstr(body, bodylen, stdout);
return bodylen;
} else {
return fwrite(body, 1, bodylen, stdout);
@ -73,7 +70,7 @@ printhdr(char *hdr)
}
if (*hdr) {
print_ascii(hdr, strlen(hdr), 1);
print_ascii(hdr, strlen(hdr));
fputc('\n', stdout);
}
}
@ -85,7 +82,7 @@ print_u8recode(char *body, size_t bodylen, char *srcenc)
ic = iconv_open("UTF-8", srcenc);
if (ic == (iconv_t)-1) {
fprintf(stderr, "unsupported encoding: %s\n", srcenc);
printf("unsupported encoding: %s\n", srcenc);
return;
}
@ -98,7 +95,7 @@ print_u8recode(char *body, size_t bodylen, char *srcenc)
size_t r = iconv(ic, &body, &bodylen, &bufptr, &buflen);
if (bufptr != buf) {
print_ascii(buf, bufptr-buf, 0);
print_ascii(buf, bufptr-buf);
final_char = bufptr[-1];
}
@ -107,7 +104,7 @@ print_u8recode(char *body, size_t bodylen, char *srcenc)
buflen = sizeof buf;
r = iconv(ic, 0, 0, &bufptr, &buflen);
if (bufptr != buf) {
print_ascii(buf, bufptr-buf, 0);
print_ascii(buf, bufptr-buf);
final_char = bufptr[-1];
}
if (r != (size_t)-1)
@ -169,12 +166,6 @@ mime_filename(struct message *msg)
filename = buf;
}
if (Bflag && filename) {
static char buf2[512];
blaze822_decode_rfc2047(buf2, filename, sizeof buf2, "UTF-8");
filename = buf2;
}
return filename;
}
@ -185,23 +176,11 @@ print_filename(char *filename)
{
if (filename) {
printf(" name=\"");
safe_u8putstr(filename, strlen(filename), 1, stdout);
safe_u8putstr(filename, strlen(filename), stdout);
printf("\"");
}
}
static int
probably_utf8(char *charset)
{
return !charset ||
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0 ||
/* best guess for: */
strcasecmp(charset, "unknown-8bit") == 0 ||
strcasecmp(charset, "x-unknown") == 0;
}
blaze822_mime_action
render_mime(int depth, struct message *msg, char *body, size_t bodylen)
{
@ -231,18 +210,12 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
char *charset = 0, *cs, *cse;
if (blaze822_mime_parameter(ct, "charset", &cs, &cse)) {
charset = strndup(cs, cse-cs);
if (!Nflag)
printf(" charset=\"%s\"", charset);
printf(" charset=\"%s\"", charset);
setenv("PIPE_CHARSET", charset, 1);
free(charset);
}
setenv("PIPE_CONTENTTYPE", ct, 1);
char *messageid = blaze822_hdr(msg, "message-id");
if (messageid) {
setenv("MESSAGE_ID", messageid, 1);
}
char *output;
size_t outlen;
int e = filter(body, bodylen, cmd, &output, &outlen);
@ -252,7 +225,7 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
printf(" render=\"%s\" ---\n", cmd);
if (outlen) {
if (e == 0)
print_ascii(output, outlen, 0);
print_ascii(output, outlen);
else
fwrite(output, 1, outlen, stdout);
if (output[outlen-1] != '\n')
@ -271,16 +244,14 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
} else if (e >= 65 && e <= 80) { // choose N-64th part
struct message *imsg = 0;
int n = e - 64;
if (!Nflag)
printf(" selector=\"%s\" part=%d ---\n", cmd, n);
printf(" selector=\"%s\" part=%d ---\n", cmd, n);
while (blaze822_multipart(msg, &imsg)) {
if (--n == 0)
blaze822_walk_mime(imsg, depth+1, render_mime);
}
blaze822_free(imsg);
} else {
if (!Nflag)
printf(" filter=\"%s\" FAILED status=%d", cmd, e);
printf(" filter=\"%s\" FAILED status=%d", cmd, e);
free(output);
goto nofilter;
}
@ -298,8 +269,11 @@ nofilter:
char *charset = 0, *cs, *cse;
if (blaze822_mime_parameter(ct, "charset", &cs, &cse))
charset = strndup(cs, cse-cs);
if (probably_utf8(charset)) {
print_ascii(body, bodylen, 0);
if (!charset ||
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0) {
print_ascii(body, bodylen);
if (bodylen > 0 && body[bodylen-1] != '\n')
putchar('\n');
} else {
@ -316,10 +290,9 @@ nofilter:
}
printf("\n");
} else if (strncmp(ct, "multipart/alternative", 21) == 0) {
if (strcmp(Aflag, "all") != 0) {
choose_alternative(msg, depth);
r = MIME_PRUNE;
} // else default blaze822_mime_walk action
choose_alternative(msg, depth);
r = MIME_PRUNE;
} else if (strncmp(ct, "multipart/", 10) == 0) {
; // default blaze822_mime_walk action
} else {
@ -336,17 +309,13 @@ nofilter:
static void
choose_alternative(struct message *msg, int depth)
{
int n = 0;
int n = 1;
int m = 0;
char *p = Aflag + strlen(Aflag);
struct message *imsg = 0;
while (blaze822_multipart(msg, &imsg)) {
m++;
if (blaze822_bodylen(imsg) == 0)
continue;
char *ict = blaze822_hdr(imsg, "content-type");
if (!ict)
ict = fallback_ct;
@ -363,13 +332,6 @@ choose_alternative(struct message *msg, int depth)
}
blaze822_free(imsg);
if (n == 0) {
// No part matched, use last part as per RFC1341 7.2.3
// "In general, choosing the best type means displaying
// only the LAST part that can be displayed."
n = m;
}
imsg = 0;
while (blaze822_multipart(msg, &imsg))
if (--n == 0)
@ -390,8 +352,11 @@ reply_mime(int depth, struct message *msg, char *body, size_t bodylen)
char *charset = 0, *cs, *cse;
if (blaze822_mime_parameter(ct, "charset", &cs, &cse))
charset = strndup(cs, cse-cs);
if (probably_utf8(charset))
print_ascii(body, bodylen, 0);
if (!charset ||
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0)
print_ascii(body, bodylen);
else
print_u8recode(body, bodylen, charset);
reply_found++;
@ -502,7 +467,7 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
fwrite(body, 1, bodylen, stdout);
} else { // extract all named attachments
if (filename) {
safe_u8putstr(filename, strlen(filename), 1, stdout);
safe_u8putstr(filename, strlen(filename), stdout);
printf("\n");
writefile(filename, body, bodylen);
}
@ -546,7 +511,6 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
printf("%s\n", bufptr);
writefile(bufptr, body, bodylen);
}
extractcount++;
} else if (filename &&
fnmatch(a, filename, FNM_PATHNAME) == 0) {
// extract by name
@ -563,11 +527,10 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
fwrite(body, 1, bodylen, stdout);
}
} else {
safe_u8putstr(filename, strlen(filename), 1, stdout);
safe_u8putstr(filename, strlen(filename), stdout);
printf("\n");
writefile(filename, body, bodylen);
}
extractcount++;
}
}
}
@ -578,8 +541,6 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
void
extract_cb(char *file)
{
while (*file == ' ' || *file == '\t')
file++;
struct message *msg = blaze822_file(file);
if (!msg)
return;
@ -609,7 +570,7 @@ print_date_header(char *v)
}
printf("Date: ");
print_ascii(v, strlen(v), 1);
print_ascii(v, strlen(v));
time_t t = blaze822_date(v);
if (t == -1) {
@ -695,7 +656,7 @@ print_decode_header(char *h, char *v)
printhdr(h);
fputc(':', stdout);
fputc(' ', stdout);
print_ascii(d, strlen(d), 1);
print_ascii(d, strlen(d));
fputc('\n', stdout);
}
@ -762,7 +723,7 @@ show(char *file)
printf("\n");
if (rflag) { // raw body
print_ascii(blaze822_body(msg), blaze822_bodylen(msg), 0);
print_ascii(blaze822_body(msg), blaze822_bodylen(msg));
goto done;
}
@ -779,11 +740,10 @@ main(int argc, char *argv[])
pid_t pid1 = -1, pid2 = -1;
int c;
while ((c = getopt(argc, argv, "h:A:BqrtFHLNx:O:Rn")) != -1)
while ((c = getopt(argc, argv, "h:A:qrtFHLNx:O:Rn")) != -1)
switch (c) {
case 'h': hflag = optarg; break;
case 'A': Aflag = optarg; break;
case 'B': Bflag = 1; break;
case 'q': qflag = 1; break;
case 'r': rflag = 1; break;
case 'F': Fflag = 1; break;
@ -806,9 +766,7 @@ main(int argc, char *argv[])
exit(1);
}
xpledge("stdio rpath wpath cpath proc exec", NULL);
if (!rflag && !xflag && !Oflag && !Rflag && !tflag)
if (!rflag && !Oflag && !Rflag)
safe_output = 1;
if (safe_output && isatty(1)) {
@ -817,7 +775,7 @@ main(int argc, char *argv[])
if (!pg) {
pg = getenv("PAGER");
if (pg && strcmp(pg, "less") == 0) {
static char lesscmd[] = "less -RFX";
static char lesscmd[] = "less -RFXe";
pg = lesscmd;
}
}
@ -833,22 +791,17 @@ main(int argc, char *argv[])
}
if (xflag) { // extract
xpledge("stdio rpath wpath cpath", NULL);
extract(xflag, argc-optind, argv+optind, 0);
} else if (Oflag) { // extract to stdout
xpledge("stdio rpath", NULL);
extract(Oflag, argc-optind, argv+optind, 1);
} else if (tflag) { // list
xpledge("stdio rpath", NULL);
if (argc == optind && isatty(0))
blaze822_loop1(".", list);
else
blaze822_loop(argc-optind, argv+optind, list);
} else if (Rflag) { // render for reply
xpledge("stdio rpath", NULL);
blaze822_loop(argc-optind, argv+optind, reply);
} else { // show
/* XXX pledge: still r/w on the whole file-system + fork/exec */
if (!(qflag || rflag || Fflag)) {
char *f = getenv("MAILFILTER");
if (!f)
@ -861,8 +814,7 @@ main(int argc, char *argv[])
else
blaze822_loop(argc-optind, argv+optind, show);
if (!nflag) // don't set cur
if (newcur)
blaze822_seq_setcur(newcur);
blaze822_seq_setcur(newcur);
}
if (pid2 > 0)
@ -870,10 +822,5 @@ main(int argc, char *argv[])
if (pid1 > 0)
pipeclose(pid1);
if ((xflag || Oflag) && extractcount < argc-optind) {
fprintf(stderr, "mshow: could not extract all attachments\n");
return 1;
}
return 0;
}

@ -10,7 +10,6 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
struct mail {
char *file;
@ -219,8 +218,8 @@ unreadorder(const void *a, const void *b)
struct mail *ia = (struct mail *)a;
struct mail *ib = (struct mail *)b;
char *fa = strstr(ia->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fb = strstr(ib->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fa = strstr(ia->file, ":2,");
char *fb = strstr(ib->file, ":2,");
int unreada = fa ? !strchr(fa, 'S') : 0;
int unreadb = fb ? !strchr(fb, 'S') : 0;
@ -234,8 +233,8 @@ flaggedorder(const void *a, const void *b)
struct mail *ia = (struct mail *)a;
struct mail *ib = (struct mail *)b;
char *fa = strstr(ia->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fb = strstr(ib->file, MAILDIR_COLON_SPEC_VER_COMMA);
char *fa = strstr(ia->file, ":2,");
char *fb = strstr(ib->file, ":2,");
int unreada = fa ? !!strchr(fa, 'F') : 0;
int unreadb = fb ? !!strchr(fb, 'F') : 0;
@ -279,9 +278,9 @@ add(char *file)
int
order(const void *a, const void *b)
{
int i;
for (i = 0; i < order_idx; i++) {
int r = (sortorders[i])(a, b);
int i, r;
for (i = 0, r = 0; i < order_idx; i++) {
r = (sortorders[i])(a, b);
if (r != 0)
return r;
}
@ -317,9 +316,8 @@ main(int argc, char *argv[])
exit(1);
}
xpledge("stdio rpath", "");
mails = calloc(mailalloc, sizeof (struct mail));
mails = calloc(sizeof (struct mail), mailalloc);
if (!mails)
exit(-1);

@ -19,16 +19,14 @@
#include <unistd.h>
#include "blaze822.h"
#include "xpledge.h"
static int vflag;
static int pflag;
static int rflag;
static int optional;
struct container {
char *mid;
char *file;
struct message *msg;
time_t date;
struct container *parent;
struct container *child;
@ -66,7 +64,7 @@ mid(struct message *msg)
} else {
// invent new message-id for internal tracking
static long i;
char buf[40];
char buf[32];
snprintf(buf, sizeof buf, "thread%08ld@localhost", ++i);
return strdup(buf);
}
@ -76,16 +74,13 @@ struct container *
midcont(char *mid)
{
struct container key, **result;
if (!mid)
exit(111);
key.mid = mid;
if (!(result = tfind(&key, &mids, midorder))) {
struct container *c = malloc(sizeof (struct container));
if (!c)
exit(111);
c->mid = mid;
c->file = 0;
c->msg = 0;
c->date = -1;
c->optional = 0;
c->parent = c->child = c->next = 0;
@ -102,6 +97,7 @@ store_id(char *file, struct message *msg)
c = midcont(mid(msg));
c->file = strdup(file);
c->msg = msg;
c->optional = optional;
return c;
@ -236,8 +232,6 @@ out2:
c->child = 0;
}
}
blaze822_free(msg);
}
time_t
@ -287,8 +281,7 @@ void
find_roots()
{
top = malloc(sizeof (struct container));
if (!top)
exit(111);
top->msg = 0;
top->date = -1;
top->file = 0;
top->next = top->child = top->parent = 0;
@ -313,8 +306,8 @@ prune_tree(struct container *c, int depth)
// turn into child if we don't exist and only have a child
c->mid = c->child->mid;
c->file = c->child->file;
if (c->child->date > c->date)
c->date = c->child->date;
c->msg = c->child->msg;
c->date = c->child->date;
c->optional = c->child->optional;
c->child = c->child->child;
}
@ -347,12 +340,6 @@ dateorder(const void *a, const void *b)
return 0;
}
static int
reverse_dateorder(const void *a, const void *b)
{
return dateorder(b, a);
}
void
sort_tree(struct container *c, int depth)
{
@ -365,15 +352,14 @@ sort_tree(struct container *c, int depth)
if (i == 1) // no sort needed
return;
struct container **a = calloc(i, sizeof (struct container *));
struct container **a = calloc(sizeof (struct container *), i);
if (!a)
return;
for (r = c->child, i = 0; r; r = r->next, i++)
a[i] = r;
qsort(a, i, sizeof (struct container *),
rflag && depth < 0 ? reverse_dateorder : dateorder);
qsort(a, i, sizeof (struct container *), dateorder);
c->child = a[0];
for (j = 0; j+1 < i; j++)
@ -389,8 +375,7 @@ print_tree(struct container *c, int depth)
{
do {
// skip toplevel threads when they are unresolved or all optional
// (or when -p is given, skip those subthreads)
if ((depth <= 1 || pflag) &&
if (depth <= 1 &&
(c->optional || !c->file) &&
(!c->child || alloptional(c->child)))
continue;
@ -414,31 +399,25 @@ int
main(int argc, char *argv[])
{
int c;
long i;
optional = 1;
xpledge("stdio rpath", "");
while ((c = getopt(argc, argv, "S:prv")) != -1)
while ((c = getopt(argc, argv, "S:v")) != -1)
switch (c) {
case 'S': blaze822_loop1(optarg, thread); break;
case 'v': vflag = 1; break;
case 'p': pflag = 1; break;
case 'r': rflag = 1; break;
default:
fprintf(stderr, "Usage: mthread [-vpr] [-S dir] [msgs...]\n");
fprintf(stderr, "Usage: mthread [-v] [-S dir] [msgs...]\n");
exit(1);
}
optional = 0;
if (argc == optind && isatty(0))
blaze822_loop1(":", thread);
i = blaze822_loop1(":", thread);
else
blaze822_loop(argc-optind, argv+optind, thread);
// the tree of all toplevel threads has depth -1,
// so toplevel threads have depth 0.
i = blaze822_loop(argc-optind, argv+optind, thread);
find_roots();
if (!vflag)
@ -446,5 +425,7 @@ main(int argc, char *argv[])
sort_tree(top, -1);
print_tree(top, -1);
fprintf(stderr, "%ld mails threaded\n", i);
return 0;
}

@ -1,28 +1,86 @@
#include <time.h>
time_t
mytimegm(struct tm *tm)
// from musl@1cc81f5cb, slightly tweaked
static long long
__year_to_secs(long long year, int *is_leap)
{
int mon = tm->tm_mon + 1 - 2; /* put March first, Feb last */
long long year = tm->tm_year + 1900;
if (year-2ULL <= 136) {
int y = year;
int leaps = (y-68)>>2;
if (!((y-68)&3)) {
leaps--;
if (is_leap) *is_leap = 1;
} else if (is_leap) *is_leap = 0;
return 31536000*(y-70) + 86400*leaps;
}
int cycles, centuries, leaps, rem;
cycles = (year-100) / 400;
rem = (year-100) % 400;
if (rem < 0) {
cycles--;
rem += 400;
}
if (!rem) {
*is_leap = 1;
centuries = 0;
leaps = 0;
} else {
if (rem >= 200) {
if (rem >= 300) centuries = 3, rem -= 300;
else centuries = 2, rem -= 200;
} else {
if (rem >= 100) centuries = 1, rem -= 100;
else centuries = 0;
}
if (!rem) {
*is_leap = 0;
leaps = 0;
} else {
leaps = rem / 4U;
rem %= 4U;
*is_leap = !rem;
}
}
leaps += 97*cycles + 24*centuries - *is_leap;
if (mon <= 0 || mon >= 12) {
int adj = mon / 12;
mon %= 12;
if (mon <= 0) {
return (year-100) * 31536000LL + leaps * 86400LL + 946684800 + 86400;
}
static int
__month_to_secs(int month, int is_leap)
{
static const int secs_through_month[] = {
0, 31*86400, 59*86400, 90*86400,
120*86400, 151*86400, 181*86400, 212*86400,
243*86400, 273*86400, 304*86400, 334*86400 };
int t = secs_through_month[month];
if (is_leap && month >= 2) t+=86400;
return t;
}
time_t tm_to_secs(const struct tm *tm)
{
int is_leap;
long long year = tm->tm_year;
int month = tm->tm_mon;
if (month >= 12 || month < 0) {
int adj = month / 12;
month %= 12;
if (month < 0) {
adj--;
mon += 12;
month += 12;
}
year += adj;
}
time_t t = 0;
t += tm->tm_sec;
t += 60 * tm->tm_min;
t += 60*60 * tm->tm_hour;
t += 24*60*60 * (tm->tm_mday - 1);
t += 24*60*60 * (367*mon/12);
t += 24*60*60 * (year/4 - year/100 + year/400);
t += 24*60*60 * (365*year - 719498L);
long long t = __year_to_secs(year, &is_leap);
t += __month_to_secs(month, is_leap);
t += 86400LL * (tm->tm_mday-1);
t += 3600LL * tm->tm_hour;
t += 60LL * tm->tm_min;
t += tm->tm_sec;
return t;
}

@ -86,8 +86,6 @@ blaze822_mime_parameter(char *s, char *name, char **starto, char **stopo)
while (*s) {
while (iswsp(*s))
s++;
if (!*s)
return 0;
if (strncasecmp(s, name, namelen) == 0 && s[namelen] == '=') {
s += namelen + 1;
break;
@ -116,26 +114,6 @@ blaze822_mime_parameter(char *s, char *name, char **starto, char **stopo)
return 1;
}
// like mymemmem but check the match is followed by \r, \n or -.
static char *
mymemmemnl(const char *h0, size_t k, const char *n0, size_t l)
{
char *r;
while (k && (r = mymemmem(h0, k, n0, l))) {
if (r + l < h0 + k && // check if r[l] safe to access
(r[l] == '\r' || r[l] == '\n' || r[l] == '-'))
return r;
else {
// skip over this match
k -= (r - h0) + 1;
h0 = r + 1;
}
}
return 0;
}
int
blaze822_multipart(struct message *msg, struct message **imsg)
{
@ -166,7 +144,7 @@ blaze822_multipart(struct message *msg, struct message **imsg)
else
prevpart = msg->body;
char *part = mymemmemnl(prevpart, msg->bodyend - prevpart, mboundary, boundarylen);
char *part = mymemmem(prevpart, msg->bodyend - prevpart, mboundary, boundarylen);
if (!part)
return 0;
@ -180,10 +158,8 @@ blaze822_multipart(struct message *msg, struct message **imsg)
else
return 0; // XXX error condition?
char *nextpart = mymemmemnl(part, msg->bodyend - part, mboundary, boundarylen);
char *nextpart = mymemmem(part, msg->bodyend - part, mboundary, boundarylen);
if (!nextpart)
nextpart = msg->bodyend; // no boundary found, take all
else if (nextpart == part) // invalid empty MIME part
return 0; // XXX error condition
if (*(nextpart-1) == '\n')
@ -204,9 +180,6 @@ blaze822_walk_mime(struct message *msg, int depth, blaze822_mime_callback visit)
blaze822_mime_action r = MIME_CONTINUE;
if (depth > 64)
return MIME_PRUNE;
if (blaze822_mime_body(msg, &ct, &body, &bodylen, &bodychunk)) {
r = visit(depth, msg, body, bodylen);

@ -82,25 +82,16 @@ blaze822_decode_b64(char *s, char *e, char **deco, size_t *decleno)
*deco = buf;
while (s + 4 <= e) {
uint32_t v = 0;
unsigned char t = 0;
#define SKIP_WS \
while (s < e && isfws((unsigned char)*s)) \
s++; \
if (s >= e) \
while (s < e && isfws((unsigned char)*s))
s++;
if (s >= e)
break;
SKIP_WS;
unsigned char c0 = *s++;
SKIP_WS;
unsigned char c1 = *s++;
SKIP_WS;
unsigned char c2 = *s++;
SKIP_WS;
unsigned char c3 = *s++;
uint32_t v = 0;
unsigned char t = 0;
#undef SKIP_WS
unsigned char c0 = s[0], c1 = s[1], c2 = s[2], c3 = s[3];
s += 4;
if ((c0 | c1 | c2 | c3) > 127)
goto error;
@ -139,10 +130,6 @@ blaze822_decode_rfc2047(char *dst, char *src, size_t dlen, char *tgtenc)
iconv_t ic = (iconv_t)-1;
char *srcenc = 0;
// need space for trailing nul
if (dlen-- == 0)
return 0;
char *startdst = dst;
size_t startdlen = dlen;
@ -201,8 +188,7 @@ blaze822_decode_rfc2047(char *dst, char *src, size_t dlen, char *tgtenc)
if (ic == (iconv_t)-1)
goto nocode;
char enc = lc(*e);
e++;
char enc = lc(*e++);
if (*e++ != '?')
goto nocode;
char *start = e;

@ -54,10 +54,8 @@ found_extended:
if (!srcenc)
return 0;
sbuf = strchr(sbuf+1, '\'');
if (!sbuf) {
free(srcenc);
if (!sbuf)
return 0;
}
sbuf++;
}
while (sbuf < ebuf && dst < dstend) {

@ -4,7 +4,7 @@
#include "u8decode.h"
void
safe_u8putstr(char *s0, size_t l, int oneline, FILE *stream)
safe_u8putstr(char *s0, size_t l, FILE *stream)
{
// tty-safe output of s, with relaxed utf-8 semantics:
// - C0 and C1 are displayed as escape sequences
@ -34,12 +34,8 @@ safe_u8putstr(char *s0, size_t l, int oneline, FILE *stream)
fputc(0xc0 | (*s >> 6), stream);
fputc(0x80 | (*s & 0x3f), stream);
}
} else if (c < 32 &&
*s != ' ' && *s != '\t' &&
(oneline || (*s != '\n' && *s != '\r'))) {
// NUL
if (l == 0)
l = 1;
} else if (c < 32 &&
*s != ' ' && *s != '\t' && *s != '\n' && *s != '\r') {
// C0
fputc(0xe2, stream);
fputc(0x90, stream);

90
seq.c

@ -110,14 +110,15 @@ blaze822_seq_load(char *map)
char *e = t;
while (s < e && isfws(*(e-1)))
e--;
// printf("{%.*s}\n", e-s, s);
char *f = strndup(s, e-s);
if (!f)
return -1;
struct msgnum key;
struct msgnum key, **result;
key.file = f;
if (!tfind(&key, &msgnums, msgnumorder)) {
if (!(result = tfind(&key, &msgnums, msgnumorder))) {
struct msgnum *c = malloc(sizeof (struct msgnum));
c->file = f;
c->pos = line;
@ -151,9 +152,6 @@ blaze822_seq_cur(void)
int
blaze822_seq_setcur(char *s)
{
if (strcmp(s, "/dev/stdin") == 0)
return 0;
char *override = getenv("MAILDOT");
if (override)
return 0;
@ -183,7 +181,7 @@ parse_relnum(char *a, long cur, long start, long last, long *out)
if (strcmp(a, "+") == 0)
a = ".+1";
else if (strcmp(a, ".-") == 0)
else if (strcmp(a, "-") == 0)
a = ".-1";
else if (strcmp(a, ".") == 0)
a = ".+0";
@ -396,6 +394,7 @@ find_cur(char *map, struct blaze822_seq_iter *iter)
while (*s == ' ' || *s == '\t')
s++;
// printf("{%.*s}\n", t-s, s);
iter->lines++;
if (!cur && curfile &&
strncmp(s, curfile, strlen(curfile)) == 0 &&
@ -427,7 +426,7 @@ blaze822_seq_next(char *map, char *range, struct blaze822_seq_iter *iter)
if (!iter->lines) // count total lines
find_cur(map, iter);
if (!iter->s) {
if (!iter->start) {
int ret = parse_range(map, range, &iter->start, &iter->stop,
iter->cur, iter->lines);
if (ret == 1) {
@ -468,49 +467,44 @@ blaze822_seq_next(char *map, char *range, struct blaze822_seq_iter *iter)
return r;
}
int mystrverscmp(const char *, const char *);
static int
mailsort(const struct dirent **a, const struct dirent **b)
{
return mystrverscmp((*a)->d_name, (*b)->d_name);
}
static long
iterdir(char *dir, void (*cb)(char *))
{
struct dirent **namelist;
int n;
char sub[PATH_MAX];
snprintf(sub, sizeof sub, "%s/cur", dir);
DIR *fd, *fd2;
struct dirent *d;
char *m = "/cur";
long i = 0;
n = scandir(sub, &namelist, 0, mailsort);
if (n == -1 && (errno == ENOENT || errno == ENOTDIR)) {
m = "";
n = scandir(dir, &namelist, 0, mailsort);
}
if (n == -1) {
fd = opendir(dir);
if (!fd) {
if (errno == ENOTDIR)
cb(dir);
return 1;
}
long i = 0;
for (i = 0; i < n; i++) {
if (namelist[i]->d_name[0] != '.' &&
MAIL_DT(namelist[i]->d_type)) {
snprintf(sub, sizeof sub, "%s%s/%s",
dir, m, namelist[i]->d_name);
cb(sub);
}
free(namelist[i]);
char sub[PATH_MAX];
snprintf(sub, sizeof sub, "%s/cur", dir);
fd2 = opendir(sub);
if (fd2) {
closedir(fd);
fd = fd2;
}
while ((d = readdir(fd))) {
#if defined(DT_REG) && defined(DT_UNKNOWN)
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
continue;
#endif
if (d->d_name[0] == '.')
continue;
if (fd2)
snprintf(sub, sizeof sub, "%s/cur/%s", dir, d->d_name);
else
snprintf(sub, sizeof sub, "%s/%s", dir, d->d_name);
cb(sub);
i++;
}
free(namelist);
closedir(fd);
return i;
}
@ -534,26 +528,13 @@ blaze822_loop(int argc, char *argv[], void (*cb)(char *))
return i;
}
char *map = 0;
int map_opened = 0;
char *map = blaze822_seq_open(0);
struct blaze822_seq_iter iter = { 0 };
int j = 0;
for (i = 0; i < argc; i++) {
if (strchr(argv[i], '/')) { // a file name
j += iterdir(argv[i], cb);
} else if (strcmp(argv[i], "-") == 0) {
if (isatty(0)) {
fprintf(stderr, "mblaze: warning: - now means "
"read mail text from standard input, "
"use .- to refer to previous mail\n");
}
cb("/dev/stdin");
j++;
} else {
if (!map_opened) {
map = blaze822_seq_open(0);
map_opened = 1;
}
struct blaze822_seq_iter iter = { 0 };
while ((line = blaze822_seq_next(map, argv[i], &iter))) {
cb(line);
free(line);
@ -561,7 +542,6 @@ blaze822_loop(int argc, char *argv[], void (*cb)(char *))
}
}
}
free(map);
return j;
}

@ -24,6 +24,11 @@ slurp(char *filename, char **bufo, off_t *leno)
r = errno;
goto out;
}
if (st.st_size == 0) {
*bufo = "";
*leno = 0;
return 0;
}
*bufo = malloc(st.st_size + 1);
if (!*bufo) {
r = ENOMEM;

@ -1,8 +1,7 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 21
plan 4
cat <<EOF >tmp
References: <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@a> <bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb@b> <ccccccccccccccccccccccccccccccc@c>
@ -10,143 +9,9 @@ References: <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@a> <bbbbbbbbbbbbbbbbbbbbbbbbbbbb
Body
EOF
# https://github.com/leahneukirchen/mblaze/issues/20
# https://github.com/chneukirchen/mblaze/issues/20
check 'mime -r runs' 'mmime -r <tmp >tmp2'
check 'no overlong lines' 'awk "{if(length(\$0)>=80)exit 1}" <tmp2'
check 'no QP when unecessary' ! grep -qF "=?" tmp2
check 'no further mime necessary' 'mmime -c <tmp2'
cat <<EOF >tmp2
Subject: inclusion test
#message/rfc822 $PWD/tmp
EOF
check 'include works' 'mmime <tmp2 | grep Body'
check 'include sets filename' 'mmime <tmp2 | grep filename=tmp'
cat <<EOF >tmp2
Subject: inclusion test no filename
#message/rfc822 $PWD/tmp>
EOF
check 'include works, overriding filename' 'mmime <tmp2 | grep Disposition | grep -v filename=tmp'
cat <<EOF >tmp2
Subject: inclusion test with other disposition
#message/rfc822#inline $PWD/tmp>
EOF
check 'include works, overriding filename' 'mmime <tmp2 | grep Disposition | grep inline'
cat <<EOF >tmp2
Subject: message with content-type
Content-Type: text/plain; format=flowed
This message has format-flowed.
EOF
check 'content-type is respected if found in input' 'mmime -r <tmp2 |grep format=flowed'
cat <<EOF >tmp2
Subject: message with content-transfer-encoding
Content-Transfer-Encoding: quoted-printable
This message has already encoded. f=C3=B6=C3=B6.
EOF
check 'content-transfer-encoding is respected if found in input' 'mmime -r <tmp2 |grep f=C3=B6=C3=B6'
cat <<EOF >tmp2
Subject: message with content-type
Content-Type: text/plain; format=flowed
This message has format-flowed.
#message/rfc822 $PWD/tmp
This part too.
EOF
check 'content-type is respected if found in input, for multipart/mixed' 'mmime <tmp2 |grep format=flowed'
cat <<EOF >tmp2
Subject: message with content-transfer-encoding
Content-Transfer-Encoding: Quoted-Printable
This message has already encoded. f=C3=B6=C3=B6.
#message/rfc822 $PWD/tmp
This part too.
EOF
check 'content-transfer-encoding is respected if found in input, for multipart/mixed' 'mmime <tmp2 |grep f=C3=B6=C3=B6'
cat <<EOF >tmp2
From: Kerstin Krüger <krueger@example.com>
Body.
EOF
check 'non-ASCII is encoded as UTF-8' 'mmime <tmp2 | grep "UTF-8.*=C3=BC"'
cat <<EOF >tmp2
From: "Krüger, Kerstin" <krueger@example.com>
Body.
EOF
check 'non-ASCII quoted-strings are encoded as one encoded-word' 'mmime <tmp2 | grep "UTF-8.*=2C_"'
check 'non-ASCII quoted-strings are encoded without quotes' 'mmime <tmp2 | grep -v "=22"'
cat <<EOF >tmp2
From: "kerstin krueger"@example.com
Body.
EOF
check 'non-encoded quoted-strings are kept correctly' 'mmime <tmp2 | grep \"@'
cat <<EOF >tmp2
Subject: inclusion without further content
#message/rfc822#inline $PWD/tmp
EOF
check 'no empty parts are generated after inclusion lines' '! mmime <tmp2 | mshow -t - | grep -q size=0'
cat <<EOF >tmp2
Subject: Strict mode
Body with lines longer than 78 characters
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
EOF
check 'body lines longer than 78 characters needs MIME formatting' '! mmime -c <tmp2'
check 'MBLAZE_RELAXED_MIME allows body lines longer than 78 characters' 'MBLAZE_RELAXED_MIME= mmime -c <tmp2'
cat <<EOF >tmp2
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1710013705;
s=s1; d=tuta.io;
h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=Jr8DQlZ7RwdJv94m7ZT/v+cv/WFsgjxpMRsHvnNfgGY=;
b=NXRl0YxYtVsWrR8v7tVKnvsnCSrBqqaf2h3m8OVGlzG0OqMqGcWg7fVk6x4nTYV+
+05afZrGfIwcfFwIe/LLvT0d3/12t4+cs/FQvmEcFUN+n2buQwt5sn8f76UUlvNMrGz
Xbq8HAdwhA364yWABa7DrF1EGysC8bEDJcCtSs/Wz3TL2A/MEeItEF+VijtgWUwoOwn
rFKkCg5Df+IOd4gEBS/KYLbzcMB1dvqy+ut2LA2+NZpzJQPgbJzWAYieT9KYgoS+hKS
5FfknNT+hKZz18IBEWH1UWbI+CcLRR8Sr80x2DZUKq8ryC5RmV5/uAc5Up03b/KZGRU
NsiBAQCx3w==
EOF
check 'header words longer then 78 characters do not cause empty lines (#257)' 'mmime < tmp2 | awk "NR < 5 && length == 0 { exit 1 }"'
check 'header words longer then 78 characters are printed on their own line' 'mmime < tmp2 |grep "^[ ]*h=From.*Sender;$"'

@ -1,26 +0,0 @@
#!/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'

@ -1,7 +1,7 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 11
plan 10
rm -rf test.dir
mkdir test.dir
@ -12,7 +12,6 @@ mkdir -p "inbox/cur"
cat <<! | mmime >"inbox/cur/1:2,"
From: Rajwinder Kaur <rajwinder@example.com>
Obs-Test: Rajwinder Kaur <@example.org:rajwinder@example.com>
Subject: namaste
Date: Thu, 30 Mar 2017 15:42:05 +0200
Message-Id: <EOH1F3NUOY.2KBVMHSBFATNY@example.org>
@ -20,7 +19,7 @@ Message-Id: <EOH1F3NUOY.2KBVMHSBFATNY@example.org>
!
cat <<! | mmime >"inbox/cur/2:2,"
From: имярек <namearek@example.com>, Rajwinder Kaur <rajwinder@example.com>
From: имярек <имярек@example.com>, Rajwinder Kaur <rajwinder@example.com>
Subject: Здравствуйте
Date: Thu, 30 Mar 2017 15:42:10 +0200
Message-Id: <EOH8EKEA1Z.2YAIFN5KVCO6Z@example.org>
@ -67,10 +66,9 @@ export MAILSEQ=seq
check_same 'from one' 'maddr 1' 'echo "Rajwinder Kaur <rajwinder@example.com>"'
check_same 'from address' 'maddr -a 1' 'echo "rajwinder@example.com"'
check_same 'from one' 'maddr -h obs-test 1' 'echo "Rajwinder Kaur <rajwinder@example.com>"'
cat <<! >expect
имярек <namearek@example.com>
имярек <имярек@example.com>
Rajwinder Kaur <rajwinder@example.com>
!
check_same 'from two' 'maddr 2' 'cat expect'
@ -80,7 +78,7 @@ check_test 'from name only' -eq 0 'maddr 4 | wc -l'
check_same 'specific header' 'maddr -h foo 4' 'echo "Perico de los palotes <palotes@example.com>"'
check_same 'long addr' 'maddr -h long 4' 'echo "heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelloooooooooooooooooo@woooooooooooooooooooooooooooooooooooooorld.com"'
check_same 'decode iso8859' 'maddr -h DecodeISO8859 5' 'echo "Keld Jørn Simonsen <keld@dkuug.dk>"'
check_same 'decode long iso8859' 'maddr -h DecodeLongISO8859 5' 'echo "\"If you can read this you understand the example. z a b\" <foo@example.com>"'
check_same 'decode long iso8859' 'maddr -h DecodeLongISO8859 5' 'echo "If you can read this you understand the example. z a b <foo@example.com>"'
check_same 'decode utf8' 'maddr -h DecodeUTF8 5' 'echo "zz <bar@example.com>"'
)

@ -1,10 +1,10 @@
#!/bin/sh
cd ${0%/*}
. ./lib.sh
plan 33
plan 26
check_addr() {
printf "From: %s\n" "$1" | check_test "parse $1" = "$2" "maddr -"
printf "From: %s\n" "$1" | check_test "parse $1" = "$2" "maddr /dev/stdin"
}
check_addr 'foo@example.org' 'foo@example.org'
@ -14,11 +14,11 @@ check_addr 'bar quux <foo@example.org>' 'bar quux <foo@example.org>'
check_addr 'bar quux <foo@example.org>' 'bar quux <foo@example.org>'
check_addr '<foo@example.org> (bar)' 'bar <foo@example.org>'
check_addr '"Real Name" <foo@example.org>' 'Real Name <foo@example.org>'
check_addr '"Dr. Real Name" <foo@example.org>' '"Dr. Real Name" <foo@example.org>'
check_addr '"Real Name" (show this) <foo@example.org>' '"Real Name (show this)" <foo@example.org>'
check_addr '"Real Name" <foo@example.org> (ignore this)' '"Real Name (ignore this)" <foo@example.org>'
check_addr '"Dr. Real Name" <foo@example.org>' 'Dr. Real Name <foo@example.org>'
check_addr '"Real Name" (show this) <foo@example.org>' 'Real Name (show this) <foo@example.org>'
check_addr '"Real Name" <foo@example.org> (ignore this)' 'Real Name (ignore this) <foo@example.org>'
check_addr '(nested (comments mail@here ) heh) "yep (yap)" <foo@example.org>' '"yep (yap)" <foo@example.org>'
check_addr '(nested (comments mail@here ) heh) "yep (yap)" <foo@example.org>' 'yep (yap) <foo@example.org>'
check_addr 'ignore-this: <foo@example.org>' 'foo@example.org'
check_addr 'ignore-this : <foo@example.org>' 'foo@example.org'
@ -39,13 +39,4 @@ check_addr 'foo@[::1] (ipv6)' 'ipv6 <foo@[::1]>'
# invalid addresses
check_addr '<Foo Bar <foobar@qux.com>' 'foobar@qux.com'
check_addr '"abc@def"@ghi' ''
check_addr '"foo@" <bar.com foo@bar.com>' '"foo@" <bar.comfoo@bar.com>'
check_addr 'test."test"@example.org' 'test.test@example.org'
check_addr '<test."test"@example.org>' 'test.test@example.org'
check_addr 'test"test"@example.org' 'testtest@example.org'
check_addr '<test"test"@example.org>' 'testtest@example.org'
check_addr 'foo<bar@example.org>' 'foo <bar@example.org>'
check_addr 'xxxxxxxxx a"test"@example.org' "xxxxxxxxx <atest@example.org>"
check_addr '"abc@def"@ghi' ''

@ -1,41 +0,0 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 2
# Nested MIME where the outer boundary is a prefix of the inner boundary
cat <<EOF >tmp
MIME-Version: 1.0
Content-type: multipart/mixed; charset=iso-8859-1;
boundary="_xec5AqfRYxfhARmklHx"
--_xec5AqfRYxfhARmklHx
Content-type: Multipart/alternative; charset=iso-8859-1;
boundary="_xec5AqfRYxfhARmklHx8"
--_xec5AqfRYxfhARmklHx8
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
foo
--_xec5AqfRYxfhARmklHx8
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
bar
--_xec5AqfRYxfhARmklHx8--
--_xec5AqfRYxfhARmklHx
Content-Type: application/zip
Content-Transfer-Encoding: Base64
quux
--_xec5AqfRYxfhARmklHx--
EOF
check 'nested mail has 5 attachments' 'mshow -t ./tmp | wc -l | grep 6'
check 'nested mail has text/html attachment' 'mshow -t ./tmp | grep text/html'

@ -1,53 +0,0 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 3
# Mail with \n\n and \r\n\r\n
cr=$(printf '\r')
cat <<EOF >tmp
Content-Type: multipart/form-data; boundary=------------------------55a586f81559face$cr
$cr
--------------------------55a586f81559face$cr
Content-Disposition: form-data; name="a"; filename="foo"$cr
Content-Type: application/octet-stream$cr
$cr
foo$cr
previously there are two NL$cr
$cr
--------------------------55a586f81559face$cr
Content-Disposition: form-data; name="a"; filename="bar"$cr
Content-Type: application/octet-stream$cr
$cr
bar$cr
$cr
--------------------------55a586f81559face--$cr
EOF
check 'mail has 3 attachments' 'mshow -t ./tmp | wc -l | grep 4'
check 'mail attachment foo has size 35' 'mshow -t ./tmp | grep size=35.*name=\"foo\"'
# Mail with linebreaks in base64 quartets
cat <<EOF >tmp
Subject: base64
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----_=_2f8f1e2243b55f8618eaf0d9_=_"
This is a multipart message in MIME format.
------_=_2f8f1e2243b55f8618eaf0d9_=_
Content-Disposition: attachment; filename=base64
Content-Type: application/binary
Content-Transfer-Encoding: base64
dGhp
cyBpc
yBzb21
lIGJhc2
U2NAo=
------_=_2f8f1e2243b55f8618eaf0d9_=_--
EOF
check 'mail decodes correctly' 'mshow -O ./tmp 2 | grep -q "this is some base64"'

@ -1,26 +0,0 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 2
cat <<EOF >tmp.1
Subject: message 1
This is message 1.
EOF
cat <<EOF >tmp.2
Subject: message 2
This is message 2. It has a trailing empty line.
EOF
printf >tmp.3 'Subject: message 3
This is message 3. It has a no trailing newline, oops.'
mexport ./tmp.1 ./tmp.2 ./tmp.3 >./tmp.mbox
check 'generated mbox has 16 lines' 'cat ./tmp.mbox | wc -l | grep 16'
check 'generated mbox has 7 empty lines' 'grep -c "^$" ./tmp.mbox | grep 7'

@ -1,85 +0,0 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 9
rm -rf test.dir
mkdir test.dir
cd test.dir
mmkdir inbox
cat <<EOF >tmp.1
Subject: message 1
This is message 1.
EOF
cat <<EOF >tmp.2
Subject: message 2
This is message 2. It has a trailing empty line.
EOF
printf >tmp.3 'Subject: message 3
This is message 3. It has a no trailing newline, oops.'
cat <<EOF >tmp.4
Subject: message 4
This is message 4. It has multiple trailing empty lines.
EOF
mexport ./tmp.1 | mdeliver -M inbox/
check 'message 1 is delivered verbatim via mbox' 'cmp ./tmp.1 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mexport ./tmp.2 | mdeliver -M inbox/
check 'message 2 is delivered verbatim via mbox' 'cmp ./tmp.2 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mexport ./tmp.3 | mdeliver -M inbox/
check 'message 3 gets a newline via mbox' 'awk 1 ./tmp.3 | cmp - ./inbox/new/*:2,'
rm -f ./inbox/new/*
mexport ./tmp.4 | mdeliver -M inbox/
check 'message 4 gets delivered verbatim via mbox' 'cmp ./tmp.4 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mdeliver inbox/ <./tmp.1
check 'message 1 is delivered verbatim via stdin' 'cmp ./tmp.1 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mdeliver inbox/ <./tmp.2
check 'message 2 is delivered verbatim via stdin' 'cmp ./tmp.2 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mdeliver inbox/ <./tmp.3
check 'message 3 gets a newline via stdin' 'cmp ./tmp.3 ./inbox/new/*:2,'
rm -f ./inbox/new/*
mdeliver inbox/ <./tmp.4
check 'message 4 is delivered verbatim via stdin' 'cmp ./tmp.4 ./inbox/new/*:2,'
rm -f ./inbox/new/*
cat <<EOF >tmp.mbox
From nobody Thu Jan 1 00:59:59 1970
Subject: message 1
This is message 1.
From nobody Thu Jan 1 00:59:59 1970
Subject: message 2
This is message 2.
EOF
mdeliver -M inbox/ <./tmp.mbox
check 'mdeliver -M is tolerant with missing empty lines' 'ls inbox/new | wc -l | grep 2'

@ -1,7 +1,7 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 29
plan 13
rm -rf test.dir
mkdir test.dir
@ -19,14 +19,14 @@ touch "inbox/cur/7:2,SR"
touch "inbox/cur/8:2,SF"
touch "inbox/cur/9:2,"
check_same 'flag trashed' 'mlist inbox | mpick -t trashed' 'mlist -T inbox'
check_same 'flag not trashed' 'mlist inbox | mpick -t !trashed' 'mlist -t inbox'
check_same 'flag seen' 'mlist inbox | mpick -t seen' 'mlist -S inbox'
check_same 'flag trashed' 'mlist inbox | mpick :T' 'mlist -T inbox'
check_same 'flag not trashed' 'mlist inbox | mpick -t "!trashed"' 'mlist -t inbox'
check_same 'flag seen' 'mlist inbox | mpick :S' 'mlist -S inbox'
check_same 'flag not seen' 'mlist inbox | mpick -t !seen' 'mlist -s inbox'
check_same 'flag seen and trashed' 'mlist inbox | mpick -t seen -t trashed' 'mlist -ST inbox'
check_same 'flag seen and not trashed' 'mlist inbox | mpick -t seen -t !trashed' 'mlist -St inbox'
check_same 'flag replied' 'mlist inbox | mpick -t replied' 'mlist -R inbox'
check_same 'flag forwarded' 'mlist inbox | mpick -t passed' 'mlist -P inbox'
check_same 'flag seen and trashed' 'mlist inbox | mpick :S :T' 'mlist -ST inbox'
check_same 'flag seen and not trashed' 'mlist inbox | mpick -t "seen && !trashed"' 'mlist -St inbox'
check_same 'flag replied' 'mlist inbox | mpick :R' 'mlist -R inbox'
check_same 'flag forwarded' 'mlist inbox | mpick :F' 'mlist -F inbox'
cat <<! | mmime >"inbox/cur/1:2,S"
@ -61,75 +61,10 @@ Greetings
#application/pdf ../../mshow
!
cat <<! >shebang
#!$(command -v mpick) -F
from.addr == "peter@example.org" && from.disp == "Peter Example"
!
chmod +x shebang
check 'search subject' 'mlist inbox | mpick -t "subject =~~ \"wow\"" | grep -q inbox/cur/9:2,'
check_test 'search addr' -eq 2 'mlist inbox | mpick -t "from.addr == \"peter@example.org\"" | wc -l'
check_test 'search name' -eq 2 'mlist inbox | mpick -t "from.disp == \"Peter Example\"" | wc -l'
check 'search subject' 'mlist inbox | mpick /wow | grep -q inbox/cur/9:2,'
check_test 'search addr' -eq 2 'mlist inbox | mpick peter@example.org | wc -l'
check_test 'search name' -eq 2 'mlist inbox | mpick "Peter Example" | wc -l'
check_test 'search spam' -eq 1 'mlist inbox | mpick -t "trashed && subject =~ \"pdf\"" | wc -l'
check_test 'any header' -eq 1 'mlist inbox | mpick -t "\"Foo\" =~~ \"bar\"" | wc -l'
check_test 'addr decode addr' -eq 2 'mlist inbox | mpick -t "from.addr == \"peter@example.org\"" | wc -l'
check_test 'addr decode disp' -eq 2 'mlist inbox | mpick -t "from.disp == \"Peter Example\"" | wc -l'
check_test 'shebang' -eq 2 'mlist inbox | ./shebang | wc -l'
check_test 'ternary' -eq 2 'mlist inbox | mpick -t "from.addr == \"peter@example.org\" ? print : skip" | wc -l'
check_same 'pipe command' 'mlist inbox | mpick -t "print |\"cat -n\" && skip"' 'mlist inbox | cat -n'
check_same 'create file' 'mlist inbox | mpick -t "print >\"foo\" && skip" && cat foo' 'mlist inbox'
check_same 'overwrite file' 'mlist inbox | mpick -t "print >\"foo\" && skip" && cat foo' 'mlist inbox'
check_same 'append file' 'mlist inbox | mpick -t "print >>\"foo\" && skip" && cat foo' 'mlist inbox && mlist inbox'
check_same 'unknown ident' 'mlist inbox | mpick -t "let x = x in x" 2>&1' \
"echo \"mpick: parse error: argv:1:9: unknown expression at 'x in x'\""
cat <<! >expr
let foo = from.addr == "peter@example.org"
let bar = from.disp == "Peter Example"
# random comment
in
foo && bar # another comment
!
check_test 'let expression' -eq 2 'mlist inbox | mpick -F ./expr | wc -l'
cat <<! >expr
let foo = from.addr == "peter@example.org"
let bar = from.disp == "Peter Example"
# random comment
in
foo && foo
!
check_test 'let expression double free' -eq 2 'mlist inbox | mpick -F ./expr | wc -l'
cat <<! >expr
let foo =
let bar = from.disp == "Peter Example"
in
bar && from.addr == "peter@example.org"
in
foo
!
check_test 'let expression nested' -eq 2 'mlist inbox | mpick -F ./expr | wc -l'
cat <<! >expr
let foo = from.addr == "peter@example.org"
let bar = foo && subject =~ "wow"
in
bar
!
check_test 'let scoping' -eq 1 'mlist inbox | mpick -F ./expr | wc -l'
cat <<! >expr
let foo = from.addr == "peter@example.org"
let bar = from.disp == "Peter Example"
in
foo |"sed ""s/^/1:&/""" && bar |"sed ""s/^/2:&/""" && skip
!
check_test 'multi redir' -eq 4 'mlist inbox | mpick -F ./expr | wc -l'
check_test 'multi redir prefixes' -eq 2 'mlist inbox | mpick -F ./expr | cut -d: -f1 | sort -u | wc -l'
)
check 'environment variable' 'mlist inbox | MSGID="<EOH1F3NUOY.2KBVMHSBFATNY@example.org>" mpick -t "\"message-id\" == \$MSGID"'

@ -172,23 +172,23 @@ inbox/cur/4:2,
export MAILSEQ=seq
check_test 'subject' -eq 1 'magrep subject:nice : | wc -l'
check_test 'ignorecase' -eq 1 'magrep -i subject:NICE : | wc -l'
check_test 'invert' -eq 2 'magrep -v subject:nice : | wc -l'
check_test 'max matches' -eq 2 'magrep -m 2 from:Piet : | wc -l'
check_test 'long subject' -eq 1 'magrep subject:aliqua : | wc -l'
check_test 'decode large rfc2047 header' -eq 1 'magrep -d to:John : | wc -l'
check_test 'subject' -eq 1 'magrep subject:nice | wc -l'
check_test 'ignorecase' -eq 1 'magrep -i subject:NICE | wc -l'
check_test 'invert' -eq 2 'magrep -v subject:nice | wc -l'
check_test 'max matches' -eq 2 'magrep -m 2 from:Piet | wc -l'
check_test 'long subject' -eq 1 'magrep subject:aliqua | wc -l'
check_test 'decode large rfc2047 header' -eq 1 'magrep -d to:John | wc -l'
echo 'inbox/cur/1:2,: subject: wow nice subject' >expect
check_same 'print' 'magrep -p subject:nice :' 'cat expect'
check_same 'print' 'magrep -p subject:nice' 'cat expect'
echo 'inbox/cur/1:2,: subject: nice' >expect
check_same 'print match' 'magrep -po subject:nice :' 'cat expect'
check_same 'print match' 'magrep -po subject:nice' 'cat expect'
echo 'nice' >expect
check_same 'print match only' 'magrep -o subject:nice :' 'cat expect'
check_same 'print match only' 'magrep -o subject:nice' 'cat expect'
echo 'inbox/cur/3:2,' >expect
check_same 'multiple subjects' 'magrep subject:multi :' 'cat expect'
check_same 'multiple subjects' 'magrep subject:multi' 'cat expect'
)

@ -1,166 +0,0 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 12
rm -rf test.dir
mkdir test.dir
(
cd test.dir
export PIPE_CONTENTTYPE='text/plain; format=flowed'
export COLUMNS=80
cat <<! >a
this
is
flowed.
!
cat <<! >b
this is flowed.
!
check 'simple reflow' 'mflow <a | cmp - b'
cat <<! >a
this
is
two spaces.
!
cat <<! >b
this is two spaces.
!
check 'simple space stuffing' 'mflow <a | cmp - b'
cat <<! >a
this
is
flowed.
this is fixed.
!
cat <<! >b
this is flowed.
this is fixed.
!
check 'simple fixed' 'mflow <a | cmp - b'
cat <<! >a
> this
> is
> quoted.
this
is
unquoted.
!
cat <<! >b
> this is quoted.
this is unquoted.
!
check 'simple quoted' 'mflow <a | cmp - b'
(
export PIPE_CONTENTTYPE='text/plain; format=flowed; delsp=yes'
cat <<! >a
> this
> is
> delsp.
> double
> spaced
!
cat <<! >b
> thisisdelsp.
> double spaced
!
check 'simple delsp' 'mflow <a | cmp - b'
)
cat <<! >a
this
is
way more than eighty chars which is the terminal width to flow.
this
is
way more than eighty chars which is the terminal width to flow.
!
cat <<! >b
this is way more than eighty chars which is the terminal width to flow. this is
way more than eighty chars which is the terminal width to flow.
!
check 'simple wrap' 'mflow <a | cmp - b'
cat <<! >a
this
is
way more than eighty chars which is the terminal width to flow.
averylongwordcomeshere.
this
is
way more than eighty chars which is the terminal width to flow.
!
cat <<! >b
this is way more than eighty chars which is the terminal width to flow.
averylongwordcomeshere. this is way more than eighty chars which is the
terminal width to flow.
!
check 'more complex wrap' 'mflow <a | cmp - b'
cat <<! >a
foo
bar.
quux.
!
cat <<! >b
foo bar.
quux.
!
check 'space before empty line' 'mflow <a | cmp - b'
cat <<! >a
Aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee
aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee
aaaaa bbbbb ccccc
ffffff gggggg hhhhhh iiiiii.
!
cat <<! >b
Aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc
ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ffffff gggggg
hhhhhh iiiiii.
!
check 'fixed lines are wrapped too' 'mflow <a | cmp - b'
cat <<! >a
some
wrapped.
--
signature
!
cat <<! >b
some wrapped.
--
signature
!
check 'passes usenet signature marker as is' 'mflow <a | cmp - b'
cat <<! >a
some regular text being force wrapped because the line is way too long oh no who writes so long lines.
!
cat <<! >b
some regular text being force wrapped because the line is way too long oh no
who writes so long lines.
!
check 'force wrapping' 'mflow -f <a | cmp - b'
cat <<! >a
> some regular text being force wrapped because the line is way too long oh no who writes so long lines.
!
cat <<! >b
> some regular text being force wrapped because the line is way too long oh no
> who writes so long lines.
!
check 'force wrapping of quoted text' 'mflow -f <a | cmp - b'
)

@ -1,7 +1,7 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 3
plan 2
rm -rf test.dir
mkdir test.dir
@ -21,13 +21,11 @@ body
cat <<! >seq
inbox/cur/1:2,
inbox/cur/1:2,
!
export MAILSEQ=seq
check_same 'ISO date' 'TZ=utc mscan -f "%16D" 1' 'echo "2017-03-30 13:42"'
check_same 'from name' 'mscan -f "%f" 1' 'echo "Rajwinder Kaur"'
check_test 'multiple mmsg' -eq 2 'mscan 1 1 | wc -l'
)

@ -51,7 +51,7 @@ inbox/cur/4:2,
export MAILSEQ=seq
check_same 'filename' 'msort -F :' 'cat seq'
check_same 'filename' 'msort -F' 'cat seq'
cat <<! >expect
inbox/cur/3:2,
@ -59,7 +59,7 @@ inbox/cur/1:2,
inbox/cur/2:2,
inbox/cur/4:2,
!
check_same 'date' 'msort -d :' 'cat expect'
check_same 'date' 'msort -d' 'cat expect'
cat <<! >expect
inbox/cur/4:2,
@ -67,7 +67,7 @@ inbox/cur/2:2,
inbox/cur/1:2,
inbox/cur/3:2,
!
check_same 'reverse date' 'msort -dr :' 'cat expect'
check_same 'reverse date' 'msort -dr' 'cat expect'
cat <<! >expect
inbox/cur/2:2,
@ -75,7 +75,7 @@ inbox/cur/3:2,
inbox/cur/4:2,
inbox/cur/1:2,
!
check_same 'from' 'msort -f :' 'cat expect'
check_same 'from' 'msort -f' 'cat expect'
cat <<! >expect
inbox/cur/3:2,
@ -83,6 +83,6 @@ inbox/cur/2:2,
inbox/cur/4:2,
inbox/cur/1:2,
!
check_same 'subject' 'msort -s :' 'cat expect'
check_same 'subject' 'msort -s' 'cat expect'
)

@ -1,7 +1,7 @@
#!/bin/sh -e
cd ${0%/*}
. ./lib.sh
plan 11
plan 10
rm -rf test.dir
mkdir test.dir
@ -25,13 +25,12 @@ export MAILCUR=cur MAILSEQ=seq
check 'set current' 'mseq -C 1 && mseq . | grep "inbox/cur/1:2,"'
check 'set next' 'mseq -C + && mseq . | grep "inbox/cur/2:2,"'
check 'set prev' 'mseq -C .- && mseq . | grep "inbox/cur/1:2,"'
check 'set prev' 'mseq -C - && mseq . | grep "inbox/cur/1:2,"'
check 'last' 'mseq "$" | grep "inbox/cur/10:2,"'
check_test 'whole thread' -eq 4 'mseq 6= | wc -l'
check_test 'subthread' -eq 2 'mseq 7_ | wc -l'
check 'parent' 'mseq 6^ | grep "inbox/cur/5_1:2,"'
check_test 'range' -eq 3 'mseq 1:3 | wc -l'
check_same 'multiple mmsg' 'mseq 1 2' 'printf "inbox/cur/1:2,\ninbox/cur/2:2,\n"'
cat <<! >seq
inbox/cur/1:2,

@ -20,20 +20,20 @@ ln -sf inbox/cur/1:2, cur
export MAILSEQ=seq MAILCUR=cur
check 'mark seen' 'mflag -S 1 && [ -e "inbox/cur/1:2,S" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'mark replied' 'mflag -R 1 && [ -e "inbox/cur/1:2,RS" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'unmark replied' 'mflag -r 1 && [ -e "inbox/cur/1:2,S" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'mark flagged' 'mflag -F 1 && [ -e "inbox/cur/1:2,FS" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'unmark flagged' 'mflag -f 1 && [ -e "inbox/cur/1:2,S" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'unmark seen' 'mflag -s 1 && [ -e "inbox/cur/1:2," ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'mark trashed' 'mflag -T 1 && [ -e "inbox/cur/1:2,T" ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
check 'unmark trashed' 'mflag -t 1 && [ -e "inbox/cur/1:2," ]'
check_test 'fix seq' -eq 2 'mseq -f : | mseq -S | wc -l'
check_test 'fix seq' -eq 2 'mseq -f | mseq -S | wc -l'
)

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save