Bump to version 0.7.10 and import of changes that have been made between

2003 and 2006 and haven't been tracked by any SCM.

The changes are the following, in reverse order:

* src/mboxgrep.h, src/main.c, src/mbox.c, src/mbox.h, src/scan.c:
Temporary mbox file (used for deleting messages) is now created
by tmpmbox_create(); tmpp global pointer is killed; portions of
code in scan.c are replaced by single call of mbox_write_message();
scan.c no longer includes zlib.h and bzlib.h.

* src/mboxgrep.h, src/main.c, src/maildir.c, src/scan.c:
Got rid off tmpp and maildir_count global variables (code
cleanup).

* src/mboxgrep.h, src/main.c, src/scan.c:
Introduction of the global runtime_t structure; mailbox counter,
MD5 hash and other global variables are now part of it (code
cleanup).

* src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
Portions of scan_mailbox() have been moved to new functions,
pcre_match() and regex_match() (code cleanup).

* src/main.c, src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
main() has been partially uncluttered by moving portions of the
code to functions pcre_init() and regex_init().

* src/main.c, src/mboxgrep.h, src/misc.c, src/misc.h:
Variables regex_s and haveregex are now part of the option_t
structure (code cleanup).

* src/main.c, src/misc.c, src/misc.h:
Parts of main() have been moved to set_default_options() and
get_runtime_options() (code cleanup).

* src/mbox.c, src/mbox.h:
File mode and ownership-altering code has been moved to a separate
function, tmpfile_mod_own (code cleanup).

* src/mbox.c, src/mbox.h:
Portions of the code from tmpfile_open moved to a new function,
tmpfile_name (code cleanup).

* src/maildir.c, src/mh.c:
Removed some unused variables (have_return_path).

* src/mboxgrep.h, src/maildir.c, src/mh.c, src/mbox.c, src/scan.c, src/main.c:
boxname, outboxname, pipecmd and tmpfilename are now a part of
the config_t structure and no longer global variables.

* src/scan.c, src/misc.c, src/misc.h:
Created postmark_print() to unclutter scan_mailbox().

* src/misc.c, src/misc.h, src/mbox.c, src/maildir.c, src/mh.c:
Some repetitive code moved to malloc_message().

* src/mbox.c:
Cleanup of mbox_write_message(); use of gzwrite_loop() and
bzwrite_loop().

* src/scan.c, src/wrap.h, src/wrap.c:
Wrote gzwrite_loop() and bzwrite_loop() to remove some repetitive
code from scan.c.

* src/scan.c:
md5_check_message(): array b and cast in strncmp are no longer
unsigned.

* src/info.c, src/mboxgrep.h:
Updated copyright information, changed author's email address
to the one at Panix.

* src/mbox.h, src/mbox.c, src/scan.c, src/main.c:
mbox_write_message(); further fixes of message deletion code.

* src/scan.c:
Fixed deleting messages from mbox folders compressed with
bzip2.

* src/main.c, src/mbox.c:
Moved James P. Dugal's ownership-preserving code from main()
to tmpfile_open().

* src/info.c:
If bzip2 support is compiled in, `--help' command should list
`bz2mbox' as a valid option to `--mailbox-format='.
This commit is contained in:
Daniel Spiljar 2018-10-04 22:07:27 +02:00
parent bd80cfbb4d
commit 0649ac9320
33 changed files with 1379 additions and 762 deletions

View File

@ -1,2 +1,5 @@
-*- text -*-
$Id: AUTHORS,v 1.2 2002/01/28 23:43:34 dspiljar Exp $
mboxgrep is written and maintained by Daniel Spiljar.
$Id: AUTHORS,v 1.3 2005-11-16 01:37:18 dspiljar Exp $

132
ChangeLog
View File

