Compare commits

..

1 Commits

Author SHA1 Message Date
fe1b5cdbd0
Code cleanup and indentation. 2023-03-03 22:49:48 +01:00
20 changed files with 594 additions and 676 deletions

2
.gitignore vendored
View File

@ -3,6 +3,4 @@ config.h
config.log
config.status
src/*.o
src/*.c~
src/*.h~
src/mboxgrep

View File

@ -13,6 +13,3 @@ GNU/Linux distrubution, for example), please drop me a line about it.
For build instructions, read the file "INSTALL", and run
`./configure --help`.
This project aims to follow the GNU coding style (https://www.gnu.org/prep/standards/html_node/Formatting.html),
at least loosely. The code should be indented with indent -gnu -nut -ppi2.

View File

@ -36,8 +36,7 @@ print_wrap (char *str, int len, int *n)
fprintf (stdout, "\n");
*n = 0;
}
else
fprintf (stdout, " ");
else fprintf (stdout, " ");
}
void
@ -67,8 +66,7 @@ version (void)
#else
# ifdef HAVE_FTW
print_wrap ("HAVE_FTW", 8, &n);
# endif
/* HAVE_FTW */
# endif /* HAVE_FTW */
#endif /* HAVE_FTS_OPEN */
/*
fprintf (stdout, "HAVE_LIBLOCKFILE ");
@ -102,15 +100,15 @@ version (void)
#endif /* HAVE_LIBDMALLOC */
fprintf (stdout, "\n");
exit (0);
exit(0);
}
void
help (void)
{
fprintf (stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n",
fprintf(stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n",
APPNAME, VERSION);
fprintf (stdout,
fprintf(stdout,
"Miscellaneous:\n\n"
" -h, --help\t\t\tThis help screen\n"
" -V, --version\t\tDisplay version, copyright and\n"
@ -128,10 +126,10 @@ help (void)
" -E, --extended-regexp\tPATTERN is an extended regular expression\n"
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
#ifdef HAVE_LIBPCRE
fprintf (stdout,
fprintf(stdout,
" -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n");
#endif /* HAVE_LIBPCRE */
fprintf (stdout,
fprintf(stdout,
" -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n"
" -i, --ignore-case\t\tIgnore case distinctions\n"
" -v, --invert-match\t\tSelect non-matching messages\n\n"
@ -143,27 +141,27 @@ help (void)
" -l, --file-lock=METHOD\tSelect file locking METHOD\n"
"\t\t\t\tMETHOD is");
#ifdef HAVE_FCNTL
fprintf (stdout, " `fcntl',");
fprintf(stdout, " `fcntl',");
#endif /* HAVE_FCNTL */
#ifdef HAVE_FLOCK
fprintf (stdout, " `flock',");
fprintf(stdout, " `flock',");
#endif /* HAVE_FLOCK */
fprintf (stdout, " or `none'\n\n"
fprintf(stdout, " or `none'\n\n"
"Mailbox type selection:\n\n"
" -m, --mailbox-format=TYPE\tSelect mailbox TYPE\n"
"\t\t\t\tTYPE is `mbox', ");
#ifdef HAVE_LIBZ
fprintf (stdout, "`zmbox', ");
fprintf(stdout, "`zmbox', ");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
fprintf (stdout, "`bz2mbox', ");
fprintf(stdout, "`bz2mbox', ");
#endif /* HAVE_LIBBZ2 */
fprintf (stdout,
fprintf(stdout,
"`mh',\n"
"\t\t\t\t`nnml', `nnmh', or `maildir'.\n\n"
"Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR);
exit (0);
exit(0);
}
void

View File

@ -18,7 +18,7 @@
*/
#ifndef INFO_H
# define INFO_H
#define INFO_H
void print_wrap (char *str, int len, int *n);
void version (void);

View File

@ -30,16 +30,13 @@
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#include <stdlib.h>
@ -55,7 +52,7 @@
#include "wrap.h"
#ifdef HAVE_LIBDMALLOC
# include <dmalloc.h>
#include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */
maildir_t *
@ -78,9 +75,9 @@ maildir_open (const char *path)
return NULL;
}
dirname = (char *) xmalloc ((sizeof (char) * (strlen (path) + 5)));
dirname = (char *) xmalloc((sizeof (char) * (strlen (path) + 5)));
mp = (maildir_t *) xmalloc (sizeof (maildir_t));
mp = (maildir_t *) xmalloc(sizeof (maildir_t));
sprintf (dirname, "%s/new", path);
mp->new = m_opendir (dirname);
if (mp->new == NULL)
@ -114,7 +111,7 @@ maildir_open (const char *path)
} /* maildir_open */
message_t *
maildir_read_message (maildir_t * mdp)
maildir_read_message (maildir_t *mdp)
{
int isheaders = 1;
int have_from = 0, have_to = 0, have_message_id = 0, have_sender = 0,
@ -127,7 +124,7 @@ maildir_read_message (maildir_t * mdp)
message = allocate_message ();
for (;;)
for(;;)
{
if (mdp->new != NULL)
{
@ -159,9 +156,8 @@ maildir_read_message (maildir_t * mdp)
continue;
filename =
(char *) xmalloc ((sizeof (char) * ((strlen (d_content->d_name))
+ (strlen (config.boxname)) +
6)));
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
+ (strlen (config.boxname)) + 6)));
/*
filename =
@ -177,7 +173,7 @@ maildir_read_message (maildir_t * mdp)
free (filename);
isheaders = 1;
fp = m_fopen (message->filename, "r");
fp = m_fopen(message->filename, "r");
if (fp == NULL)
continue;
@ -203,12 +199,11 @@ maildir_read_message (maildir_t * mdp)
if (0 == strncasecmp ("Message-ID: ", buffer, 12))
have_message_id = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
message->from = parse_return_path (buffer);
message->from = parse_return_path(buffer);
message->headers =
(char *) xrealloc (message->headers,
((1 + s +
message->hbytes) * sizeof (char)));
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
@ -217,8 +212,7 @@ maildir_read_message (maildir_t * mdp)
{
message->body =
(char *) xrealloc (message->body,
((1 + s +
message->bbytes) * sizeof (char)));
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
@ -226,22 +220,22 @@ maildir_read_message (maildir_t * mdp)
/* if (!have_from || !have_to || !have_message_id) */
if ((!have_from && !have_sender) || !have_date)
if ((!have_from && !have_sender)|| !have_date)
{
if (config.merr)
fprintf (stderr, "%s: %s: Not a RFC 2822 message\n",
fprintf(stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, message->filename);
fclose (fp);
fclose(fp);
continue;
}
fclose (fp);
fclose(fp);
return message;
} /* for */
} /* maildir_read_message */
void
maildir_write_message (message_t * m, const char *path)
maildir_write_message (message_t *m, const char *path)
{
char bla[BUFSIZ], *s1, *s2;
int t;
@ -253,9 +247,9 @@ maildir_write_message (message_t * m, const char *path)
sprintf (bla, "%i.%i_%i.%s",
t, config.pid, runtime.maildir_count, config.hostname);
s1 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char));
sprintf (s1, "%s/tmp/%s", path, bla);
sprintf(s1, "%s/tmp/%s", path, bla);
s2 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char));
sprintf (s2, "%s/new/%s", path, bla);
sprintf(s2, "%s/new/%s", path, bla);
f1 = m_fopen (s1, "w");
fprintf (f1, "%s\n%s", m->headers, m->body);
@ -274,24 +268,18 @@ maildir_check (const char *path)
sprintf (s, "%s/cur", path);
i = stat (s, &fs);
if (-1 == i)
return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
if (-1 == i) return -1;
if (! S_ISDIR (fs.st_mode)) return -1;
sprintf (s, "%s/new", path);
i = stat (s, &fs);
if (-1 == i)
return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
if (-1 == i) return -1;
if (! S_ISDIR (fs.st_mode)) return -1;
sprintf (s, "%s/tmp", path);
sprintf(s, "%s/tmp", path);
i = stat (s, &fs);
if (-1 == i)
return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
if (-1 == i) return -1;
if (! S_ISDIR (fs.st_mode)) return -1;
free (s);
@ -304,24 +292,24 @@ maildir_create (const char *path)
char *s;
int i;
s = (char *) xmalloc ((strlen (path) + 4) * sizeof (char));
s = (char *) xmalloc ((strlen (path) + 4) * sizeof(char));
errno = 0;
for (;;)
{
sprintf (s, "%s", path);
sprintf(s, "%s", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
sprintf (s, "%s/new", path);
sprintf(s, "%s/new", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
sprintf (s, "%s/cur", path);
sprintf(s, "%s/cur", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
sprintf (s, "%s/tmp", path);
sprintf(s, "%s/tmp", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
@ -333,7 +321,7 @@ maildir_create (const char *path)
{
if (config.merr)
{
fprintf (stderr, "%s:%s: ", APPNAME, s);
fprintf(stderr, "%s:%s: ", APPNAME, s);
perror (NULL);
}
}

View File

@ -18,32 +18,28 @@
*/
#ifndef MAILDIR_H
# define MAILDIR_H
#define MAILDIR_H
# include <config.h>
#include <config.h>
# ifdef HAVE_DIRENT_H
#ifdef HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
# else
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif
/* HAVE_DIRENT_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
# include "mboxgrep.h"
#include "mboxgrep.h"
typedef struct
{
@ -54,8 +50,8 @@ typedef struct
maildir_t *maildir_open (const char *path);
int maildir_check (const char *path);
void maildir_create (const char *path);
void maildir_close (maildir_t * mdp);
message_t *maildir_read_message (maildir_t * mdp);
void maildir_write_message (message_t * m, const char *path);
void maildir_close (maildir_t *mdp);
message_t *maildir_read_message (maildir_t *mdp);
void maildir_write_message (message_t *m, const char *path);
#endif /* MAILDIR_H */

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_LIBZ
# include <zlib.h>
#include <zlib.h>
#endif /* HAVE_LIBZ */
#include "getopt.h"
@ -40,7 +40,7 @@
#include "re.h"
#ifdef HAVE_LIBDMALLOC
# include <dmalloc.h>
#include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */
option_t config;
@ -54,7 +54,8 @@ main (int argc, char **argv)
runtime.count = 0;
runtime.maildir_count = 0;
static struct option long_options[] = {
static struct option long_options[] =
{
{"count", 0, 0, 'c'},
{"delete", 0, 0, 'd'},
/* {"date", 1, 0, 'D'}, */
@ -64,7 +65,7 @@ main (int argc, char **argv)
{"help", 0, 0, 'h'},
{"ignore-case", 0, 0, 'i'},
{"mailbox-format", 1, 0, 'm'},
{"no", 1, 0, 'n'},
{"no", 1, 0, 'n' },
{"pipe", 1, 0, 'p'},
{"regexp", 1, 0, 'e'},
{"invert-match", 0, 0, 'v'},
@ -101,7 +102,7 @@ main (int argc, char **argv)
runtime.cs->md5 = (char **) xcalloc (1, sizeof (char **));
runtime.cs->n = 0;
if (optind < argc && !config.haveregex)
if (optind < argc && ! config.haveregex)
{
config.regex_s = xstrdup (argv[optind]);
config.haveregex = 1;
@ -160,7 +161,7 @@ main (int argc, char **argv)
++optind;
}
if (!havemailbox)
if (! havemailbox)
{
config.format = MBOX;
scan_mailbox ("-");

View File

@ -30,13 +30,13 @@
#include <errno.h>
#include <time.h>
#ifdef HAVE_FLOCK
# include <sys/file.h>
#include <sys/file.h>
#endif /* HAVE_FLOCK */
#ifdef HAVE_LIBZ
# include <zlib.h>
#include <zlib.h>
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
# include <bzlib.h>
#include <bzlib.h>
#endif /* HAVE_LIBBZ2 */
#define BUFLEN 16384
@ -46,7 +46,7 @@
#include "wrap.h"
#ifdef HAVE_LIBDMALLOC
# include <dmalloc.h>
#include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */
mbox_t *
@ -193,8 +193,7 @@ mbox_open (const char *path, const char *mode)
fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME);
else
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME,
path);
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path);
}
if (config.format == MBOX)
fclose (mp->fp);
@ -368,7 +367,7 @@ tmpfile_name (const char *path)
void
mbox_write_message (message_t * msg, mbox_t * mbox)
mbox_write_message (message_t *msg, mbox_t *mbox)
{
if (config.format == MBOX)
fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body);
@ -376,7 +375,7 @@ mbox_write_message (message_t * msg, mbox_t * mbox)
else if (config.format == ZMBOX)
{
gzwrite_loop (mbox->fp, msg->headers);
gzwrite (mbox->fp, "\n", 1);
gzwrite(mbox->fp, "\n", 1);
gzwrite_loop (mbox->fp, msg->body);
}
#endif /* HAVE_LIBZ */
@ -403,14 +402,11 @@ tmpfile_mod_own (const int fd, const char *path)
if (stat (path, &s) != -1)
{
if (fchown (fd, s.st_uid, s.st_gid) == -1)
if (config.merr)
perror (config.tmpfilename);
if (config.merr) perror (config.tmpfilename);
if (fchmod (fd, s.st_mode) == -1)
if (config.merr)
perror (config.tmpfilename);
if (config.merr) perror (config.tmpfilename);
}
else if (config.merr)
perror (path);
else if (config.merr) perror (path);
}
}

View File

@ -18,11 +18,11 @@
*/
#ifndef MBOX_H
# define MBOX_H 1
#define MBOX_H 1
# include <config.h>
#include <config.h>
# include "message.h"
#include "message.h"
typedef struct
{
@ -39,6 +39,6 @@ void tmpfile_mod_own (const int fd, const char *path);
int tmpfile_create (void);
void mbox_close (mbox_t * mbp);
message_t *mbox_read_message (mbox_t * mp);
void mbox_write_message (message_t * m, mbox_t * mbox);
void mbox_write_message (message_t *m, mbox_t *mbox);
#endif /* MBOX_H */

View File

@ -18,9 +18,9 @@
*/
#ifndef MESSAGE_H
# define MESSAGE_H 1
#define MESSAGE_H 1
# include <config.h>
#include <config.h>
typedef struct
{

View File

@ -29,16 +29,13 @@
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#include <sys/types.h>
@ -57,8 +54,7 @@
extern option_t config;
DIR *
mh_open (const char *path)
DIR *mh_open (const char *path)
{
DIR *dp;
@ -76,14 +72,12 @@ mh_open (const char *path)
return dp;
} /* mh_open */
void
mh_close (DIR * dp)
void mh_close (DIR *dp)
{
closedir (dp);
} /* mh_close */
message_t *
mh_read_message (DIR * dp)
message_t *mh_read_message (DIR *dp)
{
int isheaders = 1;
int have_from = 0, have_date = 0, have_sender = 0;
@ -97,11 +91,10 @@ mh_read_message (DIR * dp)
filename = NULL;
for (;;)
for(;;)
{
d_content = readdir (dp);
if (d_content == NULL)
return NULL;
d_content = readdir(dp);
if (d_content == NULL) return NULL;
if (d_content->d_name[0] == '.')
continue;
@ -168,8 +161,7 @@ mh_read_message (DIR * dp)
message->headers =
(char *) realloc (message->headers,
((1 + s +
message->hbytes) * sizeof (char)));
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
@ -177,14 +169,13 @@ mh_read_message (DIR * dp)
{
message->body =
(char *) realloc (message->body,
((1 + s +
message->bbytes) * sizeof (char)));
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
} /* while */
if ((!have_from && !have_sender) || !have_date)
if ((!have_from && !have_sender)|| !have_date)
{
if (config.merr)
fprintf (stderr, "%s: %s: Not a RFC 2822 message\n",
@ -210,14 +201,12 @@ mh_read_message (DIR * dp)
} /* for */
} /* mh_read_message */
void
mh_write_message (message_t * m, const char *path)
void mh_write_message (message_t *m, const char *path)
{
struct dirent *dc;
int x, y = 0;
char s1[BUFSIZ];
DIR *d;
FILE *f;
DIR *d; FILE *f;
d = m_opendir (path);
rewinddir (d);

View File

@ -18,33 +18,29 @@
*/
#ifndef MH_H
# define MH_H 1
#define MH_H 1
# include <config.h>
#include <config.h>
# ifdef HAVE_DIRENT_H
#ifdef HAVE_DIRENT_H
# include <dirent.h>
# else
#else
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif
/* HAVE_DIRENT_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
# include "mboxgrep.h"
#include "mboxgrep.h"
DIR *mh_open (const char *path);
void mh_close (DIR * dp);
message_t *mh_read_message (DIR * dp);
void mh_write_message (message_t * m, const char *path);
void mh_close (DIR *dp);
message_t *mh_read_message (DIR *dp);
void mh_write_message (message_t *m, const char *path);
#endif /* MH_H */

View File

@ -68,8 +68,7 @@ folder_format (const char *name)
return f;
}
lockmethod_t
lock_method (const char *name)
lockmethod_t lock_method (const char *name)
{
lockmethod_t l;
@ -123,19 +122,17 @@ time_t parse_date(char *datestr)
}
*/
char *
parse_return_path (char *rpath)
char * parse_return_path(char *rpath)
{
char *blah1, blah2[BUFSIZ];
sscanf (rpath, "Return-Path: <%[^\r\n>]>", blah2);
sscanf(rpath, "Return-Path: <%[^\r\n>]>", blah2);
blah1 = xstrdup (blah2);
return blah1;
}
void *
allocate_message (void)
void * allocate_message (void)
{
message_t *message;
@ -154,8 +151,7 @@ allocate_message (void)
return message;
}
void
postmark_print (message_t * msg)
void postmark_print (message_t *msg)
{
time_t tt;
struct tm *ct;
@ -204,7 +200,7 @@ get_runtime_options (int *argc, char **argv, struct option *long_options)
switch (c)
{
case '?':
usage ();
usage();
case 'c':
config.action = COUNT;
break;
@ -230,10 +226,10 @@ get_runtime_options (int *argc, char **argv, struct option *long_options)
config.extended = 0;
config.perl = 1;
#else
fprintf (stderr,
fprintf(stderr,
"%s: Support for Perl regular expressions not "
"compiled in\n", APPNAME);
exit (2);
exit(2);
#endif /* HAVE_LIBPCRE */
break;
case 'h':
@ -292,9 +288,9 @@ get_runtime_options (int *argc, char **argv, struct option *long_options)
config.lock = 0;
break;
default:
fprintf (stderr, "%s: invalid option -- n%c\n",
fprintf(stderr, "%s: invalid option -- n%c\n",
APPNAME, optarg[0]);
exit (2);
exit(2);
}
}
} /* switch */

View File

@ -18,21 +18,20 @@
*/
#ifndef MISC_H
# define MISC_H 1
#define MISC_H 1
# include "mboxgrep.h"
# include "getopt.h"
# include "message.h"
#include "mboxgrep.h"
#include "getopt.h"
#include "message.h"
/* #include <time.h> */
format_t folder_format (const char *name);
lockmethod_t lock_method (const char *name);
/* time_t parse_date(char *datestr); */
char *parse_return_path (char *rpath);
void *allocate_message (void);
void postmark_print (message_t * msg);
char * parse_return_path(char *rpath);
void * allocate_message (void);
void postmark_print (message_t *msg);
void set_default_options (void);
void get_runtime_options (int *argc, char **argv,
struct option *long_options);
void get_runtime_options (int *argc, char **argv, struct option *long_options);
#endif /* MISC_H */

View File

@ -22,7 +22,7 @@
#include <string.h>
#include <regex.h>
#ifdef HAVE_LIBPCRE
# include <pcre.h>
#include <pcre.h>
#endif /* HAVE_LIBPCRE */
#include "mboxgrep.h"
#include "message.h"
@ -42,13 +42,14 @@ pcre_init (void)
if (config.pcre_pattern == NULL)
{
if (config.merr)
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, error);
exit (2);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
error);
exit(2);
}
}
void
pcre_match (message_t * msg)
pcre_match (message_t *msg)
{
int of[BUFSIZ];
@ -56,12 +57,14 @@ pcre_match (message_t * msg)
config.res1 =
pcre_exec ((pcre *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints,
msg->headers, (int) strlen (msg->headers), 0, 0, of, BUFSIZ);
msg->headers,
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
if (config.body)
config.res2 =
pcre_exec ((pcre *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints,
msg->body, (int) strlen (msg->body), 0, 0, of, BUFSIZ);
msg->body,
(int) strlen (msg->body), 0, 0, of, BUFSIZ);
config.res1 = config.res1 ^ 1;
config.res2 = config.res2 ^ 1;
@ -82,13 +85,12 @@ regex_init (void)
config.posix_pattern = (regex_t *) xmalloc (sizeof (regex_t));
errcode = regcomp ((regex_t *) config.posix_pattern, config.regex_s,
(flag1 | flag2 | REG_NEWLINE));
(flag1 | flag2 | REG_NEWLINE ));
if (0 != errcode)
{
if (config.merr)
{
regerror (errcode, (regex_t *) config.posix_pattern, errbuf,
BUFSIZ);
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf);
}
exit (2);
@ -96,7 +98,7 @@ regex_init (void)
}
void
regex_match (message_t * msg)
regex_match (message_t *msg)
{
if (config.headers)
config.res1 = regexec ((regex_t *) config.posix_pattern,

View File

@ -21,7 +21,7 @@
#ifdef HAVE_LIBPCRE
void pcre_init (void);
void pcre_match (message_t * msg);
void pcre_match (message_t *msg);
#endif /* HAVE_LIBPCRE */
void regex_init (void);
void regex_match (message_t * msg);
void regex_match (message_t *msg);

View File

@ -32,16 +32,13 @@
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#include <time.h>
@ -64,16 +61,14 @@
#else
# ifdef HAVE_FTW
# include <ftw.h>
# endif
/* HAVE_FTW */
# endif /* HAVE_FTW */
#endif /* HAVE_FTS_OPEN */
#ifdef HAVE_LIBDMALLOC
# include <dmalloc.h>
#include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */
void
scan_mailbox (char path[])
void scan_mailbox (char path[])
{
static FILE *outf;
static mbox_t *mbox, *out;
@ -104,19 +99,17 @@ scan_mailbox (char path[])
if (config.action == DELETE)
delete = 1;
if ((config.format == MBOX) || (config.format == ZMBOX)
|| (config.format == BZ2MBOX))
if ((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX))
{
mbox = (mbox_t *) mbox_open (path, "r");
if (mbox == NULL)
return;
if (mbox == NULL) return;
}
else if ((config.format == MH) || (config.format == NNMH)
|| (config.format == NNML))
else if ((config.format == MH) || (config.format == NNMH) ||
(config.format == NNML))
{
boxd = mh_open (path);
if (boxd == NULL)
return;
if (boxd == NULL) return;
}
else if (config.format == MAILDIR)
{
@ -131,20 +124,18 @@ scan_mailbox (char path[])
config.res1 = 1;
config.res2 = 1;
if ((config.format == MBOX) || (config.format == ZMBOX)
|| (config.format == BZ2MBOX))
if ((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX))
msg = (message_t *) mbox_read_message (mbox);
else if ((config.format == MH) || (config.format == NNMH)
|| (config.format == NNML))
else if ((config.format == MH) || (config.format == NNMH) ||
(config.format == NNML))
msg = (message_t *) mh_read_message (boxd);
else if (config.format == MAILDIR)
msg = (message_t *) maildir_read_message (maildird);
if (msg == NULL)
break;
if (msg == NULL) break;
if (msg->from == NULL)
msg->from = (char *) xstrdup ("nobody");
if (msg->from == NULL) msg->from = (char *) xstrdup ("nobody");
#ifdef HAVE_LIBPCRE
if (config.perl)
@ -173,11 +164,11 @@ scan_mailbox (char path[])
{
if (config.format == MAILDIR)
maildir_write_message (msg, config.outboxname);
else if (config.format == MH || config.format == NNMH
|| config.format == NNML)
else if (config.format == MH || config.format == NNMH ||
config.format == NNML)
mh_write_message (msg, config.outboxname);
else if ((config.format == MBOX) || (config.format == ZMBOX)
|| (config.format == BZ2MBOX))
else if ((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX))
{
out = mbox_open (config.outboxname, "w");
/* fprintf (out->fp, "%s\n%s", msg->headers, msg->body); */
@ -203,33 +194,30 @@ scan_mailbox (char path[])
else if (config.action == COUNT)
runtime.count++;
else if (config.action == DELETE &&
((config.format == MBOX) || (config.format == ZMBOX)
|| (config.format == BZ2MBOX)))
((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX)))
mbox_write_message (msg, runtime.tmp_mbox);
}
else
if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert)
&& delete) && ((config.format == MH) || (config.format == NNMH)
|| (config.format == NNML)
|| (config.format == MAILDIR)))
m_unlink (msg->filename);
else if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert) && delete) &&
((config.format == MH) || (config.format == NNMH) ||
(config.format == NNML) || (config.format == MAILDIR)))
m_unlink(msg->filename);
free (msg->body);
free (msg->headers);
free (msg);
free(msg->body);
free(msg->headers);
free(msg);
} /* for */
if ((config.format == MBOX) || (config.format == ZMBOX)
|| (config.format == BZ2MBOX))
if ((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX))
mbox_close (mbox);
else if ((config.format == MH) || (config.format == NNMH)
|| (config.format == NNML))
mh_close (boxd);
else if ((config.format == MH) || (config.format == NNMH) ||
(config.format == NNML))
mh_close(boxd);
}
void
recursive_scan (char path[])
void recursive_scan (char path[])
{
#ifdef HAVE_FTS_OPEN
FTS *ftsfoo;
@ -248,7 +236,7 @@ recursive_scan (char path[])
if (ftsfoo == NULL)
{
/* fixme (?) */
perror (APPNAME);
perror(APPNAME);
exit (2);
}
@ -262,8 +250,7 @@ recursive_scan (char path[])
#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;
char b[16];
@ -274,18 +261,17 @@ md5_check_message (char *body, checksum_t * chksum)
if (body == NULL)
md5_process_bytes ("", 0, &a);
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++)
{
if (0 == strncmp ((char *) chksum->md5[i], b, 16))
if (0 == strncmp ((char *)chksum->md5[i], b, 16))
return 1;
}
chksum->md5 =
(char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
chksum->md5 = (char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
chksum->md5[chksum->n] = xstrdup (b);

View File

@ -18,12 +18,12 @@
*/
#ifndef SCAN_H
# define SCAN_H 1
#define SCAN_H 1
# include "mboxgrep.h"
#include "mboxgrep.h"
void scan_mailbox (char path[]);
void recursive_scan (char path[]);
int md5_check_message (char *body, checksum_t * chksum);
int md5_check_message (char *body, checksum_t *chksum);
#endif /* SCAN_H */

View File

@ -31,22 +31,19 @@
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#ifdef HAVE_LIBZ
# include <zlib.h>
#include <zlib.h>
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
# include <bzlib.h>
#include <bzlib.h>
#endif /* HAVE_LIBBZ2 */
#include <sys/types.h>
@ -57,13 +54,12 @@
#include "mboxgrep.h"
#ifndef APPNAME
# define APPNAME "mboxgrep"
#define APPNAME "mboxgrep"
#endif
#define BUFLEN 16384
int
m_open (const char *pathname, int flags, mode_t mode)
int m_open (const char *pathname, int flags, mode_t mode)
{
int blah;
@ -82,8 +78,7 @@ m_open (const char *pathname, int flags, mode_t mode)
return blah;
}
FILE *
m_fopen (const char *path, const char *mode)
FILE *m_fopen (const char *path, const char *mode)
{
FILE *blah;
@ -101,8 +96,7 @@ m_fopen (const char *path, const char *mode)
return blah;
}
FILE *
m_fdopen (int fildes, const char *mode)
FILE *m_fdopen (int fildes, const char *mode)
{
FILE *blah;
@ -117,8 +111,7 @@ m_fdopen (int fildes, const char *mode)
#ifdef HAVE_LIBZ
gzFile
m_gzdopen (int fildes, const char *mode)
gzFile m_gzdopen (int fildes, const char *mode)
{
gzFile blah;
@ -133,8 +126,7 @@ m_gzdopen (int fildes, const char *mode)
#endif /* HAVE_LIBZ */
DIR *
m_opendir (const char *name)
DIR *m_opendir (const char *name)
{
DIR *blah;
@ -152,8 +144,7 @@ m_opendir (const char *name)
#ifndef HAVE_LIBDMALLOC
void *
xmalloc (size_t size)
void *xmalloc (size_t size)
{
void *foo;
@ -167,8 +158,7 @@ xmalloc (size_t size)
return foo;
}
void *
xrealloc (void *ptr, size_t size)
void *xrealloc (void *ptr, size_t size)
{
void *foo;
@ -182,8 +172,7 @@ xrealloc (void *ptr, size_t size)
return foo;
}
void *
xcalloc (size_t nmemb, size_t size)
void *xcalloc (size_t nmemb, size_t size)
{
void *foo;
@ -197,8 +186,7 @@ xcalloc (size_t nmemb, size_t size)
return foo;
}
char *
xstrdup (const char *s)
char *xstrdup (const char *s)
{
char *foo;
@ -214,8 +202,7 @@ xstrdup (const char *s)
#endif /* HAVE_LIBDMALLOC */
int
m_unlink (const char *pathname)
int m_unlink (const char *pathname)
{
int baz;
@ -233,8 +220,7 @@ m_unlink (const char *pathname)
#ifdef HAVE_LIBZ
void
gzwrite_loop (void *fp, char *str)
void gzwrite_loop (void *fp, char *str)
{
int quux, len, baz;
@ -242,7 +228,7 @@ gzwrite_loop (void *fp, char *str)
baz = strlen (str);
for (;;)
{
len = gzwrite (fp, (str + quux),
len = gzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len;
if (quux == baz)
@ -254,8 +240,7 @@ gzwrite_loop (void *fp, char *str)
#ifdef HAVE_LIBBZ2
void
bzwrite_loop (void *fp, char *str)
void bzwrite_loop (void *fp, char *str)
{
int quux, len, baz;
@ -263,7 +248,7 @@ bzwrite_loop (void *fp, char *str)
baz = strlen (str);
for (;;)
{
len = BZ2_bzwrite (fp, (str + quux),
len = BZ2_bzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len;
if (quux == baz)

View File

@ -22,64 +22,55 @@
/* wrappers around certain std functions */
#ifndef WRAP_H
# define WRAP_H
#define WRAP_H
# include <config.h>
# include <stdio.h>
# include <sys/types.h>
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
# ifdef HAVE_DIRENT_H
#ifdef HAVE_DIRENT_H
# include <dirent.h>
# else
#else
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
/* HAVE_SYS_NDIR_H */
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
/* HAVE_SYS_DIR_H */
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif
/* HAVE_DIRENT_H */
# ifdef HAVE_LIBZ
# include <zlib.h>
# endif
/* HAVE_LIBZ */
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif /* HAVE_LIBZ */
# include <stdlib.h>
#include <stdlib.h>
# ifdef HAVE_LIBDMALLOC
#ifdef HAVE_LIBDMALLOC
# include <dmalloc.h>
# endif
/* HAVE_LIBDMALLOC */
#endif /* HAVE_LIBDMALLOC */
int m_open (const char *pathname, int flags, mode_t mode);
FILE *m_fopen (const char *path, const char *mode);
FILE *m_fdopen (int fildes, const char *mode);
# ifdef HAVE_LIBZ
#ifdef HAVE_LIBZ
gzFile m_gzdopen (int fildes, const char *mode);
void gzwrite_loop (void *fp, char *str);
# endif
/* HAVE_LIBZ */
# ifdef HAVE_LIBBZ2
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
void bzwrite_loop (void *fp, char *str);
# endif
/* HAVE_LIBBZ2 */
#endif /* HAVE_LIBBZ2 */
DIR *m_opendir (const char *name);
# ifndef HAVE_LIBDMALLOC
#ifndef HAVE_LIBDMALLOC
void *xmalloc (size_t size);
void *xrealloc (void *ptr, size_t size);
void *xcalloc (size_t nmemb, size_t size);
char *xstrdup (const char *s);
# endif
/* HAVE_LIBDMALLOC */
#endif /* HAVE_LIBDMALLOC */
int m_unlink (const char *pathname);