This commit is contained in:
Alex Holst 2017-09-18 13:10:20 +02:00
commit 888ed08855
45 changed files with 341 additions and 255 deletions

View File

@ -1,11 +1,13 @@
CFLAGS+=-g -O2 -Wall -Wno-switch -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=2 CFLAGS=-g -O2
override CFLAGS:=-Wall -Wno-switch -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=2 $(CFLAGS)
LDLIBS=-lrt LDLIBS=-lrt
OS := $(shell uname) OS := $(shell uname)
ifeq ($(OS),OpenBSD) ifeq ($(OS),OpenBSD)
CFLAGS+=-I/usr/local/include -pthread LOCALBASE=/usr/local
LDLIBS=-L/usr/local/lib -liconv -pthread CFLAGS+=-I$(LOCALBASE)/include -pthread
LDLIBS=-L$(LOCALBASE)/lib -liconv -pthread
endif endif
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)
@ -28,7 +30,7 @@ maddr magrep mdeliver mexport mflag mflow mgenmid mhdr mpick mscan msed mshow \
maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort \ maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort \
mthread : seq.o slurp.o mthread : seq.o slurp.o
maddr magrep mflow mhdr mpick mscan mshow : rfc2047.o maddr magrep mflow mhdr mpick mscan mshow : rfc2047.o
magrep mflow mshow : rfc2045.o magrep mflow mhdr mshow : rfc2045.o
mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
mscan : pipeto.o mscan : pipeto.o
msort : mystrverscmp.o msort : mystrverscmp.o

View File