@ -1,3 +1,133 @@
Mon Oct 23 01:29:07 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mboxgrep.h, src/main.c, src/mbox.c, src/mbox.h, src/scan.c:
temporary mbox file (used for deleting messages) is now created
by tmpmbox_create(), tmpp global pointer is killed; portions of
code in scan.c are replaced by single call of mbox_write_message();
scan.c no longer includes zlib.h and bzlib.h
Thu Oct 19 03:50:38 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mboxgrep.h, src/main.c, src/maildir.c, src/scan.c:
got rid off tmpp and maildir_count global variables (code
cleanup)
Thu Oct 19 03:38:24 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mboxgrep.h, src/main.c, src/scan.c:
introduction of the global runtime_t structure; mailbox counter,
MD5 hash and other global variables are now part of it (code
cleanup)
Fri Jul 7 06:10:51 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
portions of scan_mailbox() have been moved to new functions,
pcre_match() and regex_match() (code cleanup)
Thu Jul 6 13:54:23 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/main.c, src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
main() has been partially uncluttered by moving portions of the
code to functions pcre_init() and regex_init()
Thu Jul 6 12:49:59 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/main.c, src/mboxgrep.h, src/misc.c, src/misc.h:
variables regex_s and haveregex are now part of the option_t
structure (code cleanup)
Thu Jul 6 10:26:57 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/main.c, src/misc.c, src/misc.h:
parts of main() have been moved to set_default_options() and
get_runtime_options() (code cleanup)
Sat Jul 1 13:06:37 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mbox.c, src/mbox.h:
file mode and ownership-altering code has been moved to a separate
function, tmpfile_mod_own (code cleanup)
Tue Jun 27 18:48:00 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mbox.c, src/mbox.h:
portions of the code from tmpfile_open moved to a new function,
tmpfile_name (code cleanup)
Mon Feb 20 18:09:59 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/maildir.c, src/mh.c:
removed some unused variables (have_return_path)
Mon Jan 30 01:35:30 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mboxgrep.h, src/maildir.c, src/mh.c, src/mbox.c, src/scan.c, src/main.c:
boxname, outboxname, pipecmd and tmpfilename are now a part of
the config_t structure and no longer global variables
Sat Jan 21 08:18:29 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/scan.c, src/misc.c, src/misc.h:
created postmark_print() to unclutter scan_mailbox()
Fri Jan 20 05:36:44 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/misc.c, src/misc.h, src/mbox.c, src/maildir.c, src/mh.c:
some repetitive code moved to malloc_message()
Fri Jan 20 05:13:06 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/mbox.c:
cleanup of mbox_write_message(); use of gzwrite_loop() and
bzwrite_loop()
Fri Jan 20 03:57:28 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/scan.c, src/wrap.h, src/wrap.c:
wrote gzwrite_loop() and bzwrite_loop() to remove some repetitive
code from scan.c
Fri Jan 20 02:11:50 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/scan.c:
md5_check_message(): array b and cast in strncmp are no longer
unsigned
Wed Jan 18 01:48:56 CET 2006 Daniel Spiljar <dspiljar@panix.com>
* src/info.c, src/mboxgrep.h:
updated copyright information, changed author's email address
to the one at Panix
Mon Apr 12 19:30:52 CEST 2004 Daniel Spiljar <dspiljar@world.std.com>
* src/info.c:
updated copyright information
Sun Apr 11 23:45:08 CEST 2004 Daniel Spiljar <dspiljar@world.std.com>
* src/mbox.h, src/mbox.c, src/scan.c, src/main.c:
mbox_write_message(); further fixes of message deletion code
Thu Sep 18 00:10:13 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* src/scan.c:
fixed deleting messages from mbox folders compressed with
bzip2
Thu Sep 18 00:08:36 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* src/main.c, src/mbox.c:
moved James P. Dugal's ownership-preserving code from main()
to tmpfile_open()
Sat Aug 30 23:13:01 CEST 2003 Vid Strpic <vms@bofhlet.net>
* src/info.c:
If bzip2 support is compiled in, `--help' command should list
`bz2mbox' as a valid option to `--mailbox-format='.
Sun Aug 24 21:49:52 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* doc/mboxgrep.1, doc/mboxgrep.texi:
@ -251,4 +381,4 @@ Tue Mar 27 01:26:22 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
$Id: ChangeLog,v 1.37 2003/08/24 19:51:12 dspiljar Exp $
$Id: ChangeLog,v 1.59 2006-10-22 23:34:47 dspiljar Exp $

0
INSTALL Executable file
View File

View File

@ -15,7 +15,7 @@
# along with mboxgrep; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id: Makefile.in,v 1.1 2001/10/26 13:07:28 dspiljar Exp $
# $Id: Makefile.in,v 1.1 2001-10-26 13:07:28 dspiljar Exp $
SHELL = /bin/sh

6
NEWS
View File

@ -1,6 +1,10 @@
Changes of mboxgrep
===================
Changes since 0.7.9
- fixed compile bug on FreeBSD and other systems
- fixed deleting messages mbox folders compressed with bzip2
Changes since 0.7.8
- implemented support for mbox folders compressed with bzip2 algorithm
- improved detection of PCRE library; this also fixes a compilation bug
@ -103,4 +107,4 @@ Changes since 0.1.0
- added support for mailboxes generated by Gnus
$Id: NEWS,v 1.21 2003/08/24 19:23:48 dspiljar Exp $
$Id: NEWS,v 1.23 2004-04-11 21:48:53 dspiljar Exp $

4
README
View File

