pop3

Tiny pop3 client designed to be tunneled through ssh
git clone git://jacobedwards.org/pop3
Log | Files | Refs

commit 678c3fc4750290caeba9d4c49c99fb8f779ede34
parent 57d78289bb609835e7da65d1b001ea80603949ef
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Sun,  3 Apr 2022 17:55:56 +0000

Add verbose flag

Currently it merely writes gives query's message to the standard
error after getting the mail.

Diffstat:
Mpop3.1 | 4++--
Mpop3.c | 25+++++++++++++++++++------
2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/pop3.1 b/pop3.1 @@ -1,4 +1,4 @@ -.\" $Id: pop3.1,v 1.3 2022/04/03 17:37:27 jacob Exp $ +.\" $Id: pop3.1,v 1.4 2022/04/03 17:55:56 jacob Exp $ .\" .\" Copyright (c) 2022 Jacob R. Edwards .\" @@ -22,7 +22,7 @@ .Nd fetch mail from POP3 server .Sh SYNOPSIS .Nm -.Op Fl kqst +.Op Fl kqstv .Op Fl m Ar mailer .Op Fl p Ar port .Op Fl u Ar user diff --git a/pop3.c b/pop3.c @@ -1,4 +1,4 @@ -/* $Id: pop3.c,v 1.2 2022/04/03 17:37:27 jacob Exp $ */ +/* $Id: pop3.c,v 1.3 2022/04/03 17:55:56 jacob Exp $ */ /* * Copyright (c) 2022 Jacob R. Edwards @@ -53,6 +53,7 @@ static int keep; static int query; static int usestdin; static int trace; +static int verbose; /* Option and argument variables */ static char *port = "110"; @@ -459,12 +460,13 @@ getmail(FILE *fp, int delete, char *mailer) } int -stat(FILE *fp) +stat(FILE *fp, FILE *out) { int msgs, bytes; + if (pop_stat(fp, &msgs, &bytes)) return 1;; - return printf("%d %s %d %s\n", + return fprintf(out, "%d %s %d %s\n", msgs, msgs == 1 ? "message" : "messages", bytes, bytes == 1 ? "byte" : "bytes") < 0; } @@ -494,7 +496,7 @@ main(int argc, char *argv[]) die("pledge"); user = getlogin(); - while ((c = getopt(argc, argv, "km:p:qstu:")) >= 0) { + while ((c = getopt(argc, argv, "km:p:qstu:v")) >= 0) { switch (c) { case 'k': keep = 1; @@ -517,6 +519,9 @@ main(int argc, char *argv[]) case 'u': user = optarg; break; + case 'v': + verbose = 1; + break; default: usage(NULL); } @@ -540,7 +545,15 @@ main(int argc, char *argv[]) if (pledge(mailer ? "stdio proc exec" : "stdio", NULL)) die("pledge"); - if (query ? stat(fp) : getmail(fp, !keep, mailer)) - die("unable to complete transaction"); + if (query) { + if (stat(fp, stdout)) + die("unable to stat"); + } else { + if (getmail(fp, !keep, mailer)) + die("unable to get mail"); + if (verbose && stat(fp, stderr)) + die("unable to stat"); + } + return !pop_quit(fp); }