static int num_maildir_entries = 0;
static int snoop = 0;
-extern char response[];
-
-static long start;
-static long stop;
+typedef struct {
+ FILE *mailout;
+ long written;
+} pop_closure;
-static FILE *pf = NULL;
+extern char response[];
/* This is an attempt to simplify things by putting all the
* privilege ops into macros.
#endif /* not MAILGROUP */
/* these variables have to be globals so that done() can correctly clean up the lockfile */
-static int locked = 0;
+static bool locked;
static char *newmail;
static FILE *in;
/*
* prototypes
*/
+static int maildir_srt(const void *va, const void *vb) PURE;
static void inc_done(int) NORETURN;
-static int pop_action(char *);
+static int pop_action(void *closure, char *);
-int
+static int
maildir_srt(const void *va, const void *vb)
{
const struct Maildir_entry *a = va, *b = vb;
bool noisy;
int width = -1;
int hghnum = 0, msgnum = 0;
+ FILE *pf = NULL;
bool sasl, tls, noverify;
int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */
char *cp, *maildir = NULL, *folder = NULL;
if (*cp == '+' || *cp == '@') {
if (folder)
adios (NULL, "only one folder at a time!");
- else
- folder = pluspath (cp);
+ folder = pluspath (cp);
} else {
adios (NULL, "usage: %s [+folder] [switches]", invo_name);
}
/* Mail from a spool file. */
if (access (newmail, W_OK) != NOTOK) {
- locked++;
+ locked = true;
if (trnflag) {
SIGNAL (SIGHUP, SIG_IGN);
SIGNAL (SIGINT, SIG_IGN);
inform("Creating Receive-Audit: %s", audfile);
if ((aud = fopen (audfile, "a")) == NULL)
adios (audfile, "unable to append to");
- else if (i == NOTOK)
+ if (i == NOTOK)
chmod (audfile, m_gmprot ());
if (from)
if (inc_type == INC_POP) {
/* Mail from a POP server. */
int i;
+ pop_closure pc;
hghnum = msgnum = mp->hghmsg;
for (i = 1; i <= nmsgs; i++) {
if ((pf = fopen (cp, "w+")) == NULL)
adios (cp, "unable to write");
chmod (cp, m_gmprot ());
- start = stop = 0L;
- if (pop_retr (i, pop_action) == NOTOK)
+ pc.written = 0;
+ pc.mailout = pf;
+ if (pop_retr(i, pop_action, &pc) == NOTOK)
adios (NULL, "%s", response);
if (fflush (pf))
fseek (pf, 0L, SEEK_SET);
switch (incerr = scan (pf, msgnum, 0, nfs, width,
msgnum == mp->hghmsg + 1 && chgflag,
- 1, NULL, stop - start, noisy, &scanl)) {
+ 1, NULL, pc.written, noisy, &scanl)) {
case SCNEOF:
printf ("%*d empty\n", DMAXFOLDER, msgnum);
break;
fseek (pf, 0L, SEEK_SET);
switch (incerr = scan (pf, msgnum, 0, nfs, width,
msgnum == mp->hghmsg + 1 && chgflag,
- 1, NULL, stop - start, noisy, &scanl)) {
+ 1, NULL, 0, noisy, &scanl)) {
case SCNEOF:
printf ("%*d empty\n", DMAXFOLDER, msgnum);
break;
}
static int
-pop_action (char *s)
+pop_action(void *closure, char *s)
{
- fprintf (pf, "%s\n", s);
- stop += strlen (s) + 1;
- return 0; /* Is return value used? This was missing before 1999-07-15. */
+ pop_closure *pc;
+ int n;
+
+ pc = closure;
+ n = fprintf(pc->mailout, "%s\n", s);
+ if (n < 0)
+ return NOTOK;
+ pc->written += n; /* Count linefeed too. */
+
+ return OK;
}