Code cleanup and indentation.

This commit is contained in:
Daniel Spiljar 2023-03-03 22:49:48 +01:00
parent 882a38f908
commit fe1b5cdbd0
Signed by: dspiljar
GPG Key ID: A32CE9C59D8003B5

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar Copyright (C) 2000 - 2004, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: scan.c,v 1.32 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h> #include <config.h>
@ -70,7 +69,6 @@
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
void scan_mailbox (char path[]) void scan_mailbox (char path[])
/* {{{ */
{ {
static FILE *outf; static FILE *outf;
static mbox_t *mbox, *out; static mbox_t *mbox, *out;
@ -85,7 +83,8 @@ void scan_mailbox (char path[])
foo = opendir (config.outboxname); /* do NOT change this to m_opendir! */ foo = opendir (config.outboxname); /* do NOT change this to m_opendir! */
if (foo == NULL && errno == ENOENT) if (foo == NULL && errno == ENOENT)
maildir_create (config.outboxname); maildir_create (config.outboxname);
else closedir (foo); else
closedir (foo);
if (-1 == maildir_check (config.outboxname)) if (-1 == maildir_check (config.outboxname))
{ {
@ -115,7 +114,9 @@ void scan_mailbox (char path[])
else if (config.format == MAILDIR) else if (config.format == MAILDIR)
{ {
maildird = maildir_open (path); maildird = maildir_open (path);
if (maildird == NULL) return;
if (maildird == NULL)
return;
} }
for (;;) for (;;)
@ -156,6 +157,7 @@ void scan_mailbox (char path[])
&& config.format != BZ2MBOX && config.format != BZ2MBOX
&& 0 != strncmp ("From ", msg->headers, 5)) && 0 != strncmp ("From ", msg->headers, 5))
postmark_print (msg); postmark_print (msg);
fprintf (stdout, "%s\n%s", msg->headers, msg->body); fprintf (stdout, "%s\n%s", msg->headers, msg->body);
} }
else if (config.action == WRITE) else if (config.action == WRITE)
@ -197,8 +199,7 @@ void scan_mailbox (char path[])
mbox_write_message (msg, runtime.tmp_mbox); mbox_write_message (msg, runtime.tmp_mbox);
} }
else if (((((config.res1 == 0) | (config.res2 == 0)) ^ else if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert) && delete) &&
config.invert) && delete) &&
((config.format == MH) || (config.format == NNMH) || ((config.format == MH) || (config.format == NNMH) ||
(config.format == NNML) || (config.format == MAILDIR))) (config.format == NNML) || (config.format == MAILDIR)))
m_unlink(msg->filename); m_unlink(msg->filename);
@ -207,6 +208,7 @@ void scan_mailbox (char path[])
free(msg->headers); free(msg->headers);
free(msg); free(msg);
} /* for */ } /* for */
if ((config.format == MBOX) || (config.format == ZMBOX) || if ((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX)) (config.format == BZ2MBOX))
mbox_close (mbox); mbox_close (mbox);
@ -214,11 +216,8 @@ void scan_mailbox (char path[])
(config.format == NNML)) (config.format == NNML))
mh_close(boxd); mh_close(boxd);
} }
/* }}} */
void recursive_scan (char path[]) void recursive_scan (char path[])
/* {{{ */
{ {
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
FTS *ftsfoo; FTS *ftsfoo;
@ -251,20 +250,19 @@ void recursive_scan (char path[])
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
} }
/* }}} */
int md5_check_message (char *body, checksum_t *chksum) int md5_check_message (char *body, checksum_t *chksum)
/* {{{ */
{ {
struct md5_ctx a; struct md5_ctx a;
char b[16]; char b[16];
int i; int i;
md5_init_ctx (&a); md5_init_ctx (&a);
if (body == NULL) if (body == NULL)
md5_process_bytes ("", 0, &a); md5_process_bytes ("", 0, &a);
else else
md5_process_bytes (body, strlen(body), &a); md5_process_bytes (body, strlen(body), &a);
md5_finish_ctx(&a, b); md5_finish_ctx(&a, b);
for (i = 0; i < chksum->n; i++) for (i = 0; i < chksum->n; i++)
@ -273,12 +271,11 @@ int md5_check_message (char *body, checksum_t *chksum)
return 1; return 1;
} }
chksum->md5 = chksum->md5 = (char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
(char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
chksum->md5[chksum->n] = xstrdup (b); chksum->md5[chksum->n] = xstrdup (b);
(chksum->n)++; (chksum->n)++;
return 0; return 0;
} }
/* }}} */