43 Commits

Author SHA1 Message Date
7255fae5d0 Bump the version to 0.7.12a. 2023-05-21 15:09:44 +02:00
03407c7afb Correction of Automake macros
Fix Automake macros to include the license file and other files and
directories in the distribution tarball.
2023-05-21 12:05:18 +02:00
dd5fefe22d Update the TODO list and bump the version to 0.7.12. 2023-05-20 20:34:23 +02:00
cbba5c2a33 Remove config.h.in from the git repo, as it is autogenerated. 2023-05-20 20:09:23 +02:00
27082f9629 Minor updates of the documentation. 2023-05-18 13:43:09 +02:00
d17f37b3c5 Include the contrib subdirectory in the distribution tarball. 2023-05-18 13:35:35 +02:00
e004f116b7 Merge branch 'pcre2-port' 2023-05-17 19:40:41 +02:00
e5409a897d Port to the pcre2 library. 2023-05-17 17:58:59 +02:00
55aa25eca3 Add migration from pcre to pcre2 to the TODO list. 2023-05-08 22:54:58 +02:00
7ebef4a322 Fix a compile error caused by an extra curly bracket. 2023-04-22 17:36:28 +02:00
d04349e9b4 Minor code cleanup and fix a compilation warning. 2023-04-19 23:04:57 +02:00
c19253d080 Check command-line options for conflicting matchers and actions. 2023-04-19 21:55:25 +02:00
3040f9c363 Fix Automake macros. Remove autogenerated files from the git repo. 2023-03-28 00:59:16 +02:00
033063befc Version bump to 0.7.11. 2023-03-24 15:18:53 +01:00
7720415afa Updates to the news and installation instructions. 2023-03-24 15:00:06 +01:00
68c0ddee91 Merge branch 'automake' 2023-03-24 14:10:14 +01:00
53d3381cd4 Merge branch 'automake' of git.datatipp.se:dspiljar/mboxgrep into automake 2023-03-24 13:50:10 +01:00
c02deefbd5 Utilize GNU Automake instead of manually written Makefile.in files. 2023-03-24 13:47:16 +01:00
b7006b77b5 Utilize GNU Automake instead of manually written Makefile.in files. 2023-03-23 22:10:04 +01:00
43e7695eac Update the basic documentation. 2023-03-08 15:19:20 +01:00
844dc84974 Ignore backup files. 2023-03-07 16:54:41 +01:00
ee2489483b Code cleanup and indentation.
C source files (with the exception of third-party files, i.e. getopt and
md5) have been indented with GNU indent.

The indentation "standard" has been documented in the readme file.
2023-03-07 16:51:33 +01:00
882a38f908 Refinement of the TODO list. 2023-03-01 20:53:15 +01:00
29a1add6f0 Updates to the news and todo list. 2023-02-23 12:59:33 +01:00
0be2cf9fda Deleting the old ChangeLog.
The git commit logs are now the source of truth about changes in the source
tree.

The contents of the ChangeLog file have been preserved as a comment to
commit 0649ac9.
2023-02-23 12:54:25 +01:00
a7920dedf3 Markdown conversion, email address obfuscation. 2023-02-17 23:37:35 +01:00
5cc84ca1bd Implement a debug mode ("--debug"). 2023-02-17 22:19:36 +01:00
af7c6c8ced Minor code cleanup and indentation. 2023-02-17 20:55:52 +01:00
7dd6f3d69d Merge branch 'documentation' 2023-02-12 21:52:03 +01:00
10a9440e57 New task - add a debug function. 2023-02-12 21:03:03 +01:00
994cb03fe5 Merge branch 'documentation' 2023-02-12 18:35:35 +01:00
c527aff34b Markdown conversion. 2023-02-12 18:30:27 +01:00
3e8c80b8e0 Merge branch 'fix_compilation_errors' 2023-02-10 17:29:19 +01:00
f7bdabb29d Fix a call of fprintf(). 2023-02-10 17:26:33 +01:00
51cc5c6d69 Prevent tracking binaries and files generated from templates. 2023-02-10 17:13:22 +01:00
654d98cbb4 Fix multiple compilation errors and memory leaks.
- Rename malloc_message() because it was causing a compilation error on
  FreeBSD.