@ -7,7 +7,7 @@ which is provided both in manpage and texinfo format, to satisfy
believers of both religions.
The author of mboxgrep is Daniel Spiljar, who can be reached via email
at <dspiljar@world.std.com>. Bug reports, feature requests and flames
at <dspiljar@panix.com>. Bug reports, feature requests and flames
are welcome.
If you intend to bundle mboxgrep with an operating system (such as a
@ -16,4 +16,4 @@ GNU/Linux distrubution, for example), please drop me a line about it.
For build instructions, read the file `INSTALL', and run
`./configure --help'
$Id: README,v 1.2 2002/12/02 20:53:07 dspiljar Exp $
$Id: README,v 1.3 2006-01-18 00:09:56 dspiljar Exp $

2
TODO
View File

@ -23,4 +23,4 @@
- add support for mail folder conversion [ ]
$Id: TODO,v 1.16 2003/04/06 21:48:23 dspiljar Exp $
$Id: TODO,v 1.16 2003-04-06 21:48:23 dspiljar Exp $

897
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
# along with mboxgrep; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id: configure.ac,v 1.13 2003/08/10 22:45:45 dspiljar Exp $
# $Id: configure.ac,v 1.13 2003-08-10 22:45:45 dspiljar Exp $
# Process this file with autoconf to produce a configure script.

View File

@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id: Makefile.in,v 1.1 2001/10/26 13:07:55 dspiljar Exp $
# $Id: Makefile.in,v 1.1 2001-10-26 13:07:55 dspiljar Exp $
MANPAGE = mboxgrep.1
INSTALL = @INSTALL@

View File

@ -1,4 +1,4 @@
.Id $Id: mboxgrep.1,v 1.15 2003/08/24 19:51:14 dspiljar Exp $
.Id $Id: mboxgrep.1,v 1.16 2006-01-18 00:09:58 dspiljar Exp $
.TH MBOXGREP 1 "24 Aug 2003"
.SH NAME
mboxgrep \- displays email messages matching a pattern
@ -119,4 +119,4 @@ well, little friend.
.SH URL
http://www.mboxgrep.org/
.SH AUTHOR
Daniel Spiljar <dspiljar@world.std.com>
Daniel Spiljar <dspiljar@panix.com>

View File

@ -1,4 +1,4 @@
This is mboxgrep.info, produced by makeinfo version 4.3 from
This is mboxgrep.info, produced by makeinfo version 4.6 from
mboxgrep.texi.
INFO-DIR-SECTION Mail
@ -29,8 +29,8 @@ File: mboxgrep.info, Node: Introduction, Next: Invoking, Up: Top
Introduction
************
`mboxgrep' is a small, non-interactive utility that scans mail
folders for messages matching regular expressions.
`mboxgrep' is a small, non-interactive utility that scans mail folders
for messages matching regular expressions.
It supports basic and extended POSIX regular expressions.
`Perl'-style regular expressions are supported as well, if `mboxgrep'
@ -59,7 +59,7 @@ File: mboxgrep.info, Node: Invoking, Next: Examples, Prev: Introduction, Up:
Command-Line Arguments
**********************
The syntax of `mboxgrep' invocation is:
The syntax of `mboxgrep' invocation is:
mboxgrep [OPTIONS] PATTERN [MAILBOX]
@ -87,6 +87,7 @@ File: mboxgrep.info, Node: Miscellaneous, Next: File locking, Up: Invoking
`-r'
Descend into directories recursively.

File: mboxgrep.info, Node: File locking, Next: Regexp selection, Prev: Miscellaneous, Up: Invoking
@ -105,6 +106,7 @@ without locking.
`-nl'
Do not attempt to lock mbox folder files.

File: mboxgrep.info, Node: Regexp selection, Next: Output control, Prev: File locking, Up: Invoking
@ -133,6 +135,7 @@ File: mboxgrep.info, Node: Regexp selection, Next: Output control, Prev: File
Invert the sense of matching, i.e. select only non-matching
messages.

File: mboxgrep.info, Node: Output control, Next: Search scope selection, Prev: Regexp selection, Up: Invoking
@ -172,6 +175,7 @@ The options below change such behavior.
`-s'
Suppress error messages.

File: mboxgrep.info, Node: Search scope selection, Next: Mailbox type selection, Prev: Output control, Up: Invoking
@ -183,22 +187,24 @@ File: mboxgrep.info, Node: Search scope selection, Next: Mailbox type selectio
`-B'
Match PATTERN against message body.