@ -59,8 +59,8 @@ blaze822_date(char *s) {
while (iswsp(*s)) while (iswsp(*s))
s++; s++;
if (i3("jan")) tm.tm_mon = 0; if (i3("jan")) tm.tm_mon = 0;
else if (i3("feb")) tm.tm_mon = 1; else if (i3("feb")) tm.tm_mon = 1;
else if (i3("mar")) tm.tm_mon = 2; else if (i3("mar")) tm.tm_mon = 2;
else if (i3("apr")) tm.tm_mon = 3; else if (i3("apr")) tm.tm_mon = 3;
@ -79,7 +79,7 @@ blaze822_date(char *s) {
while (iswsp(*s)) while (iswsp(*s))
s++; s++;
if ((c = parse_posint(&s, 1000, 9999)) > 0) { if ((c = parse_posint(&s, 1000, 9999)) > 0) {
tm.tm_year = c - 1900; tm.tm_year = c - 1900;
} else if ((c = parse_posint(&s, 0, 49)) > 0) { } else if ((c = parse_posint(&s, 0, 49)) > 0) {
@ -143,7 +143,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
if (addro) *addro = 0; if (addro) *addro = 0;
return 0; return 0;
} }
c = disp; c = disp;
e = disp + sizeof disp - 1; e = disp + sizeof disp - 1;
@ -151,7 +151,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
*addr = 0; *addr = 0;
while (*s && c < e) { while (*s && c < e) {
startover: startover:
if (*s == '<') { if (*s == '<') {
char *c = addr; char *c = addr;
char *e = addr + sizeof addr; char *e = addr + sizeof addr;
@ -188,7 +188,7 @@ blaze822_addr(char *s, char **dispo, char **addro)
} else if (*s == '(') { // XXX recurse to conform? } else if (*s == '(') { // XXX recurse to conform?
s++; s++;
if (!*addr) { // assume: user@host (name) if (!*addr) { // assume: user@host (name)
*c-- = 0; *c-- = 0;
while (c > disp && iswsp(*c)) while (c > disp && iswsp(*c))
*c-- = 0; *c-- = 0;

8
contrib/mrecode Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# mrecode - recode stdin respecting PIPE_CHARSET into UTF-8
if [ -n "$PIPE_CHARSET" ]; then
exec iconv -f "$PIPE_CHARSET" -t UTF-8
else
exec cat
fi

View File

@ -1,9 +1,9 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <poll.h> #include <poll.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -24,7 +24,7 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGPIPE); sigaddset(&mask, SIGPIPE);
sigprocmask(SIG_BLOCK, &mask, &orig_mask); sigprocmask(SIG_BLOCK, &mask, &orig_mask);
outlen = 0; outlen = 0;
output = malloc(outalloc); output = malloc(outalloc);
if (!output) if (!output)
@ -56,7 +56,7 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
} }
close(pipe0[0]); close(pipe0[0]);
close(pipe1[1]); close(pipe1[1]);
if (pid < 0) { if (pid < 0) {
close(pipe0[1]); close(pipe0[1]);
close(pipe1[0]); close(pipe1[0]);
@ -89,7 +89,7 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
} else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { } else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
fds[0].fd = -1; fds[0].fd = -1;
} }
if (fds[1].revents & POLLOUT) { if (fds[1].revents & POLLOUT) {
ssize_t ret = write(fds[1].fd, input, inlen); ssize_t ret = write(fds[1].fd, input, inlen);
if (ret > 0) { if (ret > 0) {

View File

@ -19,7 +19,7 @@ addr(char *file)
{ {
while (*file == ' ' || *file == '\t') while (*file == ' ' || *file == '\t')
file++; file++;
struct message *msg = blaze822(file); struct message *msg = blaze822(file);
if (!msg) if (!msg)
return; return;
@ -37,7 +37,7 @@ addr(char *file)
blaze822_decode_rfc2047(vdec, v, sizeof vdec - 1, "UTF-8"); blaze822_decode_rfc2047(vdec, v, sizeof vdec - 1, "UTF-8");
vdec[sizeof vdec - 1] = 0; vdec[sizeof vdec - 1] = 0;
v = vdec; v = vdec;
while ((v = blaze822_addr(v, &disp, &addr))) { while ((v = blaze822_addr(v, &disp, &addr))) {
if (disp && addr && strcmp(disp, addr) == 0) if (disp && addr && strcmp(disp, addr) == 0)
disp = 0; disp = 0;
@ -65,7 +65,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "ah:")) != -1) while ((c = getopt(argc, argv, "ah:")) != -1)
switch(c) { switch (c) {
case 'a': aflag = 1; break; case 'a': aflag = 1; break;
case 'h': hflag = optarg; break; case 'h': hflag = optarg; break;
default: default:

View File

@ -68,7 +68,7 @@ match(char *file, char *hdr, char *s)
blaze822_mime_action blaze822_mime_action
match_part(int depth, struct message *msg, char *body, size_t bodylen) match_part(int depth, struct message *msg, char *body, size_t bodylen)
{ {
(void) depth; (void)depth;
char *ct = blaze822_hdr(msg, "content-type"); char *ct = blaze822_hdr(msg, "content-type");
@ -164,7 +164,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "acdim:opqv")) != -1) while ((c = getopt(argc, argv, "acdim:opqv")) != -1)
switch(c) { switch (c) {
case 'a': aflag = 1; break; case 'a': aflag = 1; break;
case 'c': cflag = 1; break; case 'c': cflag = 1; break;
case 'd': dflag = 1; break; case 'd': dflag = 1; break;
@ -175,7 +175,7 @@ main(int argc, char *argv[])
case 'q': qflag = 1; break; case 'q': qflag = 1; break;
case 'v': vflag = 1; break; case 'v': vflag = 1; break;
default: default:
usage: usage:
fprintf(stderr, fprintf(stderr,
"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-a|-d] header:regex [msgs...]\n"); "Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-a|-d] header:regex [msgs...]\n");
exit(2); exit(2);
@ -205,7 +205,7 @@ main(int argc, char *argv[])
blaze822_loop1(":", magrep); blaze822_loop1(":", magrep);
else else
blaze822_loop(argc-optind, argv+optind, magrep); blaze822_loop(argc-optind, argv+optind, magrep);
if (cflag && !qflag && !mflag) if (cflag && !qflag && !mflag)
printf("%ld\n", matches); printf("%ld\n", matches);

View File

@ -40,9 +40,9 @@ Only search the colon-separated list of
.Ar headers .Ar headers
for mail addresses. for mail addresses.
Default: Default:
.Sq Li "from:sender:reply-to:to:cc:bcc:" .Sq Li from\&:sender\&:reply\&-to\&:to\&:cc\&:bcc\&:
and their respective and their respective
.Sq Li "resent-" .Sq Li resent\&-
variants. variants.
.El .El
.Sh EXIT STATUS .Sh EXIT STATUS

View File

@ -32,40 +32,40 @@ The following
are used by are used by
.Xr mblaze 7 : .Xr mblaze 7 :
.Bl -tag -width Ds .Bl -tag -width Ds
.It Li "Alternate-Mailboxes:" .It Li Alternate\&-Mailboxes\&:
A comma-separated list of mail addresses that belong to you, for A comma-separated list of mail addresses that belong to you, for
.Xr mscan 1 .Xr mscan 1
to recognize messages sent by or directly to you. to recognize messages sent by or directly to you.
.It Li "FQDN:" .It Li FQDN\&:
The fully qualified domain name used for The fully qualified domain name used for
.Li "Message-Id:" .Li Message\&-Id\&:
generation in generation in
.Xr mgenmid 1 . .Xr mgenmid 1 .
.It Li "Local-Mailbox:" .It Li Local\&-Mailbox\&:
Your primary mail address, used as the default value for Your primary mail address, used as the default value for
.Li "From:" .Li From\&:
in in
.Xr mcom 1 , .Xr mcom 1 ,
and in and in
.Xr mscan 1 .Xr mscan 1
to recognize messages sent to you. to recognize messages sent to you.
.It Li "Outbox:" .It Li Outbox\&:
If set, If set,
.Xr mcom 1 .Xr mcom 1
will create draft messages in this Maildir, will create draft messages in this Maildir,
and save messages there after sending. and save messages there after sending.
.It Li "Scan-Format:" .It Li Scan\&-Format\&:
The default format string for The default format string for
.Xr mscan 1 . .Xr mscan 1 .
.It Li "Sendmail:" .It Li Sendmail\&:
The program that The program that
.Xr mcom 1 .Xr mcom 1
will call to send mail. will call to send mail.
(Default: (Default:
.Sq Li sendmail ) . .Sq Li sendmail ) .
.It Li "Sendmail-Args:" .It Li Sendmail\&-Args\&:
Flags to be passed to the Flags to be passed to the
.Li "Sendmail:" .Li Sendmail\&:
program. program.
(Default: (Default:
.Sq Fl t ) . .Sq Fl t ) .

View File

@ -37,11 +37,11 @@ and deliver each message,
decoding it according to the MBOXRD convention. decoding it according to the MBOXRD convention.
.Nm .Nm
will set the mtime according to the value of will set the mtime according to the value of
.Sq Li "Date:" .Sq Li Date\&:
and the Maildir flags according to the value of and the Maildir flags according to the value of
.Sq Li "Status:" .Sq Li Status\&:
or or
.Sq Li "X-Status:" . .Sq Li X-Status\&: .
.Pp .Pp
The messages are delivered in a reliable way and use default The messages are delivered in a reliable way and use default
.Xr umask 2 . .Xr umask 2 .

View File

@ -25,11 +25,11 @@ or uses the mails in the current sequence if used interactively.
.Pp .Pp
.Nm .Nm
uses the uses the
.Sq Li "Return-Path:" .Sq Li Return\&-Path\&:
(or (or
.Sq Li "X-Envelope-To:" ) .Sq Li X\&-Envelope\&-To\&: )
and and
.Sq Li "Date:" .Sq Li Date\&:
headers from the message for the mbox headers from the message for the mbox
.Sq Li "From " .Sq Li "From "
line. line.
@ -38,9 +38,9 @@ The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl S .It Fl S
Add Add
.Sq Li "Status:" .Sq Li Status\&:
and and
.Sq Li "X-Status:" .Sq Li X\&-Status\&:
headers according to the headers according to the
.Ar msgs .Ar msgs
Maildir flags. Maildir flags.

View File

@ -1,4 +1,4 @@
.Dd July 26, 2017 .Dd September 6, 2017
.Dt MFLOW 1 .Dt MFLOW 1
.Os .Os
.Sh NAME .Sh NAME
@ -6,6 +6,9 @@
.Nd reflow format=flowed plain text mails .Nd reflow format=flowed plain text mails
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl f
.Op Fl q
.Op Fl w Ar width
\&< \&<
.Ar file .Ar file
.Sh DESCRIPTION .Sh DESCRIPTION
@ -31,6 +34,19 @@ If defined,
the environment variable the environment variable
.Ev MAXCOLUMNS .Ev MAXCOLUMNS
specifies the maximum line length. specifies the maximum line length.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl f
Force line wrapping of long lines.
.It Fl q
Prefix lines with
.Sq Li \&< .
Can be used multiple times.
.It Fl w Ar width
Set maximum line length to
.Ar width .
.El
.Sh EXIT STATUS .Sh EXIT STATUS
.Ex -std .Ex -std
.Sh SEE ALSO .Sh SEE ALSO

View File

@ -17,7 +17,7 @@ The fully qualified domain name is computed by:
.Bl -enum .Bl -enum
.It .It
Using Using
.Sq Li "FQDN:" .Sq Li FQDN\&:
from from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile" .Pa "${MBLAZE:-$HOME/.mblaze}/profile"
(if set). (if set).
@ -25,7 +25,7 @@ from
Resolving the current hostname. Resolving the current hostname.
.It .It
Using the host part of the address in Using the host part of the address in
.Sq Li "Local-Mailbox:" .Sq Li Local\&-Mailbox\&:
from from
.Pa "${MBLAZE:-$HOME/.mblaze}/profile" .Pa "${MBLAZE:-$HOME/.mblaze}/profile"
(if set). (if set).

View File

@ -6,7 +6,7 @@
.Nd show mail headers .Nd show mail headers
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl h Ar header .Op Fl h Ar header Op Fl p Ar parameter
.Op Fl d .Op Fl d
.Op Fl H .Op Fl H
.Op Fl M .Op Fl M
@ -31,6 +31,10 @@ The options are as follows:
.It Fl h Ar header .It Fl h Ar header
Only print the values of the headers in the colon-separated list Only print the values of the headers in the colon-separated list
.Ar header . .Ar header .
.It Fl p Ar parameter
Extract a particular RFC 2045
.Ar parameter
from the specified headers.
.It Fl d .It Fl d
Decode the headers according to RFC 2047. Decode the headers according to RFC 2047.
.It Fl H .It Fl H
@ -55,6 +59,13 @@ and >1 if an error occurs.
.Rs .Rs
.%A N. Freed .%A N. Freed
.%A N. Borenstein .%A N. Borenstein
.%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
.%B MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text .%B MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text
.%R RFC 2047 .%R RFC 2047
.%D November 1996 .%D November 1996

View File

@ -72,8 +72,9 @@ Don't list messages in
Don't list messages in Don't list messages in
.Pa new . .Pa new .
.It Fl i .It Fl i
Don't print filenames. Instead, print a one-line summary for each Don't print filenames.
folder, showing the number of unseen, flagged and total messages, Instead, print a one-line summary for each folder,
showing the number of unseen, flagged and total messages,
along with the folder name. along with the folder name.
.Pp .Pp
If two or more folders are specified, a total will also be printed. If two or more folders are specified, a total will also be printed.

View File

@ -49,6 +49,8 @@ Defaults to
.Sh EXIT STATUS .Sh EXIT STATUS
.Ex -std .Ex -std
.Sh SEE ALSO .Sh SEE ALSO
.Xr makemime 1 ,
.Xr mhbuild 1
.Rs .Rs
.%A N. Freed .%A N. Freed
.%A N. Borenstein .%A N. Borenstein

View File

@ -74,7 +74,7 @@ Deleted messages.
New messages. New messages.
.It Cm o .It Cm o
Old messages. Old messages.
.It Cm r, Cm S .It Cm r , Cm S
Read messages. Read messages.
.It Cm u .It Cm u
Unread messages. Unread messages.

View File

@ -94,9 +94,9 @@ is greater or equal to 19,
seconds will also be shown. seconds will also be shown.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "f" .It Cm "%" Ns Oo Ar wd Oc Ns Cm "f"
The The
.Sq Li From: .Sq Li From\&:
(or (or
.Sq Li To: , .Sq Li To\&: ,
if the message is from us). if the message is from us).
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "F" .It Cm "%" Ns Oo Ar wd Oc Ns Cm "F"
The Maildir folder the message resides in. The Maildir folder the message resides in.
@ -106,7 +106,7 @@ The Maildir folder the message resides in.
spaces per indentation depth in the thread tree. spaces per indentation depth in the thread tree.
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "I" .It Cm "%" Ns Oo Ar wd Oc Ns Cm "I"
The The
.Sq Li "Message-ID:" .Sq Li Message\&-ID\&:
of the message. of the message.
.It Cm "%M" .It Cm "%M"
The raw Maildir flags of the message. The raw Maildir flags of the message.
@ -125,22 +125,22 @@ The subject of the message (defaults to remaining width).
.It Cm "%" Ns Oo Ar wd Oc Ns Cm "S" .It Cm "%" Ns Oo Ar wd Oc Ns Cm "S"
The subject of the message (defaults to remaining width), The subject of the message (defaults to remaining width),
with leading with leading
.Sq Li "Re:" , .Sq Li Re\&: ,
.Sq Li "Fwd:" .Sq Li Fwd\&:
etc. stripped. etc. stripped.
.It Cm "%t" .It Cm "%t"
A A
.Sq Li \&> .Sq Li \&>
if you are in if you are in
.Sq Li "To:" , .Sq Li To\&: ,
a a
.Sq Li \&+ .Sq Li \&+
if you are in if you are in
.Sq Li "Cc:" , .Sq Li Cc\&: ,
a a
.Sq Li \&: .Sq Li \&:
if you are in if you are in
.Sq Li "Resent-To:" , .Sq Li Resent\&-To\&: ,
or a blank. or a blank.
.It Cm "%u" .It Cm "%u"
An An
@ -169,13 +169,13 @@ A replied-to message
.Bl -tag -width 2n -compact .Bl -tag -width 2n -compact
.It Li \&> .It Li \&>
You are in You are in
.Sq Li "To:" . .Sq Li To\&: .
.It Li \&+ .It Li \&+
You are in You are in
.Sq Li "Cc:" . .Sq Li Cc\:& .
.It Li \&: .It Li \&:
You are in You are in
.Sq Li "Resent-To:" . .Sq Li Resent\&-To\&: .
.El .El
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Bl -tag -width MBLAZE_PAGER .Bl -tag -width MBLAZE_PAGER

View File

@ -71,10 +71,10 @@ will delete all headers starting with
and and
.Sq Li "/from:to:cc/d" .Sq Li "/from:to:cc/d"
will delete the headers will delete the headers
.Sq Li "From:" , .Sq Li From\&: ,
.Sq Li "To:" , .Sq Li To\&: ,
and and
.Sq Li "Cc:" . .Sq Li Cc\&: .
.It Oo Cm \&/ Ns Ar headers Ns Cm \&/ Oc Ns Ic s Ns Cm \&/ Ns Ar regex Ns Cm \&/ Ns Ar replacement Ns Cm \&/ Ns Op Ar flags .It Oo Cm \&/ Ns Ar headers Ns Cm \&/ Oc Ns Ic s Ns Cm \&/ Ns Ar regex Ns Cm \&/ Ns Ar replacement Ns Cm \&/ Ns Op Ar flags
Substitute matches of the POSIX Basic Regular Expression Substitute matches of the POSIX Basic Regular Expression
.Ar regex .Ar regex

View File

@ -39,7 +39,7 @@ The options are as follows:
Display the headers in the colon-separated list Display the headers in the colon-separated list
.Ar headers , .Ar headers ,
instead of the default headers instead of the default headers
.Sq Li from:subject:to:cc:date:reply-to: . .Sq Li from\&:subject\&:to\&:cc\&:date\&:reply\&-to\&: .
.It Fl A Ar mimetypes .It Fl A Ar mimetypes
Define Define
.Sq Li "mixed/alternative" .Sq Li "mixed/alternative"

View File

@ -28,14 +28,14 @@ The options are as follows:
Reverse order. Reverse order.
.It Fl f .It Fl f
Sort by Sort by
.Sq Li From: . .Sq Li From\&: .
.It Fl d .It Fl d
Sort by date. Sort by date.
.It Fl s .It Fl s
Sort by Sort by
.Sq Li Subject\&: .Sq Li Subject\&:
(modulo various variants of (modulo various variants of
.Sq Li Re: ) . .Sq Li Re\&: ) .
.It Fl F .It Fl F
Sort by filename, using proper order for numbers in filenames. Sort by filename, using proper order for numbers in filenames.
.It Fl M .It Fl M

View File

@ -82,9 +82,9 @@ tryagain:
snprintf(id, sizeof id, "%ld.M%06ldP%ldQ%ld.%s", snprintf(id, sizeof id, "%ld.M%06ldP%ldQ%ld.%s",
(long)tv.tv_sec, (long)tv.tv_usec, (long)getpid(), (long)tv.tv_sec, (long)tv.tv_usec, (long)getpid(),
delivery, host); delivery, host);
snprintf(tmp, sizeof tmp, "%s/tmp/%s", targetdir, id); snprintf(tmp, sizeof tmp, "%s/tmp/%s", targetdir, id);
outfd = open(tmp, O_CREAT | O_WRONLY | O_EXCL, 0666); outfd = open(tmp, O_CREAT | O_WRONLY | O_EXCL, 0666);
if (outfd < 0) { if (outfd < 0) {
if (errno == EEXIST) if (errno == EEXIST)
@ -152,14 +152,14 @@ tryagain:
int i, j; int i, j;
for (i = sizeof statusflags - 1; i >= 0; i--) for (i = sizeof statusflags - 1; i >= 0; i--)
if (!statusflags[i]) if (!statusflags[i])
for (j = i+1; j < (int) sizeof statusflags; j++) for (j = i+1; j < (int)sizeof statusflags; j++)
statusflags[j-1] = statusflags[j]; statusflags[j-1] = statusflags[j];
if (Mflag) { if (Mflag) {
struct message *msg = blaze822_file(tmp); struct message *msg = blaze822_file(tmp);
time_t date = -1; time_t date = -1;
char *v; char *v;
if (msg && (v = blaze822_hdr(msg, "date"))) { if (msg && (v = blaze822_hdr(msg, "date"))) {
date = blaze822_date(v); date = blaze822_date(v);
if (date != -1) { if (date != -1) {
@ -173,8 +173,8 @@ tryagain:
} }
snprintf(dst, sizeof dst, "%s/%s/%s:2,%s", snprintf(dst, sizeof dst, "%s/%s/%s:2,%s",
targetdir, (cflag || is_old) ? "cur" : "new", id, targetdir, (cflag || is_old) ? "cur" : "new", id,
Xflag ? Xflag : statusflags); Xflag ? Xflag : statusflags);
if (rename(tmp, dst) != 0) if (rename(tmp, dst) != 0)
return -1; return -1;
@ -189,7 +189,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "cMvX:")) != -1) while ((c = getopt(argc, argv, "cMvX:")) != -1)
switch(c) { switch (c) {
case 'c': cflag = 1; break; case 'c': cflag = 1; break;
case 'M': Mflag = 1; break; case 'M': Mflag = 1; break;
case 'v': vflag = 1; break; case 'v': vflag = 1; break;

View File

@ -57,10 +57,10 @@ mdirs(char *fpath)
if (dotonly && d->d_name[0] != '.') if (dotonly && d->d_name[0] != '.')
continue; continue;
mdirs(d->d_name); mdirs(d->d_name);
} }
if (chdir("..") < 0) if (chdir("..") < 0)
exit(-1); exit(-1);
@ -72,9 +72,9 @@ main(int argc, char *argv[])
{ {
int c, i; int c, i;
while ((c = getopt(argc, argv, "")) != -1) while ((c = getopt(argc, argv, "")) != -1)
switch(c) { switch (c) {
default: default:
usage: usage:
fprintf(stderr, "Usage: mdirs dirs...\n"); fprintf(stderr, "Usage: mdirs dirs...\n");
exit(1); exit(1);
} }

View File

@ -51,7 +51,7 @@ export(char *file)
if (e) { if (e) {
s++; s++;
snprintf(from, sizeof from, "%.*s", snprintf(from, sizeof from, "%.*s",
(int)(e-s), s); (int)(e-s), s);
} }
} else { // return-path without <> } else { // return-path without <>
snprintf(from, sizeof from, "%s", v); snprintf(from, sizeof from, "%s", v);
@ -66,7 +66,7 @@ export(char *file)
char *line = 0; char *line = 0;
size_t linelen = 0; size_t linelen = 0;
printf("From %s %s", from, ctime(&date)); printf("From %s %s", from, ctime(&date));
int in_header = 1; int in_header = 1;
@ -83,7 +83,7 @@ export(char *file)
status = 1; status = 1;
return; return;
} }
if (in_header && line[0] == '\n' && !line[1]) { if (in_header && line[0] == '\n' && !line[1]) {
if (Sflag) { if (Sflag) {
char *flags = strstr(file, ":2,"); char *flags = strstr(file, ":2,");
@ -94,21 +94,21 @@ export(char *file)
if (strchr(flags, 'S')) if (strchr(flags, 'S'))
putchar('R'); putchar('R');
char *ee = strrchr(file, '/'); char *ee = strrchr(file, '/');
if (!ee || if (!ee ||
!(ee >= file + 3 && ee[-3] == 'n' && ee[-2] == 'e' && ee[-1] == 'w')) !(ee >= file + 3 && ee[-3] == 'n' && ee[-2] == 'e' && ee[-1] == 'w'))
putchar('O'); putchar('O');
putchar('\n'); putchar('\n');
fputs("X-Status: ", stdout); fputs("X-Status: ", stdout);
if (strchr(flags, 'R')) putchar('A'); if (strchr(flags, 'R')) putchar('A');
if (strchr(flags, 'T')) putchar('D'); if (strchr(flags, 'T')) putchar('D');
if (strchr(flags, 'F')) putchar('F'); if (strchr(flags, 'F')) putchar('F');
putchar('\n'); putchar('\n');
} }
in_header = 0; in_header = 0;
} }
// MBOXRD: add first > to >>..>>From // MBOXRD: add first > to >>..>>From
char *s = line; char *s = line;
while (*s == '>') while (*s == '>')
@ -132,7 +132,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "S")) != -1) while ((c = getopt(argc, argv, "S")) != -1)
switch(c) { switch (c) {
case 'S': Sflag = 1; break; case 'S': Sflag = 1; break;
default: default:
fprintf(stderr, "Usage: mexport [-S] [msgs...]\n"); fprintf(stderr, "Usage: mexport [-S] [msgs...]\n");
@ -148,6 +148,6 @@ main(int argc, char *argv[])
blaze822_loop1(":", export); blaze822_loop1(":", export);
else else
blaze822_loop(argc-optind, argv+optind, export); blaze822_loop(argc-optind, argv+optind, export);
return status; return status;
} }

11
mflag.c
View File

@ -99,7 +99,7 @@ doit:
return; return;
} }
skip: skip:
if (vflag) if (vflag)
printf("%s\n", file); printf("%s\n", file);
@ -110,7 +110,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "PRSTDFprstdfX:x:v")) != -1) while ((c = getopt(argc, argv, "PRSTDFprstdfX:x:v")) != -1)
switch(c) { switch (c) {
case 'P': case 'R': case 'S': case 'T': case 'D': case 'F': case 'P': case 'R': case 'S': case 'T': case 'D': case 'F':
flags[(unsigned int)c] = 1; flags[(unsigned int)c] = 1;
break; break;
@ -142,6 +142,11 @@ main(int argc, char *argv[])
curfile = blaze822_seq_cur(); curfile = blaze822_seq_cur();
if (vflag) { if (vflag) {
if (argc == optind && !isatty(0)) {
blaze822_loop(0, 0, flag); // read from stdin
return 0;
}
args = calloc(sizeof (char *), argsalloc); args = calloc(sizeof (char *), argsalloc);
if (!args) if (!args)
exit(-1); exit(-1);
@ -155,7 +160,7 @@ main(int argc, char *argv[])
blaze822_loop1(":", flag); blaze822_loop1(":", flag);
else else
blaze822_loop(0, 0, flag); blaze822_loop(0, 0, flag);
return 0; return 0;
} }

50
mflow.c
View File

@ -32,7 +32,7 @@ fixed(int quotes, char *line, size_t linelen)
{ {
chgquote(quotes); chgquote(quotes);
if (linelen > (size_t)(maxcolumn - column)) { if (column && linelen > (size_t)(maxcolumn - column)) {
putchar('\n'); putchar('\n');
column = 0; column = 0;
} }
@ -75,7 +75,8 @@ flowed(int quotes, char *line, ssize_t linelen)
done = 1; done = 1;
} }
if (column + (eow - line) > maxcolumn) { if (column + (eow - line) > maxcolumn &&
eow - line < maxcolumn) {
putchar('\n'); putchar('\n');
column = 0; column = 0;
if (*line == ' ') { if (*line == ' ') {
@ -92,23 +93,26 @@ flowed(int quotes, char *line, ssize_t linelen)
} }
int int
main() main(int argc, char *argv[])
{ {
char *linebuf = 0; char *linebuf = 0;
char *line; char *line;
size_t linelen = 0; size_t linelen = 0;
int quotes = 0; int outer_quotes = 0;
int quotes;
int reflow = 1; // re-evaluated on $PIPE_CONTENTTYPE int reflow = 1; // re-evaluated on $PIPE_CONTENTTYPE
int force = 0;
int delsp = 0; int delsp = 0;
char *ct = getenv("PIPE_CONTENTTYPE"); char *ct = getenv("PIPE_CONTENTTYPE");
if (ct) { if (ct) {
char *s, *se; char *s, *se;
blaze822_mime_parameter(ct, "format", &s, &se); reflow = 0;
reflow = s && (strncasecmp(s, "flowed", 6) == 0); if (blaze822_mime_parameter(ct, "format", &s, &se) && s)
blaze822_mime_parameter(ct, "delsp", &s, &se); reflow = (strncasecmp(s, "flowed", 6) == 0);
delsp = s && (strncasecmp(s, "yes", 3) == 0); if (blaze822_mime_parameter(ct, "delsp", &s, &se) && s)
delsp = (strncasecmp(s, "yes", 3) == 0);
} }
char *cols = getenv("COLUMNS"); char *cols = getenv("COLUMNS");
@ -131,6 +135,17 @@ main()
maxcolumn = m; maxcolumn = m;
} }
int c;
while ((c = getopt(argc, argv, "fqw:")) != -1)
switch (c) {
case 'f': force = 1; break;
case 'q': outer_quotes++; break;
case 'w': maxcolumn = atoi(optarg); break;
default:
fprintf(stderr, "Usage: mflow [-f] [-q] [-w MAXCOLUMNS]\n");
exit(2);
}
while (1) { while (1) {
errno = 0; errno = 0;
ssize_t rd = getdelim(&linebuf, &linelen, '\n', stdin); ssize_t rd = getdelim(&linebuf, &linelen, '\n', stdin);
@ -144,24 +159,24 @@ main()
line = linebuf; line = linebuf;
if (!reflow) { if (!reflow && !force) {
fwrite(line, 1, rd, stdout); fwrite(line, 1, rd, stdout);
continue; continue;
} }
if (rd > 0 && line[rd-1] == '\n') if (rd > 0 && line[rd-1] == '\n')
line[--rd] = 0; line[--rd] = 0;
if (rd > 0 && line[rd-1] == '\r') if (rd > 0 && line[rd-1] == '\r')
line[--rd] = 0; line[--rd] = 0;
quotes = 0; quotes = outer_quotes;
while (*line == '>') { // measure quote depth while (*line == '>') { // measure quote depth
line++; line++;
quotes++; quotes++;
rd--; rd--;
} }
if (*line == ' ') { // space stuffing if (reflow && *line == ' ') { // space stuffing
line++; line++;
rd--; rd--;
} }
@ -178,7 +193,12 @@ main()
line[--rd] = 0; line[--rd] = 0;
flowed(quotes, line, rd); flowed(quotes, line, rd);
} else { } else {
fixed(quotes, line, rd); if (force && rd > maxcolumn) {
flowed(quotes, line, rd);
fixed(quotes, "", 0);
} else {
fixed(quotes, line, rd);
}
} }
} }

View File

@ -21,9 +21,10 @@ printb36(uint64_t x)
char outbuf[16]; char outbuf[16];
char *o = outbuf + sizeof outbuf; char *o = outbuf + sizeof outbuf;
*o = 0;
*--o = 0;
do { *--o = base36[x % 36]; } while (x /= 36); do { *--o = base36[x % 36]; } while (x /= 36);
fputs(o, stdout); fputs(o, stdout);
} }
@ -46,8 +47,8 @@ int main()
hostbuf[sizeof hostbuf - 1] = 0; hostbuf[sizeof hostbuf - 1] = 0;
struct addrinfo hints = { .ai_family = AF_UNSPEC, struct addrinfo hints = { .ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM, .ai_socktype = SOCK_STREAM,
.ai_flags = AI_CANONNAME }; .ai_flags = AI_CANONNAME };
struct addrinfo *info; struct addrinfo *info;
if (getaddrinfo(hostbuf, 0, &hints, &info) == 0) { if (getaddrinfo(hostbuf, 0, &hints, &info) == 0) {
// sanity checks: no (null), at least one dot, // sanity checks: no (null), at least one dot,
@ -83,7 +84,7 @@ int main()
" or add a FQDN to /etc/hosts.\n"); " or add a FQDN to /etc/hosts.\n");
exit(1); exit(1);
} }
struct timeval tp; struct timeval tp;
gettimeofday(&tp, (struct timezone *)0); gettimeofday(&tp, (struct timezone *)0);

22
mhdr.c
View File

@ -13,6 +13,7 @@
#include "blaze822.h" #include "blaze822.h"
static char *hflag; static char *hflag;
static char *pflag;
static int Aflag; static int Aflag;
static int Dflag; static int Dflag;
static int Hflag; static int Hflag;
@ -75,7 +76,7 @@ print_addresses(char *s)
printf("%s\t", curfile); printf("%s\t", curfile);
if (disp && addr) if (disp && addr)
printf("%s <%s>\n", disp, addr); printf("%s <%s>\n", disp, addr);
else if (addr) else if (addr)
printf("%s\n", addr); printf("%s\n", addr);
} }
@ -101,6 +102,16 @@ print_decode_header(char *s)
void void
print_header(char *v) print_header(char *v)
{ {
if (pflag) {
char *s, *se;
if (blaze822_mime_parameter(v, pflag, &s, &se)) {
*se = 0;
v = s;
} else {
return;
}
}
status = 0; status = 0;
if (Hflag && !Aflag) if (Hflag && !Aflag)
@ -189,9 +200,10 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "h:ADHMd")) != -1) while ((c = getopt(argc, argv, "h:p:ADHMd")) != -1)
switch(c) { switch (c) {
case 'h': hflag = optarg; break; case 'h': hflag = optarg; break;
case 'p': pflag = optarg; break;
case 'A': Aflag = 1; break; case 'A': Aflag = 1; break;
case 'D': Dflag = 1; break; case 'D': Dflag = 1; break;
case 'H': Hflag = 1; break; case 'H': Hflag = 1; break;
@ -199,7 +211,7 @@ main(int argc, char *argv[])
case 'd': dflag = 1; break; case 'd': dflag = 1; break;
default: default:
fprintf(stderr, fprintf(stderr,
"Usage: mhdr [-h header] [-d] [-H] [-M] [-A|-D] [msgs...]\n"); "Usage: mhdr [-h header [-p parameter]] [-d] [-H] [-M] [-A|-D] [msgs...]\n");
exit(2); exit(2);
} }
@ -212,6 +224,6 @@ main(int argc, char *argv[])
blaze822_loop1(".", header); blaze822_loop1(".", header);
else else
blaze822_loop(argc-optind, argv+optind, header); blaze822_loop(argc-optind, argv+optind, header);
return status; return status;
} }

