2016-07-11 19:50:04 +00:00
|
|
|
#include <sys/stat.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-07-11 19:50:04 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <fcntl.h>
|
2016-07-22 22:46:48 +00:00
|
|
|
#include <fnmatch.h>
|
2016-07-18 14:48:42 +00:00
|
|
|
#include <iconv.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-07-26 16:17:31 +00:00
|
|
|
#include <strings.h>
|
2016-07-24 21:17:16 +00:00
|
|
|
#include <time.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <unistd.h>
|
2016-07-11 19:50:04 +00:00
|
|
|
|
|
|
|
#include "blaze822.h"
|
|
|
|
|
2018-04-17 13:26:19 +00:00
|
|
|
static int Bflag;
|
2016-07-16 20:19:20 +00:00
|
|
|
static int rflag;
|
2016-07-20 14:57:40 +00:00
|
|
|
static int Rflag;
|
2016-07-16 20:19:20 +00:00
|
|
|
static int qflag;
|
2017-09-22 13:37:36 +00:00
|
|
|
static int Fflag;
|
2016-07-16 20:19:20 +00:00
|
|
|
static int Hflag;
|
|
|
|
static int Lflag;
|
2017-06-18 15:31:19 +00:00
|
|
|
static int Nflag;
|
2016-07-16 20:19:20 +00:00
|
|
|
static int tflag;
|
2016-07-18 16:37:14 +00:00
|
|
|
static int nflag;
|
2017-06-18 15:56:07 +00:00
|
|
|
static char defaulthflags[] = "from:subject:to:cc:date:reply-to:";
|
2016-07-16 20:19:20 +00:00
|
|
|
static char *hflag = defaulthflags;
|
|
|
|
static char *xflag;
|
|
|
|
static char *Oflag;
|
|
|
|
|
2017-08-05 15:46:25 +00:00
|
|
|
static char fallback_ct[] = "text/plain";
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
struct message *filters;
|
|
|
|
|
|
|
|
static int mimecount;
|
2019-01-02 17:39:19 +00:00
|
|
|
static int extractcount;
|
2017-03-13 14:50:41 +00:00
|
|
|
static int safe_output;
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2018-01-09 16:01:35 +00:00
|
|
|
static int reply_found;
|
|
|
|
|
2016-07-29 15:07:25 +00:00
|
|
|
static char defaultAflags[] = "text/plain:text/html";
|
|
|
|
static char *Aflag = defaultAflags;
|
|
|
|
|
2017-03-13 14:50:41 +00:00
|
|
|
static int
|
|
|
|
printable(int c)
|
|
|
|
{
|
|
|
|
return (unsigned)c-0x20 < 0x5f;
|
|
|
|
}
|
|
|
|
|
2017-10-06 11:15:28 +00:00
|
|
|
size_t
|
2017-03-13 14:50:41 +00:00
|
|
|
print_ascii(char *body, size_t bodylen)
|
|
|
|
{
|
|
|
|
if (safe_output) {
|
|
|
|
safe_u8putstr(body, bodylen, stdout);
|
|
|
|
return bodylen;
|
|
|
|
} else {
|
|
|
|
return fwrite(body, 1, bodylen, stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:50:04 +00:00
|
|
|
void
|
|
|
|
printhdr(char *hdr)
|
|
|
|
{
|
|
|
|
int uc = 1;
|
|
|
|
|
2017-03-13 14:50:41 +00:00
|
|
|
while (*hdr && *hdr != ':' && printable(*hdr)) {
|
2016-07-11 19:50:04 +00:00
|
|
|
putc(uc ? toupper(*hdr) : *hdr, stdout);
|
|
|
|
uc = (*hdr == '-');
|
|
|
|
hdr++;
|
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2017-03-13 14:50:41 +00:00
|
|
|
if (*hdr) {
|
|
|
|
print_ascii(hdr, strlen(hdr));
|
|
|
|
fputc('\n', stdout);
|
2016-07-29 13:08:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-18 14:48:42 +00:00
|
|
|
void
|
|
|
|
print_u8recode(char *body, size_t bodylen, char *srcenc)
|
|
|
|
{
|
|
|
|
iconv_t ic;
|
|
|
|
|
|
|
|
ic = iconv_open("UTF-8", srcenc);
|
|
|
|
if (ic == (iconv_t)-1) {
|
|
|
|
printf("unsupported encoding: %s\n", srcenc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char final_char = 0;
|
|
|
|
|
|
|
|
char buf[4096];
|
|
|
|
while (bodylen > 0) {
|
|
|
|
char *bufptr = buf;
|
|
|
|
size_t buflen = sizeof buf;
|
|
|
|
size_t r = iconv(ic, &body, &bodylen, &bufptr, &buflen);
|
|
|
|
|
|
|
|
if (bufptr != buf) {
|
2016-07-29 13:08:16 +00:00
|
|
|
print_ascii(buf, bufptr-buf);
|
2016-07-18 14:48:42 +00:00
|
|
|
final_char = bufptr[-1];
|
|
|
|
}
|
|
|
|
|
2017-08-31 15:30:17 +00:00
|
|
|
if (r != (size_t)-1) { // done, flush iconv
|
2016-07-18 14:48:42 +00:00
|
|
|
bufptr = buf;
|
|
|
|
buflen = sizeof buf;
|
|
|
|
r = iconv(ic, 0, 0, &bufptr, &buflen);
|
|
|
|
if (bufptr != buf) {
|
2016-07-29 13:08:16 +00:00
|
|
|
print_ascii(buf, bufptr-buf);
|
2016-07-18 14:48:42 +00:00
|
|
|
final_char = bufptr[-1];
|
|
|
|
}
|
|
|
|
if (r != (size_t)-1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r == (size_t)-1 && errno != E2BIG) {
|
|
|
|
perror("iconv");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (final_char != '\n')
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
iconv_close(ic);
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
char *
|
|
|
|
mimetype(char *ct)
|
|
|
|
{
|
|
|
|
char *s;
|
2016-07-20 21:11:13 +00:00
|
|
|
|
|
|
|
if (!ct)
|
|
|
|
return 0;
|
2016-07-16 20:19:20 +00:00
|
|
|
for (s = ct; *s && *s != ';' && *s != ' ' && *s != '\t'; s++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return strndup(ct, s-ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
tlmimetype(char *ct)
|
|
|
|
{
|
|
|
|
char *s;
|
2016-07-20 21:11:13 +00:00
|
|
|
|
|
|
|
if (!ct)
|
|
|
|
return 0;
|
2016-07-16 20:19:20 +00:00
|
|
|
for (s = ct; *s && *s != ';' && *s != ' ' && *s != '\t' && *s != '/'; s++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return strndup(ct, s-ct);
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:11:13 +00:00
|
|
|
char *
|
|
|
|
mime_filename(struct message *msg)
|
|
|
|
{
|
2017-04-06 19:01:11 +00:00
|
|
|
static char buf[512];
|
|
|
|
char *v;
|
|
|
|
char *filename = 0;
|
2016-07-20 21:11:13 +00:00
|
|
|
|
|
|
|
if ((v = blaze822_hdr(msg, "content-disposition"))) {
|
2017-04-06 19:01:11 +00:00
|
|
|
if (blaze822_mime2231_parameter(v, "filename",
|
|
|
|
buf, sizeof buf, "UTF-8"))
|
|
|
|
filename = buf;
|
2016-07-20 21:11:13 +00:00
|
|
|
} else if ((v = blaze822_hdr(msg, "content-type"))) {
|
2017-04-06 19:01:11 +00:00
|
|
|
if (blaze822_mime2231_parameter(v, "name",
|
|
|
|
buf, sizeof buf, "UTF-8"))
|
|
|
|
filename = buf;
|
2016-07-20 21:11:13 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 13:26:19 +00:00
|
|
|
if (Bflag && filename) {
|
|
|
|
static char buf2[512];
|
|
|
|
blaze822_decode_rfc2047(buf2, filename, sizeof buf2, "UTF-8");
|
|
|
|
filename = buf2;
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:11:13 +00:00
|
|
|
return filename;
|
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2016-07-29 15:07:25 +00:00
|
|
|
static void choose_alternative(struct message *msg, int depth);
|
|
|
|
|
2017-04-06 20:31:27 +00:00
|
|
|
void
|
|
|
|
print_filename(char *filename)
|
|
|
|
{
|
|
|
|
if (filename) {
|
|
|
|
printf(" name=\"");
|
|
|
|
safe_u8putstr(filename, strlen(filename), stdout);
|
|
|
|
printf("\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_mime_action
|
2016-07-20 21:11:13 +00:00
|
|
|
render_mime(int depth, struct message *msg, char *body, size_t bodylen)
|
2016-07-16 20:19:20 +00:00
|
|
|
{
|
2016-07-20 21:11:13 +00:00
|
|
|
char *ct = blaze822_hdr(msg, "content-type");
|
2016-07-22 22:12:46 +00:00
|
|
|
if (!ct)
|
2017-08-05 15:46:25 +00:00
|
|
|
ct = fallback_ct;
|
2016-07-16 20:19:20 +00:00
|
|
|
char *mt = mimetype(ct);
|
|
|
|
char *tlmt = tlmimetype(ct);
|
2016-07-20 21:11:13 +00:00
|
|
|
char *filename = mime_filename(msg);
|
2016-07-16 20:19:20 +00:00
|
|
|
|
|
|
|
mimecount++;
|
|
|
|
|
2017-06-18 15:31:19 +00:00
|
|
|
if (!Nflag) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < depth+1; i++)
|
|
|
|
printf("--- ");
|
|
|
|
printf("%d: %s size=%zd", mimecount, mt, bodylen);
|
|
|
|
print_filename(filename);
|
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
|
|
|
|
char *cmd;
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_mime_action r = MIME_CONTINUE;
|
2016-07-16 20:19:20 +00:00
|
|
|
|
|
|
|
if (filters &&
|
|
|
|
((cmd = blaze822_chdr(filters, mt)) ||
|
|
|
|
(cmd = blaze822_chdr(filters, tlmt)))) {
|
2016-07-20 12:48:27 +00:00
|
|
|
char *charset = 0, *cs, *cse;
|
|
|
|
if (blaze822_mime_parameter(ct, "charset", &cs, &cse)) {
|
|
|
|
charset = strndup(cs, cse-cs);
|
2018-02-07 10:30:31 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" charset=\"%s\"", charset);
|
2016-07-20 12:48:27 +00:00
|
|
|
setenv("PIPE_CHARSET", charset, 1);
|
|
|
|
free(charset);
|
|
|
|
}
|
2016-07-29 13:15:57 +00:00
|
|
|
setenv("PIPE_CONTENTTYPE", ct, 1);
|
|
|
|
|
2018-09-17 13:29:47 +00:00
|
|
|
char *messageid = blaze822_hdr(msg, "message-id");
|
|
|
|
if (messageid) {
|
|
|
|
setenv("MESSAGE_ID", messageid, 1);
|
|
|
|
}
|
|
|
|
|
2016-07-29 13:15:57 +00:00
|
|
|
char *output;
|
|
|
|
size_t outlen;
|
|
|
|
int e = filter(body, bodylen, cmd, &output, &outlen);
|
|
|
|
|
2017-08-20 15:00:14 +00:00
|
|
|
if (e == 0 || e == 62) { // replace output (62 == raw)
|
2017-06-18 15:31:19 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" render=\"%s\" ---\n", cmd);
|
2017-04-06 18:42:19 +00:00
|
|
|
if (outlen) {
|
2017-08-20 15:00:14 +00:00
|
|
|
if (e == 0)
|
|
|
|
print_ascii(output, outlen);
|
|
|
|
else
|
2017-10-06 11:16:30 +00:00
|
|
|
fwrite(output, 1, outlen, stdout);
|
2017-04-06 18:42:19 +00:00
|
|
|
if (output[outlen-1] != '\n')
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2016-07-29 13:55:57 +00:00
|
|
|
} else if (e == 63) { // skip filter
|
|
|
|
free(output);
|
|
|
|
goto nofilter;
|
2016-07-29 13:15:57 +00:00
|
|
|
} else if (e == 64) { // decode output again
|
2017-06-18 15:31:19 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" filter=\"%s\" ---\n", cmd);
|
2016-07-29 13:15:57 +00:00
|
|
|
struct message *imsg = blaze822_mem(output, outlen);
|
|
|
|
if (imsg)
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(imsg, depth+1, render_mime);
|
2016-07-29 13:15:57 +00:00
|
|
|
blaze822_free(imsg);
|
2016-07-29 13:55:57 +00:00
|
|
|
} else if (e >= 65 && e <= 80) { // choose N-64th part
|
|
|
|
struct message *imsg = 0;
|
|
|
|
int n = e - 64;
|
2018-02-07 10:30:31 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" selector=\"%s\" part=%d ---\n", cmd, n);
|
2016-07-29 13:55:57 +00:00
|
|
|
while (blaze822_multipart(msg, &imsg)) {
|
|
|
|
if (--n == 0)
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(imsg, depth+1, render_mime);
|
2016-07-29 13:55:57 +00:00
|
|
|
}
|
|
|
|
blaze822_free(imsg);
|
2016-07-29 13:15:57 +00:00
|
|
|
} else {
|
2018-02-07 10:30:31 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" filter=\"%s\" FAILED status=%d", cmd, e);
|
2016-07-29 13:15:57 +00:00
|
|
|
free(output);
|
2016-07-16 20:19:20 +00:00
|
|
|
goto nofilter;
|
|
|
|
}
|
2016-07-29 13:15:57 +00:00
|
|
|
|
|
|
|
free(output);
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
r = MIME_PRUNE;
|
|
|
|
} else {
|
|
|
|
nofilter:
|
2017-06-18 15:31:19 +00:00
|
|
|
if (!Nflag)
|
|
|
|
printf(" ---\n");
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2018-01-16 17:14:06 +00:00
|
|
|
if (strncmp(ct, "text/", 5) == 0 ||
|
|
|
|
strncmp(ct, "message/delivery-status", 23) == 0) {
|
2016-07-18 14:48:42 +00:00
|
|
|
char *charset = 0, *cs, *cse;
|
|
|
|
if (blaze822_mime_parameter(ct, "charset", &cs, &cse))
|
|
|
|
charset = strndup(cs, cse-cs);
|
|
|
|
if (!charset ||
|
|
|
|
strcasecmp(charset, "utf-8") == 0 ||
|
|
|
|
strcasecmp(charset, "utf8") == 0 ||
|
2016-08-09 18:53:43 +00:00
|
|
|
strcasecmp(charset, "us-ascii") == 0) {
|
2016-07-29 13:08:16 +00:00
|
|
|
print_ascii(body, bodylen);
|
2017-08-21 17:13:14 +00:00
|
|
|
if (bodylen > 0 && body[bodylen-1] != '\n')
|
2016-08-09 18:53:43 +00:00
|
|
|
putchar('\n');
|
|
|
|
} else {
|
2016-07-18 14:48:42 +00:00
|
|
|
print_u8recode(body, bodylen, charset);
|
2016-08-09 18:53:43 +00:00
|
|
|
}
|
2016-07-18 14:48:42 +00:00
|
|
|
free(charset);
|
2016-07-16 20:19:20 +00:00
|
|
|
} else if (strncmp(ct, "message/rfc822", 14) == 0) {
|
|
|
|
struct message *imsg = blaze822_mem(body, bodylen);
|
|
|
|
char *h = 0;
|
2016-07-26 15:00:15 +00:00
|
|
|
while (imsg && (h = blaze822_next_header(imsg, h))) {
|
|
|
|
char d[4096];
|
|
|
|
blaze822_decode_rfc2047(d, h, sizeof d, "UTF-8");
|
|
|
|
printhdr(d);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
2016-07-26 15:00:15 +00:00
|
|
|
printf("\n");
|
2016-07-29 15:07:25 +00:00
|
|
|
} else if (strncmp(ct, "multipart/alternative", 21) == 0) {
|
|
|
|
choose_alternative(msg, depth);
|
|
|
|
|
|
|
|
r = MIME_PRUNE;
|
2016-07-16 20:19:20 +00:00
|
|
|
} else if (strncmp(ct, "multipart/", 10) == 0) {
|
2016-08-02 14:13:25 +00:00
|
|
|
; // default blaze822_mime_walk action
|
2016-07-16 20:19:20 +00:00
|
|
|
} else {
|
|
|
|
printf("no filter or default handler\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(mt);
|
|
|
|
free(tlmt);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-07-29 15:07:25 +00:00
|
|
|
static void
|
|
|
|
choose_alternative(struct message *msg, int depth)
|
|
|
|
{
|
|
|
|
int n = 1;
|
|
|
|
int m = 0;
|
|
|
|
char *p = Aflag + strlen(Aflag);
|
|
|
|
|
|
|
|
struct message *imsg = 0;
|
|
|
|
while (blaze822_multipart(msg, &imsg)) {
|
|
|
|
m++;
|
2018-11-14 14:04:36 +00:00
|
|
|
|
|
|
|
if (blaze822_bodylen(imsg) == 0)
|
|
|
|
continue;
|
|
|
|
|
2016-07-29 15:07:25 +00:00
|
|
|
char *ict = blaze822_hdr(imsg, "content-type");
|
|
|
|
if (!ict)
|
2017-08-05 15:46:25 +00:00
|
|
|
ict = fallback_ct;
|
2016-07-29 15:07:25 +00:00
|
|
|
char *imt = mimetype(ict);
|
|
|
|
|
|
|
|
char *s = strstr(Aflag, imt);
|
|
|
|
if (s && s < p &&
|
|
|
|
(s[strlen(imt)] == 0 || s[strlen(imt)] == ':')) {
|
|
|
|
p = s;
|
|
|
|
n = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(imt);
|
|
|
|
}
|
|
|
|
blaze822_free(imsg);
|
|
|
|
|
|
|
|
imsg = 0;
|
|
|
|
while (blaze822_multipart(msg, &imsg))
|
|
|
|
if (--n == 0)
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(imsg, depth+1, render_mime);
|
2016-07-29 15:07:25 +00:00
|
|
|
blaze822_free(imsg);
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_mime_action
|
2016-07-20 21:11:13 +00:00
|
|
|
reply_mime(int depth, struct message *msg, char *body, size_t bodylen)
|
2016-07-20 14:57:40 +00:00
|
|
|
{
|
2017-08-31 15:30:17 +00:00
|
|
|
(void)depth;
|
2016-07-20 14:57:40 +00:00
|
|
|
|
2016-07-22 22:12:46 +00:00
|
|
|
char *ct = blaze822_hdr(msg, "content-type");
|
2016-07-20 14:57:40 +00:00
|
|
|
char *mt = mimetype(ct);
|
|
|
|
char *tlmt = tlmimetype(ct);
|
|
|
|
|
2016-07-22 16:43:34 +00:00
|
|
|
if (!ct || strncmp(ct, "text/plain", 10) == 0) {
|
2016-07-20 14:57:40 +00:00
|
|
|
char *charset = 0, *cs, *cse;
|
|
|
|
if (blaze822_mime_parameter(ct, "charset", &cs, &cse))
|
|
|
|
charset = strndup(cs, cse-cs);
|
|
|
|
if (!charset ||
|
|
|
|
strcasecmp(charset, "utf-8") == 0 ||
|
|
|
|
strcasecmp(charset, "utf8") == 0 ||
|
|
|
|
strcasecmp(charset, "us-ascii") == 0)
|
2016-07-29 13:08:16 +00:00
|
|
|
print_ascii(body, bodylen);
|
2016-07-20 14:57:40 +00:00
|
|
|
else
|
|
|
|
print_u8recode(body, bodylen, charset);
|
2018-01-09 16:01:35 +00:00
|
|
|
reply_found++;
|
2016-07-20 14:57:40 +00:00
|
|
|
free(charset);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(mt);
|
|
|
|
free(tlmt);
|
|
|
|
|
|
|
|
return MIME_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_mime_action
|
2016-07-20 21:11:13 +00:00
|
|
|
list_mime(int depth, struct message *msg, char *body, size_t bodylen)
|
2016-07-16 20:19:20 +00:00
|
|
|
{
|
2017-08-31 15:30:17 +00:00
|
|
|
(void)body;
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2016-07-20 21:11:13 +00:00
|
|
|
char *ct = blaze822_hdr(msg, "content-type");
|
2016-07-22 22:12:46 +00:00
|
|
|
if (!ct)
|
2017-08-05 15:46:25 +00:00
|
|
|
ct = fallback_ct;
|
2016-07-16 20:19:20 +00:00
|
|
|
char *mt = mimetype(ct);
|
2016-07-20 21:11:13 +00:00
|
|
|
char *filename = mime_filename(msg);
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2016-07-20 21:11:48 +00:00
|
|
|
printf(" %*.s%d: %s size=%zd", depth*2, "", ++mimecount, mt, bodylen);
|
2017-04-06 20:31:27 +00:00
|
|
|
print_filename(filename);
|
2016-07-16 20:19:20 +00:00
|
|
|
printf("\n");
|
|
|
|
|
2018-01-11 14:39:51 +00:00
|
|
|
free(mt);
|
2016-07-16 20:19:20 +00:00
|
|
|
return MIME_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:50:04 +00:00
|
|
|
void
|
2016-07-16 20:19:20 +00:00
|
|
|
list(char *file)
|
2016-07-11 19:50:04 +00:00
|
|
|
{
|
2017-12-06 13:00:38 +00:00
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
2016-07-16 20:19:20 +00:00
|
|
|
struct message *msg = blaze822_file(file);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
mimecount = 0;
|
2016-07-20 16:51:41 +00:00
|
|
|
printf("%s\n", file);
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(msg, 0, list_mime);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 14:57:40 +00:00
|
|
|
void
|
|
|
|
reply(char *file)
|
|
|
|
{
|
2017-12-06 13:00:38 +00:00
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
2016-07-20 14:57:40 +00:00
|
|
|
struct message *msg = blaze822_file(file);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
2018-01-09 16:01:35 +00:00
|
|
|
reply_found = 0;
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(msg, 0, reply_mime);
|
2018-01-09 16:01:35 +00:00
|
|
|
if (!reply_found)
|
|
|
|
exit(1);
|
2016-07-20 14:57:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
static int extract_argc;
|
|
|
|
static char **extract_argv;
|
|
|
|
static int extract_stdout;
|
|
|
|
|
2016-07-20 21:10:35 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
basenam(const char *s)
|
|
|
|
{
|
2017-01-26 19:27:26 +00:00
|
|
|
char *r = strrchr(s, '/');
|
|
|
|
return r ? r + 1 : s;
|
2016-07-20 21:10:35 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
static int
|
|
|
|
writefile(char *name, char *buf, ssize_t len)
|
|
|
|
{
|
2016-07-20 21:10:35 +00:00
|
|
|
int fd = open(basenam(name), O_CREAT | O_EXCL | O_WRONLY, 0666);
|
2016-07-16 20:19:20 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
perror("open");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-07-26 20:05:44 +00:00
|
|
|
|
|
|
|
ssize_t wr = 0, n;
|
|
|
|
do {
|
|
|
|
if ((n = write(fd, buf + wr, len - wr)) == -1) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
perror("write");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wr += n;
|
|
|
|
} while (wr < len);
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_mime_action
|
2016-07-20 21:11:13 +00:00
|
|
|
extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
|
2016-07-16 20:19:20 +00:00
|
|
|
{
|
2017-08-31 15:30:17 +00:00
|
|
|
(void)depth;
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2016-07-20 21:11:13 +00:00
|
|
|
char *filename = mime_filename(msg);
|
2016-07-16 20:19:20 +00:00
|
|
|
|
|
|
|
mimecount++;
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
if (extract_argc == 0) {
|
|
|
|
if (extract_stdout) { // output all parts
|
2016-07-18 14:52:11 +00:00
|
|
|
fwrite(body, 1, bodylen, stdout);
|
2016-07-16 20:19:20 +00:00
|
|
|
} else { // extract all named attachments
|
|
|
|
if (filename) {
|
2017-04-06 20:31:27 +00:00
|
|
|
safe_u8putstr(filename, strlen(filename), stdout);
|
|
|
|
printf("\n");
|
2016-07-16 20:19:20 +00:00
|
|
|
writefile(filename, body, bodylen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < extract_argc; i++) {
|
|
|
|
char *a = extract_argv[i];
|
|
|
|
char *b;
|
|
|
|
errno = 0;
|
|
|
|
long d = strtol(a, &b, 10);
|
|
|
|
if (errno == 0 && !*b && d == mimecount) {
|
|
|
|
// extract by id
|
|
|
|
if (extract_stdout) {
|
2016-08-06 18:10:33 +00:00
|
|
|
if (rflag) {
|
2016-08-06 17:30:45 +00:00
|
|
|
fwrite(blaze822_orig_header(msg),
|
|
|
|
1, blaze822_headerlen(msg),
|
|
|
|
stdout);
|
2017-05-26 21:27:48 +00:00
|
|
|
if (blaze822_orig_header(msg)[
|
|
|
|
blaze822_headerlen(msg)]
|
|
|
|
== '\r')
|
|
|
|
printf("\r\n\r\n");
|
|
|
|
else
|
|
|
|
printf("\n\n");
|
2016-08-06 18:10:33 +00:00
|
|
|
fwrite(blaze822_body(msg),
|
|
|
|
1, blaze822_bodylen(msg),
|
|
|
|
stdout);
|
|
|
|
} else {
|
|
|
|
fwrite(body, 1, bodylen, stdout);
|
2016-08-06 17:30:45 +00:00
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
} else {
|
|
|
|
char buf[255];
|
2016-07-21 18:26:37 +00:00
|
|
|
char *bufptr;
|
|
|
|
if (filename) {
|
|
|
|
bufptr = filename;
|
|
|
|
} else {
|
2016-07-16 20:19:20 +00:00
|
|
|
snprintf(buf, sizeof buf,
|
|
|
|
"attachment%d", mimecount);
|
2016-07-21 18:26:37 +00:00
|
|
|
bufptr = buf;
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
2016-07-21 18:26:37 +00:00
|
|
|
printf("%s\n", bufptr);
|
|
|
|
writefile(bufptr, body, bodylen);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
2019-01-02 17:39:19 +00:00
|
|
|
extractcount++;
|
2016-07-22 22:46:48 +00:00
|
|
|
} else if (filename &&
|
2017-08-31 15:30:17 +00:00
|
|
|
fnmatch(a, filename, FNM_PATHNAME) == 0) {
|
2016-07-16 20:19:20 +00:00
|
|
|
// extract by name
|
|
|
|
if (extract_stdout) {
|
2016-08-06 18:10:33 +00:00
|
|
|
if (rflag) {
|
2016-08-06 17:30:45 +00:00
|
|
|
fwrite(blaze822_orig_header(msg),
|
|
|
|
1, blaze822_headerlen(msg),
|
|
|
|
stdout);
|
|
|
|
printf("\n\n");
|
2016-08-06 18:10:33 +00:00
|
|
|
fwrite(blaze822_body(msg),
|
|
|
|
1, blaze822_bodylen(msg),
|
|
|
|
stdout);
|
|
|
|
} else {
|
|
|
|
fwrite(body, 1, bodylen, stdout);
|
2016-08-06 17:30:45 +00:00
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
} else {
|
2017-04-06 20:31:27 +00:00
|
|
|
safe_u8putstr(filename, strlen(filename), stdout);
|
|
|
|
printf("\n");
|
2016-07-16 20:19:20 +00:00
|
|
|
writefile(filename, body, bodylen);
|
|
|
|
}
|
2019-01-02 17:39:19 +00:00
|
|
|
extractcount++;
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MIME_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-22 22:25:27 +00:00
|
|
|
extract_cb(char *file)
|
2016-07-16 20:19:20 +00:00
|
|
|
{
|
2018-12-16 17:53:22 +00:00
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
2016-07-16 20:19:20 +00:00
|
|
|
struct message *msg = blaze822_file(file);
|
2016-07-11 19:50:04 +00:00
|
|
|
if (!msg)
|
|
|
|
return;
|
2016-07-16 20:19:20 +00:00
|
|
|
mimecount = 0;
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(msg, 0, extract_mime);
|
2016-07-22 22:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
extract(char *file, int argc, char **argv, int use_stdout)
|
|
|
|
{
|
2016-07-16 20:19:20 +00:00
|
|
|
extract_argc = argc;
|
|
|
|
extract_argv = argv;
|
|
|
|
extract_stdout = use_stdout;
|
2016-07-22 22:25:27 +00:00
|
|
|
blaze822_loop1(file, extract_cb);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2016-07-17 22:06:18 +00:00
|
|
|
static char *newcur;
|
|
|
|
|
2016-07-24 21:17:16 +00:00
|
|
|
static void
|
|
|
|
print_date_header(char *v)
|
|
|
|
{
|
|
|
|
static time_t now = -1;
|
|
|
|
if (now == -1) {
|
|
|
|
setenv("TZ", "", 1);
|
|
|
|
tzset();
|
|
|
|
now = time(0);
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:50:41 +00:00
|
|
|
printf("Date: ");
|
|
|
|
print_ascii(v, strlen(v));
|
2017-08-31 15:30:17 +00:00
|
|
|
|
2016-07-24 21:17:16 +00:00
|
|
|
time_t t = blaze822_date(v);
|
|
|
|
if (t == -1) {
|
|
|
|
printf(" (invalid)");
|
|
|
|
} else {
|
|
|
|
printf(" (");
|
|
|
|
time_t d = t < now ? now - t : t - now;
|
|
|
|
|
2017-10-06 11:15:28 +00:00
|
|
|
char l;
|
2016-07-24 21:17:16 +00:00
|
|
|
if (d > 60*60*24*7*52) l = 'y';
|
|
|
|
else if (d > 60*60*24*7) l = 'w';
|
|
|
|
else if (d > 60*60*24) l = 'd';
|
|
|
|
else if (d > 60*60) l = 'h';
|
|
|
|
else if (d > 60) l = 'm';
|
|
|
|
else l = 's';
|
|
|
|
int p = 3;
|
2017-08-31 15:30:17 +00:00
|
|
|
|
2017-10-06 11:15:28 +00:00
|
|
|
long z;
|
2017-08-31 15:30:17 +00:00
|
|
|
switch (l) {
|
2016-07-24 21:17:16 +00:00
|
|
|
case 'y':
|
|
|
|
z = d / (60*60*24*7*52);
|
|
|
|
d = d % (60*60*24*7*52);
|
|
|
|
if (z > 0) {
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld year%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
if (!--p) break;
|
|
|
|
printf(", ");
|
|
|
|
}
|
2017-08-31 15:30:17 +00:00
|
|
|
/* FALL THROUGH */
|
2016-07-24 21:17:16 +00:00
|
|
|
case 'w':
|
|
|
|
z = d / (60*60*24*7);
|
|
|
|
d = d % (60*60*24*7);
|
|
|
|
if (z > 0) {
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld week%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
if (!--p) break;
|
|
|
|
printf(", ");
|
|
|
|
}
|
2017-08-31 15:30:17 +00:00
|
|
|
/* FALL THROUGH */
|
2016-07-24 21:17:16 +00:00
|
|
|
case 'd':
|
|
|
|
z = d / (60*60*24);
|
|
|
|
d = d % (60*60*24);
|
|
|
|
if (z > 0) {
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld day%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
if (!--p) break;
|
|
|
|
printf(", ");
|
|
|
|
}
|
2017-08-31 15:30:17 +00:00
|
|
|
/* FALL THROUGH */
|
2016-07-24 21:17:16 +00:00
|
|
|
case 'h':
|
|
|
|
z = d / (60*60);
|
|
|
|
d = d % (60*60);
|
|
|
|
if (z > 0) {
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld hour%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
if (!--p) break;
|
|
|
|
printf(", ");
|
|
|
|
}
|
2017-08-31 15:30:17 +00:00
|
|
|
/* FALL THROUGH */
|
2016-07-24 21:17:16 +00:00
|
|
|
case 'm':
|
|
|
|
z = d / (60);
|
|
|
|
d = d % (60);
|
|
|
|
if (z > 0) {
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld minute%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
if (!--p) break;
|
|
|
|
printf(", ");
|
|
|
|
}
|
2017-08-31 15:30:17 +00:00
|
|
|
/* FALL THROUGH */
|
2016-07-24 21:17:16 +00:00
|
|
|
case 's':
|
|
|
|
z = d;
|
2017-10-13 13:48:39 +00:00
|
|
|
printf("%ld second%s", z, z > 1 ? "s" : "");
|
2016-07-24 21:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (t < now)
|
|
|
|
printf(" ago)");
|
|
|
|
else
|
|
|
|
printf(" in the future)");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_decode_header(char *h, char *v)
|
|
|
|
{
|
2017-06-13 15:30:53 +00:00
|
|
|
char d[16384];
|
2016-07-24 21:17:16 +00:00
|
|
|
blaze822_decode_rfc2047(d, v, sizeof d, "UTF-8");
|
|
|
|
printhdr(h);
|
2017-03-13 14:50:41 +00:00
|
|
|
fputc(':', stdout);
|
|
|
|
fputc(' ', stdout);
|
|
|
|
print_ascii(d, strlen(d));
|
|
|
|
fputc('\n', stdout);
|
2016-07-24 21:17:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
void
|
|
|
|
show(char *file)
|
|
|
|
{
|
|
|
|
struct message *msg;
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2016-07-17 22:06:18 +00:00
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
|
|
|
|
|
|
|
if (newcur) {
|
|
|
|
printf("\014\n");
|
|
|
|
free(newcur);
|
|
|
|
}
|
|
|
|
newcur = strdup(file);
|
|
|
|
|
2016-08-06 17:28:25 +00:00
|
|
|
if (qflag && !Hflag)
|
2016-07-16 20:19:20 +00:00
|
|
|
msg = blaze822(file);
|
|
|
|
else
|
|
|
|
msg = blaze822_file(file);
|
2016-07-17 22:06:18 +00:00
|
|
|
if (!msg) {
|
2016-07-20 14:03:20 +00:00
|
|
|
fprintf(stderr, "mshow: %s: %s\n", file, strerror(errno));
|
2016-07-16 20:19:20 +00:00
|
|
|
return;
|
2016-07-17 22:06:18 +00:00
|
|
|
}
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
if (Hflag) { // raw headers
|
2016-08-06 17:28:25 +00:00
|
|
|
fwrite(blaze822_orig_header(msg), 1, blaze822_headerlen(msg),
|
|
|
|
stdout);
|
2016-07-26 17:41:10 +00:00
|
|
|
printf("\n");
|
2016-07-16 20:19:20 +00:00
|
|
|
} else if (Lflag) { // all headers
|
|
|
|
char *h = 0;
|
|
|
|
while ((h = blaze822_next_header(msg, h))) {
|
|
|
|
char d[4096];
|
|
|
|
blaze822_decode_rfc2047(d, h, sizeof d, "UTF-8");
|
|
|
|
printhdr(d);
|
|
|
|
}
|
|
|
|
} else { // selected headers
|
|
|
|
char *h = hflag;
|
|
|
|
char *v;
|
|
|
|
while (*h) {
|
|
|
|
char *n = strchr(h, ':');
|
|
|
|
if (n)
|
|
|
|
*n = 0;
|
|
|
|
v = blaze822_chdr(msg, h);
|
|
|
|
if (v) {
|
2016-07-31 22:04:35 +00:00
|
|
|
if (strcasecmp("date", h) == 0)
|
2016-07-24 21:17:16 +00:00
|
|
|
print_date_header(v);
|
|
|
|
else
|
|
|
|
print_decode_header(h, v);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
|
|
|
if (n) {
|
|
|
|
*n = ':';
|
|
|
|
h = n + 1;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2016-07-11 19:50:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
if (qflag) // no body
|
|
|
|
goto done;
|
|
|
|
|
2016-07-11 19:50:04 +00:00
|
|
|
printf("\n");
|
|
|
|
|
2017-09-06 16:38:42 +00:00
|
|
|
if (rflag) { // raw body
|
2017-03-13 14:50:41 +00:00
|
|
|
print_ascii(blaze822_body(msg), blaze822_bodylen(msg));
|
2016-07-16 20:19:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mimecount = 0;
|
2016-08-02 14:13:25 +00:00
|
|
|
blaze822_walk_mime(msg, 0, render_mime);
|
2016-07-16 20:19:20 +00:00
|
|
|
|
|
|
|
done:
|
2016-07-13 15:18:16 +00:00
|
|
|
blaze822_free(msg);
|
2016-07-11 19:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2017-05-23 13:16:27 +00:00
|
|
|
pid_t pid1 = -1, pid2 = -1;
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
int c;
|
2018-04-17 13:26:19 +00:00
|
|
|
while ((c = getopt(argc, argv, "h:A:BqrtFHLNx:O:Rn")) != -1)
|
2017-08-31 15:30:17 +00:00
|
|
|
switch (c) {
|
2016-07-16 20:19:20 +00:00
|
|
|
case 'h': hflag = optarg; break;
|
2016-07-29 15:07:25 +00:00
|
|
|
case 'A': Aflag = optarg; break;
|
2018-04-17 13:26:19 +00:00
|
|
|
case 'B': Bflag = 1; break;
|
2016-07-16 20:19:20 +00:00
|
|
|
case 'q': qflag = 1; break;
|
|
|
|
case 'r': rflag = 1; break;
|
2017-09-22 13:37:36 +00:00
|
|
|
case 'F': Fflag = 1; break;
|
2016-07-16 20:19:20 +00:00
|
|
|
case 'H': Hflag = 1; break;
|
|
|
|
case 'L': Lflag = 1; break;
|
2017-06-18 15:31:19 +00:00
|
|
|
case 'N': Nflag = 1; break;
|
2016-07-16 20:19:20 +00:00
|
|
|
case 't': tflag = 1; break;
|
|
|
|
case 'x': xflag = optarg; break;
|
|
|
|
case 'O': Oflag = optarg; break;
|
2016-07-20 14:57:40 +00:00
|
|
|
case 'R': Rflag = 1; break;
|
2016-07-18 16:37:14 +00:00
|
|
|
case 'n': nflag = 1; break;
|
2017-01-26 19:27:26 +00:00
|
|
|
default:
|
2016-07-26 19:58:02 +00:00
|
|
|
fprintf(stderr,
|
2017-09-22 13:37:36 +00:00
|
|
|
"Usage: mshow [-h headers] [-A mimetypes] [-nqrFHLN] [msgs...]\n"
|
2017-01-26 19:27:26 +00:00
|
|
|
" mshow -x msg parts...\n"
|
|
|
|
" mshow -O msg parts...\n"
|
|
|
|
" mshow -t msgs...\n"
|
|
|
|
" mshow -R msg\n"
|
2016-07-26 19:58:02 +00:00
|
|
|
);
|
2017-01-26 19:27:26 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-07-16 20:19:20 +00:00
|
|
|
|
2020-03-14 16:30:48 +00:00
|
|
|
if (!rflag && !xflag && !Oflag && !Rflag)
|
2017-03-13 14:50:41 +00:00
|
|
|
safe_output = 1;
|
|
|
|
|
2017-05-23 13:16:27 +00:00
|
|
|
if (safe_output && isatty(1)) {
|
|
|
|
char *pg;
|
|
|
|
pg = getenv("MBLAZE_PAGER");
|
2017-08-17 19:07:46 +00:00
|
|
|
if (!pg) {
|
2017-05-23 13:16:27 +00:00
|
|
|
pg = getenv("PAGER");
|
2017-08-17 19:07:46 +00:00
|
|
|
if (pg && strcmp(pg, "less") == 0) {
|
2019-08-14 18:22:41 +00:00
|
|
|
static char lesscmd[] = "less -RFX";
|
2017-08-17 19:07:46 +00:00
|
|
|
pg = lesscmd;
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 13:16:27 +00:00
|
|
|
if (pg && *pg && strcmp(pg, "cat") != 0) {
|
|
|
|
pid2 = pipeto(pg);
|
|
|
|
if (pid2 < 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"mshow: spawning pager '%s': %s\n",
|
|
|
|
pg, strerror(errno));
|
|
|
|
else if (!getenv("MBLAZE_NOCOLOR"))
|
|
|
|
pid1 = pipeto("mcolor"); // ignore error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:19:20 +00:00
|
|
|
if (xflag) { // extract
|
|
|
|
extract(xflag, argc-optind, argv+optind, 0);
|
|
|
|
} else if (Oflag) { // extract to stdout
|
|
|
|
extract(Oflag, argc-optind, argv+optind, 1);
|
|
|
|
} else if (tflag) { // list
|
2016-07-22 22:18:05 +00:00
|
|
|
if (argc == optind && isatty(0))
|
|
|
|
blaze822_loop1(".", list);
|
|
|
|
else
|
2016-07-22 22:16:40 +00:00
|
|
|
blaze822_loop(argc-optind, argv+optind, list);
|
2016-07-20 14:57:40 +00:00
|
|
|
} else if (Rflag) { // render for reply
|
|
|
|
blaze822_loop(argc-optind, argv+optind, reply);
|
2016-07-16 20:19:20 +00:00
|
|
|
} else { // show
|
2017-09-22 13:37:36 +00:00
|
|
|
if (!(qflag || rflag || Fflag)) {
|
2016-07-20 12:07:59 +00:00
|
|
|
char *f = getenv("MAILFILTER");
|
|
|
|
if (!f)
|
2016-09-01 23:50:20 +00:00
|
|
|
f = blaze822_home_file("filter");
|
2016-07-20 12:07:59 +00:00
|
|
|
if (f)
|
|
|
|
filters = blaze822(f);
|
|
|
|
}
|
2016-07-22 22:18:05 +00:00
|
|
|
if (argc == optind && isatty(0))
|
|
|
|
blaze822_loop1(".", show);
|
|
|
|
else
|
2016-07-20 13:38:35 +00:00
|
|
|
blaze822_loop(argc-optind, argv+optind, show);
|
2016-07-18 16:37:14 +00:00
|
|
|
if (!nflag) // don't set cur
|
|
|
|
blaze822_seq_setcur(newcur);
|
2016-07-16 20:19:20 +00:00
|
|
|
}
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2017-05-23 13:16:27 +00:00
|
|
|
if (pid2 > 0)
|
|
|
|
pipeclose(pid2);
|
|
|
|
if (pid1 > 0)
|
|
|
|
pipeclose(pid1);
|
|
|
|
|
2019-01-02 17:39:19 +00:00
|
|
|
if ((xflag || Oflag) && extractcount < argc-optind) {
|
|
|
|
fprintf(stderr, "mshow: could not extract all attachments\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:50:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|