Compare commits

..

2 Commits

15 changed files with 342 additions and 380 deletions

View File

@ -28,7 +28,6 @@
void
print_wrap (char *str, int len, int *n)
/* {{{ */
{
*n += len;
fprintf (stdout, str);
@ -39,11 +38,9 @@ print_wrap (char *str, int len, int *n)
}
else fprintf (stdout, " ");
}
/* }}} */
void
version (void)
/* {{{ */
{
int n = 0;
@ -93,13 +90,12 @@ version (void)
print_wrap ("HAVE_SYS_NDIR_H", 15, &n);
#endif
fprintf (stdout, "\n");
exit(0);
}
/* }}} */
void
help (void)
/* {{{ */
{
fprintf(stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n",
APPNAME, VERSION);
@ -157,15 +153,12 @@ help (void)
exit(0);
}
/* }}} */
void
usage (void)
/* {{{ */
{
printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n"
"Try `%s --help' for more information.\n", APPNAME, APPNAME);
exit (2);
}
/* }}} */

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: info.h,v 1.5 2003-04-13 19:15:58 dspiljar Exp $ */
*/
#ifndef INFO_H
#define INFO_H

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: maildir.c,v 1.25 2006-10-19 01:53:43 dspiljar Exp $ */
*/
#include <config.h>
@ -84,10 +83,10 @@ maildir_open (const char *path)
if (mp->new == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL);
}
free (dirname);
errno = 0;
return NULL;
@ -98,10 +97,10 @@ maildir_open (const char *path)
if (mp->cur == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL);
}
free (dirname);
errno = 0;
return NULL;
@ -128,37 +127,37 @@ maildir_read_message (maildir_t *mdp)
for(;;)
{
if (mdp->new != NULL)
{
d_content = readdir (mdp->new);
if (d_content == NULL)
{
closedir (mdp->new);
mdp->new = NULL;
}
}
{
d_content = readdir (mdp->new);
if (d_content == NULL)
{
closedir (mdp->new);
mdp->new = NULL;
}
}
if (mdp->new == NULL && mdp->cur != NULL)
{
d_content = readdir (mdp->cur);
if (d_content == NULL)
{
closedir (mdp->cur);
mdp->cur = NULL;
}
}
{
d_content = readdir (mdp->cur);
if (d_content == NULL)
{
closedir (mdp->cur);
mdp->cur = NULL;
}
}
if (mdp->new == NULL && mdp->cur == NULL)
{
free (message->headers);
free (message->body);
free (message);
return NULL;
}
{
free (message->headers);
free (message->body);
free (message);
return NULL;
}
if (d_content->d_name[0] == '.')
continue;
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 =
@ -166,9 +165,10 @@ maildir_read_message (maildir_t *mdp)
+ (strlen(config.boxname)) + 2)));
*/
if (mdp->new != NULL)
sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name);
sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name);
else
sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name);
sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name);
message->filename = (char *) xstrdup (filename);
free (filename);
@ -176,55 +176,58 @@ maildir_read_message (maildir_t *mdp)
fp = m_fopen(message->filename, "r");
if (fp == NULL)
continue;
continue;
while (fgets (buffer, BUFSIZ, fp) != NULL)
{
s = strlen (buffer);
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
{
isheaders = 0;
continue;
} /* if */
if (isheaders)
{
if (0 == strncasecmp ("From: ", buffer, 6))
have_from = 1;
if (0 == strncasecmp ("Sender: ", buffer, 8))
have_sender = 1;
if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1;
if (0 == strncasecmp ("To: ", buffer, 4))
have_to = 1;
if (0 == strncasecmp ("Message-ID: ", buffer, 12))
have_message_id = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
message->from = parse_return_path(buffer);
{
s = strlen (buffer);
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
{
isheaders = 0;
continue;
} /* if */
if (isheaders)
{
if (0 == strncasecmp ("From: ", buffer, 6))
have_from = 1;
if (0 == strncasecmp ("Sender: ", buffer, 8))
have_sender = 1;
if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1;
if (0 == strncasecmp ("To: ", buffer, 4))
have_to = 1;
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->headers =
(char *) xrealloc (message->headers,
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
else
{
message->body =
(char *) xrealloc (message->body,
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
} /* while */
message->headers =
(char *) xrealloc (message->headers,
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
else
{
message->body =
(char *) xrealloc (message->body,
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
} /* while */
/* if (!have_from || !have_to || !have_message_id) */
if ((!have_from && !have_sender)|| !have_date)
{
if (config.merr)
fprintf(stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, message->filename);
fclose(fp);
continue;
}
{
if (config.merr)
fprintf(stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, message->filename);
fclose(fp);
continue;
}
fclose(fp);
return message;
@ -297,19 +300,19 @@ maildir_create (const char *path)
sprintf(s, "%s", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
break;
sprintf(s, "%s/new", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
break;
sprintf(s, "%s/cur", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
break;
sprintf(s, "%s/tmp", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
break;
break;
}
@ -317,9 +320,9 @@ maildir_create (const char *path)
if (errno != 0)
{
if (config.merr)
{
fprintf(stderr, "%s:%s: ", APPNAME, s);
perror (NULL);
}
{
fprintf(stderr, "%s:%s: ", APPNAME, s);
perror (NULL);
}
}
}

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: maildir.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
*/
#ifndef MAILDIR_H
#define MAILDIR_H

View File

@ -15,7 +15,6 @@
You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>

View File

@ -1,4 +1,4 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mbox.c,v 1.34 2006-10-22 23:34:49 dspiljar Exp $ */
*/
#include <config.h>
@ -52,7 +51,6 @@
mbox_t *
mbox_open (const char *path, const char *mode)
/* {{{ */
{
mbox_t *mp;
static int fd;
@ -69,155 +67,153 @@ mbox_open (const char *path, const char *mode)
else
{
if (mode[0] == 'r')
fd = m_open (path, O_RDONLY, 0);
fd = m_open (path, O_RDONLY, 0);
else if (mode[0] == 'w')
fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND),
fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND),
(S_IWUSR | S_IRUSR));
else
{
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
"get this error...", APPNAME, mode[0]);
exit (2);
}
{
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
"get this error...", APPNAME, mode[0]);
exit (2);
}
if (fd == -1)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
return NULL;
}
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
return NULL;
}
if (config.lock)
{
{
#ifdef HAVE_FLOCK
int op;
int op;
if (mode[0] == 'r')
op = LOCK_SH;
else
op = LOCK_EX;
if (-1 == flock (fd, op))
if (mode[0] == 'r')
op = LOCK_SH;
else
op = LOCK_EX;
if (-1 == flock (fd, op))
#else
memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET;
if (mode[0] == 'r')
lck.l_type = F_RDLCK;
else
lck.l_type = F_WRLCK;
memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET;
if (mode[0] == 'r')
lck.l_type = F_RDLCK;
else
lck.l_type = F_WRLCK;
if (-1 == fcntl (fd, F_SETLK, &lck))
if (-1 == fcntl (fd, F_SETLK, &lck))
#endif /* HAVE_FLOCK */
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
}
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
}
if (mode[0] == 'r')
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "r");
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "r");
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "rb");
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "rb");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb");
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb");
#endif /* HAVE_LIBBZ2 */
}
}
else if (mode[0] == 'w')
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "w");
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "w");
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "wb");
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "wb");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb");
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb");
#endif /* HAVE_LIBBZ2 */
}
}
if (mp->fp == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
}
if (mode[0] == 'r')
{
if (config.format == MBOX)
fgets (buffer, BUFSIZ, mp->fp);
fgets (buffer, BUFSIZ, mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
gzgets (mp->fp, buffer, BUFSIZ);
gzgets (mp->fp, buffer, BUFSIZ);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
{
char c[1] = "\0";
int n = 0;
{
char c[1] = "\0";
int n = 0;
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
}
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
}
#endif /* HAVE_LIBBZ2 */
if (0 != strncmp ("From ", buffer, 5))
{
if (config.merr)
{
if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME);
else
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path);
}
if (config.format == MBOX)
fclose (mp->fp);
{
if (config.merr)
{
if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME);
else
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path);
}
if (config.format == MBOX)
fclose (mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
gzclose (mp->fp);
else if (config.format == ZMBOX)
gzclose (mp->fp);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
BZ2_bzclose (mp->fp);
else if (config.format == BZ2MBOX)
BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */
return NULL;
}
return NULL;
}
strcpy (mp->postmark_cache, buffer);
}
return mp;
}
/* }}} */
void
mbox_close (mbox_t * mp)
/* {{{ */
{
if (config.format == MBOX)
fclose (mp->fp);
@ -233,12 +229,9 @@ mbox_close (mbox_t * mp)
free (mp->postmark_cache);
free (mp);
}
/* }}} */
message_t *
mbox_read_message (mbox_t * mp)
/* {{{ */
{
int isheaders = 1, s;
char buffer[BUFSIZ];
@ -256,93 +249,89 @@ mbox_read_message (mbox_t * mp)
for (;;)
{
if (config.format == MBOX)
{
if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
{
if (isheaders)
return NULL;
else
return message;
}
}
{
if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
{
if (isheaders)
return NULL;
else
return message;
}
}
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
{
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
{
if (isheaders)
return NULL;
else
return message;
}
}
{
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
{
if (isheaders)
return NULL;
else
return message;
}
}
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
{
char c[1] = "\0";
int n = 0;
{
char c[1] = "\0";
int n = 0;
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
if (buffer[0] == '\0')
{
if (isheaders)
return NULL;
else
return message;
}
}
if (buffer[0] == '\0')
{
if (isheaders)
return NULL;
else
return message;
}
}
#endif /* HAVE_LIBBZ2 */
s = strlen (buffer);
if (buffer[0] == '\n' && isheaders == 1)
{
isheaders = 0;
continue;
}
{
isheaders = 0;
continue;
}
if (isheaders)
{
message->headers =
(char *) realloc (message->headers,
{
message->headers =
(char *) realloc (message->headers,
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
}
else
{
if (0 == strncmp (buffer, "From ", 5))
{
strcpy (mp->postmark_cache, buffer);
return message;
}
message->body =
(char *) realloc (message->body,
{
if (0 == strncmp (buffer, "From ", 5))
{
strcpy (mp->postmark_cache, buffer);
return message;
}
message->body =
(char *) realloc (message->body,
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
}
} /* for */
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
}
}
return NULL;
}
/* }}} */
void
tmpmbox_create (const char *path)
/* {{{ */
{
int foo;
@ -351,11 +340,9 @@ tmpmbox_create (const char *path)
tmpfile_mod_own (foo, path);
}
/* }}} */
void
tmpfile_name (const char *path)
/* {{{ */
{
char *fname, *tmpdir;
@ -363,7 +350,7 @@ tmpfile_name (const char *path)
{
tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL)
tmpdir = xstrdup ("/tmp");
tmpdir = xstrdup ("/tmp");
fname = xstrdup ("/mboxgrepXXXXXX");
}
else
@ -377,13 +364,10 @@ tmpfile_name (const char *path)
* sizeof (char));
sprintf (config.tmpfilename, "%s%s", tmpdir, fname);
}
/* }}} */
void
mbox_write_message (message_t *msg, mbox_t *mbox)
/* {{{ */
{
if (config.format == MBOX)
fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body);
@ -404,11 +388,9 @@ mbox_write_message (message_t *msg, mbox_t *mbox)
}
#endif /* HAVE_LIBBZ2 */
}
/* }}} */
void
tmpfile_mod_own (const int fd, const char *path)
/* {{{ */
{
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
* so rename() will thus retain the original's ownership & permissions.
@ -418,20 +400,18 @@ tmpfile_mod_own (const int fd, const char *path)
struct stat s;
if (stat (path, &s) != -1)
{
if (fchown (fd, s.st_uid, s.st_gid) == -1)
if (config.merr) perror (config.tmpfilename);
if (fchmod (fd, s.st_mode) == -1)
if (config.merr) perror (config.tmpfilename);
}
{
if (fchown (fd, s.st_uid, s.st_gid) == -1)
if (config.merr) perror (config.tmpfilename);
if (fchmod (fd, s.st_mode) == -1)
if (config.merr) perror (config.tmpfilename);
}
else if (config.merr) perror (path);
}
}
/* }}} */
int
tmpfile_create (void)
/* {{{ */
{
int fd;
@ -439,12 +419,11 @@ tmpfile_create (void)
if (-1 == fd)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
perror (NULL);
}
exit (2);
}
return fd;
}
/* }}} */

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004 Daniel Spiljar
Copyright (C) 2000 - 2004, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mbox.h,v 1.13 2006-10-22 23:34:49 dspiljar Exp $ */
*/
#ifndef MBOX_H
#define MBOX_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2020 Daniel Spiljar
Copyright (C) 2020, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id$ */
*/
#ifndef MESSAGE_H
#define MESSAGE_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mh.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
*/
#ifndef MH_H
#define MH_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: misc.h,v 1.9 2006-07-06 10:53:49 dspiljar Exp $ */
*/
#ifndef MISC_H
#define MISC_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2006 Daniel Spiljar
Copyright (C) 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: re.c,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
*/
#include <config.h>
#include <stdio.h>
@ -37,13 +36,13 @@ pcre_init (void)
config.pcre_pattern =
(pcre *) pcre_compile (config.regex_s,
(config.ignorecase ? PCRE_CASELESS : 0),
&error, &errptr, NULL);
(config.ignorecase ? PCRE_CASELESS : 0),
&error, &errptr, NULL);
if (config.pcre_pattern == NULL)
{
if (config.merr)
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
error);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
error);
exit(2);
}
}
@ -56,15 +55,15 @@ pcre_match (message_t *msg)
if (config.headers)
config.res1 =
pcre_exec ((pcre *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints,
msg->headers,
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
(pcre_extra *) config.pcre_hints,
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);
(pcre_extra *) config.pcre_hints,
msg->body,
(int) strlen (msg->body), 0, 0, of, BUFSIZ);
config.res1 = config.res1 ^ 1;
config.res2 = config.res2 ^ 1;
@ -88,11 +87,10 @@ regex_init (void)
if (0 != errcode)
{
if (config.merr)
{
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
errbuf);
}
{
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf);
}
exit (2);
}
}
@ -102,8 +100,8 @@ regex_match (message_t *msg)
{
if (config.headers)
config.res1 = regexec ((regex_t *) config.posix_pattern,
msg->headers, 0, NULL, 0);
msg->headers, 0, NULL, 0);
if (config.body)
config.res2 = regexec ((regex_t *) config.posix_pattern,
msg->body, 0, NULL, 0);
msg->body, 0, NULL, 0);
}

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2006 Daniel Spiljar
Copyright (C) 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: re.h,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
*/
#include "mboxgrep.h"

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: scan.h,v 1.7 2003-03-30 23:07:10 dspiljar Exp $ */
*/
#ifndef SCAN_H
#define SCAN_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*-
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: wrap.c,v 1.13 2006-01-20 03:00:39 dspiljar Exp $ */
*/
#include <config.h>
#include <unistd.h>
@ -65,13 +64,13 @@ int m_open (const char *pathname, int flags, mode_t mode)
if (blah == -1 && config.merr)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL);
}
/* failure to open a file for writing should be fatal */
{
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL);
}
/* failure to open a file for writing should be fatal */
if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR))
exit (2);
exit (2);
}
return blah;
}
@ -84,12 +83,12 @@ FILE *m_fopen (const char *path, const char *mode)
if (blah == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
if (mode[0] == 'w')
exit (2);
exit (2);
}
return blah;
}
@ -102,7 +101,7 @@ FILE *m_fdopen (int fildes, const char *mode)
if (blah == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
}
return blah;
}
@ -117,7 +116,7 @@ gzFile *m_gzdopen (int fildes, const char *mode)
if (blah == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
}
return blah;
}
@ -132,10 +131,10 @@ DIR *m_opendir (const char *name)
if (blah == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, name);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, name);
perror (NULL);
}
}
return blah;
}
@ -150,7 +149,7 @@ void *xmalloc (size_t size)
if (foo == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
exit (2);
}
return foo;
@ -164,7 +163,7 @@ void *xrealloc (void *ptr, size_t size)
if (foo == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
exit (2);
}
return foo;
@ -178,7 +177,7 @@ void *xcalloc (size_t nmemb, size_t size)
if (foo == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
exit (2);
}
return foo;
@ -192,7 +191,7 @@ char *xstrdup (const char *s)
if (foo == NULL)
{
if (config.merr)
perror (APPNAME);
perror (APPNAME);
exit (2);
}
return foo;
@ -208,10 +207,10 @@ int m_unlink (const char *pathname)
if (baz == -1)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL);
}
{
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL);
}
}
return baz;
}
@ -227,10 +226,10 @@ void gzwrite_loop (void *fp, char *str)
for (;;)
{
len = gzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len;
if (quux == baz)
break;
break;
}
}
@ -247,10 +246,10 @@ void bzwrite_loop (void *fp, char *str)
for (;;)
{
len = BZ2_bzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len;
if (quux == baz)
break;
break;
}
}

View File

@ -1,6 +1,6 @@
/* -*- C -*-
/*
mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it
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
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: wrap.h,v 1.12 2006-01-20 03:00:39 dspiljar Exp $ */
*/
/* This file is part of mboxgrep. */