4
minc.c
View File

@ -66,10 +66,10 @@ main(int argc, char *argv[])
{ {
int c, i; int c, i;
while ((c = getopt(argc, argv, "q")) != -1) while ((c = getopt(argc, argv, "q")) != -1)
switch(c) { switch (c) {
case 'q': qflag = 1; break; case 'q': qflag = 1; break;
default: default:
usage: usage:
fprintf(stderr, "Usage: minc [-q] dirs...\n"); fprintf(stderr, "Usage: minc [-q] dirs...\n");
exit(1); exit(1);
} }

18
mlist.c
View File

@ -99,11 +99,11 @@ list(char *prefix, char *file)
#include <sys/syscall.h> #include <sys/syscall.h>
struct linux_dirent64 { struct linux_dirent64 {
ino64_t d_ino; /* 64-bit inode number */ ino64_t d_ino; /* 64-bit inode number */
off64_t d_off; /* 64-bit offset to next structure */ off64_t d_off; /* 64-bit offset to next structure */
unsigned short d_reclen; /* Size of this dirent */ unsigned short d_reclen; /* Size of this dirent */
unsigned char d_type; /* File type */ unsigned char d_type; /* File type */
char d_name[]; /* Filename (null-terminated) */ char d_name[]; /* Filename (null-terminated) */
}; };
#define BUF_SIZE 1024000 #define BUF_SIZE 1024000
@ -120,18 +120,18 @@ listdir(char *dir)
perror("open"); perror("open");
return; return;
} }
while (1) { while (1) {
nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE); nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
if (nread == -1) { if (nread == -1) {
perror("getdents64"); perror("getdents64");
break; break;
} }
if (nread == 0) if (nread == 0)
break; break;
for (bpos = 0; bpos < nread;) { for (bpos = 0; bpos < nread; ) {
d = (struct linux_dirent64 *)(buf + bpos); d = (struct linux_dirent64 *)(buf + bpos);
if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN) if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
goto next; goto next;
@ -225,7 +225,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "PRSTDFprstdfX:x:NnCci")) != -1) while ((c = getopt(argc, argv, "PRSTDFprstdfX:x:NnCci")) != -1)
switch(c) { switch (c) {
case 'P': case 'R': case 'S': case 'T': case 'D': case 'F': case 'P': case 'R': case 'S': case 'T': case 'D': case 'F':
flags[(unsigned int)c] = 1; flags[(unsigned int)c] = 1;
break; break;
@ -246,7 +246,7 @@ main(int argc, char *argv[])
case 'c': Cflag = -1; break; case 'c': Cflag = -1; break;
case 'i': iflag = 1; break; case 'i': iflag = 1; break;
default: default:
usage: usage:
fprintf(stderr, fprintf(stderr,
"Usage: mlist [-DFPRST] [-X str]\n" "Usage: mlist [-DFPRST] [-X str]\n"
" [-dfprst] [-x str]\n" " [-dfprst] [-x str]\n"

16
mmime.c
View File

@ -135,7 +135,7 @@ gen_attachment(const char *filename, char *content_disposition)
return; return;
} }
for (s = (char *) filename; *s; s++) { for (s = (char *)filename; *s; s++) {
if (*s < 32 || *s == '"' || *s >= 127 || s - filename > 35) if (*s < 32 || *s == '"' || *s >= 127 || s - filename > 35)
goto rfc2231; goto rfc2231;
if (strchr(" ()<>@,;:\\/[]?=", *s)) if (strchr(" ()<>@,;:\\/[]?=", *s))
@ -162,9 +162,9 @@ rfc2231:
} }
while (*s && i < 78 - 3) { while (*s && i < 78 - 3) {
if (*s <= 32 || *s == '"' || *s > 126) if (*s <= 32 || *s == '"' || *s > 126)
i += printf("%%%02x", (uint8_t) *s++); i += printf("%%%02x", (uint8_t)*s++);
else else
i += printf("%c", (uint8_t) *s++); i += printf("%c", (uint8_t)*s++);
} }
} }
@ -197,7 +197,7 @@ gen_file(char *file, char *ct)
file, strerror(r)); file, strerror(r));
return -1; return -1;
} }
if (strcmp(ct, "mblaze/raw") == 0) if (strcmp(ct, "mblaze/raw") == 0)
goto raw; goto raw;
@ -292,7 +292,7 @@ print_header(char *line) {
while (*e && *e == ' ') while (*e && *e == ' ')
e++; e++;
for (; *e && *e != ' '; e++) { for (; *e && *e != ' '; e++) {
if ((uint8_t) *e >= 127) if ((uint8_t)*e >= 127)
highbit++; highbit++;
} }
@ -399,7 +399,7 @@ gen_build()
printf("Content-Type: text/plain; charset=UTF-8\n"); printf("Content-Type: text/plain; charset=UTF-8\n");
printf("Content-Disposition: inline\n"); printf("Content-Disposition: inline\n");
printf("Content-Transfer-Encoding: quoted-printable\n\n"); printf("Content-Transfer-Encoding: quoted-printable\n\n");
intext = 1; intext = 1;
} }
@ -471,12 +471,12 @@ main(int argc, char *argv[])
int c; int c;
while ((c = getopt(argc, argv, "crt:")) != -1) while ((c = getopt(argc, argv, "crt:")) != -1)
switch(c) { switch (c) {
case 'r': rflag = 1; break; case 'r': rflag = 1; break;
case 'c': cflag = 1; break; case 'c': cflag = 1; break;
case 't': tflag = optarg; break; case 't': tflag = optarg; break;
default: default:
usage: usage:
fprintf(stderr, fprintf(stderr,
"Usage: mmime [-c|-r] [-t CONTENT-TYPE] < message\n"); "Usage: mmime [-c|-r] [-t CONTENT-TYPE] < message\n");
exit(1); exit(1);

26
mpick.c
View File

@ -29,17 +29,17 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h>
#include <locale.h>
#include <regex.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <locale.h>
#include <limits.h>
#include <regex.h>
#include "blaze822.h" #include "blaze822.h"
@ -163,7 +163,7 @@ static int prune;
static void static void
ws() ws()
{ {
while (isspace((unsigned char) *pos)) while (isspace((unsigned char)*pos))
pos++; pos++;
} }
@ -306,7 +306,7 @@ parse_string(char **s)
char t; char t;
char *e = ++pos; char *e = ++pos;
while (isalnum((unsigned char) *pos) || *pos == '_') while (isalnum((unsigned char)*pos) || *pos == '_')
pos++; pos++;
if (e == pos) if (e == pos)
parse_error("invalid environment variable name"); parse_error("invalid environment variable name");
@ -407,12 +407,12 @@ static int64_t
parse_num(int64_t *r) parse_num(int64_t *r)
{ {
char *s = pos; char *s = pos;
if (isdigit((unsigned char) *pos)) { if (isdigit((unsigned char)*pos)) {
int64_t n; int64_t n;
for (n = 0; isdigit((unsigned char) *pos) && n <= INT64_MAX / 10 - 10; pos++) for (n = 0; isdigit((unsigned char)*pos) && n <= INT64_MAX / 10 - 10; pos++)
n = 10 * n + (*pos - '0'); n = 10 * n + (*pos - '0');
if (isdigit((unsigned char) *pos)) if (isdigit((unsigned char)*pos))
parse_error("number too big: %s", s); parse_error("number too big: %s", s);
if (token("c")) ; if (token("c")) ;
else if (token("b")) n *= 512LL; else if (token("b")) n *= 512LL;
@ -499,7 +499,7 @@ parse_cmp()
e->a.prop = prop; e->a.prop = prop;
e->b.num = n; e->b.num = n;
return e; return e;
} else if(token("cur")) { } else if (token("cur")) {
struct expr *e = mkexpr(op); struct expr *e = mkexpr(op);
e->a.prop = prop; e->a.prop = prop;
e->b.var = VAR_CUR; e->b.var = VAR_CUR;
@ -905,7 +905,7 @@ eval(struct expr *e, struct mailinfo *m)
case EXPR_REGEX: case EXPR_REGEX:
case EXPR_REGEXI: { case EXPR_REGEXI: {
const char *s = ""; const char *s = "";
switch(e->a.prop) { switch (e->a.prop) {
case PROP_PATH: s = m->fpath; break; case PROP_PATH: s = m->fpath; break;
case PROP_FROM: s = msg_addr(m, "from", e->extra); break; case PROP_FROM: s = msg_addr(m, "from", e->extra); break;
case PROP_TO: s = msg_addr(m, "to", e->extra); break; case PROP_TO: s = msg_addr(m, "to", e->extra); break;
@ -951,7 +951,7 @@ mailfile(char *file)
m->sb = 0; m->sb = 0;
m->msg = 0; m->msg = 0;
while (*m->fpath == ' ' || *m->fpath== '\t') { while (*m->fpath == ' ' || *m->fpath == '\t') {
m->depth++; m->depth++;
m->fpath++; m->fpath++;
} }
@ -1079,7 +1079,7 @@ collect(char *file)
} else if (thr->cur->m->depth > m->depth) { } else if (thr->cur->m->depth > m->depth) {
/* find parent mail */ /* find parent mail */
struct mlist *pl; struct mlist *pl;
for (pl = thr->cur; pl->m->depth >= m->depth; pl--); for (pl = thr->cur; pl->m->depth >= m->depth; pl--) ;
ml->parent = pl; ml->parent = pl;
} }

2
mquote
View File

@ -7,6 +7,6 @@
printf '%s wrote:\n' "$from" printf '%s wrote:\n' "$from"
mshow -R "$1" | mshow -R "$1" |
sed -n '/^-- $/!p;//q' | # strip signature sed -n '/^-- $/,$!p' | # strip signature
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | # strip empty lines sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | # strip empty lines
sed 's/^/> /' # prefix with > sed 's/^/> /' # prefix with >

12
mscan.c
View File

@ -9,6 +9,7 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -16,7 +17,6 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <locale.h>
#include "blaze822.h" #include "blaze822.h"
@ -281,7 +281,7 @@ oneline(char *file)
indent++; indent++;
file++; file++;
} }
struct message *msg = blaze822(file); struct message *msg = blaze822(file);
char *flags = msg ? strstr(file, ":2,") : 0; char *flags = msg ? strstr(file, ":2,") : 0;
if (!flags) if (!flags)
@ -493,7 +493,7 @@ main(int argc, char *argv[])
int c; int c;
while ((c = getopt(argc, argv, "If:n")) != -1) while ((c = getopt(argc, argv, "If:n")) != -1)
switch(c) { switch (c) {
case 'I': Iflag++; break; case 'I': Iflag++; break;
case 'f': fflag = optarg; break; case 'f': fflag = optarg; break;
case 'n': nflag = 1; break; case 'n': nflag = 1; break;
@ -517,7 +517,7 @@ main(int argc, char *argv[])
struct tm *tm = localtime(&now); struct tm *tm = localtime(&now);
curyear = tm->tm_year; curyear = tm->tm_year;
setlocale(LC_ALL, ""); // for wcwidth later setlocale(LC_ALL, ""); // for wcwidth later
if (wcwidth(0xfffd) > 0) if (wcwidth(0xfffd) > 0)
replacement = 0xfffd; replacement = 0xfffd;
@ -549,12 +549,12 @@ main(int argc, char *argv[])
char *v, *d, *a; char *v, *d, *a;
if ((v = blaze822_hdr(config, "local-mailbox"))) if ((v = blaze822_hdr(config, "local-mailbox")))
while (alias_idx < (int)(sizeof aliases / sizeof aliases[0]) && while (alias_idx < (int)(sizeof aliases / sizeof aliases[0]) &&
(v = blaze822_addr(v, &d, &a))) (v = blaze822_addr(v, &d, &a)))
if (a) if (a)
aliases[alias_idx++] = strdup(a); aliases[alias_idx++] = strdup(a);
if ((v = blaze822_hdr(config, "alternate-mailboxes"))) if ((v = blaze822_hdr(config, "alternate-mailboxes")))
while (alias_idx < (int)(sizeof aliases / sizeof aliases[0]) && while (alias_idx < (int)(sizeof aliases / sizeof aliases[0]) &&
(v = blaze822_addr(v, &d, &a))) (v = blaze822_addr(v, &d, &a)))
if (a) if (a)
aliases[alias_idx++] = strdup(a); aliases[alias_idx++] = strdup(a);
if ((v = blaze822_hdr(config, "scan-format"))) if ((v = blaze822_hdr(config, "scan-format")))

84
msed.c
View File

@ -24,9 +24,9 @@ subst(char *str, char *srch, char *repl, char *flags)
int iflag = !!strchr(flags, 'i'); int iflag = !!strchr(flags, 'i');
int gflag = !!strchr(flags, 'g'); int gflag = !!strchr(flags, 'g');
#define APP(o,l) do {if(bufe-b<(ssize_t)l) return str; memcpy(b,str+i+o,l); b+=l;} while(0) #define APP(o, l) do { if (bufe-b < (ssize_t)l) return str; memcpy(b, str+i+o, l); b += l; } while (0)
#define APPC(c) do {if(b>=bufe) return str; *b++=c;} while(0) #define APPC(c) do { if (b >= bufe) return str; *b++ = c; } while (0)
regex_t srchrx; regex_t srchrx;
regmatch_t pmatch[10]; regmatch_t pmatch[10];
if (regcomp(&srchrx, srch, iflag ? REG_ICASE : 0) != 0) if (regcomp(&srchrx, srch, iflag ? REG_ICASE : 0) != 0)
@ -53,7 +53,7 @@ subst(char *str, char *srch, char *repl, char *flags)
t++; t++;
n = *t++ - '0'; n = *t++ - '0';
} }
APP(pmatch[n].rm_so, APP(pmatch[n].rm_so,
pmatch[n].rm_eo - pmatch[n].rm_so); pmatch[n].rm_eo - pmatch[n].rm_so);
} else if (*t == '\\' && *(t+1)) { } else if (*t == '\\' && *(t+1)) {
@ -63,7 +63,7 @@ subst(char *str, char *srch, char *repl, char *flags)
APPC(*t++); APPC(*t++);
} }
} }
i += pmatch[0].rm_eo; // advance to end of match i += pmatch[0].rm_eo; // advance to end of match
if (!gflag) if (!gflag)
break; break;
@ -199,7 +199,7 @@ sed(char *file)
char *from = strndup(s, t-s-1); char *from = strndup(s, t-s-1);
char *to = strndup(t, u-t-1); char *to = strndup(t, u-t-1);
char *flags = strndup(u, e-u); char *flags = strndup(u, e-u);
char *ov = v; char *ov = v;
v = strdup(subst(ov, from, to, flags)); v = strdup(subst(ov, from, to, flags));
free(ov); free(ov);
@ -232,7 +232,7 @@ sed(char *file)
while (*e && while (*e &&
(*e == ' ' || *e == '\t' || *e == '\n' || *e == ';')) (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';'))
e++; e++;
hs = he = 0; hs = he = 0;
if (*e == '/') { if (*e == '/') {
e++; e++;
@ -244,49 +244,49 @@ sed(char *file)
if (*e) if (*e)
e++; e++;
} }
char sep; char sep;
char *s; char *s;
char *h = 0; char *h = 0;
char *v = 0; char *v = 0;
switch (*e) { switch (*e) {
case 'a': case 'a':
if (he != hs) { if (he != hs) {
h = strndup(hs, he-hs); h = strndup(hs, he-hs);
} else { } else {
fprintf(stderr, "msed: used command a without header name\n"); fprintf(stderr, "msed: used command a without header name\n");
exit(1);
}
e++;
if (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';' || !*e) {
fprintf(stderr, "msed: no header value for %s\n", h);
exit(1);
} else {
sep = *e;
if (!sep) {
fprintf(stderr, "msed: unterminated a command\n");
exit(1); exit(1);
} }
s = ++e;
while (*e && *e != sep)
e++;
v = strndup(s, e-s);
}
e++; if (blaze822_chdr(msg, h))
if (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';' || !*e) {
fprintf(stderr, "msed: no header value for %s\n", h);
exit(1);
} else {
sep = *e;
if (!sep) {
fprintf(stderr, "msed: unterminated a command\n");
exit(1);
}
s = ++e;
while (*e && *e != sep)
e++;
v = strndup(s, e-s);
}
if (blaze822_chdr(msg, h))
break;
printhdr(h, 0);
printf(": %s\n", v);
break; break;
case 'c': printhdr(h, 0);
case 'd': printf(": %s\n", v);
case 's':
// ignore here; break;
break;
case 'c':
case 'd':
case 's':
// ignore here;
break;
} }
while (*e && *e != ';' && *e != '\n') while (*e && *e != ';' && *e != '\n')
e++; e++;
@ -301,7 +301,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "")) != -1) while ((c = getopt(argc, argv, "")) != -1)
switch(c) { switch (c) {
default: default:
fprintf(stderr, "Usage: msed [expr] [msgs...]\n"); fprintf(stderr, "Usage: msed [expr] [msgs...]\n");
exit(1); exit(1);
@ -317,6 +317,6 @@ main(int argc, char *argv[])
blaze822_loop1(".", sed); blaze822_loop1(".", sed);
else else
blaze822_loop(argc-optind, argv+optind, sed); blaze822_loop(argc-optind, argv+optind, sed);
return 0; return 0;
} }