File: mboxgrep.info, Node: Mailbox type selection, Prev: Search scope selection, Up: Invoking
`--mailbox-format=FORMAT'
`-m FORMAT'
Specify mailbox FORMAT. Supported formats are `mbox' (default),
`zmbox' (gzip compressed mbox), `bzmbox' (bzip2 compressed mbox)
`zmbox' (gzip compressed mbox), `bz2mbox' (bzip2 compressed mbox)
`mh', `nnml', `nnmh', and `maildir'.

File: mboxgrep.info, Node: Examples, Next: Bugs, Prev: Invoking, Up: Top
Examples
********
Scan `$MAIL' for messages from Dirty Harry:
Scan `$MAIL' for messages from Dirty Harry:
mboxgrep -H '^From:.*callahan@homicide\.SFPD\.gov' $MAIL
@ -226,10 +232,10 @@ File: mboxgrep.info, Node: Bugs, Next: To Vicky, Prev: Examples, Up: Top
Detecting Vermin
****************
Shortly, if `mboxgrep' crashes and/or works differently than
described in this manual, you've found a bug.
Shortly, if `mboxgrep' crashes and/or works differently than described
in this manual, you've found a bug.
Please report bugs to <dspiljar@world.std.com>. Instructions how to
Please report bugs to <dspiljar@panix.com>. Instructions how to
reproduce the bug or output from a debugger would be highly
appreciated. Don't, however, send any coredumps.
@ -239,8 +245,8 @@ File: mboxgrep.info, Node: To Vicky, Prev: Bugs, Up: Top
Author's Dedication
*******************
`Mboxgrep' is dedicated in loving memory of Vicky, my cat who died
of tumor on Sep 12, 2002.
`Mboxgrep' is dedicated in loving memory of Vicky, my cat who died of
tumor on Sep 12, 2002.
You haven't been long with us, but you gave us a lot of joy and all
your big heart that stopped ticking too early. I will never forget you.
@ -251,15 +257,15 @@ Sleep well, little friend.
Tag Table:
Node: Top197
Node: Introduction598
Node: Invoking1469
Node: Miscellaneous1830
Node: File locking2115
Node: Regexp selection2756
Node: Output control3307
Node: Search scope selection4300
Node: Mailbox type selection4541
Node: Examples4862
Node: Bugs5681
Node: To Vicky6089
Node: Invoking1466
Node: Miscellaneous1824
Node: File locking2110
Node: Regexp selection2752
Node: Output control3304
Node: Search scope selection4298
Node: Mailbox type selection4540
Node: Examples4863
Node: Bugs5679
Node: To Vicky6080

End Tag Table

View File

@ -1,5 +1,5 @@
\input texinfo @c -*-texinfo-*-
@c $Id: mboxgrep.texi,v 1.19 2003/08/24 19:51:14 dspiljar Exp $
@c $Id: mboxgrep.texi,v 1.20 2006-01-18 00:09:58 dspiljar Exp $
@setfilename mboxgrep.info
@settitle Grep through mailboxes
@finalout
@ -260,7 +260,7 @@ mboxgrep -nd -c . spam
Shortly, if @code{mboxgrep} crashes and/or works differently than described
in this manual, you've found a bug.
Please report bugs to @email{dspiljar@@world.std.com}.
Please report bugs to @email{dspiljar@@panix.com}.
Instructions how to reproduce the bug or output from a debugger would be
highly appreciated. Don't, however, send any coredumps.

View File

@ -10,8 +10,8 @@ Description: mboxgrep is a small utility that scans a mailbox for messages
It supports mbox (both plain and compressed), MH, nnmh, nnml
and maildir folders.
Keywords: mail, mail-tools, mbox, MH, nnmh, nnml, maildir, regex
Author: dspiljar@world.std.com (Daniel Spiljar)
Maintained-by: dspiljar@world.std.com (Daniel Spiljar)
Author: dspiljar@panix.com (Daniel Spiljar)
Maintained-by: dspiljar@panix.com (Daniel Spiljar)
Primary-site: http://www.mboxgrep.org/
75k mboxgrep-0.7.9.tar.gz
Alternate-site:

View File

@ -1,5 +1,5 @@
# mboxgrep - scan mailbox for messages matching a regular expression
# Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
# Copyright (C) 2000, 2001, 2002, 2003, 2006 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,15 +15,15 @@
# along with mboxgrep; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id: Makefile.in,v 1.9 2003/03/30 23:07:10 dspiljar Exp $
# $Id: Makefile.in,v 1.12 2006-07-07 04:38:53 dspiljar Exp $
srcdir = @srcdir@
CC = @CC@
OBJS = info.o main.o mh.o scan.o maildir.o mbox.o misc.o \
wrap.o getopt.o getopt1.o md5.o
wrap.o getopt.o getopt1.o md5.o re.o
SRCS = info.c main.c mh.c scan.c maildir.c mbox.c misc.c \
wrap.c getopt.c getopt1.c md5.c
wrap.c getopt.c getopt1.c md5.c re.c
TARGET = mboxgrep
CFLAGS = @CFLAGS@
LIBS = @LIBS@

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 - 2004, 2006, 2010 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
@ -16,7 +16,7 @@
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: info.c,v 1.19 2003/04/13 19:15:58 dspiljar Exp $ */
$Id: info.c,v 1.22 2006-01-18 00:44:36 dspiljar Exp $ */
#include <config.h>
@ -48,7 +48,7 @@ version (void)
int n = 0;
fprintf (stdout, "%s %s\n\n"
"Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar\n"
"Copyright (C) 2000 - 2004, 2006, 2010 Daniel Spiljar\n"
"This program is free software; you can redistribute it and/or "
"modify\nit under the terms of the GNU General Public License "
"as published by\nthe Free Software Foundation; either version "
@ -147,9 +147,12 @@ help (void)
#ifdef HAVE_LIBZ
fprintf(stdout, "`zmbox', ");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
fprintf(stdout, "`bz2mbox', ");
#endif /* HAVE_LIBBZ2 */
fprintf(stdout,
"`mh', `nnml',\n"
"\t\t\t\t`nnmh', or `maildir'.\n\n"
"`mh',\n"
"\t\t\t\t`nnml', `nnmh', or `maildir'.\n\n"
"Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR);
exit(0);

View File

@ -16,7 +16,7 @@
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 $ */
$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 Daniel Spiljar
Copyright (C) 2000, 2001, 2002, 2003, 2006 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
@ -16,7 +16,7 @@
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.21 2003/03/30 23:07:10 dspiljar Exp $ */
$Id: maildir.c,v 1.25 2006-10-19 01:53:43 dspiljar Exp $ */
#include <config.h>
@ -115,26 +115,15 @@ message_t *
maildir_read_message (maildir_t *mdp)
{
int isheaders = 1;
int have_from = 0, have_to = 0, have_message_id = 0, have_return_path = 0,
have_sender = 0, have_date = 0;
int have_from = 0, have_to = 0, have_message_id = 0, have_sender = 0,
have_date = 0;
static message_t *message;
static struct dirent *d_content;
char *filename, buffer[BUFSIZ];
extern char *boxname;
static FILE *fp;
static int s;
message = (message_t *) xmalloc (sizeof (message_t));
message->headers = (char *) xmalloc (sizeof (char));
message->headers[0] = '\0';
message->hbytes = 0;
message->body = (char *) xmalloc (sizeof (char));
message->body[0] = '\0';
message->bbytes = 0;
message->from = NULL;
message = malloc_message ();
for(;;)
{
@ -169,17 +158,17 @@ maildir_read_message (maildir_t *mdp)
filename =
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
+ (strlen (boxname)) + 6)));
+ (strlen (config.boxname)) + 6)));
/*
filename =
(char *) alloca((sizeof(char)*((strlen(d_content->d_name))
+ (strlen(boxname)) + 2)));
+ (strlen(config.boxname)) + 2)));
*/
if (mdp->new != NULL)
sprintf (filename, "%s/new/%s", boxname, d_content->d_name);
sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name);
else
sprintf (filename, "%s/cur/%s", boxname, d_content->d_name);
sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name);
message->filename = (char *) xstrdup (filename);
free (filename);
@ -210,10 +199,7 @@ maildir_read_message (maildir_t *mdp)
if (0 == strncasecmp ("Message-ID: ", buffer, 12))
have_message_id = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
{
have_return_path = 1;
message->from = parse_return_path(buffer);
}
message->headers =
(char *) xrealloc (message->headers,
@ -248,15 +234,15 @@ maildir_read_message (maildir_t *mdp)
void
maildir_write_message (message_t *m, const char *path)
{
extern int maildir_count;
char bla[BUFSIZ], *s1, *s2;
int t;
static FILE *f1;
maildir_count++;
runtime.maildir_count++;
t = (int) time (NULL);
sprintf (bla, "%i.%i_%i.%s", t, config.pid, maildir_count, config.hostname);
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);
s2 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char));

