commit 10c8b6a8d65ae8c91677ec3a532416ab8f594058
parent 717c83de225a97142498c75854e7648369da6597
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 4 Apr 2022 14:59:27 +0000
Allow arguments to be given to the mailer program
While you could make a wrapper script, this is much easier.
Diffstat:
M | pop3.1 | | | 12 | +++++++----- |
M | pop3.c | | | 26 | ++++++++++++-------------- |
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/pop3.1 b/pop3.1
@@ -1,4 +1,4 @@
-.\" $Id: pop3.1,v 1.5 2022/04/04 14:34:09 jacob Exp $
+.\" $Id: pop3.1,v 1.6 2022/04/04 14:59:27 jacob Exp $
.\"
.\" Copyright (c) 2022 Jacob R. Edwards
.\"
@@ -23,10 +23,10 @@
.Sh SYNOPSIS
.Nm
.Op Fl dqstv
-.Op Fl m Ar mailer
.Op Fl p Ar port
.Op Fl u Ar user
.Ar host
+.Op Ar mailer Op arg ...
.Sh DESCRIPTION
The
.Nm
@@ -54,9 +54,6 @@ by default
is used.
.It Fl t
Trace POP3 communication.
-.It Fl m Ar mailer
-Pipe each message through
-.Ar mailer .
.It Fl p Ar port
Connect to
.Ar host
@@ -70,6 +67,11 @@ By default your login name (as returned by
.Xr getlogin 2 )
is used.
.El
+.Pp
+If
+.Ar mailer
+is given, optionally with arguments, each message is piped through
+it.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
diff --git a/pop3.c b/pop3.c
@@ -1,4 +1,4 @@
-/* $Id: pop3.c,v 1.4 2022/04/04 14:34:09 jacob Exp $ */
+/* $Id: pop3.c,v 1.5 2022/04/04 14:59:27 jacob Exp $ */
/*
* Copyright (c) 2022 Jacob R. Edwards
@@ -59,7 +59,7 @@ static int verbose;
static char *port = "110";
static char *user;
static char *host;
-static char *mailer;
+static char **mailer;
struct scanlisting {
char msg[4 + 1]; /* See LISTMAX */
@@ -92,7 +92,7 @@ usage(char *why)
{
if (why)
fprintf(stderr, "%s\n", why);
- fprintf(stderr, "usage: %s [-dqstv] [-m mailer] [-p port] [-u user] host\n",
+ fprintf(stderr, "usage: %s [-dqstv] [-p port] [-u user] host [mailer [arg ...]]\n",
getprogname());
exit(1);
}
@@ -391,7 +391,7 @@ pop_dele(FILE *fp, char *msg)
}
int
-mail(FILE *fp, char *msg, char *mailer)
+mail(FILE *fp, char *msg, char **mailer)
{
int fds[2];
int status;
@@ -408,7 +408,7 @@ mail(FILE *fp, char *msg, char *mailer)
case 0:
if (close(fds[1]) < 0 || dup2(fds[0], 0) < 0)
_exit(127);
- execlp(mailer, mailer, NULL);
+ execvp(*mailer, mailer);
_exit(127);
}
@@ -430,17 +430,17 @@ mail(FILE *fp, char *msg, char *mailer)
}
int
-mbox(FILE *fp, char *msg, char *unused)
+mbox(FILE *fp, char *msg, char **unused)
{
return pop_retr(fp, msg);
}
int
-getmail(FILE *fp, int delete, char *mailer)
+getmail(FILE *fp, int delete, char **mailer)
{
int len, i;
struct scanlisting *listings;
- int (*sendmail)(FILE *, char *, char *);
+ int (*sendmail)(FILE *, char *, char **);
listings = pop_list(fp, &len);
if (listings == NULL)
@@ -496,14 +496,11 @@ main(int argc, char *argv[])
die("pledge");
user = getlogin();
- while ((c = getopt(argc, argv, "dm:p:qstu:v")) >= 0) {
+ while ((c = getopt(argc, argv, "dp:qstu:v")) >= 0) {
switch (c) {
case 'd':
delete = 1;
break;
- case 'm':
- mailer = optarg;
- break;
case 'p':
port = optarg;
break;
@@ -529,12 +526,13 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc > 1)
- usage("Too many arguments");
if (argc < 1)
usage("No host");
host = argv[0];
+ if (argc > 1)
+ mailer = argv + 1;
+
fp = pop_open(host, port);
if (fp == NULL)
die("'%s'", host);