8
mseq.c
View File

@ -3,9 +3,9 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <search.h> #include <search.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "blaze822.h" #include "blaze822.h"
@ -152,7 +152,7 @@ fix(FILE *out, char *file)
return 0; return 0;
ok: ok:
while(i--) while (i--)
putc(' ', out); putc(' ', out);
fprintf(out, "%s\n", bufptr); fprintf(out, "%s\n", bufptr);
return 1; return 1;
@ -277,7 +277,7 @@ main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "c:frAC:S")) != -1) while ((c = getopt(argc, argv, "c:frAC:S")) != -1)
switch(c) { switch (c) {
case 'c': cflag = optarg; break; case 'c': cflag = optarg; break;
case 'f': fflag = 1; break; case 'f': fflag = 1; break;
case 'r': rflag = 1; break; case 'r': rflag = 1; break;
@ -285,7 +285,7 @@ main(int argc, char *argv[])
case 'C': Cflag = optarg; break; case 'C': Cflag = optarg; break;
case 'S': Sflag = 1; break; case 'S': Sflag = 1; break;
default: default:
usage: usage:
fprintf(stderr, fprintf(stderr,
"Usage: mseq [-fr] [-c msg] [msgs...]\n" "Usage: mseq [-fr] [-c msg] [msgs...]\n"
" mseq -S [-fr] < sequence\n" " mseq -S [-fr] < sequence\n"

58
mshow.c
View File

@ -97,7 +97,7 @@ print_u8recode(char *body, size_t bodylen, char *srcenc)
final_char = bufptr[-1]; final_char = bufptr[-1];
} }
if (r != (size_t)-1) { // done, flush iconv if (r != (size_t)-1) { // done, flush iconv
bufptr = buf; bufptr = buf;
buflen = sizeof buf; buflen = sizeof buf;
r = iconv(ic, 0, 0, &bufptr, &buflen); r = iconv(ic, 0, 0, &bufptr, &buflen);
@ -218,11 +218,14 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
size_t outlen; size_t outlen;
int e = filter(body, bodylen, cmd, &output, &outlen); int e = filter(body, bodylen, cmd, &output, &outlen);
if (e == 0) { // replace output if (e == 0 || e == 62) { // replace output (62 == raw)
if (!Nflag) if (!Nflag)
printf(" render=\"%s\" ---\n", cmd); printf(" render=\"%s\" ---\n", cmd);
if (outlen) { if (outlen) {
print_ascii(output, outlen); if (e == 0)
print_ascii(output, outlen);
else
return fwrite(output, 1, outlen, stdout);
if (output[outlen-1] != '\n') if (output[outlen-1] != '\n')
putchar('\n'); putchar('\n');
} }
@ -268,7 +271,7 @@ nofilter:
strcasecmp(charset, "utf8") == 0 || strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0) { strcasecmp(charset, "us-ascii") == 0) {
print_ascii(body, bodylen); print_ascii(body, bodylen);
if (body[bodylen-1] != '\n') if (bodylen > 0 && body[bodylen-1] != '\n')
putchar('\n'); putchar('\n');
} else { } else {
print_u8recode(body, bodylen, charset); print_u8recode(body, bodylen, charset);
@ -336,7 +339,7 @@ choose_alternative(struct message *msg, int depth)
blaze822_mime_action blaze822_mime_action
reply_mime(int depth, struct message *msg, char *body, size_t bodylen) reply_mime(int depth, struct message *msg, char *body, size_t bodylen)
{ {
(void) depth; (void)depth;
char *ct = blaze822_hdr(msg, "content-type"); char *ct = blaze822_hdr(msg, "content-type");
char *mt = mimetype(ct); char *mt = mimetype(ct);
@ -365,7 +368,7 @@ reply_mime(int depth, struct message *msg, char *body, size_t bodylen)
blaze822_mime_action blaze822_mime_action
list_mime(int depth, struct message *msg, char *body, size_t bodylen) list_mime(int depth, struct message *msg, char *body, size_t bodylen)
{ {
(void) body; (void)body;
char *ct = blaze822_hdr(msg, "content-type"); char *ct = blaze822_hdr(msg, "content-type");
if (!ct) if (!ct)
@ -441,7 +444,7 @@ writefile(char *name, char *buf, ssize_t len)
blaze822_mime_action blaze822_mime_action
extract_mime(int depth, struct message *msg, char *body, size_t bodylen) extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
{ {
(void) depth; (void)depth;
char *filename = mime_filename(msg); char *filename = mime_filename(msg);
@ -497,7 +500,7 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
writefile(bufptr, body, bodylen); writefile(bufptr, body, bodylen);
} }
} else if (filename && } else if (filename &&
fnmatch(a, filename, FNM_PATHNAME) == 0) { fnmatch(a, filename, FNM_PATHNAME) == 0) {
// extract by name // extract by name
if (extract_stdout) { if (extract_stdout) {
if (rflag) { if (rflag) {
@ -556,7 +559,7 @@ print_date_header(char *v)
printf("Date: "); printf("Date: ");
print_ascii(v, strlen(v)); print_ascii(v, strlen(v));
time_t t = blaze822_date(v); time_t t = blaze822_date(v);
if (t == -1) { if (t == -1) {
printf(" (invalid)"); printf(" (invalid)");
@ -572,57 +575,57 @@ print_date_header(char *v)
else if (d > 60) l = 'm'; else if (d > 60) l = 'm';
else l = 's'; else l = 's';
int p = 3; int p = 3;
int z; int z;
switch(l) { switch (l) {
case 'y': case 'y':
z = d / (60*60*24*7*52); z = d / (60*60*24*7*52);
d = d % (60*60*24*7*52); d = d % (60*60*24*7*52);
if (z > 0) { if (z > 0) {
printf("%d year%s", z, z>1 ? "s" : ""); printf("%d year%s", z, z > 1 ? "s" : "");
if (!--p) break; if (!--p) break;
printf(", "); printf(", ");
} }
/* FALL THROUGH */ /* FALL THROUGH */
case 'w': case 'w':
z = d / (60*60*24*7); z = d / (60*60*24*7);
d = d % (60*60*24*7); d = d % (60*60*24*7);
if (z > 0) { if (z > 0) {
printf("%d week%s", z, z>1 ? "s" : ""); printf("%d week%s", z, z > 1 ? "s" : "");
if (!--p) break; if (!--p) break;
printf(", "); printf(", ");
} }
/* FALL THROUGH */ /* FALL THROUGH */
case 'd': case 'd':
z = d / (60*60*24); z = d / (60*60*24);
d = d % (60*60*24); d = d % (60*60*24);
if (z > 0) { if (z > 0) {
printf("%d day%s", z, z>1 ? "s" : ""); printf("%d day%s", z, z > 1 ? "s" : "");
if (!--p) break; if (!--p) break;
printf(", "); printf(", ");
} }
/* FALL THROUGH */ /* FALL THROUGH */
case 'h': case 'h':
z = d / (60*60); z = d / (60*60);
d = d % (60*60); d = d % (60*60);
if (z > 0) { if (z > 0) {
printf("%d hour%s", z, z>1 ? "s" : ""); printf("%d hour%s", z, z > 1 ? "s" : "");
if (!--p) break; if (!--p) break;
printf(", "); printf(", ");
} }
/* FALL THROUGH */ /* FALL THROUGH */
case 'm': case 'm':
z = d / (60); z = d / (60);
d = d % (60); d = d % (60);
if (z > 0) { if (z > 0) {
printf("%d minute%s", z, z>1 ? "s" : ""); printf("%d minute%s", z, z > 1 ? "s" : "");
if (!--p) break; if (!--p) break;
printf(", "); printf(", ");
} }
/* FALL THROUGH */ /* FALL THROUGH */
case 's': case 's':
z = d; z = d;
printf("%d second%s", z, z>1 ? "s" : ""); printf("%d second%s", z, z > 1 ? "s" : "");
} }
if (t < now) if (t < now)
@ -707,7 +710,7 @@ show(char *file)
printf("\n"); printf("\n");
if (rflag || !blaze822_check_mime(msg)) { // raw body if (rflag) { // raw body
print_ascii(blaze822_body(msg), blaze822_bodylen(msg)); print_ascii(blaze822_body(msg), blaze822_bodylen(msg));
goto done; goto done;
} }
@ -726,7 +729,7 @@ main(int argc, char *argv[])
int c; int c;
while ((c = getopt(argc, argv, "h:A:qrtHLNx:O:Rn")) != -1) while ((c = getopt(argc, argv, "h:A:qrtHLNx:O:Rn")) != -1)
switch(c) { switch (c) {
case 'h': hflag = optarg; break; case 'h': hflag = optarg; break;
case 'A': Aflag = optarg; break; case 'A': Aflag = optarg; break;
case 'q': qflag = 1; break; case 'q': qflag = 1; break;
@ -759,8 +762,13 @@ main(int argc, char *argv[])
if (safe_output && isatty(1)) { if (safe_output && isatty(1)) {
char *pg; char *pg;
pg = getenv("MBLAZE_PAGER"); pg = getenv("MBLAZE_PAGER");
if (!pg) if (!pg) {
pg = getenv("PAGER"); pg = getenv("PAGER");
if (pg && strcmp(pg, "less") == 0) {
static char lesscmd[] = "less -RFXe";
pg = lesscmd;
}
}
if (pg && *pg && strcmp(pg, "cat") != 0) { if (pg && *pg && strcmp(pg, "cat") != 0) {
pid2 = pipeto(pg); pid2 = pipeto(pg);
if (pid2 < 0) if (pid2 < 0)

View File

@ -1,5 +1,5 @@
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <err.h> #include <err.h>
@ -301,7 +301,7 @@ main(int argc, char *argv[])
int c, i; int c, i;
while ((c = getopt(argc, argv, "fdsFMSUIr")) != -1) while ((c = getopt(argc, argv, "fdsFMSUIr")) != -1)
switch(c) { switch (c) {
case 'f': addorder(fromorder); break; case 'f': addorder(fromorder); break;
case 'd': addorder(dateorder); break; case 'd': addorder(dateorder); break;
case 's': addorder(subjorder); break; case 's': addorder(subjorder); break;

View File

@ -171,7 +171,7 @@ thread(char *file)
parent = me; parent = me;
} }
} }
v = blaze822_hdr(msg, "in-reply-to"); v = blaze822_hdr(msg, "in-reply-to");
char *irt; char *irt;
if (v) { if (v) {
@ -182,7 +182,7 @@ thread(char *file)
if (!v) if (!v)
goto out; goto out;
irt = strndup(m+1, v-m-1); irt = strndup(m+1, v-m-1);
if (strcmp(irt, mid) != 0) { if (strcmp(irt, mid) != 0) {
parent = midcont(irt); parent = midcont(irt);
} }
@ -279,7 +279,7 @@ find_root(const void *nodep, const VISIT which, const int depth)
void void
find_roots() find_roots()
{ {
top = malloc (sizeof (struct container)); top = malloc(sizeof (struct container));
top->msg = 0; top->msg = 0;
top->date = -1; top->date = -1;
top->file = 0; top->file = 0;
@ -388,7 +388,7 @@ print_tree(struct container *c, int depth)
else else
printf("<%s>\n", c->mid); printf("<%s>\n", c->mid);
} }
if (c->child) if (c->child)
print_tree(c->child, depth+1); print_tree(c->child, depth+1);
} while ((c = c->next)); } while ((c = c->next));
@ -404,14 +404,14 @@ main(int argc, char *argv[])
if (pledge("stdio rpath tty", NULL) == -1) if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge"); err(1, "pledge");
while ((c = getopt(argc, argv, "S:v")) != -1) while ((c = getopt(argc, argv, "S:v")) != -1)
switch(c) { switch (c) {
case 'S': blaze822_loop1(optarg, thread); break; case 'S': blaze822_loop1(optarg, thread); break;
case 'v': vflag = 1; break; case 'v': vflag = 1; break;
default: default:
fprintf(stderr, "Usage: mthread [-v] [-S dir] [msgs...]\n"); fprintf(stderr, "Usage: mthread [-v] [-S dir] [msgs...]\n");
exit(1); exit(1);
} }
optional = 0; optional = 0;

View File

@ -47,7 +47,7 @@ pipeto(const char *cmdline)
break; break;
*cp++ = 0; *cp++ = 0;
while (*cp == ' ') while (*cp == ' ')
cp++; cp++;
} }
argv[argc] = 0; argv[argc] = 0;
@ -96,6 +96,6 @@ pipeclose(pid_t pid)
fflush(0); fflush(0);
close(1); close(1);
waitpid(pid, &s, 0); waitpid(pid, &s, 0);
return s; return s;
} }

View File

@ -1,8 +1,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "blaze822.h" #include "blaze822.h"
#include "blaze822_priv.h" #include "blaze822_priv.h"

View File

@ -82,7 +82,7 @@ blaze822_decode_b64(char *s, char *e, char **deco, size_t *decleno)
*deco = buf; *deco = buf;
while (s + 4 <= e) { while (s + 4 <= e) {
while (s < e && isfws((unsigned char) *s)) while (s < e && isfws((unsigned char)*s))
s++; s++;
if (s >= e) if (s >= e)
break; break;
@ -90,7 +90,7 @@ blaze822_decode_b64(char *s, char *e, char **deco, size_t *decleno)
uint32_t v = 0; uint32_t v = 0;
unsigned char t = 0; unsigned char t = 0;
unsigned char c0=s[0], c1=s[1], c2=s[2], c3=s[3]; unsigned char c0 = s[0], c1 = s[1], c2 = s[2], c3 = s[3];
s += 4; s += 4;
if ((c0 | c1 | c2 | c3) > 127) if ((c0 | c1 | c2 | c3) > 127)
@ -273,7 +273,7 @@ nocodeok:
} }
#ifdef TEST #ifdef TEST
int int
main() { main() {
char *r; char *r;
size_t l; size_t l;

View File

@ -39,7 +39,7 @@ blaze822_mime2231_parameter(char *s, char *name,
i = 100; i = 100;
goto found_plain; goto found_plain;
} }
while (i < 100) { while (i < 100) {
snprintf(namenum, sizeof namenum, "%s*%d*", name, i); snprintf(namenum, sizeof namenum, "%s*%d*", name, i);
if (blaze822_mime_parameter(s, namenum, &sbuf, &ebuf)) { if (blaze822_mime_parameter(s, namenum, &sbuf, &ebuf)) {
@ -48,13 +48,13 @@ found_extended:
if (i == 0 || i == 100) { // extended-initial-value if (i == 0 || i == 100) { // extended-initial-value
char *encstart = sbuf; char *encstart = sbuf;
sbuf = strchr(sbuf, '\''); sbuf = strchr(sbuf, '\'');
if (!sbuf) if (!sbuf)
return 0; return 0;
srcenc = strndup(encstart, sbuf - encstart); srcenc = strndup(encstart, sbuf - encstart);
if (!srcenc) if (!srcenc)
return 0; return 0;
sbuf = strchr(sbuf+1, '\''); sbuf = strchr(sbuf+1, '\'');
if (!sbuf) if (!sbuf)
return 0; return 0;
sbuf++; sbuf++;
} }
@ -110,7 +110,7 @@ found_plain:
size_t dstlen = dst - dststart; size_t dstlen = dst - dststart;
dst = dststart; dst = dststart;
int r = iconv(ic, &dst, &dstlen, &tmpend, &tmplen); int r = iconv(ic, &dst, &dstlen, &tmpend, &tmplen);
if (r < 0) { if (r < 0) {
free(tmp); free(tmp);

View File

@ -1,5 +1,5 @@
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
void void
safe_u8putstr(char *s0, size_t l, FILE *stream) safe_u8putstr(char *s0, size_t l, FILE *stream)
@ -10,7 +10,7 @@ safe_u8putstr(char *s0, size_t l, FILE *stream)
// - rest is assumed to be latin1, and translated into utf8 // - rest is assumed to be latin1, and translated into utf8
// - translate CRLF to CR // - translate CRLF to CR
unsigned char *s = (unsigned char* )s0; unsigned char *s = (unsigned char *)s0;
unsigned char *e = s + l; unsigned char *e = s + l;
while (s < e) { while (s < e) {
@ -56,13 +56,13 @@ safe_u8putstr(char *s0, size_t l, FILE *stream)
f = (s[0]<<24) | (s[1]<<16); f = (s[0]<<24) | (s[1]<<16);
else if (e - s == 1) else if (e - s == 1)
f = (s[0]<<24); f = (s[0]<<24);
if ((f & 0xe0c00000) == 0xc0800000) goto u2; if ((f & 0xe0c00000) == 0xc0800000) goto u2;
else if ((f & 0xf0c0c000) == 0xe0808000) goto u3; else if ((f & 0xf0c0c000) == 0xe0808000) goto u3;
else if ((f & 0xf8c0c0c0) == 0xf0808080) { else if ((f & 0xf8c0c0c0) == 0xf0808080) {
fputc(*s++, stream); fputc(*s++, stream);
u3: fputc(*s++, stream); u3: fputc(*s++, stream);
u2: fputc(*s++, stream); u2: fputc(*s++, stream);
fputc(*s, stream); fputc(*s, stream);
} else { } else {
latin1: latin1:

4
seq.c
View File

@ -349,7 +349,7 @@ parse_range(char *map, char *a, long *start, long *stop, long cur, long lines)
a = b; a = b;
} }
if (*start == 0) if (*start == 0)
*start = strchr("=^_", *a) ? cur : 1; *start = strchr("=^_", *a) ? cur : 1;
while (*a == '^') { while (*a == '^') {
a++; a++;
@ -428,7 +428,7 @@ blaze822_seq_next(char *map, char *range, struct blaze822_seq_iter *iter)
if (!iter->start) { if (!iter->start) {
int ret = parse_range(map, range, &iter->start, &iter->stop, int ret = parse_range(map, range, &iter->start, &iter->stop,
iter->cur, iter->lines); iter->cur, iter->lines);
if (ret == 1) { if (ret == 1) {
fprintf(stderr, "can't parse range: %s\n", range); fprintf(stderr, "can't parse range: %s\n", range);
return 0; return 0;

View File

@ -14,7 +14,7 @@ slurp(char *filename, char **bufo, off_t *leno)
ssize_t nread = 0; ssize_t nread = 0;
ssize_t n; ssize_t n;
int r = 0; int r = 0;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
r = errno; r = errno;