View File

@ -16,7 +16,7 @@
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 $ */
$Id: maildir.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef MAILDIR_H
#define MAILDIR_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, 2001, 2002, 2003, 2004, 2006 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
@ -16,7 +16,7 @@
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: main.c,v 1.32 2003/08/24 19:23:50 dspiljar Exp $ */
$Id: main.c,v 1.41 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h>
@ -24,12 +24,8 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <regex.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_LIBPCRE
#include <pcre.h>
#endif /* HAVE_LIBPCRE */
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif /* HAVE_LIBZ */
@ -42,39 +38,21 @@
#include "mh.h"
#include "scan.h"
#include "wrap.h" /* xcalloc() et cetera */
#include "re.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */
regex_t posix_pattern;
#ifdef HAVE_LIBPCRE
pcre *pcre_pattern;
pcre_extra *hints;
#endif /* HAVE_LIBPCRE */
char *boxname, *outboxname, *pipecmd, *tmpfilename;
int maildir_count = 0;
int count = 0;
void *tmpp;
checksum_t *cs;
int
main (int argc, char **argv)
/* {{{ */
{
int option_index = 0;
int c;
#ifdef HAVE_LIBPCRE
int errptr;
const char *error;
#endif /* HAVE_LIBPCRE */
int haveregex = 0, havemailbox = 0;
static char *regex_s;
int havemailbox = 0;
int singlefile = 0;
int errcode = 0;
char errbuf[BUFSIZ];
runtime.count = 0;
runtime.maildir_count = 0;
static struct option long_options[] =
/* {{{ */
@ -107,124 +85,9 @@ main (int argc, char **argv)
/* }}} */
config.perl = 0;
config.extended = 1;
config.invert = 0;
config.headers = 0;
config.body = 0;
config.action = DISPLAY;
config.dedup = 0;
config.recursive = 0;
config.ignorecase = 0;
config.format = MBOX; /* default mailbox format */
config.lock = FCNTL; /* default file locking method */
config.merr = 1; /* report errors by default */
set_default_options ();
while (1)
{
c = getopt_long (argc, argv, "BcdEe:GHhil:m:n:o:Pp:rsVv", long_options,
&option_index);
if (c == -1)
break;
switch (c)
/* {{{ */
{
case '?':
usage();
case 'c':
config.action = COUNT;
break;
case 'd':
config.action = DELETE;
break;
case 'e':
regex_s = xstrdup (optarg);
haveregex = 1;
break;
case 'o':
outboxname = xstrdup (optarg);
config.action = WRITE;
break;
case 'E':
config.extended = 1;
break;
case 'G':
config.extended = 0;
break;
case 'P':
#ifdef HAVE_LIBPCRE
config.extended = 0;
config.perl = 1;
#else
fprintf(stderr,
"%s: Support for Perl regular expressions not "
"compiled in\n");
exit(2);
#endif /* HAVE_LIBPCRE */
break;
case 'h':
help ();
break;
case 'i':
config.ignorecase = 1;
break;
case 'm':
config.format = folder_format (optarg);
break;
case 'l':
config.lock = lock_method (optarg);
break;
case 'p':
config.action = PIPE;
pipecmd = xstrdup (optarg);
break;
case 'V':
version ();
break;
case 'v':
config.invert = 1;
break;
case 'H':
config.headers = 1;
break;
case 'B':
config.body = 1;
break;
case 's':
config.merr = 0;
break;
case 201:
config.lock = 0;
break;
case 'r':
config.recursive = 1;
break;
case 200:
config.dedup = 1;
break;
case 'n':
{
switch (optarg[0])
{
case 'd':
config.dedup = 1;
break;
case 'l':
config.lock = 0;
break;
default:
fprintf(stderr, "%s: invalid option -- n%c\n",
APPNAME, optarg[0]);
exit(2);
}
}
} /* switch */
/* }}} */
} /* while */
get_runtime_options (&argc, argv, long_options);
if ((config.body == 0) && (config.headers == 0))
{
@ -238,62 +101,25 @@ main (int argc, char **argv)
config.pid = (int) getpid ();
}
cs = (checksum_t *) xmalloc (sizeof (checksum_t));
cs->md5 = (char **) xcalloc (1, sizeof (char **));
cs->n = 0;
runtime.cs = (checksum_t *) xmalloc (sizeof (checksum_t));
runtime.cs->md5 = (char **) xcalloc (1, sizeof (char **));
runtime.cs->n = 0;
if (optind < argc && ! haveregex)
if (optind < argc && ! config.haveregex)
{
regex_s = xstrdup (argv[optind]);
haveregex = 1;
config.regex_s = xstrdup (argv[optind]);
config.haveregex = 1;
++optind;
} /* if */
if (haveregex)
if (config.haveregex)
{
#ifdef HAVE_LIBPCRE
if (config.perl)
/* {{{ */
{
pcre_pattern = pcre_compile (regex_s,
(config.ignorecase ? PCRE_CASELESS : 0),
&error, &errptr, NULL);
if (pcre_pattern == NULL)
{
if (config.merr)
fprintf (stderr, "%s: %s: %s\n", APPNAME, regex_s, error);
exit(2);
}
}
/* }}} */
pcre_init ();
else
#endif /* HAVE_LIBPCRE */
/* {{{ */
{
int flag1 = 0, flag2 = 0;
if (config.ignorecase)
flag1 = REG_ICASE;
if (config.extended)
flag2 = REG_EXTENDED;
errcode = regcomp (&posix_pattern, regex_s,
(flag1 | flag2 | REG_NEWLINE ));
if (0 != errcode)
{
if (config.merr)
{
regerror (errcode, &posix_pattern, errbuf, BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, regex_s, errbuf);
}
exit (2);
} /* if */
} /* if */
/* }}} */
regex_init ();
} /* if */
else
usage ();
@ -306,24 +132,11 @@ main (int argc, char **argv)
{
if (config.action == DELETE) {
tmpp = tmpfile_open (argv[optind]);
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
* so rename() will thus retain the original's ownership & permissions.
*/
if (geteuid() == 0) {
struct stat s;
if (stat(argv[optind], &s) != -1) {
if (fchown(fileno(tmpp), s.st_uid, s.st_gid) == -1)
if (config.merr) perror(tmpfilename);
if (fchmod(fileno(tmpp), s.st_mode) == -1)
if (config.merr) perror(tmpfilename);
}
else if (config.merr) perror(argv[optind]);
}
tmpmbox_create (argv[optind]);
runtime.tmp_mbox = mbox_open (config.tmpfilename, "w");
}
boxname = xstrdup (argv[optind]);
config.boxname = xstrdup (argv[optind]);
if (config.recursive)
recursive_scan (argv[optind]);
@ -333,24 +146,19 @@ main (int argc, char **argv)
if (config.action == COUNT)
{
if (singlefile)
fprintf (stdout, "%i\n", count);
fprintf (stdout, "%i\n", runtime.count);
else
{
if (0 == strcmp ("-", argv[optind]))
fprintf (stdout, "(standard input):%i\n", count);
fprintf (stdout, "(standard input):%i\n", runtime.count);
else
fprintf (stdout, "%s:%i\n", argv[optind], count);
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
}
}
if (config.action == DELETE)
{
#ifdef HAVE_LIBZ
if (config.format == ZMBOX)
gzclose (tmpp);
#endif /* HAVE_LIBZ */
if (config.format == MBOX)
fclose (tmpp);
rename (tmpfilename, argv[optind]);
mbox_close (runtime.tmp_mbox);
rename (config.tmpfilename, argv[optind]);
}
++optind;
} /* while */
@ -364,7 +172,7 @@ main (int argc, char **argv)
config.format = MBOX;
scan_mailbox ("-");
if (config.action == COUNT)
fprintf (stdout, "%i\n", count);
fprintf (stdout, "%i\n", runtime.count);
}
/* }}} */

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, 2001, 2002, 2003, 2004, 2006 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
@ -16,7 +16,7 @@
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.26 2003/08/24 19:23:50 dspiljar Exp $ */
$Id: mbox.c,v 1.34 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h>
@ -39,6 +39,7 @@
#ifdef HAVE_LIBBZ2
#include <bzlib.h>
#endif /* HAVE_LIBBZ2 */
#define BUFLEN 16384
#include "mboxgrep.h"
#include "mbox.h"
@ -243,17 +244,7 @@ mbox_read_message (mbox_t * mp)
char buffer[BUFSIZ];
message_t *message;
message = (message_t *) xmalloc (sizeof (message_t));
message->headers = (char *) xmalloc (sizeof (char));
message->headers[0] = '\0';
message->hbytes = 0;
message->body = (char *) xmalloc (sizeof (char));
message->body[0] = '\0';
message->bbytes = 0;
message->from = NULL;
message = malloc_message ();
s = strlen (mp->postmark_cache);
message->headers =
@ -348,53 +339,112 @@ mbox_read_message (mbox_t * mp)
/* }}} */
void *
tmpfile_open (const char *path)
void
tmpmbox_create (const char *path)
/* {{{ */
{
extern char *tmpfilename;
char *fname;
char *tmpdir;
int foo;
if (path == NULL) { /* no path prefix given, use /tmp or TMPDIR */
tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL)
tmpdir = xstrdup ("/tmp");
fname = xstrdup ("/mboxgrepXXXXXX");
}
else {
tmpdir = (char *)path;
fname = xstrdup (".XXXXXX");
}
tmpfile_name (path);
foo = tmpfile_create ();
tmpfile_mod_own (foo, path);
}
tmpfilename = (char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
* sizeof (char));
sprintf (tmpfilename, "%s%s", tmpdir, fname);
foo = mkstemp (tmpfilename);
if (-1 == foo)
/* }}} */
void
tmpfile_name (const char *path)
/* {{{ */
{
char *fname, *tmpdir;
if (path == NULL) /* no path prefix given, use /tmp or TMPDIR */
{
tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL)
tmpdir = xstrdup ("/tmp");
fname = xstrdup ("/mboxgrepXXXXXX");
}
else
{
tmpdir = xstrdup (path);
fname = xstrdup (".XXXXXX");
}
config.tmpfilename =
(char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
* 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);
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
{
gzwrite_loop (mbox->fp, msg->headers);
gzwrite(mbox->fp, "\n", 1);
gzwrite_loop (mbox->fp, msg->body);
}
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
{
bzwrite_loop (mbox->fp, msg->headers);
BZ2_bzwrite (mbox->fp, "\n", 1);
bzwrite_loop (mbox->fp, msg->body);
}
#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.
*/
if (geteuid () == 0)
{
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);
}
else if (config.merr) perror (path);
}
}
/* }}} */
int
tmpfile_create (void)
/* {{{ */
{
int fd;
fd = mkstemp (config.tmpfilename);
if (-1 == fd)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, tmpfilename);
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
perror (NULL);
}
exit (2);
}
if (config.format == MBOX)
return (m_fdopen (foo, "w"));
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
return (m_gzdopen (foo, "wb"));
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
return (BZ2_bzdopen (foo, "wb"));
#endif /* HAVE_LIBZ */
return NULL; /* not reached */
return fd;
}
/* }}} */
/* }}} */

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, 2001, 2002, 2003, 2004 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
@ -16,7 +16,7 @@
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.9 2003/08/24 19:23:50 dspiljar Exp $ */
$Id: mbox.h,v 1.13 2006-10-22 23:34:49 dspiljar Exp $ */
#ifndef MBOX_H
#define MBOX_H 1
@ -34,8 +34,14 @@ typedef struct
mbox_t *mbox_open (const char *path, const char *mode);
void *tmpfile_open (const char *path);
void tmpmbox_create (const char *path);
void tmpfile_name (const char *path);
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 * mbp);
/* FIXME -- it doesn't compile with this portion uncommented
message_t *mbox_read_message (mbox_t * mp);
void mbox_write_message (message_t *m, mbox_t *mbox);
*/
#endif /* MBOX_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, 2001, 2002, 2003, 2006 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
@ -16,14 +16,14 @@
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mboxgrep.h,v 1.21 2003/04/06 21:01:49 dspiljar Exp $ */
$Id: mboxgrep.h,v 1.31 2006-10-22 23:34:49 dspiljar Exp $ */
#ifndef MBOXGREP_H
#define MBOXGREP_H
#define APPNAME "mboxgrep"
#define VERSION "0.7.9"
#define BUGREPORT_ADDR "dspiljar@world.std.com"
#define VERSION "0.7.10"
#define BUGREPORT_ADDR "dspiljar@panix.com"
#define HOST_NAME_SIZE 256
@ -45,6 +45,7 @@
# endif /* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */
#include "mbox.h"
typedef enum
{
@ -120,15 +121,30 @@ typedef struct
int ignorecase;
int merr;
int pid;
int haveregex;
char hostname[HOST_NAME_SIZE];
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
void *pcre_pattern, *pcre_hints, *posix_pattern;
int res1, res2;
action_t action;
format_t format;
lockmethod_t lock;
}
option_t;
option_t;
typedef struct
{
int count;
int maildir_count;
checksum_t *cs;
mbox_t *tmp_mbox;
}
runtime_t;
option_t config;
runtime_t runtime;
#endif /* 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, 2001, 2002, 2003, 2006 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
@ -16,7 +16,7 @@
along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mh.c,v 1.15 2003/03/30 23:07:10 dspiljar Exp $ */
$Id: mh.c,v 1.18 2006-02-20 17:12:22 dspiljar Exp $ */
#include <stdio.h>
#include <string.h>
@ -80,24 +80,14 @@ void mh_close (DIR *dp)
message_t *mh_read_message (DIR *dp)
{
int isheaders = 1;
int have_from = 0, have_return_path = 0,
have_date = 0, have_sender = 0;
int have_from = 0, have_date = 0, have_sender = 0;
static int s;
message_t *message;
struct dirent *d_content;
char buffer[BUFSIZ], *filename;
FILE *fp;
extern char *boxname;
message = (message_t *) xmalloc (sizeof (message_t));
message->headers = NULL;
message->hbytes = 0;
message->body = NULL;
message->bbytes = 0;
message->from = NULL;
message = malloc_message ();
filename = NULL;
@ -110,7 +100,7 @@ message_t *mh_read_message (DIR *dp)
filename = (char *) xrealloc
(filename, ((strlen (d_content->d_name)) +
(strlen (boxname)) + 2));
(strlen (config.boxname)) + 2));
/* message->headers = (char *) xrealloc (message->headers, 0); */
/* message->hbytes = 0; */
@ -118,7 +108,7 @@ message_t *mh_read_message (DIR *dp)
/* message->bbytes = 0; */
filename[0] = '\0';
sprintf (filename, "%s/%s", boxname, d_content->d_name);
sprintf (filename, "%s/%s", config.boxname, d_content->d_name);
fp = m_fopen (filename, "r");
isheaders = 1;
if (fp == NULL)
@ -167,10 +157,7 @@ message_t *mh_read_message (DIR *dp)
if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
{
have_return_path = 1;
message->from = parse_return_path (buffer);
}
message->headers =
(char *) realloc (message->headers,

View File

@ -16,7 +16,7 @@
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 $ */
$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 @@