- Use correct type as a return from gzdopen().
- Memory allocation, header file includes, etc.
2023-02-10 16:54:39 +01:00
8ad7b77cf3 Merge branch 'documentation' 2023-02-10 09:41:13 +01:00
2063e7fcba Minor updates of the documentation. 2023-02-10 09:35:50 +01:00
85f4938776 Spell check, re-format and re-phrase the TODO list. 2023-02-09 16:02:40 +01:00
3db6edf467 Re-phrase the TODO list and add a new task. 2023-02-08 10:50:02 +01:00
50316df104 Update version() with more #define statements from config.h. 2023-02-04 14:29:58 +00:00
95d67d850c Merge pull request 'Code indentation and other minor cleanups.' (#1) from code_cleanup into master
Reviewed-on: #1
2023-01-30 22:48:41 +00:00
7c94d17bec Code indentation and other minor cleanups. 2023-01-30 23:07:29 +01:00
43 changed files with 13430 additions and 7524 deletions

19
.gitignore vendored Normal file
View File

@@ -0,0 +1,19 @@
Makefile
config.h
config.h.in
config.log
config.status
src/*.o
src/*.c~
src/*.h~
src/mboxgrep
src/.deps/
src/stamp-h1
aclocal.m4
autom4te.cache/
Makefile.in
configure
compile
depcomp
install-sh
missing

384
ChangeLog
View File

@@ -1,384 +0,0 @@
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:
small updates
Sat Aug 23 20:56:39 CEST 2003 James P. Dugal <jpd@louisiana.edu>
* src/main.c, src/mbox.h, src/mbox.c
If we are to use rename() to move a temp file (resulting from
deletions done in a mailbox) back over the original mailbox, we
must be sure the temp file is on the same file system. Also,
we should try to preserve the same ownership and permissions.
Mon Aug 11 00:39:14 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* configure.ac:
look for pcre-config(1) script; this effectively fixes a
compilation bug on recent RedHat Linux systems
Sun Apr 13 21:16:25 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* src/info.c, src/info.h:
print_wrap(); list of compile-time options is now printed wrapped
Mon Apr 7 01:24:20 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* src/mbox.c, src/wrap.c, src/wrap.h:
m_gzdopen()
Sun Apr 6 23:04:19 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* src/mbox.c, src/mbox.h, src/mboxgrep.h, src/misc.c, src/scan.c:
support for bzip2 compressed mailboxes
Fri Apr 4 00:14:01 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
* configure.ac:
check for libbz2
Sun Oct 27 23:57:31 CET 2002 Daniel Spiljar <dspiljar@world.std.com>
* src/mbox.c:
mbox_open() should now complain if called with an unknown argument
mode. Shouldn't normally happen, but...
Sun Aug 25 22:43:38 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/mbox.c, src/mbox.h, src/scan.c:
removed the gzmbox* functions in order to avoid code duplication;
as a side effect, mboxgrep can now read compressed mbox folders
from standard input
Sun Aug 11 01:36:02 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* configure.ac:
AC_HEADER_STDC, which fixed another compiler warning
Sat Aug 10 22:03:31 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/mbox.c, src/mh.c, src/scan.c, src/misc.c, src/maildir.c, src/mboxgrep.h:
made various code cleanups: got rid of a couple of global variables,
fixed compiler warnings and things like that
Sat Aug 10 00:35:21 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mh.h, src/wrap.h, src/mboxgrep.h:
removed some unnecessary #defines that have been causing compiler
errors
Sun Aug 4 20:11:29 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/scan.c, src/scan.h:
code clean up: moved recursive scan code from main()
to recursive_scan()
Wed Jul 24 00:20:59 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/maildir.c:
same thing with maildir as with MH below
Sat Jul 6 22:51:45 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mh.c:
MH module doesn't read files which aren't RFC 2822 messages anymore
Sat Jun 29 01:43:36 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* configure.in, src/maildir.c, src/main.c, src/mbox.c, src/mh.c, src/scan.c:
added debugging with dmalloc library
Sat Jun 29 01:39:21 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mbox.c, src/maildir.c:
fixed potential problem as with MH folders (below)
Sat Jun 29 01:28:30 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mh.c, src/scan.c:
(hopefully) fixed crashes on MH folders
Sat Feb 23 22:22:12 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mbox.c, src/maildir.c, src/mh.c, src/misc.c:
removed useless code that required strptime ()
Sat Feb 23 15:43:05 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/mbox.h, src/mbox.c, src/scan.c:
mboxgrep can now read mbox folders from standard input
Fri Feb 8 02:15:36 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c:
fixed a bug which prevented mboxgrep from being compiled;
this happened because I've put some assignments *before*
declarations
Wed Feb 6 23:11:50 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/maildir.c, src/main.c, src/mbox.c, src/mboxgrep.h, src/mh.c, src/mh.h, src/misc.c, src/scan.c, src/wrap.c
code cleanups; many global variables have been replaced with
a single option_t structure
Fri Feb 1 00:31:05 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/maildir.c:
fixed a bug which occured on recursive search of maildirs
Wed Jan 2 00:32:37 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/misc.c, src/wrap.h:
applied a patch (kindly submitted by John R. Daily
<jdaily@progeny.com>), which fixes missing prototypes that might
cause mboxgrep to coredump on IA64 platform
Sat Dec 15 20:12:40 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/scan.c, src/scan.h:
recursive search through directories has been reimplemented
Sat Dec 8 22:13:54 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/main.c, src/maildir.c:
replaced remaining occurences of malloc() with xmalloc()
Sat Dec 8 21:21:58 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/maildir.c, src/main.c, src/mbox.c, src/mh.c, src/misc.c, src/scan.c, src/wrap.c, src/wrap.h:
wrote xstrdup(), an error-checking wrapper around strdup() and
replaced all occurences of strdup() with xstrdup()
Sun Dec 2 18:05:57 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/Makefile.in, src/info.c, src/main.c, src/mboxgrep.h, src/md5.c, src/md5.h, src/scan.c, src/scan.h, doc/mboxgrep.texi:
mboxgrep can now ignore duplicate messages, thanks to the MD5
algorithm
* src/maildir.c, src/main.c, src/scan.c, src/wrap.c, src/wrap.h:
wrote xcalloc() and renamed m_realloc() to xrealloc()
Sat Nov 17 22:57:57 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mbox.c, src/mh.c, src/maildir.c
message->headers and message->body pointers are now initially malloc'd
to size of one character in order to prevent NULL pointers from being
passed to regexec()
Wed Nov 7 22:47:34 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* configure.ac, src/mboxgrep.h, src/main.c, src/misc.h, src/misc.c, src/info.c, src/config.h, src/mbox.c:
file locking method can now be selected at run time
* src/info.c, src/maildir.c, src/main.c, src/mbox.h, src/misc.c, src/scan.c, src/Makefile.in
changed `#include "config.h"' to `#include <config.h>', and fixed
other bugs with #including
Sat Nov 3 16:08:22 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* configure.ac, src/config.h.in, src/info.c, src/mbox.c
files can be locked with flock() instead of fcntl(), if
enabled at compile time
Sun Oct 28 19:01:44 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/Makefile.in:
forgot to mention getopt.c and getopt1.c
Sun Oct 28 16:06:28 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/mh.c, src/main.c, src/scan.c:
#included certain neccessary files
Sun Oct 28 14:43:21 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/maildir.c, src/maildir.h, src/scan.c:
wrote functions maildir_check and maildir_create;
if the target maildir doesn't exist, mboxgrep creates one;
if it does exist, mboxgrep checks its consistency and refuses to
write to it unless `tmp', `new' and `cur' subdirectories exist
Sun Oct 28 13:02:10 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/info.c, doc/mboxgrep.texi, doc/mboxgrep.1
the "--regexp" command was implemented in version 0.7.0, but I
forgot to document it
Sat Oct 27 21:48:36 CEST 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/scan.c:
if the input is a non-mbox folder, a proper postmark line (with
date) is put on top of each message written to stdout
Mon Oct 8 22:53:34 CEST 2001 Daniel Spiljar <dspiljar@bofhlet.net>
* src/*:
source code now completely rewritten
Sun May 27 00:19:52 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* doc/mboxgrep.1:
updated the manual page -- it now refers to RFC 2822, instead
of the obsoleted 822
Tue May 1 15:06:03 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* configure.in, doc/Makefile.in, src/Makefile.in, Makefile.in:
moved manpage to the `doc' subdirectory; changed files above
accordingly
Sun Apr 15 23:00:08 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* src/mboxgrep.h, src/main.c, src/file.c, src/scan.c, src/info.c:
added support for writing messages to another mail folder
Mon Apr 9 21:55:15 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* src/file.c, src/scan.c: all calls of malloc() are now checked
and mboxgrep exits with code 2 if it fails to allocate memory
Sun Apr 8 19:40:33 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* src/mboxgrep.h, src/main.c: wrote mboxgrep_stat()
Sun Apr 8 16:58:36 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* src/mboxgrep.h, src/main.c: wrote mboxgrep_error()
Tue Mar 27 01:26:22 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
* configure.in: check for gethostname()
$Id: ChangeLog,v 1.59 2006-10-22 23:34:47 dspiljar Exp $

View File

26
INSTALL.md Normal file
View File

@@ -0,0 +1,26 @@
# Compilation and installation of mboxgrep
`mboxgrep` should compile on a modern Unix-like operating system, such as GNU/Linux or FreeBSD.
Autoconf and Automake are used, and the most basic compilation procedure consists of:
```
autoreconf --install
./configure
make
make install # root rights probably needed here, prefix with sudo in such case
```
(Invocation of `autoreconf` is only required if the source tree has been cloned from the
git repository.)
To see the list of flags accepted by the configure script, run:
```
./configure --help
```
Optionally, `mboxgrep` can be linked with the following libraries:
- PCRE2, to enable support for regular expressions compatible with Perl 5;
- zlib and bzlib, to enable support for compressed mbox folders.

2
Makefile.am Normal file
View File

@@ -0,0 +1,2 @@
SUBDIRS = doc src
EXTRA_DIST = contrib COPYING.md INSTALL.md NEWS.md README.md TODO.md

View File

@@ -1,37 +0,0 @@
# mboxgrep - scan mailbox for messages matching a regular expression
# Copyright (C) 2000, 01 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Mboxgrep is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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: Makefile.in,v 1.1 2001-10-26 13:07:28 dspiljar Exp $
SHELL = /bin/sh
all:
cd src; $(MAKE)
clean:
cd src; $(MAKE) clean
distclean:
rm -f *~ Makefile config.status config.log config.cache
cd src; $(MAKE) distclean
cd doc; $(MAKE) distclean
install:
cd src; $(MAKE) install
cd doc; $(MAKE) install
.NOEXPORT:

110
NEWS
View File

@@ -1,110 +0,0 @@
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
on recent RedHat Linux systems
- fixed a problem with message deletion, which used to occur if an mbox
folder and temporary directory were on different filesystems;
thanks to James P. Dugal <jpd@louisiana.edu> for providing a patch
Changes since 0.7.7
- fixed crashes on MH folders, as well as a potential problem with mbox
and maildir folders with the same cause
- debugging with dmalloc library
- MH and maildir functions no longer read files which aren't RFC 2822 messages
- mboxgrep can now read gzip compressed mbox folders from standard input
(which is a side effect of a code cleanup!)
Changes since 0.7.6a
- mboxgrep can now read mbox folders from standard input
Changes since 0.7.6
- fixed a bug which prevented mboxgrep from being compiled
Changes since 0.7.5
- fixed a bug which caused mboxgrep to coredump on recursive search of
maildirs
- code cleanups
Changes since 0.7.4
- recursive search through directories has been reimplemented
Changes since 0.7.3
- mboxgrep can now ignore messages with identical bodies
Changes since 0.7.2
- file locking method can be selected at runtime
- mboxgrep used to coredump on messages with empty headers; the problem is
now hopefully fixed
- mboxgrep now compiles on FreeBSD
Changes since 0.7.1
- file locking with flock() instead of fcntl() is now supported
- mboxgrep should now compile on systems which don't have getopt_long()
- other minor bugfixes
Changes since 0.7.0
- bugfixes
Changes since 0.5.3
- NOTE: there was no stable version between 0.5.x and 0.7.x
- mboxgrep is almost completely rewritten
- implemented message deleting feature (--delete)
- implemented piping messages to a command (--pipe) (using this option,
each selected message is piped to a separate instance of the specified
command)
- added support for compressed mbox folders
Changes since 0.5.2
- implemented ability to write found messages to another folder (instead
of stdout)
- started writing *real* changelog (while this file has been renamed to
"NEWS")
- wrote a manual in Texinfo format
Changes since 0.5.1
- implemented message counting (-c, --count)
- fixed manual page installation target in src/Makefile.in -- manual page
is now installed in $(manpath)/man1/ rather than in $(prefix)/man/man1/
- added `--without-sense-of-humor' switch to the configure script, which
disables checking whether Garfield still hates Mondays
- short version of `--version' switch is now `-V' instead of `-v',
because `-v' will be used for inverted matching
- implemented inverted matching (-v, --invert-match)
- implemented recursive search through directories (-r, --recursive)
- config.h[.in] is now wrapped (#ifndef CONFIG_H and stuff)
Changes since 0.5.0
- added support for qmail-style maildir folders
Changes since 0.4.0
- source of getopt_long() is now included, so long options are also available
on platforms that don't use GNU libc
- file locking is now performed on mbox folders only
Changes since 0.2.0
- added support for MH mailboxes
- added scope selection switches `-B' (or `--body') and `-H' (or `--headers')
- getopt() (or getopt_long(), if available) is now used to parse command line
arguments, instead of my own lousy routine
- configure script now looks for PCRE by default, unless `--with-pcre=no' or
`--without-pcre' is specified
- the feature of reading from standard input is gone
- added `-v' (or `--version') switch
Changes since 0.1.1
- mboxgrep now puts a shared lock on a mailbox before reading it
- various code cleanups
Changes since 0.1.0
- fixed install target in Makefile (`install' is now used instead of `cp')
- added support for mailboxes generated by Gnus
$Id: NEWS,v 1.23 2004-04-11 21:48:53 dspiljar Exp $

144
NEWS.md Normal file
View File

@@ -0,0 +1,144 @@
# Changes of mboxgrep
## Changes since 0.7.12
- Fix Automake macros to include the license file and others.
## Changes since 0.7.11
- Port to the pcre2 library (pcre1 is no longer supported).
- Check command-line options for conflicting matchers and actions.
- Various minor code cleanups.
## Changes since 0.7.10
- GNU Automake is now utilized instead of manually written Makefile.in files.
- Code indentation has been corrected and documented (GNU indent is used for this purpose).
## Changes since 0.7.9
- development has been restarted after a longer hiatus
- moved the source tree to git
- fixed compile bug on FreeBSD and other systems
- fixed deleting messages mbox folders compressed with bzip2
- fixed multiple compilation errors and warnings on Linux and FreeBSD
- started implementing a debug mode
## 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
on recent RedHat Linux systems
- fixed a problem with message deletion, which used to occur if an mbox
folder and temporary directory were on different filesystems;
thanks to James P. Dugal <jpd AT louisiana.edu> for providing a patch
## Changes since 0.7.7
- fixed crashes on MH folders, as well as a potential problem with mbox
and maildir folders with the same cause
- debugging with the dmalloc library
- MH and maildir functions no longer read files which aren't RFC 2822 messages
- mboxgrep can now read gzip compressed mbox folders from standard input
(which is a side effect of a code cleanup!)
## Changes since 0.7.6a
- mboxgrep can now read mbox folders from standard input
## Changes since 0.7.6
- fixed a bug which prevented mboxgrep from being compiled
## Changes since 0.7.5
- fixed a bug which caused mboxgrep to coredump on recursive search of
maildirs
- code cleanups
## Changes since 0.7.4
- recursive search through directories has been reimplemented
## Changes since 0.7.3
- mboxgrep can now ignore messages with identical bodies
## Changes since 0.7.2
- file locking method can be selected at runtime
- mboxgrep used to coredump on messages with empty headers; the problem is
now hopefully fixed
- mboxgrep now compiles on FreeBSD
## Changes since 0.7.1
- file locking with `flock()` instead of `fcntl()` is now supported
- mboxgrep should now compile on systems which don't have `getopt_long()`
- other minor bugfixes
## Changes since 0.7.0
- bugfixes
## Changes since 0.5.3
- NOTE: there was no stable version between 0.5.x and 0.7.x
- mboxgrep is almost completely rewritten
- implemented message deleting feature (`--delete`)
- implemented piping messages to a command (`--pipe`) (using this option,
each selected message is piped to a separate instance of the specified
command)
- added support for compressed mbox folders
## Changes since 0.5.2
- implemented ability to write found messages to another folder (instead
of standard output)
- started writing a *real* changelog (while this file has been renamed to
"NEWS")
- wrote a manual in Texinfo format
## Changes since 0.5.1
- implemented message counting (`-c, --count`)
- fixed manual page installation target in src/Makefile.in -- manual page
is now installed in `$(manpath)/man1/` rather than `$(prefix)/man/man1/`
- added `--without-sense-of-humor` switch to the configure script, which
disables checking whether Garfield still hates Mondays
- short version of `--version` switch is now `-V` instead of `-v`,
because `-v` will be used for inverted matching
- implemented inverted matching (`-v, --invert-match`)
- implemented recursive search through directories (`-r, --recursive`)
- config.h[.in] is now wrapped (`#ifndef CONFIG_H` and stuff)
## Changes since 0.5.0
- added support for qmail-style maildir folders
## Changes since 0.4.0
- the source of `getopt_long()` is now included, so long options are also available
on platforms that don't use GNU libc
- file locking is now performed on mbox folders only
## Changes since 0.2.0
- added support for MH mailboxes
- added scope selection switches `-B` (or `--body`) and `-H` (or `--headers`)
- `getopt()` (or `getopt_long()`, if available) is now used to parse command line
arguments, instead of my own lousy routine
- the configure script now looks for PCRE by default, unless `--with-pcre=no` or
`--without-pcre` is specified
- the feature of reading from standard input is gone
- added `-v` (or `--version`) switch
## Changes since 0.1.1
- mboxgrep now puts a shared lock on a mailbox before reading it
- various code cleanups
## Changes since 0.1.0
- fixed install target in Makefile (`install` is now used instead of `cp`)
- added support for mailboxes generated by Gnus

View File

@@ -1,4 +1,7 @@
mboxgrep - displays e-mail messages matching a pattern # mboxgrep - selects e-mail messages matching a pattern
`mboxgrep` is a `grep(1)`-like tool which scans mailboxes and selects
e-mail messages matching a pattern.
Full description of mboxgrep is contained in the documentation, Full description of mboxgrep is contained in the documentation,
which is provided both in manpage and texinfo format, to satisfy which is provided both in manpage and texinfo format, to satisfy
@@ -11,5 +14,8 @@ are welcome.
If you intend to bundle mboxgrep with an operating system (such as a If you intend to bundle mboxgrep with an operating system (such as a
GNU/Linux distrubution, for example), please drop me a line about it. GNU/Linux distrubution, for example), please drop me a line about it.
For build instructions, read the file "INSTALL", and run For build instructions, read the file `INSTALL.md`, and run
`./configure --help`. `./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`.

48
TODO.md
View File

@@ -1,21 +1,39 @@
# The TODO list for mboxgrep
## Behavior
- [x] use cryptographic hashes for detecting duplicate messages
- [x] add checking for conflicting command-line options
- [ ] support for deletion of messages after being matched and displayed
- [x] ignore .overview when grepping Gnus folders - [x] ignore .overview when grepping Gnus folders
- [x] implement inverted matching - [x] inverted matching
- [x] re-implement recursive search through directories - [x] recursive search through directories
- [ ] implement literal date matching - [x] writing selected messages to a new folder
- [x] deleting selected messages
- [ ] basic time and date matching
- [ ] more advanced time and date matching, with strings such as "yesterday"
- [x] reading messages from standard input
- [x] run-time selection of file locking method
- [x] add a debug function
## File formats, encodings and standards
- [x] migrate to pcre2, as pcre is obsolete
- [ ] use a more modern hash function than MD5
- [ ] MIME support
- [ ] support for GnuPG
- [x] support for compressed mbox folders
- [x] support for bzip2 compression
- [ ] support for XZ-format compression
- [ ] support for mail folder conversion
- [ ] improve error detection when a directory is not a Maildir or MH folder
- [ ] document criteria for folder format detection
## Miscellaneous
- [x] write Texinfo documentation - [x] write Texinfo documentation
- [x] implement writing selected messages to a new folder - [ ] configuration files
- [x] implement deleting selected messages
- [ ] add support for config files
- [x] add support for reading messages from stdin
- [x] add support for compressed mbox folders
- [ ] make use of lockfile library - [ ] make use of lockfile library
- [ ] make use of Solaris' maillock library - [ ] make use of Solaris' maillock library
- [x] provide possibility to use flock() instead of fcntl() - [x] provide possibility to use flock() instead of fcntl()
- [ ] provide national language support with gettext() - [ ] provide national language support with gettext()
- [x] allow run-time selection of file locking method
- [ ] make mboxgrep understand MIME
- [x] enable removing duplicate messages w/ MD5 checksums
- [ ] add checking for conflicting command-line options
- [ ] add support for GnuPG
- [x] add support for bzip2 compression
- [ ] add support for mail folder conversion

5274
configure vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
# mboxgrep - scan mailbox for messages matching a regular expression # 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 # Mboxgrep is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by # under the terms of the GNU General Public License as published by
@@ -15,13 +15,13 @@
# along with mboxgrep; if not, write to the Free Software Foundation, # along with mboxgrep; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id: configure.ac,v 1.13 2003-08-10 22:45:45 dspiljar Exp $
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
# Yawn. # Yawn.
AC_INIT AC_INIT([mboxgrep], [0.7.12a], [dspiljar@datatipp.se], [mboxgrep], [https://www.mboxgrep.org/])
AC_LANG(C) #AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([foreign])
AC_LANG([C])
AC_CONFIG_HEADER([src/config.h]) AC_CONFIG_HEADER([src/config.h])
# Checks for programs. # Checks for programs.
@@ -34,34 +34,35 @@ AC_HEADER_DIRENT
# Checks for libraries. # Checks for libraries.
# Check for PCRE library # Check for PCRE2 library
AC_ARG_WITH(pcre, [ --without-pcre Compile without Perl regexp support],, AC_ARG_WITH(pcre2, [ --without-pcre2 Compile without Perl regexp support],,
[ [
AC_PATH_PROG(PCRE_CONFIG, pcre-config) AC_PATH_PROG(PCRE2_CONFIG, pcre2-config)
if test "$PCRE_CONFIG"; then if test "$PCRE2_CONFIG"; then
CFLAGS="$CFLAGS `$PCRE_CONFIG --cflags`" CFLAGS="$CFLAGS `$PCRE2_CONFIG --cflags`"
LIBS="$LIBS `$PCRE_CONFIG --libs`" LIBS="$LIBS `$PCRE2_CONFIG --libs32`"
AC_LINK_IFELSE( AC_LINK_IFELSE(
[ [
#include <pcre.h> #define PCRE2_CODE_UNIT_WIDTH 32
#include <pcre2.h>
int main () int main ()
{ {
return 0; return 0;
} }
], ],
AC_DEFINE(HAVE_LIBPCRE), AC_DEFINE(HAVE_LIBPCRE2),
[ [
AC_MSG_NOTICE(found pcre-config but could not compile test program.) AC_MSG_NOTICE(found pcre2-config but could not compile test program.)
AC_MSG_FAILURE(is PCRE properly installed?) AC_MSG_FAILURE(is PCRE2 properly installed?)
] ]
) )
else else
AC_MSG_NOTICE(pcre-config not found) AC_MSG_NOTICE(pcre2-config not found)
AC_MSG_NOTICE(trying to find PCRE anyway) AC_MSG_NOTICE(trying to find PCRE2 anyway)
AC_CHECK_LIB(pcre, main) AC_CHECK_LIB(pcre2, main)
fi fi
] ]
) )

View File

@@ -1,5 +0,0 @@
This directory is intended to hold third-party contributions.
- mboxgrep.spec is an RPM spec file, kindly contributed by
Vaclav Slavik <v.slavik@volny.cz>

3
contrib/README.md Normal file
View File

@@ -0,0 +1,3 @@
This directory is intended to hold third-party contributions.
- mboxgrep.spec is an RPM spec file, kindly contributed by Vaclav Slavik <v.slavik AT volny.cz>

2
doc/Makefile.am Normal file
View File

@@ -0,0 +1,2 @@
dist_man_MANS = mboxgrep.1
info_TEXINFOS = mboxgrep.texi

View File

@@ -1,41 +0,0 @@
# mboxgrep - search mailbox for messages matching a regular expression
# Copyright (C) 2000, 01 Daniel Spiljar
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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 $
MANPAGE = mboxgrep.1
INSTALL = @INSTALL@
prefix = @prefix@
mandir = @mandir@
infodir = @infodir@
SHELL = /bin/sh
.PHONY: all
all:
.PHONY: distclean
distclean:
rm -f *~ Makefile
.PHONY: install
install: mboxgrep.1
$(INSTALL) -d $(mandir)/man1
$(INSTALL) -m 0644 $(MANPAGE) $(mandir)/man1
$(INSTALL) -d $(infodir)
$(INSTALL) -m 0644 mboxgrep.info $(infodir)
.NOEXPORT:

View File

@@ -1,5 +1,4 @@
.Id $Id: mboxgrep.1,v 1.16 2006-01-18 00:09:58 dspiljar Exp $ .TH MBOXGREP 1 "21 May 2023"
.TH MBOXGREP 1 "26 Jan 2023"
.SH NAME .SH NAME
mboxgrep \- displays email messages matching a pattern mboxgrep \- displays email messages matching a pattern
.SH SYNOPSIS .SH SYNOPSIS
@@ -11,7 +10,7 @@ mboxgrep \- displays email messages matching a pattern
This manual page refers to This manual page refers to
.B mboxgrep .B mboxgrep
version version
.BR 0.7.10 . .BR 0.7.12a .
.PP .PP
.B mboxgrep .B mboxgrep
scans a scans a
@@ -84,14 +83,18 @@ caution.
Ignore duplicate messages. Ignore duplicate messages.
.IP "-m, --mailbox-format=TYPE" .IP "-m, --mailbox-format=TYPE"
Select input and output mailbox TYPE. TYPE can be either `mbox' (default), Select input and output mailbox TYPE. TYPE can be either `mbox' (default),
`zmbox' (meaning `gzip compressed mbox'), `bz2mbox' (meaning `bzip2 `zmbox' (gzip compressed mbox), `bz2mbox' (bzip2 compressed mbox), `mh', `nnml',
compressed mbox'), `mh', `nnml', `nnmh' or `maildir'. `nnmh' or `maildir'.
.IP "-s, --no-messages"
Suppress most error messages.
.IP "--debug"
Print messages useful for debugging.
.SH EXAMPLES .SH EXAMPLES
.TP .TP
\(bu \(bu
Search $MAIL for messages from Dirty Harry: Search $MAIL for messages from Dirty Harry:
.PP .PP
mboxgrep '^From:.*callahan@homicide\\.SFPD\\.gov' $MAIL mboxgrep '^From:.*callahan@sanfranciscopolice\\.org' $MAIL
.TP .TP
\(bu \(bu
Display all messages contained in folder ~/Mail/incoming, except those Display all messages contained in folder ~/Mail/incoming, except those
@@ -100,9 +103,6 @@ that appear to originate from AOL:
mboxgrep -v 'Received:.*aol\\.com' ~/Mail/incoming mboxgrep -v 'Received:.*aol\\.com' ~/Mail/incoming
.SH BUGS .SH BUGS
Report them to address below. Report them to address below.
.SH NOTICE
Mboxgrep was alomost completely rewritten since version 0.5.3. Additionally,
there was no stable 0.6.x branch between 0.5.3 and 0.7.0.
.SH SEE ALSO .SH SEE ALSO
grep(1), grep(1),
regex(7), regex(7),

View File

@@ -9,7 +9,7 @@ END-INFO-DIR-ENTRY
 
File: mboxgrep.info, Node: Top, Up: (dir) File: mboxgrep.info, Node: Top, Up: (dir)
This file documents 'mboxgrep' (version 0.7.10), a mailbox scanning This file documents 'mboxgrep' (version 0.7.12a), a mailbox scanning
utility. utility.
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
@@ -169,6 +169,9 @@ options below change such behavior.
'-s' '-s'
Suppress error messages. Suppress error messages.
'--debug'
Print messages useful for debugging.
 
File: mboxgrep.info, Node: Search scope selection, Next: Mailbox type selection, Prev: Output control, Up: Invoking File: mboxgrep.info, Node: Search scope selection, Next: Mailbox type selection, Prev: Output control, Up: Invoking
@@ -197,7 +200,7 @@ File: mboxgrep.info, Node: Examples, Next: Bugs, Prev: Invoking, Up: Top
Scan '$MAIL' for messages from Dirty Harry: Scan '$MAIL' for messages from Dirty Harry:
mboxgrep -H '^From:.*callahan@homicide\.SFPD\.gov' $MAIL mboxgrep -H '^From:.*callahan@sanfranciscopolice\.org' $MAIL
Re-mail to George messages that mention his name: Re-mail to George messages that mention his name:
@@ -224,11 +227,11 @@ File: mboxgrep.info, Node: Bugs, Next: To Vicky, Prev: Examples, Up: Top
****************** ******************
Shortly, if 'mboxgrep' crashes and/or works differently than described Shortly, if 'mboxgrep' crashes and/or works differently than described
in this manual, you've found a bug. in this manual, you have found a bug.
Please report bugs to <dspiljar@datatipp.se>. Instructions how to Please report bugs to <dspiljar@datatipp.se>. Instructions how to
reproduce the bug or output from a debugger would be highly appreciated. reproduce the bug or output from a debugger would be highly appreciated.
Don't, however, send any coredumps. Please do not, however, send any core dumps.
 
File: mboxgrep.info, Node: To Vicky, Prev: Bugs, Up: Top File: mboxgrep.info, Node: To Vicky, Prev: Bugs, Up: Top
@@ -247,17 +250,17 @@ Sleep well, little friend.
 
Tag Table: Tag Table:
Node: Top197 Node: Top197
Node: Introduction596 Node: Introduction597
Node: Invoking1465 Node: Invoking1466
Node: Miscellaneous1827 Node: Miscellaneous1828
Node: File locking2112 Node: File locking2113
Node: Regexp selection2749 Node: Regexp selection2750
Node: Output control3301 Node: Output control3302
Node: Search scope selection4292 Node: Search scope selection4346
Node: Mailbox type selection4533 Node: Mailbox type selection4587
Node: Examples4854 Node: Examples4908
Node: Bugs5674 Node: Bugs5732
Node: To Vicky6081 Node: To Vicky6150
 
End Tag Table End Tag Table

View File

@@ -1,13 +1,12 @@
\input texinfo @c -*-texinfo-*- \input texinfo
@c $Id: mboxgrep.texi,v 1.20 2006-01-18 00:09:58 dspiljar Exp $
@setfilename mboxgrep.info @setfilename mboxgrep.info
@settitle Grep through mailboxes @settitle Grep through mailboxes
@finalout @finalout
@setchapternewpage odd @setchapternewpage odd
@set EDITION 0.7 @set EDITION 0.7
@set VERSION 0.7.10 @set VERSION 0.7.12a
@set UPDATED 26 Jan 2023 @set UPDATED 21 May 2023
@dircategory Mail @dircategory Mail
@direntry @direntry
@@ -189,6 +188,9 @@ instance of COMMAND.
@itemx -s @itemx -s
Suppress error messages. Suppress error messages.
@item --debug
Print messages useful for debugging.
@end table @end table
@node Search scope selection, Mailbox type selection, Output control, Invoking @node Search scope selection, Mailbox type selection, Output control, Invoking
@@ -224,7 +226,7 @@ mbox) @code{mh}, @code{nnml}, @code{nnmh}, and @code{maildir}.
Scan @env{$MAIL} for messages from Dirty Harry: Scan @env{$MAIL} for messages from Dirty Harry:
@example @example
mboxgrep -H '^From:.*callahan@@homicide\.SFPD\.gov' $MAIL mboxgrep -H '^From:.*callahan@@sanfranciscopolice\.org' $MAIL
@end example @end example
Re-mail to George messages that mention his name: Re-mail to George messages that mention his name:
@@ -258,11 +260,11 @@ mboxgrep -nd -c . spam
@cindex bug, insect, vermin, bugreport @cindex bug, insect, vermin, bugreport
Shortly, if @code{mboxgrep} crashes and/or works differently than described Shortly, if @code{mboxgrep} crashes and/or works differently than described
in this manual, you've found a bug. in this manual, you have found a bug.
Please report bugs to @email{dspiljar@@datatipp.se}. Please report bugs to @email{dspiljar@@datatipp.se}.
Instructions how to reproduce the bug or output from a debugger would be Instructions how to reproduce the bug or output from a debugger would be
highly appreciated. Don't, however, send any coredumps. highly appreciated. Please do not, however, send any core dumps.
@node To Vicky, , Bugs, Top @node To Vicky, , Bugs, Top
@chapter Author's Dedication @chapter Author's Dedication

11772
doc/texinfo.tex Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,251 +0,0 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

6
src/Makefile.am Normal file
View File

@@ -0,0 +1,6 @@
bin_PROGRAMS = mboxgrep
mboxgrep_SOURCES = info.c info.h maildir.c maildir.h main.c mbox.c mbox.h \
mboxgrep.h md5.c md5.h message.h misc.c misc.h mh.c mh.h \
getopt.c getopt1.c getopt.h re.c re.h scan.c scan.h wrap.c wrap.h
mboxgrep_LDADD = $(LIBOBJS)

View File

@@ -1,57 +0,0 @@
# mboxgrep - scan mailbox for messages matching a regular expression
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Mboxgrep is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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: 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 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 re.c
TARGET = mboxgrep
CFLAGS = @CFLAGS@
LIBS = @LIBS@
INSTALL = @INSTALL@
prefix = @prefix@
SHELL = /bin/sh
INCLUDES = -I. -I$(srcdir)
.SUFFIXES:
.SUFFIXES: .c .o
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS) core
.PHONY: distclean
distclean:
rm -f *~ Makefile config.h
.PHONY: install
install: mboxgrep
$(INSTALL) -d $(prefix)/bin
$(INSTALL) -s $(TARGET) $(prefix)/bin
.NOEXPORT:

View File

@@ -1,67 +0,0 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the `fcntl' function. */
#undef HAVE_FCNTL
/* Define to 1 if you have the `flock' function. */
#undef HAVE_FLOCK
/* Define to 1 if you have the `fts_open' function. */
#undef HAVE_FTS_OPEN
/* Define to 1 if you have the `ftw' function. */
#undef HAVE_FTW
/* Define to 1 if you have the `bz2' library (-lbz2). */
#undef HAVE_LIBBZ2
/* Define to 1 if you have the `dmalloc' library (-ldmalloc). */
#undef HAVE_LIBDMALLOC
/* Define to 1 if you have the `garfield' library (-lgarfield). */
#undef HAVE_LIBGARFIELD
/* Define to 1 if you have the `pcre' library (-lpcre). */
#undef HAVE_LIBPCRE
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the `regcomp' function. */
#undef HAVE_REGCOMP
/* Define to 1 if you have the `strptime' function. */
#undef HAVE_STRPTIME
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

View File

@@ -22,150 +22,156 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "mboxgrep.h" #include "mboxgrep.h"
void void
print_wrap (char *str, int len, int *n) print_wrap (char *str)
/* {{{ */
{ {
*n += len; static int n = 0;
fprintf (stdout, str);
if (*n >= 50) n += strlen (str);
fprintf (stdout, "%s", str);
if (n >= 50)
{ {
fprintf (stdout, "\n"); fprintf (stdout, "\n");
*n = 0; n = 0;
} }
else fprintf (stdout, " "); else
fprintf (stdout, " ");
} }
/* }}} */
void void
version (void) version (void)
/* {{{ */
{ {
int n = 0;
fprintf (stdout, "%s %s\n\n" fprintf (stdout, "%s %s\n\n"
"Copyright (C) 2000 - 2004, 2006, 2010, 2023 Daniel Spiljar\n" "Copyright (C) 2000 - 2004, 2006, 2010, 2023 Daniel Spiljar\n"
"This program is free software; you can redistribute it and/or " "This program is free software; you can redistribute it and/or "
"modify\nit under the terms of the GNU General Public License " "modify\nit under the terms of the GNU General Public License "
"as published by\nthe Free Software Foundation; either version " "as published by\nthe Free Software Foundation; either version "
"2 of the License, or\n(at your option) any later version.\n\n", "2 of the License, or\n(at your option) any later version.\n\n",
APPNAME, VERSION); APPNAME, VERSION);
fprintf (stdout, "Compilation options:\n"); fprintf (stdout, "Compilation options:\n");
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
print_wrap ("HAVE_DIRENT_H", 13, &n); print_wrap ("HAVE_DIRENT_H");
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
print_wrap ("HAVE_FCNTL", 10, &n); print_wrap ("HAVE_FCNTL");
#endif /* HAVE_FCNTL */ #endif /* HAVE_FCNTL */
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
print_wrap ("HAVE_FLOCK", 10, &n); print_wrap ("HAVE_FLOCK");
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
print_wrap ("HAVE_FTS_OPEN", 13, &n); print_wrap ("HAVE_FTS_OPEN");
#else #else
# ifdef HAVE_FTW # ifdef HAVE_FTW
print_wrap ("HAVE_FTW", 8, &n); print_wrap ("HAVE_FTW");
# endif /* HAVE_FTW */ # endif
/* HAVE_FTW */
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
/* /*
fprintf (stdout, "HAVE_LIBLOCKFILE "); fprintf (stdout, "HAVE_LIBLOCKFILE ");
*/ */
#ifdef HAVE_LIBPCRE #ifdef HAVE_LIBPCRE2
print_wrap ("HAVE_LIBPCRE", 12, &n); print_wrap ("HAVE_LIBPCRE2");
#endif /* HAVE_LIBPCRE */ #endif /* HAVE_LIBPCRE2 */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
print_wrap ("HAVE_LIBZ", 9, &n); print_wrap ("HAVE_LIBZ");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
print_wrap ("HAVE_LIBBZ2", 11, &n); print_wrap ("HAVE_LIBBZ2");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
#ifdef HAVE_NDIR_H #ifdef HAVE_NDIR_H
print_wrap ("HAVE_NDIR_H", 11, &n); print_wrap ("HAVE_NDIR_H");
#endif /* HAVE_NDIR_H */ #endif /* HAVE_NDIR_H */
#ifdef HAVE_SYS_DIR_H #ifdef HAVE_SYS_DIR_H
print_wrap ("HAVE_SYS_DIR_H", 14, &n); print_wrap ("HAVE_SYS_DIR_H");
#endif /* HAVE_SYS_DIR_H */ #endif /* HAVE_SYS_DIR_H */
#ifdef HAVE_SYS_NDIR_H #ifdef HAVE_SYS_NDIR_H
print_wrap ("HAVE_SYS_NDIR_H", 15, &n); print_wrap ("HAVE_SYS_NDIR_H");
#endif #endif /* HAVE_SYS_NDIR_H */
#ifdef HAVE_STRPTIME
print_wrap ("HAVE_STRPTIME");
#endif /* HAVE_STRPTIME */
#ifdef HAVE_REGCOMP
print_wrap ("HAVE_REGCOMP");
#endif /* HAVE_REGCOMP */
#ifdef HAVE_LIBDMALLOC
print_wrap ("HAVE_LIBDMALLOC");
#endif /* HAVE_LIBDMALLOC */
fprintf (stdout, "\n"); fprintf (stdout, "\n");
exit(0);
}
/* }}} */
void exit (0);
}
void
help (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); APPNAME, VERSION);
fprintf(stdout, fprintf (stdout,
"Miscellaneous:\n\n" "Miscellaneous:\n\n"
" -h, --help\t\t\tThis help screen\n" " -h, --help\t\t\tThis help screen\n"
" -V, --version\t\tDisplay version, copyright and\n" " -V, --version\t\tDisplay version, copyright and\n"
"\t\t\t\tcompile-time options information\n" "\t\t\t\tcompile-time options information\n"
" -r, --recursive\t\tDescend into directories recursively\n\n" " -r, --recursive\t\tDescend into directories recursively\n\n"
"Output control:\n\n" "Output control:\n\n"
" -c, --count\t\t\tPrint a count of matching messages\n" " -c, --count\t\t\tPrint a count of matching messages\n"
" -d, --delete\t\t\tDelete matching messages\n" " -d, --delete\t\t\tDelete matching messages\n"
" -nd, --no-duplicates\t\tIgnore duplicate messages\n" " -nd, --no-duplicates\t\tIgnore duplicate messages\n"
" -o, --output=MAILBOX\t\tWrite messages to MAILBOX\n" " -o, --output=MAILBOX\t\tWrite messages to MAILBOX\n"
" -p, --pipe=COMMAND\t\tPipe each found message to COMMAND\n" " -p, --pipe=COMMAND\t\tPipe each found message to COMMAND\n"
" -s, --no-messages\t\tSuppress most error messages\n\n" " -s, --no-messages\t\tSuppress most error messages\n"
"Matching criteria:\n\n" " --debug\t\t\tPrint messages useful for debugging\n\n"
" -E, --extended-regexp\tPATTERN is an extended regular expression\n" "Matching criteria:\n\n"
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n"); " -E, --extended-regexp\tPATTERN is an extended regular expression\n"
#ifdef HAVE_LIBPCRE " -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
fprintf(stdout, #ifdef HAVE_LIBPCRE2
" -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n"); fprintf (stdout,
#endif /* HAVE_LIBPCRE */ " -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n");
fprintf(stdout, #endif /* HAVE_LIBPCRE2 */
" -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n" fprintf (stdout,
" -i, --ignore-case\t\tIgnore case distinctions\n" " -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n"
" -v, --invert-match\t\tSelect non-matching messages\n\n" " -i, --ignore-case\t\tIgnore case distinctions\n"
"Search scope selection:\n\n" " -v, --invert-match\t\tSelect non-matching messages\n\n"
" -H, --headers\t\tMatch PATTERN against message headers\n" "Search scope selection:\n\n"
" -B, --body\t\t\tMatch PATTERN against message body\n\n" " -H, --headers\t\tMatch PATTERN against message headers\n"
"File locking:\n\n" " -B, --body\t\t\tMatch PATTERN against message body\n\n"
" -nl, --no-file-lock\t\tDo not lock files\n" "File locking:\n\n"
" -l, --file-lock=METHOD\tSelect file locking METHOD\n" " -nl, --no-file-lock\t\tDo not lock files\n"
"\t\t\t\tMETHOD is"); " -l, --file-lock=METHOD\tSelect file locking METHOD\n"
"\t\t\t\tMETHOD is");
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
fprintf(stdout, " `fcntl',"); fprintf (stdout, " `fcntl',");
#endif /* HAVE_FCNTL */ #endif /* HAVE_FCNTL */
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
fprintf(stdout, " `flock',"); fprintf (stdout, " `flock',");
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
fprintf(stdout, " or `none'\n\n" fprintf (stdout, " or `none'\n\n"
"Mailbox type selection:\n\n" "Mailbox type selection:\n\n"
" -m, --mailbox-format=TYPE\tSelect mailbox TYPE\n" " -m, --mailbox-format=TYPE\tSelect mailbox TYPE\n"
"\t\t\t\tTYPE is `mbox', "); "\t\t\t\tTYPE is `mbox', ");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
fprintf(stdout, "`zmbox', "); fprintf (stdout, "`zmbox', ");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
fprintf(stdout, "`bz2mbox', "); fprintf (stdout, "`bz2mbox', ");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
fprintf(stdout, fprintf (stdout,
"`mh',\n" "`mh',\n"
"\t\t\t\t`nnml', `nnmh', or `maildir'.\n\n" "\t\t\t\t`nnml', `nnmh', or `maildir'.\n\n"
"Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR); "Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR);
exit(0); exit (0);
} }
/* }}} */
void void
usage (void) usage (void)
/* {{{ */
{ {
printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n" printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n"
"Try `%s --help' for more information.\n", APPNAME, APPNAME); "Try `%s --help' for more information.\n", APPNAME, APPNAME);
exit (2); exit (2);
} }
/* }}} */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,13 +15,12 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: info.h,v 1.5 2003-04-13 19:15:58 dspiljar Exp $ */
#ifndef INFO_H #ifndef INFO_H
#define INFO_H # define INFO_H
void print_wrap (char *str, int len, int *n); void print_wrap (char *str);
void version (void); void version (void);
void help (void); void help (void);
void usage (void); void usage (void);

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: maildir.c,v 1.25 2006-10-19 01:53:43 dspiljar Exp $ */
#include <config.h> #include <config.h>
@@ -24,20 +23,23 @@
#include <string.h> #include <string.h>
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
# include <dirent.h> # include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name) # define NAMLEN(dirent) strlen((dirent)->d_name)
#else #else
# define dirent direct # define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen # define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <stdlib.h> #include <stdlib.h>
@@ -53,7 +55,7 @@
#include "wrap.h" #include "wrap.h"
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
#include <dmalloc.h> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
maildir_t * maildir_t *
@@ -65,29 +67,29 @@ maildir_open (const char *path)
foo = m_opendir (path); foo = m_opendir (path);
if (foo == NULL) if (foo == NULL)
return NULL; return NULL;
closedir (foo); closedir (foo);
if (-1 == maildir_check (path)) if (-1 == maildir_check (path))
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME, path); fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME, path);
return NULL; 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); sprintf (dirname, "%s/new", path);
mp->new = m_opendir (dirname); mp->new = m_opendir (dirname);
if (mp->new == NULL) if (mp->new == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, dirname); fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL); perror (NULL);
} }
free (dirname); free (dirname);
errno = 0; errno = 0;
return NULL; return NULL;
@@ -98,67 +100,68 @@ maildir_open (const char *path)
if (mp->cur == NULL) if (mp->cur == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, dirname); fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL); perror (NULL);
} }
free (dirname); free (dirname);
errno = 0; errno = 0;
return NULL; return NULL;
} }
free (dirname); free (dirname);
return mp; return mp;
} /* maildir_open */ } /* maildir_open */
message_t * message_t *
maildir_read_message (maildir_t *mdp) maildir_read_message (maildir_t * mdp)
{ {
int isheaders = 1; int isheaders = 1;
int have_from = 0, have_to = 0, have_message_id = 0, have_sender = 0, int have_from = 0, have_to = 0, have_message_id = 0, have_sender = 0,
have_date = 0; have_date = 0;
static message_t *message; static message_t *message;
static struct dirent *d_content; static struct dirent *d_content;
char *filename, buffer[BUFSIZ]; char *filename, buffer[BUFSIZ];
static FILE *fp; static FILE *fp;
static int s; static int s;
message = malloc_message (); message = allocate_message ();
for(;;) for (;;)
{ {
if (mdp->new != NULL) if (mdp->new != NULL)
{ {
d_content = readdir (mdp->new); d_content = readdir (mdp->new);
if (d_content == NULL) if (d_content == NULL)
{ {
closedir (mdp->new); closedir (mdp->new);
mdp->new = NULL; mdp->new = NULL;
} }
} }
if (mdp->new == NULL && mdp->cur != NULL) if (mdp->new == NULL && mdp->cur != NULL)
{ {
d_content = readdir (mdp->cur); d_content = readdir (mdp->cur);
if (d_content == NULL) if (d_content == NULL)
{ {
closedir (mdp->cur); closedir (mdp->cur);
mdp->cur = NULL; mdp->cur = NULL;
} }
} }
if (mdp->new == NULL && mdp->cur == NULL) if (mdp->new == NULL && mdp->cur == NULL)
{ {
free (message->headers); free (message->headers);
free (message->body); free (message->body);
free (message); free (message);
return NULL; return NULL;
} }
if (d_content->d_name[0] == '.') if (d_content->d_name[0] == '.')
continue; continue;
filename = filename =
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name)) (char *) xmalloc ((sizeof (char) * ((strlen (d_content->d_name))
+ (strlen (config.boxname)) + 6))); + (strlen (config.boxname)) +
6)));
/* /*
filename = filename =
@@ -166,73 +169,79 @@ maildir_read_message (maildir_t *mdp)
+ (strlen(config.boxname)) + 2))); + (strlen(config.boxname)) + 2)));
*/ */
if (mdp->new != NULL) 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 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); message->filename = (char *) xstrdup (filename);
free (filename); free (filename);
isheaders = 1; isheaders = 1;
fp = m_fopen(message->filename, "r"); fp = m_fopen (message->filename, "r");
if (fp == NULL) if (fp == NULL)
continue; continue;
while (fgets (buffer, BUFSIZ, fp) != NULL) while (fgets (buffer, BUFSIZ, fp) != NULL)
{ {
s = strlen (buffer); s = strlen (buffer);
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1) if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
{ {
isheaders = 0; isheaders = 0;
continue; continue;
} /* if */ } /* if */
if (isheaders) if (isheaders)
{ {
if (0 == strncasecmp ("From: ", buffer, 6)) if (0 == strncasecmp ("From: ", buffer, 6))
have_from = 1; have_from = 1;
if (0 == strncasecmp ("Sender: ", buffer, 8)) if (0 == strncasecmp ("Sender: ", buffer, 8))
have_sender = 1; have_sender = 1;
if (0 == strncasecmp ("Date: ", buffer, 6)) if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1; have_date = 1;
if (0 == strncasecmp ("To: ", buffer, 4)) if (0 == strncasecmp ("To: ", buffer, 4))
have_to = 1; have_to = 1;
if (0 == strncasecmp ("Message-ID: ", buffer, 12)) if (0 == strncasecmp ("Message-ID: ", buffer, 12))
have_message_id = 1; have_message_id = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13)) 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)));
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_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;
}
fclose(fp);
return message;
} /* for */
} /* maildir_read_message */
void if ((!have_from && !have_sender) || !have_date)
maildir_write_message (message_t *m, const char *path) {
if (config.merr)
fprintf (stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, message->filename);
fclose (fp);
continue;
}
fclose (fp);
return message;
} /* for */
} /* maildir_read_message */
void
maildir_write_message (message_t * m, const char *path)
{ {
char bla[BUFSIZ], *s1, *s2; char bla[BUFSIZ], *s1, *s2;
int t; int t;
@@ -242,11 +251,11 @@ maildir_write_message (message_t *m, const char *path)
t = (int) time (NULL); t = (int) time (NULL);
sprintf (bla, "%i.%i_%i.%s", sprintf (bla, "%i.%i_%i.%s",
t, config.pid, runtime.maildir_count, config.hostname); t, config.pid, runtime.maildir_count, config.hostname);
s1 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char)); 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)); 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"); f1 = m_fopen (s1, "w");
fprintf (f1, "%s\n%s", m->headers, m->body); fprintf (f1, "%s\n%s", m->headers, m->body);
@@ -254,7 +263,7 @@ maildir_write_message (message_t *m, const char *path)
rename (s1, s2); rename (s1, s2);
} }
int int
maildir_check (const char *path) maildir_check (const char *path)
{ {
static struct stat fs; static struct stat fs;
@@ -265,51 +274,57 @@ maildir_check (const char *path)
sprintf (s, "%s/cur", path); sprintf (s, "%s/cur", path);
i = stat (s, &fs); i = stat (s, &fs);
if (-1 == i) return -1; if (-1 == i)
if (! S_ISDIR (fs.st_mode)) return -1; return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
sprintf (s, "%s/new", path); sprintf (s, "%s/new", path);
i = stat (s, &fs); i = stat (s, &fs);
if (-1 == i) return -1; if (-1 == i)
if (! S_ISDIR (fs.st_mode)) return -1; return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
sprintf(s, "%s/tmp", path); sprintf (s, "%s/tmp", path);
i = stat (s, &fs); i = stat (s, &fs);
if (-1 == i) return -1; if (-1 == i)
if (! S_ISDIR (fs.st_mode)) return -1; return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
free (s); free (s);
return 0; return 0;
} }
void void
maildir_create (const char *path) maildir_create (const char *path)
{ {
char *s; char *s;
int i; int i;
s = (char *) xmalloc ((strlen (path) + 4) * sizeof(char)); s = (char *) xmalloc ((strlen (path) + 4) * sizeof (char));
errno = 0; errno = 0;
for (;;) for (;;)
{ {
sprintf(s, "%s", path); sprintf (s, "%s", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
sprintf(s, "%s/new", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf(s, "%s/cur", path); sprintf (s, "%s/new", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf(s, "%s/tmp", path); sprintf (s, "%s/cur", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf (s, "%s/tmp", path);
i = mkdir (s, S_IRWXU);
if (-1 == i)
break;
break; break;
} }
@@ -317,9 +332,9 @@ maildir_create (const char *path)
if (errno != 0) if (errno != 0)
{ {
if (config.merr) if (config.merr)
{ {
fprintf(stderr, "%s:%s: ", APPNAME, s); fprintf (stderr, "%s:%s: ", APPNAME, s);
perror (NULL); perror (NULL);
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,32 +15,35 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: maildir.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef MAILDIR_H #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> # include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name) # define NAMLEN(dirent) strlen((dirent)->d_name)
#else # else
# define dirent direct # define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen # define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
#endif /* HAVE_DIRENT_H */ # include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif
/* HAVE_DIRENT_H */
#include "mboxgrep.h" # include "mboxgrep.h"
typedef struct typedef struct
{ {
@@ -51,8 +54,8 @@ typedef struct
maildir_t *maildir_open (const char *path); maildir_t *maildir_open (const char *path);
int maildir_check (const char *path); int maildir_check (const char *path);
void maildir_create (const char *path); void maildir_create (const char *path);
void maildir_close (maildir_t *mdp); void maildir_close (maildir_t * mdp);
message_t *maildir_read_message (maildir_t *mdp); message_t *maildir_read_message (maildir_t * mdp);
void maildir_write_message (message_t *m, const char *path); void maildir_write_message (message_t * m, const char *path);
#endif /* MAILDIR_H */ #endif /* MAILDIR_H */

View File

@@ -15,7 +15,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <config.h> #include <config.h>
@@ -25,9 +24,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> # include <zlib.h>
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#include "getopt.h" #include "getopt.h"
@@ -37,11 +35,11 @@
#include "mbox.h" #include "mbox.h"
#include "mh.h" #include "mh.h"
#include "scan.h" #include "scan.h"
#include "wrap.h" /* xcalloc() et cetera */ #include "wrap.h" /* xcalloc() et cetera */
#include "re.h" #include "re.h"
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
#include <dmalloc.h> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
option_t config; option_t config;
@@ -49,81 +47,65 @@ runtime_t runtime;
int int
main (int argc, char **argv) main (int argc, char **argv)
/* {{{ */
{ {
int havemailbox = 0; int havemailbox = 0;
int singlefile = 0; int singlefile = 0;
runtime.count = 0; runtime.count = 0;
runtime.maildir_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'}, */
{"extended-regexp", 0, 0, 'E'},
{"basic-regexp", 0, 0, 'G'},
{"perl-regexp", 0, 0, 'P'},
{"help", 0, 0, 'h'},
{"ignore-case", 0, 0, 'i'},
{"mailbox-format", 1, 0, 'm'},
{"no", 1, 0, 'n'},
{"pipe", 1, 0, 'p'},
{"regexp", 1, 0, 'e'},
{"invert-match", 0, 0, 'v'},
{"version", 0, 0, 'V'},
{"headers", 0, 0, 'H'},
{"body", 0, 0, 'B'},
{"no-messages", 0, 0, 's'},
{"output", 1, 0, 'o'},
{"no-duplicates", 0, 0, 200},
{"no-file-lock", 0, 0, 201},
{"debug", 0, 0, 202},
{"file-lock", 1, 0, 'l'},
{"recursive", 0, 0, 'r'},
{0, 0, 0, 0}
};
{ init_options ();
{"count", 0, 0, 'c'},
{"delete", 0, 0, 'd'},
/* {"date", 1, 0, 'D'}, */
{"extended-regexp", 0, 0, 'E'},
{"basic-regexp", 0, 0, 'G'},
{"perl-regexp", 0, 0, 'P'},
{"help", 0, 0, 'h'},
{"ignore-case", 0, 0, 'i'},
{"mailbox-format", 1, 0, 'm'},
{"no", 1, 0, 'n' },
{"pipe", 1, 0, 'p'},
{"regexp", 1, 0, 'e'},
{"invert-match", 0, 0, 'v'},
{"version", 0, 0, 'V'},
{"headers", 0, 0, 'H'},
{"body", 0, 0, 'B'},
{"no-messages", 0, 0, 's'},
{"output", 1, 0, 'o'},
{"no-duplicates", 0, 0, 200},
{"no-file-lock", 0, 0, 201},
{"file-lock", 1, 0, 'l'},
{"recursive", 0, 0, 'r'},
{0, 0, 0, 0}
};
/* }}} */ get_options (&argc, argv, long_options);
set_default_options (); check_options ();
get_runtime_options (&argc, argv, long_options);
if ((config.body == 0) && (config.headers == 0))
{
config.body = 1;
config.headers = 1;
}
if (config.format == MAILDIR && config.action == WRITE)
{
gethostname (config.hostname, HOST_NAME_SIZE);
config.pid = (int) getpid ();
}
runtime.cs = (checksum_t *) xmalloc (sizeof (checksum_t)); runtime.cs = (checksum_t *) xmalloc (sizeof (checksum_t));
runtime.cs->md5 = (char **) xcalloc (1, sizeof (char **)); runtime.cs->md5 = (char **) xcalloc (1, sizeof (char **));
runtime.cs->n = 0; runtime.cs->n = 0;
if (optind < argc && ! config.haveregex) if (optind < argc && !config.haveregex)
{ {
config.regex_s = xstrdup (argv[optind]); config.regex_s = xstrdup (argv[optind]);
config.haveregex = 1; config.haveregex = 1;
++optind; ++optind;
} /* if */ }
if (config.haveregex) if (config.haveregex)
{ {
#ifdef HAVE_LIBPCRE #ifdef HAVE_LIBPCRE2
if (config.perl) if (config.regextype == REGEX_PERL)
pcre_init (); pcre_init ();
else else
#endif /* HAVE_LIBPCRE */ #endif /* HAVE_LIBPCRE2 */
regex_init (); regex_init ();
} /* if */ }
else else
usage (); usage ();
@@ -131,56 +113,50 @@ main (int argc, char **argv)
singlefile = 1; singlefile = 1;
while (optind < argc) while (optind < argc)
/* {{{ */
{ {
if (config.action == DELETE) { if (config.action == ACTION_DELETE)
tmpmbox_create (argv[optind]); {
runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, "w"); tmpmbox_create (argv[optind]);
} runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, "w");
}
config.boxname = xstrdup (argv[optind]); config.boxname = xstrdup (argv[optind]);
if (config.recursive) if (config.recursive)
recursive_scan (argv[optind]); recursive_scan (argv[optind]);
else else
scan_mailbox (argv[optind]); scan_mailbox (argv[optind]);
havemailbox = 1; havemailbox = 1;
if (config.action == COUNT)
{ if (config.action == ACTION_COUNT)
if (singlefile) {
fprintf (stdout, "%i\n", runtime.count); if (singlefile)
else fprintf (stdout, "%i\n", runtime.count);
{ else
if (0 == strcmp ("-", argv[optind])) {
fprintf (stdout, "(standard input):%i\n", runtime.count); if (0 == strcmp ("-", argv[optind]))
else fprintf (stdout, "(standard input):%i\n", runtime.count);
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count); else
} fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
} }
if (config.action == DELETE) }
{ if (config.action == ACTION_DELETE)
mbox_close (runtime.tmp_mbox); {
rename (config.tmpfilename, argv[optind]); mbox_close (runtime.tmp_mbox);
} rename (config.tmpfilename, argv[optind]);
}
++optind; ++optind;
} /* while */
/* }}} */
if (! havemailbox)
/* {{{ */
{
config.format = MBOX;
scan_mailbox ("-");
if (config.action == COUNT)
fprintf (stdout, "%i\n", runtime.count);
} }
/* }}} */ if (!havemailbox)
{
config.format = FORMAT_MBOX;
scan_mailbox ("-");
if (config.action == ACTION_COUNT)
fprintf (stdout, "%i\n", runtime.count);
}
return 0; return 0;
} /* main */ }
/* }}} */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mbox.c,v 1.34 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h> #include <config.h>
@@ -31,13 +30,13 @@
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
#include <sys/file.h> # include <sys/file.h>
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> # include <zlib.h>
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
#include <bzlib.h> # include <bzlib.h>
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
#define BUFLEN 16384 #define BUFLEN 16384
@@ -47,12 +46,11 @@
#include "wrap.h" #include "wrap.h"
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
#include <dmalloc.h> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
mbox_t * mbox_t *
mbox_open (const char *path, const char *mode) mbox_open (const char *path, const char *mode)
/* {{{ */
{ {
mbox_t *mp; mbox_t *mp;
static int fd; static int fd;
@@ -69,182 +67,178 @@ mbox_open (const char *path, const char *mode)
else else
{ {
if (mode[0] == 'r') if (mode[0] == 'r')
fd = m_open (path, O_RDONLY, 0); fd = m_open (path, O_RDONLY, 0);
else if (mode[0] == 'w') 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)); (S_IWUSR | S_IRUSR));
else else
{ {
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't " fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
"get this error...", APPNAME, mode[0]); "get this error...", APPNAME, mode[0]);
exit (2); exit (2);
} }
if (fd == -1) if (fd == -1)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
return NULL; return NULL;
} }
if (config.lock) if (config.lock > LOCK_NONE)
{ {
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
int op; int op;
if (mode[0] == 'r') if (mode[0] == 'r')
op = LOCK_SH; op = LOCK_SH;
else else
op = LOCK_EX; op = LOCK_EX;
if (-1 == flock (fd, op)) if (-1 == flock (fd, op))
#else #else
memset (&lck, 0, sizeof (struct flock)); memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET; lck.l_whence = SEEK_SET;
if (mode[0] == 'r') if (mode[0] == 'r')
lck.l_type = F_RDLCK; lck.l_type = F_RDLCK;
else else
lck.l_type = F_WRLCK; lck.l_type = F_WRLCK;
if (-1 == fcntl (fd, F_SETLK, &lck)) if (-1 == fcntl (fd, F_SETLK, &lck))
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
close (fd); close (fd);
return NULL; return NULL;
} }
} }
if (mode[0] == 'r') if (mode[0] == 'r')
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
mp->fp = (FILE *) m_fdopen (fd, "r"); mp->fp = (FILE *) m_fdopen (fd, "r");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "rb"); mp->fp = (gzFile *) m_gzdopen (fd, "rb");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb"); mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
else if (mode[0] == 'w') else if (mode[0] == 'w')
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
mp->fp = (FILE *) m_fdopen (fd, "w"); mp->fp = (FILE *) m_fdopen (fd, "w");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "wb"); mp->fp = (gzFile *) m_gzdopen (fd, "wb");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb"); mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
if (mp->fp == NULL) if (mp->fp == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
close (fd); close (fd);
return NULL; return NULL;
} }
} }
if (mode[0] == 'r') if (mode[0] == 'r')
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
fgets (buffer, BUFSIZ, mp->fp); fgets (buffer, BUFSIZ, mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
gzgets (mp->fp, buffer, BUFSIZ); gzgets (mp->fp, buffer, BUFSIZ);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
{ {
char c[1] = "\0"; char c[1] = "\0";
int n = 0; int n = 0;
while (c[0] != '\n' && n < BUFSIZ) while (c[0] != '\n' && n < BUFSIZ)
{ {
BZ2_bzread (mp->fp, c, 1); BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0]; buffer[n] = c[0];
n++; n++;
} }
buffer[n] = '\0'; buffer[n] = '\0';
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
if (0 != strncmp ("From ", buffer, 5)) if (0 != strncmp ("From ", buffer, 5))
{ {
if (config.merr) if (config.merr)
{ {
if (0 == strcmp ("-", path)) if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not a mbox folder\n", fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME); APPNAME);
else 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); if (config.format == FORMAT_MBOX)
fclose (mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
gzclose (mp->fp); gzclose (mp->fp);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
BZ2_bzclose (mp->fp); BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
return NULL; return NULL;
} }
strcpy (mp->postmark_cache, buffer); strcpy (mp->postmark_cache, buffer);
} }
return mp; return mp;
} }
/* }}} */
void void
mbox_close (mbox_t * mp) mbox_close (mbox_t * mp)
/* {{{ */
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
fclose (mp->fp); fclose (mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
gzclose (mp->fp); gzclose (mp->fp);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
BZ2_bzclose (mp->fp); BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
free (mp->postmark_cache); free (mp->postmark_cache);
free (mp); free (mp);
} }
/* }}} */
message_t * message_t *
mbox_read_message (mbox_t * mp) mbox_read_message (mbox_t * mp)
/* {{{ */
{ {
int isheaders = 1, s; int isheaders = 1, s;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
message_t *message; message_t *message;
message = malloc_message (); message = allocate_message ();
s = strlen (mp->postmark_cache); s = strlen (mp->postmark_cache);
message->headers = message->headers =
@@ -255,94 +249,90 @@ mbox_read_message (mbox_t * mp)
for (;;) for (;;)
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
{ {
if (fgets (buffer, BUFSIZ, mp->fp) == NULL) if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
{ {
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL) if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
{ {
char c[1] = "\0"; char c[1] = "\0";
int n = 0; int n = 0;
while (c[0] != '\n' && n < BUFSIZ) while (c[0] != '\n' && n < BUFSIZ)
{ {
BZ2_bzread (mp->fp, c, 1); BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0]; buffer[n] = c[0];
n++; n++;
} }
buffer[n] = '\0'; buffer[n] = '\0';
if (buffer[0] == '\0') if (buffer[0] == '\0')
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
s = strlen (buffer); s = strlen (buffer);
if (buffer[0] == '\n' && isheaders == 1) if (buffer[0] == '\n' && isheaders == 1)
{ {
isheaders = 0; isheaders = 0;
continue; continue;
} }
if (isheaders) if (isheaders)
{ {
message->headers = message->headers =
(char *) realloc (message->headers, (char *) realloc (message->headers,
((1 + s + message->hbytes) * sizeof (char))); ((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer); strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s; message->hbytes += s;
} /* if */ }
else else
{ {
if (0 == strncmp (buffer, "From ", 5)) if (0 == strncmp (buffer, "From ", 5))
{ {
strcpy (mp->postmark_cache, buffer); strcpy (mp->postmark_cache, buffer);
return message; return message;
} }
message->body = message->body =
(char *) realloc (message->body, (char *) realloc (message->body,
((1 + s + message->bbytes) * sizeof (char))); ((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer); strcpy (message->body + message->bbytes, buffer);
message->bbytes += s; message->bbytes += s;
}
} }
} /* for */
return NULL; return NULL;
} }
/* }}} */
void void
tmpmbox_create (const char *path) tmpmbox_create (const char *path)
/* {{{ */
{ {
int foo; int foo;
@@ -351,19 +341,17 @@ tmpmbox_create (const char *path)
tmpfile_mod_own (foo, path); tmpfile_mod_own (foo, path);
} }
/* }}} */
void void
tmpfile_name (const char *path) tmpfile_name (const char *path)
/* {{{ */
{ {
char *fname, *tmpdir; char *fname, *tmpdir;
if (path == NULL) /* no path prefix given, use /tmp or TMPDIR */ if (path == NULL) /* no path prefix given, use /tmp or TMPDIR */
{ {
tmpdir = getenv ("TMPDIR"); tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL) if (tmpdir == NULL)
tmpdir = xstrdup ("/tmp"); tmpdir = xstrdup ("/tmp");
fname = xstrdup ("/mboxgrepXXXXXX"); fname = xstrdup ("/mboxgrepXXXXXX");
} }
else else
@@ -374,29 +362,26 @@ tmpfile_name (const char *path)
config.tmpfilename = config.tmpfilename =
(char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1)) (char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
* sizeof (char)); * sizeof (char));
sprintf (config.tmpfilename, "%s%s", tmpdir, fname); sprintf (config.tmpfilename, "%s%s", tmpdir, fname);
} }
/* }}} */
void void
mbox_write_message (message_t *msg, mbox_t *mbox) mbox_write_message (message_t * msg, mbox_t * mbox)
/* {{{ */
{ {
if (config.format == MBOX) if (config.format == FORMAT_MBOX)
fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body); fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == FORMAT_ZMBOX)
{ {
gzwrite_loop (mbox->fp, msg->headers); gzwrite_loop (mbox->fp, msg->headers);
gzwrite(mbox->fp, "\n", 1); gzwrite (mbox->fp, "\n", 1);
gzwrite_loop (mbox->fp, msg->body); gzwrite_loop (mbox->fp, msg->body);
} }
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == FORMAT_BZ2MBOX)
{ {
bzwrite_loop (mbox->fp, msg->headers); bzwrite_loop (mbox->fp, msg->headers);
BZ2_bzwrite (mbox->fp, "\n", 1); BZ2_bzwrite (mbox->fp, "\n", 1);
@@ -404,11 +389,9 @@ mbox_write_message (message_t *msg, mbox_t *mbox)
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
/* }}} */
void void
tmpfile_mod_own (const int fd, const char *path) tmpfile_mod_own (const int fd, const char *path)
/* {{{ */
{ {
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile /* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
* so rename() will thus retain the original's ownership & permissions. * so rename() will thus retain the original's ownership & permissions.
@@ -418,20 +401,21 @@ tmpfile_mod_own (const int fd, const char *path)
struct stat s; struct stat s;
if (stat (path, &s) != -1) if (stat (path, &s) != -1)
{ {
if (fchown (fd, s.st_uid, s.st_gid) == -1) if (fchown (fd, s.st_uid, s.st_gid) == -1)
if (config.merr) perror (config.tmpfilename); if (config.merr)
if (fchmod (fd, s.st_mode) == -1) perror (config.tmpfilename);
if (config.merr) perror (config.tmpfilename); if (fchmod (fd, s.st_mode) == -1)
} if (config.merr)
else if (config.merr) perror (path); perror (config.tmpfilename);
}
else if (config.merr)
perror (path);
} }
} }
/* }}} */
int int
tmpfile_create (void) tmpfile_create (void)
/* {{{ */
{ {
int fd; int fd;
@@ -439,12 +423,11 @@ tmpfile_create (void)
if (-1 == fd) if (-1 == fd)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename); fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
perror (NULL); perror (NULL);
} }
exit (2); exit (2);
} }
return fd; return fd;
} }
/* }}} */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004 Daniel Spiljar Copyright (C) 2000 - 2004, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,15 +15,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mbox.h,v 1.13 2006-10-22 23:34:49 dspiljar Exp $ */
#ifndef MBOX_H #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 typedef struct
{ {
@@ -40,6 +39,6 @@ void tmpfile_mod_own (const int fd, const char *path);
int tmpfile_create (void); int tmpfile_create (void);
void mbox_close (mbox_t * mbp); void mbox_close (mbox_t * mbp);
message_t *mbox_read_message (mbox_t * mp); 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 */ #endif /* MBOX_H */

View File

@@ -15,14 +15,13 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef MBOXGREP_H #ifndef MBOXGREP_H
#define MBOXGREP_H #define MBOXGREP_H
#define APPNAME "mboxgrep" #define APPNAME "mboxgrep"
#define VERSION "0.7.10" #define VERSION "0.7.12a"
#define BUGREPORT_ADDR "dspiljar AT datatipp.se" #define BUGREPORT_ADDR "dspiljar AT datatipp.se"
#define HOST_NAME_SIZE 256 #define HOST_NAME_SIZE 256
@@ -47,34 +46,46 @@
typedef enum typedef enum
{ {
MBOX, FORMAT_UNDEF,
ZMBOX, FORMAT_MBOX,
MH, FORMAT_ZMBOX,
NNML, FORMAT_MH,
NNMH, FORMAT_NNML,
MAILDIR, FORMAT_NNMH,
BZ2MBOX FORMAT_MAILDIR,
FORMAT_BZ2MBOX
} }
format_t; format_t;
typedef enum typedef enum
{ {
NONE, LOCK_UNDEF,
FCNTL, LOCK_NONE,
FLOCK LOCK_FCNTL,
LOCK_FLOCK
} }
lockmethod_t; lockmethod_t;
typedef enum typedef enum
{ {
DISPLAY, ACTION_UNDEF,
WRITE, ACTION_DISPLAY,
COUNT, ACTION_WRITE,
DELETE, ACTION_COUNT,
PIPE ACTION_DELETE,
ACTION_PIPE
} }
action_t; action_t;
typedef enum
{
REGEX_UNDEF,
REGEX_BASIC,
REGEX_EXTENDED,
REGEX_PERL
}
regextype_t;
typedef struct typedef struct
{ {
FILE *fp; FILE *fp;
@@ -94,9 +105,6 @@ checksum_t;
typedef struct typedef struct
{ {
int extended;
int perl;
int body; int body;
int headers; int headers;
int dedup; int dedup;
@@ -107,16 +115,18 @@ typedef struct
int merr; int merr;
int pid; int pid;
int haveregex; int haveregex;
int debug;
char hostname[HOST_NAME_SIZE]; char hostname[HOST_NAME_SIZE];
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s; char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
void *pcre_pattern, *pcre_hints, *posix_pattern; void *pcre_pattern, *posix_pattern, *match_data;
int res1, res2; int res1, res2;
action_t action; action_t action;
format_t format; format_t format;
lockmethod_t lock; lockmethod_t lock;
regextype_t regextype;
} }
option_t; option_t;

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2020 Daniel Spiljar Copyright (C) 2020, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,18 +15,17 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id$ */
#ifndef MESSAGE_H #ifndef MESSAGE_H
#define MESSAGE_H 1 # define MESSAGE_H 1
#include <config.h> # include <config.h>
typedef struct typedef struct
{ {
char *filename; /* used with directory formats, such as maildir or MH */ char *filename; /* used with directory formats, such as maildir or MH */
char *msgid; char *msgid;
char *from; char *from;
char *headers; char *headers;
int hbytes; int hbytes;

209
src/mh.c
View File

@@ -1,6 +1,6 @@
/* -*- C -*- /* -*- C -*-
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -22,20 +22,23 @@
#include <string.h> #include <string.h>
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
# include <dirent.h> # include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name) # define NAMLEN(dirent) strlen((dirent)->d_name)
#else #else
# define dirent direct # define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen # define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <sys/types.h> #include <sys/types.h>
@@ -49,12 +52,13 @@
#include "wrap.h" #include "wrap.h"
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
# include <dmalloc.h> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
extern option_t config; extern option_t config;
DIR *mh_open (const char *path) DIR *
mh_open (const char *path)
{ {
DIR *dp; DIR *dp;
@@ -62,22 +66,24 @@ DIR *mh_open (const char *path)
if (dp == NULL) if (dp == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
return NULL; return NULL;
} }
return dp; return dp;
} /* mh_open */ } /* mh_open */
void mh_close (DIR *dp) void
mh_close (DIR * dp)
{ {
closedir (dp); closedir (dp);
} /* mh_close */ } /* mh_close */
message_t *mh_read_message (DIR *dp) message_t *
mh_read_message (DIR * dp)
{ {
int isheaders = 1; int isheaders = 1;
int have_from = 0, have_date = 0, have_sender = 0; int have_from = 0, have_date = 0, have_sender = 0;
@@ -87,20 +93,21 @@ message_t *mh_read_message (DIR *dp)
char buffer[BUFSIZ], *filename; char buffer[BUFSIZ], *filename;
FILE *fp; FILE *fp;
message = malloc_message (); message = allocate_message ();
filename = NULL; filename = NULL;
for(;;) for (;;)
{ {
d_content = readdir(dp); d_content = readdir (dp);
if (d_content == NULL) return NULL; if (d_content == NULL)
return NULL;
if (d_content->d_name[0] == '.') if (d_content->d_name[0] == '.')
continue; continue;
filename = (char *) xrealloc filename = (char *) xrealloc
(filename, ((strlen (d_content->d_name)) + (filename, ((strlen (d_content->d_name)) +
(strlen (config.boxname)) + 2)); (strlen (config.boxname)) + 2));
/* message->headers = (char *) xrealloc (message->headers, 0); */ /* message->headers = (char *) xrealloc (message->headers, 0); */
/* message->hbytes = 0; */ /* message->hbytes = 0; */
@@ -112,17 +119,17 @@ message_t *mh_read_message (DIR *dp)
fp = m_fopen (filename, "r"); fp = m_fopen (filename, "r");
isheaders = 1; isheaders = 1;
if (fp == NULL) if (fp == NULL)
{ {
free (message->headers); free (message->headers);
free (message->body); free (message->body);
message->hbytes = 0; message->hbytes = 0;
message->bbytes = 0; message->bbytes = 0;
continue; continue;
} }
fgets (buffer, BUFSIZ, fp); fgets (buffer, BUFSIZ, fp);
/* if (config.format == NNML || config.format == NNMH) */ /* if (config.format == FORMAT_NNML || config.format == FORMAT_NNMH) */
/* { */ /* { */
/* if (0 != strncmp ("X-From-Line: ", buffer, 13)) */ /* if (0 != strncmp ("X-From-Line: ", buffer, 13)) */
/* { */ /* { */
@@ -137,76 +144,80 @@ message_t *mh_read_message (DIR *dp)
/* continue; */ /* continue; */
/* } */ /* } */
/* } */ /* } */
fseek (fp, 0, SEEK_SET); fseek (fp, 0, SEEK_SET);
while (fgets (buffer, BUFSIZ, fp) != NULL) while (fgets (buffer, BUFSIZ, fp) != NULL)
{ {
s = strlen (buffer); s = strlen (buffer);
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1) if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
{ {
isheaders = 0; isheaders = 0;
continue; continue;
} /* if */ } /* if */
if (isheaders) if (isheaders)
{ {
if (0 == strncasecmp ("From: ", buffer, 6)) if (0 == strncasecmp ("From: ", buffer, 6))
have_from = 1; have_from = 1;
if (0 == strncasecmp ("Sender: ", buffer, 8)) if (0 == strncasecmp ("Sender: ", buffer, 8))
have_sender = 1; have_sender = 1;
if (0 == strncasecmp ("Date: ", buffer, 6)) if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1; have_date = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13)) if (0 == strncasecmp ("Return-Path: ", buffer, 13))
message->from = parse_return_path (buffer); message->from = parse_return_path (buffer);
message->headers = message->headers =
(char *) realloc (message->headers, (char *) realloc (message->headers,
((1 + s + message->hbytes) * sizeof (char))); ((1 + s +
strcpy (message->headers + message->hbytes, buffer); message->hbytes) * sizeof (char)));
message->hbytes += s; strcpy (message->headers + message->hbytes, buffer);
} /* if */ message->hbytes += s;
else } /* if */
{ else
message->body = {
(char *) realloc (message->body, message->body =
((1 + s + message->bbytes) * sizeof (char))); (char *) realloc (message->body,
strcpy (message->body + message->bbytes, buffer); ((1 + s +
message->bbytes += s; message->bbytes) * sizeof (char)));
} /* else */ strcpy (message->body + message->bbytes, buffer);
} /* while */ message->bbytes += s;
} /* else */
} /* while */
if ((!have_from && !have_sender)|| !have_date) if ((!have_from && !have_sender) || !have_date)
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: Not a RFC 2822 message\n", fprintf (stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, filename); APPNAME, filename);
fclose (fp); fclose (fp);
free (message->headers); free (message->headers);
message->headers = NULL; message->headers = NULL;
free (message->body); free (message->body);
message->body = NULL; message->body = NULL;
message->hbytes = 0; message->hbytes = 0;
message->bbytes = 0; message->bbytes = 0;
continue; continue;
} }
else else
{ {
message->filename = (char *) xstrdup (filename); message->filename = (char *) xstrdup (filename);
fclose (fp); fclose (fp);
free (filename); free (filename);
return message; return message;
} }
} /* for */ } /* for */
} /* mh_read_message */ } /* 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; struct dirent *dc;
int x, y = 0; int x, y = 0;
char s1[BUFSIZ]; char s1[BUFSIZ];
DIR *d; FILE *f; DIR *d;
FILE *f;
d = m_opendir (path); d = m_opendir (path);
rewinddir (d); rewinddir (d);
@@ -215,11 +226,11 @@ void mh_write_message (message_t *m, const char *path)
{ {
x = strtol (dc->d_name, NULL, 10); x = strtol (dc->d_name, NULL, 10);
if (x > y) if (x > y)
y = x; y = x;
} }
y++; y++;
sprintf (s1, "%s/%i", path, y); sprintf (s1, "%s/%i", path, y);
f = m_fopen (s1, "w"); f = m_fopen (s1, "w");
fprintf (f, "%s\n%s", m->headers, m->body); fprintf (f, "%s\n%s", m->headers, m->body);
fclose (f); fclose (f);

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,33 +15,36 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mh.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef MH_H #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> # include <dirent.h>
#else # else
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
#endif /* HAVE_DIRENT_H */ # include <ndir.h>
# endif
/* HAVE_NDIR_H */
# endif
/* HAVE_DIRENT_H */
#include "mboxgrep.h" # include "mboxgrep.h"
DIR *mh_open (const char *path); DIR *mh_open (const char *path);
void mh_close (DIR *dp); void mh_close (DIR * dp);
message_t *mh_read_message (DIR *dp); message_t *mh_read_message (DIR * dp);
void mh_write_message (message_t *m, const char *path); void mh_write_message (message_t * m, const char *path);
#endif /* MH_H */ #endif /* MH_H */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000 - 2004, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,12 +15,11 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: misc.c,v 1.17 2006-07-06 10:53:49 dspiljar Exp $ */ #define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */
#define _DEFAULT_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
#define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */ * from string.h. */
#define _BSD_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
* from string.h. */
#include <config.h> #include <config.h>
@@ -29,117 +28,128 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include "mboxgrep.h" #include "mboxgrep.h"
#include "misc.h"
#include "wrap.h" #include "wrap.h"
#include "getopt.h" #include "getopt.h"
#include "info.h" #include "info.h"
#include "message.h" #include "message.h"
format_t /* Determine the folder format passed to -m. */
folder_format (const char *name)
/* {{{ */
{
format_t f;
if (0 == strncasecmp (name, "mbox", 4)) void
f = MBOX; set_folder_format (const char *name)
else if (0 == strncasecmp (name, "zmbox", 5)) {
f = ZMBOX; if (config.format > 0)
else if (0 == strncasecmp (name, "gzmbox", 6))
f = ZMBOX;
else if (0 == strncasecmp (name, "bzmbox", 5))
f = BZ2MBOX;
else if (0 == strncasecmp (name, "bz2mbox", 5))
f = BZ2MBOX;
else if (0 == strncasecmp (name, "mh", 2))
f = MH;
else if (0 == strncasecmp (name, "nnml", 4))
f = NNML;
else if (0 == strncasecmp (name, "nnmh", 4))
f = NNMH;
else if (0 == strncasecmp (name, "maildir", 7))
f = MAILDIR;
else
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "mboxgrep: %s: unknown folder type\n", name); fprintf (stderr, "%s: multiple mailbox types specified\n", APPNAME);
exit (2); exit (2);
} }
return f; if (0 == strncasecmp (name, "mbox", 4))
config.format = FORMAT_MBOX;
else if (0 == strncasecmp (name, "zmbox", 5))
config.format = FORMAT_ZMBOX;
else if (0 == strncasecmp (name, "gzmbox", 6))
config.format = FORMAT_ZMBOX;
else if (0 == strncasecmp (name, "bzmbox", 5))
config.format = FORMAT_BZ2MBOX;
else if (0 == strncasecmp (name, "bz2mbox", 5))
config.format = FORMAT_BZ2MBOX;
else if (0 == strncasecmp (name, "mh", 2))
config.format = FORMAT_MH;
else if (0 == strncasecmp (name, "nnml", 4))
config.format = FORMAT_NNML;
else if (0 == strncasecmp (name, "nnmh", 4))
config.format = FORMAT_NNMH;
else if (0 == strncasecmp (name, "maildir", 7))
config.format = FORMAT_MAILDIR;
else
{
if (config.merr)
fprintf (stderr, "%s: %s: unknown folder type\n", APPNAME, name);
exit (2);
}
} }
/* }}} */
lockmethod_t lock_method (const char *name) /* Determine the file locking method passed to -l. */
/* {{{ */
void
set_lock_method (const char *name)
{ {
lockmethod_t l; if (config.lock > 0)
{
if (config.merr)
fprintf (stderr, "%s: conflicting file locking options specified\n", APPNAME);
exit (2);
}
if (0 == strncasecmp (name, "none", 4)) if (0 == strncasecmp (name, "none", 4))
l = NONE; config.lock = LOCK_NONE;
else if (0 == strncasecmp (name, "off", 3)) else if (0 == strncasecmp (name, "off", 3))
l = NONE; config.lock = LOCK_NONE;
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
else if (0 == strncasecmp (name, "fcntl", 5)) else if (0 == strncasecmp (name, "fcntl", 5))
l = FCNTL; config.lock = LOCK_FCNTL;
#endif /* HAVE_FCNTL */ #endif /* HAVE_FCNTL */
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
else if (0 == strncasecmp (name, "flock", 5)) else if (0 == strncasecmp (name, "flock", 5))
l = FLOCK; config.lock = LOCK_FLOCK;
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
else else
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "mboxgrep: %s: unknown file locking method\n", name); fprintf (stderr, "mboxgrep: %s: unknown file locking method\n", name);
exit (2); exit (2);
} }
return l;
} }
/* }}} */
/* time_t parse_date(char *datestr) */ /* Dead code */
/* {{{ */
/* { */
/* time_t t; */
/* const char *fmt = "%d%n%b%n%Y%n%T"; */
/* int h, m; */
/* struct tm tm; */
/* char *str2, str1[BUFSIZ]; */
/* sscanf (datestr, "Date: %[^\r\n]", str1); */ /*
time_t parse_date(char *datestr)
{
time_t t;
const char *fmt = "%d%n%b%n%Y%n%T";
int h, m;
struct tm tm;
char *str2, str1[BUFSIZ];
/* str2 = (char *) strptime (str1, "%d%n%b%n%Y%n%T", &tm); */ sscanf (datestr, "Date: %[^\r\n]", str1);
/* if (str2 == NULL) */
/* str2 = (char *) strptime (str1, "%a, %d%n%b%n%Y%n%T", &tm); */
/* if (str2 == NULL) */
/* return (time_t) 0; */
/* if (sscanf (str2, "%3d%2d", &h, &m) == 2) */
/* { */
/* tm.tm_hour -= h; */
/* tm.tm_min -= (h >= 0 ? m : -m); */
/* t = (time_t) mktime (&tm); */
/* } */
/* return t; */ str2 = (char *) strptime (str1, "%d%n%b%n%Y%n%T", &tm);
/* } */ if (str2 == NULL)
/* }}} */ str2 = (char *) strptime (str1, "%a, %d%n%b%n%Y%n%T", &tm);
if (str2 == NULL)
return (time_t) 0;
char * parse_return_path(char *rpath) if (sscanf (str2, "%3d%2d", &h, &m) == 2)
/* {{{ */ {
tm.tm_hour -= h;
tm.tm_min -= (h >= 0 ? m : -m);
t = (time_t) mktime (&tm);
}
return t;
}
*/
char *
parse_return_path (char *rpath)
{ {
char *blah1, blah2[BUFSIZ]; char *blah1, blah2[BUFSIZ];
sscanf(rpath, "Return-Path: <%[^\r\n>]>", blah2); sscanf (rpath, "Return-Path: <%[^\r\n>]>", blah2);
blah1 = xstrdup (blah2); blah1 = xstrdup (blah2);
return blah1; return blah1;
} }
/* }}} */
void * malloc_message (void) void *
allocate_message (void)
{ {
message_t *message; message_t *message;
@@ -158,7 +168,8 @@ void * malloc_message (void)
return message; return message;
} }
void postmark_print (message_t *msg) void
postmark_print (message_t * msg)
{ {
time_t tt; time_t tt;
struct tm *ct; struct tm *ct;
@@ -173,131 +184,203 @@ void postmark_print (message_t *msg)
fprintf (stdout, "From nobody %s\n", date_str); fprintf (stdout, "From nobody %s\n", date_str);
} }
/* Initialize the option_t struct. */
void void
set_default_options (void) init_options (void)
{ {
config.perl = 0; config.regextype = REGEX_UNDEF;
config.extended = 1;
config.invert = 0; config.invert = 0;
config.headers = 0; config.headers = 0;
config.body = 0; config.body = 0;
config.action = DISPLAY; config.action = ACTION_UNDEF;
config.dedup = 0; config.dedup = 0;
config.recursive = 0; config.recursive = 0;
config.ignorecase = 0; config.ignorecase = 0;
config.format = MBOX; /* default mailbox format */ config.format = FORMAT_UNDEF;
config.lock = FCNTL; /* default file locking method */ config.lock = LOCK_UNDEF; /* default file locking method */
config.merr = 1; /* report errors by default */ config.merr = 1; /* report errors by default */
config.debug = 0;
} }
/* Parse command-line arguments and assign values to option_t. */
void void
get_runtime_options (int *argc, char **argv, struct option *long_options) get_options (int *argc, char **argv, struct option *long_options)
{ {
int option_index = 0, c; int option_index = 0, c;
while (1) while (1)
{ {
c = getopt_long (*argc, argv, "BcdEe:GHhil:m:n:o:Pp:rsVv", long_options, c = getopt_long (*argc, argv, "BcdEe:GHhil:m:n:o:Pp:rsVv", long_options,
&option_index); &option_index);
if (c == -1) if (c == -1)
break; break;
switch (c) switch (c)
/* {{{ */ {
case '?':
{ usage ();
case '?': case 'c':
usage(); set_option_action (ACTION_COUNT, NULL);
case 'c': break;
config.action = COUNT; case 'd':
break; set_option_action (ACTION_DELETE, NULL);
case 'd': break;
config.action = DELETE; case 'e':
break; config.regex_s = xstrdup (optarg);
case 'e': config.haveregex = 1;
config.regex_s = xstrdup (optarg); break;
config.haveregex = 1; case 'o':
break; set_option_action (ACTION_WRITE, optarg);
case 'o': break;
config.outboxname = xstrdup (optarg); case 'E':
config.action = WRITE; set_option_regextype (REGEX_EXTENDED);
break; break;
case 'E': case 'G':
config.extended = 1; set_option_regextype (REGEX_BASIC);
break; break;
case 'G': case 'P':
config.extended = 0; set_option_regextype (REGEX_PERL);
break; break;
case 'P': case 'h':
#ifdef HAVE_LIBPCRE help ();
config.extended = 0; break;
config.perl = 1; case 'i':
#else config.ignorecase = 1;
fprintf(stderr, break;
"%s: Support for Perl regular expressions not " case 'm':
"compiled in\n"); set_folder_format (optarg);
exit(2); break;
#endif /* HAVE_LIBPCRE */ case 'l':
break; set_lock_method (optarg);
case 'h': break;
help (); case 'p':
break; set_option_action (ACTION_PIPE, optarg);
case 'i': break;
config.ignorecase = 1; case 'V':
break; version ();
case 'm': break;
config.format = folder_format (optarg); case 'v':
break; config.invert = 1;
case 'l': break;
config.lock = lock_method (optarg); case 'H':
break; config.headers = 1;
case 'p': break;
config.action = PIPE; case 'B':
config.pipecmd = xstrdup (optarg); config.body = 1;
break; break;
case 'V': case 's':
version (); config.merr = 0;
break; break;
case 'v': case 201:
config.invert = 1; config.lock = 0;
break; break;
case 'H': case 202:
config.headers = 1; config.debug = 1;
break; fprintf (stderr, "%s: %s, line %d: enable debugging\n",
case 'B': APPNAME, __FILE__, __LINE__);
config.body = 1; break;
break; case 'r':
case 's': config.recursive = 1;
config.merr = 0; break;
break;
case 201:
config.lock = 0;
break;
case 'r':
config.recursive = 1;
break;
case 200: case 200:
config.dedup = 1; config.dedup = 1;
break; break;
case 'n': case 'n':
{ {
switch (optarg[0]) switch (optarg[0])
{ {
case 'd': case 'd':
config.dedup = 1; config.dedup = 1;
break; break;
case 'l': case 'l':
config.lock = 0; set_lock_method ("none");
break; break;
default: default:
fprintf(stderr, "%s: invalid option -- n%c\n", fprintf (stderr, "%s: invalid option -- n%c\n",
APPNAME, optarg[0]); APPNAME, optarg[0]);
exit(2); exit (2);
} }
} }
} /* switch */ } /* switch */
} /* while */
/* }}} */ }
} /* while */
/* Check the state of command-line options after parsing them.
* Raise error on conflicting options and set uninitialized ones to default values.
*/
void
check_options (void)
{
gethostname (config.hostname, HOST_NAME_SIZE);
config.pid = (int) getpid ();
if (config.action == ACTION_UNDEF)
{
config.action = ACTION_DISPLAY;
}
if (config.format == FORMAT_UNDEF)
{
config.format = FORMAT_MBOX; /* default mailbox format */
}
if (config.regextype == REGEX_UNDEF)
{
config.regextype = REGEX_EXTENDED; /* default regex type */
}
if ((config.body == 0) && (config.headers == 0))
{
config.body = 1;
config.headers = 1;
}
}
void
set_option_action (action_t action, char *path)
{
if (config.action > 0)
{
if (config.merr)
fprintf (stderr, "%s: conflicting actions specified\n", APPNAME);
exit (2);
}
config.action = action;
if (action == ACTION_WRITE)
{
config.outboxname = xstrdup (path);
}
if (action == ACTION_PIPE)
{
config.pipecmd = xstrdup (optarg);
}
}
void
set_option_regextype (regextype_t regextype)
{
if (config.regextype > 0)
{
if (config.merr)
fprintf (stderr, "%s: conflicting matchers specified\n", APPNAME);
exit (2);
}
#ifndef HAVE_LIBPCRE2
if (regextype == REGEX_PERL);
{
fprintf (stderr,
"%s: Support for Perl regular expressions not compiled in\n",
APPNAME);
exit (2);
}
#endif /* HAVE_LIBPCRE2 */
config.regextype = regextype;
} }

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,24 +15,27 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: misc.h,v 1.9 2006-07-06 10:53:49 dspiljar Exp $ */
#ifndef MISC_H #ifndef MISC_H
#define MISC_H 1 # define MISC_H 1
#include "mboxgrep.h" # include "mboxgrep.h"
#include "getopt.h" # include "getopt.h"
#include "message.h" # include "message.h"
/* #include <time.h> */ /* #include <time.h> */
format_t folder_format (const char *name); void set_folder_format (const char *name);
lockmethod_t lock_method (const char *name); void set_lock_method (const char *name);
/* time_t parse_date(char *datestr); */ /* time_t parse_date(char *datestr); */
char * parse_return_path(char *rpath); char *parse_return_path (char *rpath);
void * malloc_message (void); void *allocate_message (void);
void postmark_print (message_t *msg); void postmark_print (message_t * msg);
void set_default_options (void); void init_options (void);
void get_runtime_options (int *argc, char **argv, struct option *long_options); void get_options (int *argc, char **argv,
struct option *long_options);
void check_options (void);
void set_option_action (action_t action, char *path);
void set_option_regextype (regextype_t regextype);
#endif /* MISC_H */ #endif /* MISC_H */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2006 Daniel Spiljar Copyright (C) 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,61 +15,64 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: re.c,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <regex.h> #include <regex.h>
#ifdef HAVE_LIBPCRE #ifdef HAVE_LIBPCRE2
#include <pcre.h> # define PCRE2_CODE_UNIT_WIDTH 32
#endif /* HAVE_LIBPCRE */ # include <pcre2.h>
#endif /* HAVE_LIBPCRE2 */
#include "mboxgrep.h" #include "mboxgrep.h"
#include "message.h" #include "message.h"
#include "wrap.h" /* xcalloc() et cetera */
#ifdef HAVE_LIBPCRE #ifdef HAVE_LIBPCRE2
void void
pcre_init (void) pcre_init (void)
{ {
int errptr; int errornumber;
const char *error; PCRE2_SIZE erroroffset;
config.pcre_pattern = config.pcre_pattern =
(pcre *) pcre_compile (config.regex_s, (pcre2_code *) pcre2_compile ((PCRE2_SPTR) config.regex_s, (PCRE2_SIZE) strlen (config.regex_s),
(config.ignorecase ? PCRE_CASELESS : 0), (config.ignorecase ? PCRE2_CASELESS : 0),
&error, &errptr, NULL); &errornumber, &erroroffset, NULL);
if (config.pcre_pattern == NULL) if (config.pcre_pattern == NULL)
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, {
error); PCRE2_UCHAR buffer[256];
exit(2);
pcre2_get_error_message (errornumber, buffer, sizeof(buffer));
fprintf (stderr, "%s: PCRE2 compilation failed at offset %d: %s\n",
APPNAME, (int) erroroffset, (char *) buffer);
}
exit (2);
} }
config.match_data =
(pcre2_match_data* ) pcre2_match_data_create_from_pattern (config.pcre_pattern, NULL);
} }
void void
pcre_match (message_t *msg) pcre_match (message_t * msg)
{ {
int of[BUFSIZ];
if (config.headers) if (config.headers)
config.res1 = config.res1 =
pcre_exec ((pcre *) config.pcre_pattern, pcre2_match ((pcre2_code *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints, (PCRE2_SPTR) msg->headers, (int) strlen (msg->headers), 0, 0, config.match_data, NULL);
msg->headers,
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
if (config.body) if (config.body)
config.res2 = config.res2 =
pcre_exec ((pcre *) config.pcre_pattern, pcre2_match ((pcre2_code *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints, (PCRE2_SPTR) msg->body, (int) strlen (msg->body), 0, 0, config.match_data, NULL);
msg->body,
(int) strlen (msg->body), 0, 0, of, BUFSIZ);
config.res1 = config.res1 ^ 1; config.res1 = config.res1 ^ 1;
config.res2 = config.res2 ^ 1; config.res2 = config.res2 ^ 1;
} }
#endif /* HAVE_LIBPCRE */ #endif /* HAVE_LIBPCRE2 */
void void
regex_init (void) regex_init (void)
@@ -77,33 +80,34 @@ regex_init (void)
int flag1 = 0, flag2 = 0; int flag1 = 0, flag2 = 0;
int errcode = 0; int errcode = 0;
char errbuf[BUFSIZ]; char errbuf[BUFSIZ];
if (config.ignorecase) if (config.ignorecase)
flag1 = REG_ICASE; flag1 = REG_ICASE;
if (config.extended) if (config.regextype == REGEX_EXTENDED)
flag2 = REG_EXTENDED; flag2 = REG_EXTENDED;
errcode = regcomp ((regex_t *) config.posix_pattern, config.regex_s, config.posix_pattern = (regex_t *) xmalloc (sizeof (regex_t));
(flag1 | flag2 | REG_NEWLINE )); errcode = regcomp ((regex_t *) config.posix_pattern, config.regex_s,
(flag1 | flag2 | REG_NEWLINE));
if (0 != errcode) if (0 != errcode)
{ {
if (config.merr) if (config.merr)
{ {
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ); regerror (errcode, (regex_t *) config.posix_pattern, errbuf,
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, BUFSIZ);
errbuf); fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf);
} }
exit (2); exit (2);
} }
} }
void void
regex_match (message_t *msg) regex_match (message_t * msg)
{ {
if (config.headers) if (config.headers)
config.res1 = regexec ((regex_t *) config.posix_pattern, config.res1 = regexec ((regex_t *) config.posix_pattern,
msg->headers, 0, NULL, 0); msg->headers, 0, NULL, 0);
if (config.body) if (config.body)
config.res2 = regexec ((regex_t *) config.posix_pattern, 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 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 Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,14 +15,13 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: re.h,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
#include "mboxgrep.h" #include "mboxgrep.h"
#ifdef HAVE_LIBPCRE #ifdef HAVE_LIBPCRE2
void pcre_init (void); void pcre_init (void);
void pcre_match (message_t *msg); void pcre_match (message_t * msg);
#endif /* HAVE_LIBPCRE */ #endif /* HAVE_LIBPCRE2 */
void regex_init (void); void regex_init (void);
void regex_match (message_t *msg); void regex_match (message_t * msg);

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar Copyright (C) 2000 - 2004, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: scan.c,v 1.32 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h> #include <config.h>
@@ -26,20 +25,23 @@
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
# include <dirent.h> # include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name) # define NAMLEN(dirent) strlen((dirent)->d_name)
#else #else
# define dirent direct # define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen # define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <time.h> #include <time.h>
@@ -57,20 +59,21 @@
#include "misc.h" #include "misc.h"
#include "re.h" #include "re.h"
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
# include <sys/stat.h> # include <sys/stat.h>
# include <fts.h> # include <fts.h>
#else #else
# ifdef HAVE_FTW # ifdef HAVE_FTW
# include <ftw.h> # include <ftw.h>
# endif /* HAVE_FTW */ # endif
/* HAVE_FTW */
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
#include <dmalloc.h> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
void scan_mailbox (char path[]) void
/* {{{ */ scan_mailbox (char path[])
{ {
static FILE *outf; static FILE *outf;
static mbox_t *mbox, *out; static mbox_t *mbox, *out;
@@ -80,42 +83,47 @@ void scan_mailbox (char path[])
int delete = 0; int delete = 0;
int isdup = 0; int isdup = 0;
if (config.format == MAILDIR && config.action == WRITE) if (config.format == FORMAT_MAILDIR && config.action == ACTION_WRITE)
{ {
foo = opendir (config.outboxname); /* do NOT change this to m_opendir! */ foo = opendir (config.outboxname); /* do NOT change this to m_opendir! */
if (foo == NULL && errno == ENOENT) if (foo == NULL && errno == ENOENT)
maildir_create (config.outboxname); maildir_create (config.outboxname);
else closedir (foo); else
closedir (foo);
if (-1 == maildir_check (config.outboxname)) if (-1 == maildir_check (config.outboxname))
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME, fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME,
config.outboxname); config.outboxname);
exit (2); exit (2);
} }
} }
runtime.count = 0; runtime.count = 0;
if (config.action == DELETE) if (config.action == ACTION_DELETE)
delete = 1; delete = 1;
if ((config.format == MBOX) || (config.format == ZMBOX) || if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX)
(config.format == BZ2MBOX)) || (config.format == FORMAT_BZ2MBOX))
{ {
mbox = (mbox_t *) mbox_open (path, "r"); mbox = (mbox_t *) mbox_open (path, "r");
if (mbox == NULL) return; if (mbox == NULL)
return;
} }
else if ((config.format == MH) || (config.format == NNMH) || else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH)
(config.format == NNML)) || (config.format == FORMAT_NNML))
{ {
boxd = mh_open (path); boxd = mh_open (path);
if (boxd == NULL) return; if (boxd == NULL)
return;
} }
else if (config.format == MAILDIR) else if (config.format == FORMAT_MAILDIR)
{ {
maildird = maildir_open (path); maildird = maildir_open (path);
if (maildird == NULL) return;
if (maildird == NULL)
return;
} }
for (;;) for (;;)
@@ -123,102 +131,105 @@ void scan_mailbox (char path[])
config.res1 = 1; config.res1 = 1;
config.res2 = 1; config.res2 = 1;
if ((config.format == MBOX) || (config.format == ZMBOX) || if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX)
(config.format == BZ2MBOX)) || (config.format == FORMAT_BZ2MBOX))
msg = (message_t *) mbox_read_message (mbox); msg = (message_t *) mbox_read_message (mbox);
else if ((config.format == MH) || (config.format == NNMH) || else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH)
(config.format == NNML)) || (config.format == FORMAT_NNML))
msg = (message_t *) mh_read_message (boxd); msg = (message_t *) mh_read_message (boxd);
else if (config.format == MAILDIR) else if (config.format == FORMAT_MAILDIR)
msg = (message_t *) maildir_read_message (maildird); 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 #ifdef HAVE_LIBPCRE2
if (config.perl) if (config.regextype == REGEX_PERL)
pcre_match (msg); pcre_match (msg);
else else
#endif /* HAVE_LIBPCRE */ #endif /* HAVE_LIBPCRE2 */
regex_match (msg); regex_match (msg);
if (config.dedup) if (config.dedup)
isdup = md5_check_message (msg->body, runtime.cs); isdup = md5_check_message (msg->body, runtime.cs);
if (((config.res1 == 0) | (config.res2 == 0)) ^ if (((config.res1 == 0) | (config.res2 == 0)) ^
((config.invert ^ delete)) && ((config.invert ^ delete)) &&
((config.dedup && !isdup) || !config.dedup)) ((config.dedup && !isdup) || !config.dedup))
{ {
if (config.action == DISPLAY) if (config.action == ACTION_DISPLAY)
{ {
if (config.format != MBOX && config.format != ZMBOX if (config.format != FORMAT_MBOX && config.format != FORMAT_ZMBOX
&& config.format != BZ2MBOX && config.format != FORMAT_BZ2MBOX
&& 0 != strncmp ("From ", msg->headers, 5)) && 0 != strncmp ("From ", msg->headers, 5))
postmark_print (msg); postmark_print (msg);
fprintf (stdout, "%s\n%s", msg->headers, msg->body);
}
else if (config.action == WRITE)
{
if (config.format == MAILDIR)
maildir_write_message (msg, config.outboxname);
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))
{
out = mbox_open (config.outboxname, "w");
/* fprintf (out->fp, "%s\n%s", msg->headers, msg->body); */
mbox_write_message (msg, out);
mbox_close (out);
}
}
else if (config.action == PIPE)
{
outf = popen (config.pipecmd, "w");
if (outf == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, config.pipecmd);
perror (NULL);
}
exit (2);
} /* if */
fprintf (outf, "%s\n%s", msg->headers, msg->body);
pclose (outf);
}
else if (config.action == COUNT)
runtime.count++;
else if (config.action == DELETE &&
((config.format == MBOX) || (config.format == ZMBOX) ||
(config.format == BZ2MBOX)))
mbox_write_message (msg, runtime.tmp_mbox);
}
else if (((((config.res1 == 0) | (config.res2 == 0)) ^ fprintf (stdout, "%s\n%s", msg->headers, msg->body);
config.invert) && delete) && }
((config.format == MH) || (config.format == NNMH) || else if (config.action == ACTION_WRITE)
(config.format == NNML) || (config.format == MAILDIR))) {
m_unlink(msg->filename); if (config.format == FORMAT_MAILDIR)
maildir_write_message (msg, config.outboxname);
else if (config.format == FORMAT_MH || config.format == FORMAT_NNMH
|| config.format == FORMAT_NNML)
mh_write_message (msg, config.outboxname);
else if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX)
|| (config.format == FORMAT_BZ2MBOX))
{
out = mbox_open (config.outboxname, "w");
/* fprintf (out->fp, "%s\n%s", msg->headers, msg->body); */
mbox_write_message (msg, out);
mbox_close (out);
}
}
else if (config.action == ACTION_PIPE)
{
outf = popen (config.pipecmd, "w");
if (outf == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, config.pipecmd);
perror (NULL);
}
exit (2);
} /* if */
fprintf (outf, "%s\n%s", msg->headers, msg->body);
pclose (outf);
}
else if (config.action == ACTION_COUNT)
runtime.count++;
else if (config.action == ACTION_DELETE &&
((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX)
|| (config.format == FORMAT_BZ2MBOX)))
mbox_write_message (msg, runtime.tmp_mbox);
}
free(msg->body); else
free(msg->headers); if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert)
free(msg); && delete) && ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH)
} /* for */ || (config.format == FORMAT_NNML)
if ((config.format == MBOX) || (config.format == ZMBOX) || || (config.format == FORMAT_MAILDIR)))
(config.format == BZ2MBOX)) m_unlink (msg->filename);
free (msg->body);
free (msg->headers);
free (msg);
} /* for */
if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX)
|| (config.format == FORMAT_BZ2MBOX))
mbox_close (mbox); mbox_close (mbox);
else if ((config.format == MH) || (config.format == NNMH) || else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH)
(config.format == NNML)) || (config.format == FORMAT_NNML))
mh_close(boxd); mh_close (boxd);
} }
/* }}} */
void recursive_scan (char path[])
/* {{{ */
void
recursive_scan (char path[])
{ {
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
FTS *ftsfoo; FTS *ftsfoo;
@@ -236,9 +247,9 @@ void recursive_scan (char path[])
if (ftsfoo == NULL) if (ftsfoo == NULL)
{ {
/* fixme (?) */ /* fixme (?) */
perror(APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
while ((ftsbar = fts_read (ftsfoo))) while ((ftsbar = fts_read (ftsfoo)))
@@ -251,34 +262,34 @@ void recursive_scan (char path[])
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
} }
/* }}} */ int
md5_check_message (char *body, checksum_t * chksum)
int md5_check_message (char *body, checksum_t *chksum)
/* {{{ */
{ {
struct md5_ctx a; struct md5_ctx a;
char b[16]; char b[16];
int i; int i;
md5_init_ctx (&a); md5_init_ctx (&a);
if (body == NULL) if (body == NULL)
md5_process_bytes ("", 0, &a); md5_process_bytes ("", 0, &a);
else else
md5_process_bytes (body, strlen(body), &a); md5_process_bytes (body, strlen (body), &a);
md5_finish_ctx(&a, b);
md5_finish_ctx (&a, b);
for (i = 0; i < chksum->n; i++) for (i = 0; i < chksum->n; i++)
{ {
if (0 == strncmp ((char *)chksum->md5[i], b, 16)) if (0 == strncmp ((char *) chksum->md5[i], b, 16))
return 1; return 1;
} }
chksum->md5 = chksum->md5 =
(char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *)); (char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
chksum->md5[chksum->n] = xstrdup (b); chksum->md5[chksum->n] = xstrdup (b);
(chksum->n)++; (chksum->n)++;
return 0; return 0;
} }
/* }}} */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,16 +15,15 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: scan.h,v 1.7 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef SCAN_H #ifndef SCAN_H
#define SCAN_H 1 # define SCAN_H 1
#include "mboxgrep.h" # include "mboxgrep.h"
void scan_mailbox (char path[]); void scan_mailbox (char path[]);
void recursive_scan (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 */ #endif /* SCAN_H */

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /* -*- C -*-
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: wrap.c,v 1.13 2006-01-20 03:00:39 dspiljar Exp $ */
#include <config.h> #include <config.h>
#include <unistd.h> #include <unistd.h>
@@ -25,24 +24,30 @@
#include <errno.h> #include <errno.h>
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
# include <dirent.h> # include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name) # define NAMLEN(dirent) strlen((dirent)->d_name)
#else #else
# define dirent direct # define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen # define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> # include <zlib.h>
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
# include <bzlib.h>
#endif /* HAVE_LIBBZ2 */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -52,12 +57,13 @@
#include "mboxgrep.h" #include "mboxgrep.h"
#ifndef APPNAME #ifndef APPNAME
#define APPNAME "mboxgrep" # define APPNAME "mboxgrep"
#endif #endif
#define BUFLEN 16384 #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; int blah;
@@ -65,18 +71,19 @@ int m_open (const char *pathname, int flags, mode_t mode)
if (blah == -1 && config.merr) if (blah == -1 && config.merr)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, pathname); fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL); perror (NULL);
} }
/* failure to open a file for writing should be fatal */ /* failure to open a file for writing should be fatal */
if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR)) if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR))
exit (2); exit (2);
} }
return blah; return blah;
} }
FILE *m_fopen (const char *path, const char *mode) FILE *
m_fopen (const char *path, const char *mode)
{ {
FILE *blah; FILE *blah;
@@ -84,17 +91,18 @@ FILE *m_fopen (const char *path, const char *mode)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
if (mode[0] == 'w') if (mode[0] == 'w')
exit (2); exit (2);
} }
return blah; return blah;
} }
FILE *m_fdopen (int fildes, const char *mode) FILE *
m_fdopen (int fildes, const char *mode)
{ {
FILE *blah; FILE *blah;
@@ -102,29 +110,31 @@ FILE *m_fdopen (int fildes, const char *mode)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
} }
return blah; return blah;
} }
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
gzFile *m_gzdopen (int fildes, const char *mode) gzFile
m_gzdopen (int fildes, const char *mode)
{ {
gzFile *blah; gzFile blah;
blah = gzdopen (fildes, mode); blah = gzdopen (fildes, mode);
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
} }
return blah; return blah;
} }
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
DIR *m_opendir (const char *name) DIR *
m_opendir (const char *name)
{ {
DIR *blah; DIR *blah;
@@ -132,17 +142,18 @@ DIR *m_opendir (const char *name)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, name); fprintf (stderr, "%s: %s: ", APPNAME, name);
perror (NULL); perror (NULL);
} }
} }
return blah; return blah;
} }
#ifndef HAVE_LIBDMALLOC #ifndef HAVE_LIBDMALLOC
void *xmalloc (size_t size) void *
xmalloc (size_t size)
{ {
void *foo; void *foo;
@@ -150,13 +161,14 @@ void *xmalloc (size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
} }
void *xrealloc (void *ptr, size_t size) void *
xrealloc (void *ptr, size_t size)
{ {
void *foo; void *foo;
@@ -164,13 +176,14 @@ void *xrealloc (void *ptr, size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
} }
void *xcalloc (size_t nmemb, size_t size) void *
xcalloc (size_t nmemb, size_t size)
{ {
void *foo; void *foo;
@@ -178,13 +191,14 @@ void *xcalloc (size_t nmemb, size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
} }
char *xstrdup (const char *s) char *
xstrdup (const char *s)
{ {
char *foo; char *foo;
@@ -192,7 +206,7 @@ char *xstrdup (const char *s)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
@@ -200,7 +214,8 @@ char *xstrdup (const char *s)
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
int m_unlink (const char *pathname) int
m_unlink (const char *pathname)
{ {
int baz; int baz;
@@ -208,17 +223,18 @@ int m_unlink (const char *pathname)
if (baz == -1) if (baz == -1)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, pathname); fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL); perror (NULL);
} }
} }
return baz; return baz;
} }
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
void gzwrite_loop (void *fp, char *str) void
gzwrite_loop (void *fp, char *str)
{ {
int quux, len, baz; int quux, len, baz;
@@ -226,11 +242,11 @@ void gzwrite_loop (void *fp, char *str)
baz = strlen (str); baz = strlen (str);
for (;;) for (;;)
{ {
len = gzwrite (fp, (str+quux), len = gzwrite (fp, (str + quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux))); (((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len; quux += len;
if (quux == baz) if (quux == baz)
break; break;
} }
} }
@@ -238,7 +254,8 @@ void gzwrite_loop (void *fp, char *str)
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
void bzwrite_loop (void *fp, char *str) void
bzwrite_loop (void *fp, char *str)
{ {
int quux, len, baz; int quux, len, baz;
@@ -246,11 +263,11 @@ void bzwrite_loop (void *fp, char *str)
baz = strlen (str); baz = strlen (str);
for (;;) for (;;)
{ {
len = BZ2_bzwrite (fp, (str+quux), len = BZ2_bzwrite (fp, (str + quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux))); (((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len; quux += len;
if (quux == baz) if (quux == baz)
break; break;
} }
} }

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@@ -15,63 +15,71 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: wrap.h,v 1.12 2006-01-20 03:00:39 dspiljar Exp $ */
/* This file is part of mboxgrep. */ /* This file is part of mboxgrep. */
/* wrappers around certain std functions */ /* wrappers around certain std functions */
#ifndef WRAP_H #ifndef WRAP_H
#define WRAP_H # define WRAP_H
#include <config.h> # include <config.h>
#include <stdio.h> # include <stdio.h>
#include <sys/types.h> # include <sys/types.h>
#ifdef HAVE_DIRENT_H # ifdef HAVE_DIRENT_H
# include <dirent.h> # include <dirent.h>
#else # else
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */ # endif
# ifdef HAVE_SYS_DIR_H /* HAVE_SYS_NDIR_H */
# include <sys/dir.h> # ifdef HAVE_SYS_DIR_H
# endif /* HAVE_SYS_DIR_H */ # include <sys/dir.h>
# ifdef HAVE_NDIR_H # endif
# include <ndir.h> /* HAVE_SYS_DIR_H */
# endif /* HAVE_NDIR_H */ # ifdef HAVE_NDIR_H
#endif /* HAVE_DIRENT_H */ # include <ndir.h>
#ifdef HAVE_LIBZ # endif
#include <zlib.h> /* HAVE_NDIR_H */
#endif /* HAVE_LIBZ */ # 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> # include <dmalloc.h>
#endif /* HAVE_LIBDMALLOC */ # endif
/* HAVE_LIBDMALLOC */
int m_open (const char *pathname, int flags, mode_t mode); int m_open (const char *pathname, int flags, mode_t mode);
FILE *m_fopen (const char *path, const char *mode); FILE *m_fopen (const char *path, const char *mode);
FILE *m_fdopen (int fildes, 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); gzFile m_gzdopen (int fildes, const char *mode);
void gzwrite_loop (void *fp, char *str); void gzwrite_loop (void *fp, char *str);
#endif /* HAVE_LIBZ */ # endif
#ifdef HAVE_LIBBZ2 /* HAVE_LIBZ */
# ifdef HAVE_LIBBZ2
void bzwrite_loop (void *fp, char *str); void bzwrite_loop (void *fp, char *str);
#endif /* HAVE_LIBBZ2 */ # endif
/* HAVE_LIBBZ2 */
DIR *m_opendir (const char *name); DIR *m_opendir (const char *name);
#ifndef HAVE_LIBDMALLOC # ifndef HAVE_LIBDMALLOC
void *xmalloc (size_t size); void *xmalloc (size_t size);
void *xrealloc (void *ptr, size_t size); void *xrealloc (void *ptr, size_t size);
void *xcalloc (size_t nmemb, size_t size); void *xcalloc (size_t nmemb, size_t size);
char *xstrdup (const char *s); char *xstrdup (const char *s);
#endif /* HAVE_LIBDMALLOC */ # endif
/* HAVE_LIBDMALLOC */
int m_unlink (const char *pathname); int m_unlink (const char *pathname);