1 Commits

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

17
.gitignore vendored
View File

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

5
AUTHORS Normal file
View File

@@ -0,0 +1,5 @@
-*- text -*-
mboxgrep is written and maintained by Daniel Spiljar.
$Id: AUTHORS,v 1.3 2005-11-16 01:37:18 dspiljar Exp $

View File

@@ -1 +0,0 @@
mboxgrep is written and maintained by Daniel Spiljar with contributors.

0
INSTALL Normal file
View File

View File

@@ -1,26 +0,0 @@
# 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.

View File

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

37
Makefile.in Normal file
View File

@@ -0,0 +1,37 @@
# 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:

60
NEWS.md
View File

@@ -1,28 +1,6 @@
# Changes of mboxgrep # Changes of mboxgrep
## Changes in 0.7.13 ## Changes since 0.7.9
- Improve the readability of this file.
- Failure to lock a file (mbox) is now a fatal error.
- Fix Autoconf on Windows.
- Code refactoring, mostly of mbox-related functions.
## Changes in 0.7.12a
- Fix Automake macros to include the license file and others.
## Changes in 0.7.12
- Port to the pcre2 library (pcre1 is no longer supported).
- Check command-line options for conflicting matchers and actions.
- Various minor code cleanups.
## Changes in 0.7.11
- 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 in 0.7.10
- development has been restarted after a longer hiatus - development has been restarted after a longer hiatus
- moved the source tree to git - moved the source tree to git
@@ -31,7 +9,7 @@
- fixed multiple compilation errors and warnings on Linux and FreeBSD - fixed multiple compilation errors and warnings on Linux and FreeBSD
- started implementing a debug mode - started implementing a debug mode
## Changes in 0.7.9 ## Changes since 0.7.8
- implemented support for mbox folders compressed with bzip2 algorithm - implemented support for mbox folders compressed with bzip2 algorithm
- improved detection of PCRE library; this also fixes a compilation bug - improved detection of PCRE library; this also fixes a compilation bug
@@ -40,7 +18,7 @@
folder and temporary directory were on different filesystems; folder and temporary directory were on different filesystems;
thanks to James P. Dugal <jpd AT louisiana.edu> for providing a patch thanks to James P. Dugal <jpd AT louisiana.edu> for providing a patch
## Changes in 0.7.8 ## Changes since 0.7.7
- fixed crashes on MH folders, as well as a potential problem with mbox - fixed crashes on MH folders, as well as a potential problem with mbox
and maildir folders with the same cause and maildir folders with the same cause
@@ -49,46 +27,46 @@
- mboxgrep can now read gzip compressed mbox folders from standard input - mboxgrep can now read gzip compressed mbox folders from standard input
(which is a side effect of a code cleanup!) (which is a side effect of a code cleanup!)
## Changes in 0.7.7 ## Changes since 0.7.6a
- mboxgrep can now read mbox folders from standard input - mboxgrep can now read mbox folders from standard input
## Changes in 0.7.6a ## Changes since 0.7.6
- fixed a bug which prevented mboxgrep from being compiled - fixed a bug which prevented mboxgrep from being compiled
## Changes in 0.7.6 ## Changes since 0.7.5
- fixed a bug which caused mboxgrep to coredump on recursive search of - fixed a bug which caused mboxgrep to coredump on recursive search of
maildirs maildirs
- code cleanups - code cleanups
## Changes in 0.7.5 ## Changes since 0.7.4
- recursive search through directories has been reimplemented - recursive search through directories has been reimplemented
## Changes in 0.7.4 ## Changes since 0.7.3
- mboxgrep can now ignore messages with identical bodies - mboxgrep can now ignore messages with identical bodies
## Changes in 0.7.3 ## Changes since 0.7.2
- file locking method can be selected at runtime - file locking method can be selected at runtime
- mboxgrep used to coredump on messages with empty headers; the problem is - mboxgrep used to coredump on messages with empty headers; the problem is
now hopefully fixed now hopefully fixed
- mboxgrep now compiles on FreeBSD - mboxgrep now compiles on FreeBSD
## Changes in 0.7.2 ## Changes since 0.7.1
- file locking with `flock()` instead of `fcntl()` is now supported - file locking with `flock()` instead of `fcntl()` is now supported
- mboxgrep should now compile on systems which don't have `getopt_long()` - mboxgrep should now compile on systems which don't have `getopt_long()`
- other minor bugfixes - other minor bugfixes
## Changes in 0.7.1 ## Changes since 0.7.0
- bugfixes - bugfixes
## Changes in 0.7.0 ## Changes since 0.5.3
- NOTE: there was no stable version between 0.5.x and 0.7.x - NOTE: there was no stable version between 0.5.x and 0.7.x
- mboxgrep is almost completely rewritten - mboxgrep is almost completely rewritten
@@ -98,7 +76,7 @@
command) command)
- added support for compressed mbox folders - added support for compressed mbox folders
## Changes in 0.5.3 ## Changes since 0.5.2
- implemented ability to write found messages to another folder (instead - implemented ability to write found messages to another folder (instead
of standard output) of standard output)
@@ -106,7 +84,7 @@
"NEWS") "NEWS")
- wrote a manual in Texinfo format - wrote a manual in Texinfo format
## Changes in 0.5.2 ## Changes since 0.5.1
- implemented message counting (`-c, --count`) - implemented message counting (`-c, --count`)
- fixed manual page installation target in src/Makefile.in -- manual page - fixed manual page installation target in src/Makefile.in -- manual page
@@ -119,17 +97,17 @@
- implemented recursive search through directories (`-r, --recursive`) - implemented recursive search through directories (`-r, --recursive`)
- config.h[.in] is now wrapped (`#ifndef CONFIG_H` and stuff) - config.h[.in] is now wrapped (`#ifndef CONFIG_H` and stuff)
## Changes in 0.5.1 ## Changes since 0.5.0
- added support for qmail-style maildir folders - added support for qmail-style maildir folders
## Changes in 0.5.0 ## Changes since 0.4.0
- the source of `getopt_long()` is now included, so long options are also available - the source of `getopt_long()` is now included, so long options are also available
on platforms that don't use GNU libc on platforms that don't use GNU libc
- file locking is now performed on mbox folders only - file locking is now performed on mbox folders only
## Changes in 0.4.0 ## Changes since 0.2.0
- added support for MH mailboxes - added support for MH mailboxes
- added scope selection switches `-B` (or `--body`) and `-H` (or `--headers`) - added scope selection switches `-B` (or `--body`) and `-H` (or `--headers`)
@@ -140,12 +118,12 @@
- the feature of reading from standard input is gone - the feature of reading from standard input is gone
- added `-v` (or `--version`) switch - added `-v` (or `--version`) switch
## Changes in 0.2.0 ## Changes since 0.1.1
- mboxgrep now puts a shared lock on a mailbox before reading it - mboxgrep now puts a shared lock on a mailbox before reading it
- various code cleanups - various code cleanups
## Changes in 0.1.1 ## Changes since 0.1.0
- fixed install target in Makefile (`install` is now used instead of `cp`) - fixed install target in Makefile (`install` is now used instead of `cp`)
- added support for mailboxes generated by Gnus - added support for mailboxes generated by Gnus

View File

@@ -1,7 +1,4 @@
# mboxgrep - selects e-mail messages matching a pattern mboxgrep - displays 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
@@ -14,8 +11,5 @@ 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.md`, and run For build instructions, read the file "INSTALL", 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`.

View File

@@ -3,7 +3,7 @@
## Behavior ## Behavior
- [x] use cryptographic hashes for detecting duplicate messages - [x] use cryptographic hashes for detecting duplicate messages
- [x] add checking for conflicting command-line options - [ ] add checking for conflicting command-line options
- [ ] support for deletion of messages after being matched and displayed - [ ] 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] inverted matching - [x] inverted matching
@@ -15,21 +15,18 @@
- [x] reading messages from standard input - [x] reading messages from standard input
- [x] run-time selection of file locking method - [x] run-time selection of file locking method
- [x] add a debug function - [x] add a debug function
- [ ] Remove the option to recursively traverse directories and instruct the users to run mboxgrep in conjuction with find(1) instead.
## File formats, encodings and standards ## File formats, encodings and standards
- [x] migrate to pcre2, as pcre is obsolete
- [ ] use a more modern hash function than MD5
- [ ] MIME support - [ ] MIME support
- [ ] support for GnuPG - [ ] support for GnuPG
- [x] support for compressed mbox folders - [x] support for compressed mbox folders
- [x] support for bzip2 compression - [x] support for bzip2 compression
- [ ] support for XZ-format compression - [ ] support for XZ-format compression
- [ ] support for mail folder conversion - [ ] support for mail folder conversion
- [ ] use a more modern hash function than MD5
- [ ] improve error detection when a directory is not a Maildir or MH folder - [ ] improve error detection when a directory is not a Maildir or MH folder
- [ ] document criteria for folder format detection - [ ] document criteria for folder format detection
- [ ] Maildir: check if an atomic rename() fails. This could be caused if "new" and "cur" subdirectories are not on the same filesystem, for example.
## Miscellaneous ## Miscellaneous

5274
configure vendored Executable file

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 - 2003, 2023 - 2024 Daniel Spiljar # Copyright (C) 2000, 2001, 2002, 2003 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([mboxgrep], [0.7.13], [dspiljar@datatipp.se], [mboxgrep], [https://www.mboxgrep.org/]) AC_INIT
#AM_INIT_AUTOMAKE AC_LANG(C)
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,35 +34,34 @@ AC_HEADER_DIRENT
# Checks for libraries. # Checks for libraries.
# Check for PCRE2 library # Check for PCRE library
AC_ARG_WITH(pcre2, [ --without-pcre2 Compile without Perl regexp support],, AC_ARG_WITH(pcre, [ --without-pcre Compile without Perl regexp support],,
[ [
AC_PATH_PROG(PCRE2_CONFIG, pcre2-config) AC_PATH_PROG(PCRE_CONFIG, pcre-config)
if test "$PCRE2_CONFIG"; then if test "$PCRE_CONFIG"; then
CFLAGS="$CFLAGS `$PCRE2_CONFIG --cflags`" CFLAGS="$CFLAGS `$PCRE_CONFIG --cflags`"
LIBS="$LIBS `$PCRE2_CONFIG --libs32`" LIBS="$LIBS `$PCRE_CONFIG --libs`"
AC_LINK_IFELSE( AC_LINK_IFELSE(
[ [
#define PCRE2_CODE_UNIT_WIDTH 32 #include <pcre.h>
#include <pcre2.h>
int main () int main ()
{ {
return 0; return 0;
} }
], ],
AC_DEFINE(HAVE_LIBPCRE2), AC_DEFINE(HAVE_LIBPCRE),
[ [
AC_MSG_NOTICE(found pcre2-config but could not compile test program.) AC_MSG_NOTICE(found pcre-config but could not compile test program.)
AC_MSG_FAILURE(is PCRE2 properly installed?) AC_MSG_FAILURE(is PCRE properly installed?)
] ]
) )
else else
AC_MSG_NOTICE(pcre2-config not found) AC_MSG_NOTICE(pcre-config not found)
AC_MSG_NOTICE(trying to find PCRE2 anyway) AC_MSG_NOTICE(trying to find PCRE anyway)
AC_CHECK_LIB(pcre2, main) AC_CHECK_LIB(pcre, main)
fi fi
] ]
) )
@@ -93,5 +92,7 @@ AC_CHECK_FUNCS([strptime])
AC_CHECK_FUNCS(ftw) AC_CHECK_FUNCS(ftw)
AC_CHECK_FUNCS(fts_open) AC_CHECK_FUNCS(fts_open)
AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile]) AC_CONFIG_FILES([Makefile
doc/Makefile
src/Makefile])
AC_OUTPUT AC_OUTPUT

View File

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

41
doc/Makefile.in Normal file
View File

@@ -0,0 +1,41 @@
# 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,4 +1,4 @@
.TH MBOXGREP 1 "23 September 2024" .TH MBOXGREP 1 "17 Feb 2023"
.SH NAME .SH NAME
mboxgrep \- displays email messages matching a pattern mboxgrep \- displays email messages matching a pattern
.SH SYNOPSIS .SH SYNOPSIS
@@ -10,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.13 . .BR 0.7.10 .
.PP .PP
.B mboxgrep .B mboxgrep
scans a scans a
@@ -72,8 +72,8 @@ Do not lock files. This option is meaningful only if a mbox folder (see below)
is scanned. is scanned.
.IP "-c, --count" .IP "-c, --count"
Suppress normal output and print a count of matching messages. Suppress normal output and print a count of matching messages.
.IP "-o, --output=MAILBOX" .IP "-o, --output=FOLDER"
Suppress normal output and write messages to destination MAILBOX instead. Suppress normal output and write messages to destination folder FOLDER instead.
.IP "-p, --pipe=COMMAND" .IP "-p, --pipe=COMMAND"
Pipe each found message to COMMAND Pipe each found message to COMMAND
.IP "-d, --delete" .IP "-d, --delete"
@@ -97,26 +97,10 @@ Search $MAIL for messages from Dirty Harry:
mboxgrep '^From:.*callahan@sanfranciscopolice\\.org' $MAIL mboxgrep '^From:.*callahan@sanfranciscopolice\\.org' $MAIL
.TP .TP
\(bu \(bu
Re-mail to George messages that mention his name:
.PP
mboxgrep --pipe="/usr/lib/sendmail george" --ignore-case george ~/Mail/*
.TP
\(bu
Display all messages contained in folder ~/Mail/incoming, except those Display all messages contained in folder ~/Mail/incoming, except those
that appear to originate from AOL: that appear to originate from AOL:
.PP .PP
mboxgrep -v 'Received:.*aol\\.com' ~/Mail/incoming mboxgrep -v 'Received:.*aol\\.com' ~/Mail/incoming
.TP
\(bu
Do a case-insensitive scan of ~/Mail/incoming for messages with subject
``Weekly News'' and write them to folder ~/Mail/archive:
.PP
mboxgrep -o ~/Mail/archive -H -i '^Subject: Weekly News' ~/Mail/incoming
.TP
\(bu
Count all messages stored in folder spam, ignoring duplicates:
.PP
mboxgrep -nd -c . spam
.SH BUGS .SH BUGS
Report them to address below. Report them to address below.
.SH SEE ALSO .SH SEE ALSO
@@ -124,8 +108,7 @@ grep(1),
regex(7), regex(7),
perlre(1), perlre(1),
mbox(5), mbox(5),
RFC 2822, RFC 2822
RFC 4155
.SH DEDICATION .SH DEDICATION
Mboxgrep is dedicated in loving memory of Vicky, my cat who died of Mboxgrep is dedicated in loving memory of Vicky, my cat who died of
tumor on Sep 12, 2002. tumor on Sep 12, 2002.
@@ -133,11 +116,7 @@ tumor on Sep 12, 2002.
You haven't been long with us, but you gave us a lot of joy and all your You haven't been long with us, but you gave us a lot of joy and all your
big heart that stopped ticking too early. I will never forget you. Sleep big heart that stopped ticking too early. I will never forget you. Sleep
well, little friend. well, little friend.
.SH HOMEPAGE .SH URL
https://www.mboxgrep.org/ http://www.mboxgrep.org/
.SH GIT
https://git.datatipp.se/dspiljar/mboxgrep
.PP
https://github.com/dspiljar/mboxgrep
.SH AUTHOR .SH AUTHOR
Daniel Spiljar <dspiljar@datatipp.se> Daniel Spiljar <dspiljar AT datatipp.se>

View File

@@ -1,4 +1,4 @@
This is mboxgrep.info, produced by makeinfo version 6.8 from This is mboxgrep.info, produced by makeinfo version 6.7 from
mboxgrep.texi. mboxgrep.texi.
INFO-DIR-SECTION Mail INFO-DIR-SECTION Mail
@@ -9,10 +9,10 @@ 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.13), a mailbox scanning This file documents 'mboxgrep' (version 0.7.10), a mailbox scanning
utility. utility.
Copyright (C) 2000 - 2003, 2024 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
* Menu: * Menu:
@@ -151,10 +151,10 @@ options below change such behavior.
'-nd' '-nd'
Ignore duplicate messages. Ignore duplicate messages.
'--output=MAILBOX' '--output=FOLDER'
'-o MAILBOX' '-o FOLDER'
Suppress normal output and write messages to destination MAILBOX Suppress normal output and write messages to destination folder
instead. FOLDER instead.
Note that 'mboxgrep' assumes the output folder is of the same Note that 'mboxgrep' assumes the output folder is of the same
format as the input folder. Currently there is no possibility to format as the input folder. Currently there is no possibility to
@@ -250,17 +250,17 @@ Sleep well, little friend.
 
Tag Table: Tag Table:
Node: Top197 Node: Top197
Node: Introduction591 Node: Introduction596
Node: Invoking1460 Node: Invoking1465
Node: Miscellaneous1822 Node: Miscellaneous1827
Node: File locking2107 Node: File locking2112
Node: Regexp selection2744 Node: Regexp selection2749
Node: Output control3296 Node: Output control3301
Node: Search scope selection4336 Node: Search scope selection4345
Node: Mailbox type selection4577 Node: Mailbox type selection4586
Node: Examples4898 Node: Examples4907
Node: Bugs5722 Node: Bugs5731
Node: To Vicky6140 Node: To Vicky6149
 
End Tag Table End Tag Table

View File

@@ -5,8 +5,8 @@
@setchapternewpage odd @setchapternewpage odd
@set EDITION 0.7 @set EDITION 0.7
@set VERSION 0.7.13 @set VERSION 0.7.10
@set UPDATED 23 September 2024 @set UPDATED 17 Feb 2023
@dircategory Mail @dircategory Mail
@direntry @direntry
@@ -19,7 +19,7 @@
This file documents @code{mboxgrep} (version @value{VERSION}), a This file documents @code{mboxgrep} (version @value{VERSION}), a
mailbox scanning utility. mailbox scanning utility.
Copyright (C) 2000 - 2003, 2024 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
@end ifinfo @end ifinfo
@menu @menu
@@ -171,9 +171,10 @@ Use with extreme caution.
@itemx -nd @itemx -nd
Ignore duplicate messages. Ignore duplicate messages.
@item --output=MAILBOX @item --output=FOLDER
@itemx -o MAILBOX @itemx -o FOLDER
Suppress normal output and write messages to destination MAILBOX instead. Suppress normal output and write messages to destination folder FOLDER
instead.
Note that @code{mboxgrep} assumes the output folder is of the same format Note that @code{mboxgrep} assumes the output folder is of the same format
as the input folder. Currently there is no possibility to convert folders. as the input folder. Currently there is no possibility to convert folders.

File diff suppressed because it is too large Load Diff

251
install-sh Executable file
View File

@@ -0,0 +1,251 @@
#!/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

View File

@@ -1,6 +0,0 @@
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)

57
src/Makefile.in Normal file
View File

@@ -0,0 +1,57 @@
# 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:

67
src/config.h.in Normal file
View File

@@ -0,0 +1,67 @@
/* 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,30 +22,28 @@
#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) print_wrap (char *str, int len, int *n)
{ {
static int n = 0; *n += len;
n += strlen (str);
fprintf (stdout, "%s", str); fprintf (stdout, "%s", str);
if (n >= 50) if (*n >= 50)
{ {
fprintf (stdout, "\n"); fprintf (stdout, "\n");
n = 0; *n = 0;
} }
else else fprintf (stdout, " ");
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 "
@@ -55,51 +53,50 @@ version (void)
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"); print_wrap ("HAVE_DIRENT_H", 13, &n);
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
print_wrap ("HAVE_FCNTL"); print_wrap ("HAVE_FCNTL", 10, &n);
#endif /* HAVE_FCNTL */ #endif /* HAVE_FCNTL */
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
print_wrap ("HAVE_FLOCK"); print_wrap ("HAVE_FLOCK", 10, &n);
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
print_wrap ("HAVE_FTS_OPEN"); print_wrap ("HAVE_FTS_OPEN", 13, &n);
#else #else
# ifdef HAVE_FTW # ifdef HAVE_FTW
print_wrap ("HAVE_FTW"); print_wrap ("HAVE_FTW", 8, &n);
# endif # endif /* HAVE_FTW */
/* HAVE_FTW */
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
/* /*
fprintf (stdout, "HAVE_LIBLOCKFILE "); fprintf (stdout, "HAVE_LIBLOCKFILE ");
*/ */
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
print_wrap ("HAVE_LIBPCRE2"); print_wrap ("HAVE_LIBPCRE", 12, &n);
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
print_wrap ("HAVE_LIBZ"); print_wrap ("HAVE_LIBZ", 9, &n);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
print_wrap ("HAVE_LIBBZ2"); print_wrap ("HAVE_LIBBZ2", 11, &n);
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
#ifdef HAVE_NDIR_H #ifdef HAVE_NDIR_H
print_wrap ("HAVE_NDIR_H"); print_wrap ("HAVE_NDIR_H", 11, &n);
#endif /* HAVE_NDIR_H */ #endif /* HAVE_NDIR_H */
#ifdef HAVE_SYS_DIR_H #ifdef HAVE_SYS_DIR_H
print_wrap ("HAVE_SYS_DIR_H"); print_wrap ("HAVE_SYS_DIR_H", 14, &n);
#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"); print_wrap ("HAVE_SYS_NDIR_H", 15, &n);
#endif /* HAVE_SYS_NDIR_H */ #endif /* HAVE_SYS_NDIR_H */
#ifdef HAVE_STRPTIME #ifdef HAVE_STRPTIME
print_wrap ("HAVE_STRPTIME"); print_wrap ("HAVE_STRPTIME", 15, &n);
#endif /* HAVE_STRPTIME */ #endif /* HAVE_STRPTIME */
#ifdef HAVE_REGCOMP #ifdef HAVE_REGCOMP
print_wrap ("HAVE_REGCOMP"); print_wrap ("HAVE_REGCOMP", 15, &n);
#endif /* HAVE_REGCOMP */ #endif /* HAVE_REGCOMP */
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
print_wrap ("HAVE_LIBDMALLOC"); print_wrap ("HAVE_LIBDMALLOC", 15, &n);
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
fprintf (stdout, "\n"); fprintf (stdout, "\n");
@@ -128,10 +125,10 @@ help (void)
"Matching criteria:\n\n" "Matching criteria:\n\n"
" -E, --extended-regexp\tPATTERN is an extended regular expression\n" " -E, --extended-regexp\tPATTERN is an extended regular expression\n"
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n"); " -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
fprintf(stdout, fprintf(stdout,
" -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n"); " -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n");
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
fprintf(stdout, fprintf(stdout,
" -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n" " -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n"
" -i, --ignore-case\t\tIgnore case distinctions\n" " -i, --ignore-case\t\tIgnore case distinctions\n"

View File

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

View File

@@ -30,16 +30,13 @@
# 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 # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <stdlib.h> #include <stdlib.h>
@@ -160,8 +157,7 @@ maildir_read_message (maildir_t * mdp)
filename = filename =
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name)) (char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
+ (strlen (config.boxname)) + + (strlen (config.boxname)) + 6)));
6)));
/* /*
filename = filename =
@@ -207,8 +203,7 @@ maildir_read_message (maildir_t * mdp)
message->headers = message->headers =
(char *) xrealloc (message->headers, (char *) xrealloc (message->headers,
((1 + s + ((1 + s + message->hbytes) * sizeof (char)));
message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer); strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s; message->hbytes += s;
@@ -217,8 +212,7 @@ maildir_read_message (maildir_t * mdp)
{ {
message->body = message->body =
(char *) xrealloc (message->body, (char *) xrealloc (message->body,
((1 + s + ((1 + s + message->bbytes) * sizeof (char)));
message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer); strcpy (message->body + message->bbytes, buffer);
message->bbytes += s; message->bbytes += s;
} /* else */ } /* else */
@@ -274,24 +268,18 @@ 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) if (-1 == i) return -1;
return -1; if (! S_ISDIR (fs.st_mode)) 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) if (-1 == i) return -1;
return -1; if (! S_ISDIR (fs.st_mode)) 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) if (-1 == i) return -1;
return -1; if (! S_ISDIR (fs.st_mode)) return -1;
if (!S_ISDIR (fs.st_mode))
return -1;
free (s); free (s);

View File

@@ -30,18 +30,14 @@
# 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 # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */ #endif /* HAVE_DIRENT_H */
# endif
/* HAVE_DIRENT_H */
#include "mboxgrep.h" #include "mboxgrep.h"

View File

@@ -1,6 +1,6 @@
/* /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000 - 2004, 2006, 2023 - 2024 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
@@ -24,6 +24,7 @@
#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 */
@@ -53,7 +54,8 @@ main (int argc, char **argv)
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'}, {"count", 0, 0, 'c'},
{"delete", 0, 0, 'd'}, {"delete", 0, 0, 'd'},
/* {"date", 1, 0, 'D'}, */ /* {"date", 1, 0, 'D'}, */
@@ -80,11 +82,21 @@ main (int argc, char **argv)
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
init_options (); set_default_options ();
get_options (&argc, argv, long_options); get_runtime_options (&argc, argv, long_options);
check_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 **));
@@ -99,11 +111,11 @@ main (int argc, char **argv)
if (config.haveregex) if (config.haveregex)
{ {
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
if (config.regextype == REGEX_PERL) if (config.perl)
pcre_init (); pcre_init ();
else else
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
regex_init (); regex_init ();
} }
else else
@@ -114,10 +126,10 @@ main (int argc, char **argv)
while (optind < argc) while (optind < argc)
{ {
if (config.action == ACTION_DELETE) if (config.action == DELETE)
{ {
tmpmbox_create (argv[optind]); tmpmbox_create (argv[optind]);
runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, w); runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, "w");
} }
config.boxname = xstrdup (argv[optind]); config.boxname = xstrdup (argv[optind]);
@@ -129,7 +141,7 @@ main (int argc, char **argv)
havemailbox = 1; havemailbox = 1;
if (config.action == ACTION_COUNT) if (config.action == COUNT)
{ {
if (singlefile) if (singlefile)
fprintf (stdout, "%i\n", runtime.count); fprintf (stdout, "%i\n", runtime.count);
@@ -141,20 +153,19 @@ main (int argc, char **argv)
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count); fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
} }
} }
if (config.action == ACTION_DELETE) if (config.action == DELETE)
{ {
mbox_close (runtime.tmp_mbox); mbox_close (runtime.tmp_mbox);
rename (config.tmpfilename, argv[optind]); rename (config.tmpfilename, argv[optind]);
} }
++optind; ++optind;
} }
if (! havemailbox) if (! havemailbox)
{ {
config.format = FORMAT_MBOX; config.format = MBOX;
scan_mailbox ("-"); scan_mailbox ("-");
if (config.action == ACTION_COUNT) if (config.action == COUNT)
fprintf (stdout, "%i\n", runtime.count); fprintf (stdout, "%i\n", runtime.count);
} }

View File

@@ -1,6 +1,6 @@
/* /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000 - 2004, 2006, 2023 - 2024 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 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
@@ -50,61 +50,179 @@
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
mbox_t * mbox_t *
mbox_open (const char *path, const mbox_mode_t mbox_mode) mbox_open (const char *path, const char *mode)
{ {
mbox_t *mp; mbox_t *mp;
static int fd; static int fd;
#ifndef HAVE_FLOCK #ifndef HAVE_FLOCK
struct flock lck; struct flock lck;
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
char buffer[BUFSIZ];
mp = (mbox_t *) xmalloc (sizeof (mbox_t)); mp = (mbox_t *) xmalloc (sizeof (mbox_t));
mp->postmark_cache = NULL; mp->postmark_cache = (char *) xmalloc (BUFSIZ * sizeof (char));
if (0 == strcmp ("-", path)) if (0 == strcmp ("-", path))
mp->fp = stdin; mp->fp = stdin;
else else
{ {
if (mbox_mode == w) if (mode[0] == 'r')
fd = m_open (path, O_RDONLY, 0);
else if (mode[0] == 'w')
fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND), fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND),
(S_IWUSR | S_IRUSR)); (S_IWUSR | S_IRUSR));
else else
fd = m_open (path, O_RDONLY, 0); {
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
"get this error...", APPNAME, mode[0]);
exit (2);
}
if (fd == -1) if (fd == -1)
{ {
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0; errno = 0;
return NULL; return NULL;
} }
if (config.lock > LOCK_NONE) if (config.lock)
mbox_lock (fd, path, mbox_mode);
mp->fp = mbox_fdopen (fd, path, mbox_mode);
}
if (mbox_mode == r)
{ {
mp->postmark_cache = mbox_check_postmark (mp, path); #ifdef HAVE_FLOCK
int op;
if (! mp->postmark_cache) if (mode[0] == 'r')
op = LOCK_SH;
else
op = LOCK_EX;
if (-1 == flock (fd, op))
#else
memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET;
if (mode[0] == 'r')
lck.l_type = F_RDLCK;
else
lck.l_type = F_WRLCK;
if (-1 == fcntl (fd, F_SETLK, &lck))
#endif /* HAVE_FLOCK */
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL; return NULL;
} }
}
if (mode[0] == 'r')
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "r");
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "rb");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb");
#endif /* HAVE_LIBBZ2 */
}
else if (mode[0] == 'w')
{
if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "w");
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "wb");
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb");
#endif /* HAVE_LIBBZ2 */
}
if (mp->fp == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
}
if (mode[0] == 'r')
{
if (config.format == MBOX)
fgets (buffer, BUFSIZ, mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
gzgets (mp->fp, buffer, BUFSIZ);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
{
char c[1] = "\0";
int n = 0;
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
}
#endif /* HAVE_LIBBZ2 */
if (0 != strncmp ("From ", buffer, 5))
{
if (config.merr)
{
if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME);
else
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path);
}
if (config.format == MBOX)
fclose (mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == ZMBOX)
gzclose (mp->fp);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX)
BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */
return NULL;
}
strcpy (mp->postmark_cache, buffer);
}
return mp; return mp;
} }
void void
mbox_close (mbox_t * mp) mbox_close (mbox_t * mp)
{ {
if (config.format == FORMAT_MBOX) if (config.format == MBOX)
fclose (mp->fp); fclose (mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == FORMAT_ZMBOX) else if (config.format == ZMBOX)
gzclose (mp->fp); gzclose (mp->fp);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX) else if (config.format == BZ2MBOX)
BZ2_bzclose (mp->fp); BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
@@ -130,7 +248,7 @@ mbox_read_message (mbox_t * mp)
for (;;) for (;;)
{ {
if (config.format == FORMAT_MBOX) if (config.format == MBOX)
{ {
if (fgets (buffer, BUFSIZ, mp->fp) == NULL) if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
{ {
@@ -142,7 +260,7 @@ mbox_read_message (mbox_t * mp)
} }
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == FORMAT_ZMBOX) else if (config.format == ZMBOX)
{ {
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL) if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
{ {
@@ -155,7 +273,7 @@ mbox_read_message (mbox_t * mp)
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX) else if (config.format == BZ2MBOX)
{ {
char c[1] = "\0"; char c[1] = "\0";
int n = 0; int n = 0;
@@ -251,10 +369,10 @@ tmpfile_name (const char *path)
void void
mbox_write_message (message_t *msg, mbox_t *mbox) mbox_write_message (message_t *msg, mbox_t *mbox)
{ {
if (config.format == FORMAT_MBOX) if (config.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 == FORMAT_ZMBOX) else if (config.format == ZMBOX)
{ {
gzwrite_loop (mbox->fp, msg->headers); gzwrite_loop (mbox->fp, msg->headers);
gzwrite(mbox->fp, "\n", 1); gzwrite(mbox->fp, "\n", 1);
@@ -262,7 +380,7 @@ mbox_write_message (message_t * msg, mbox_t * mbox)
} }
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX) else if (config.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);
@@ -284,14 +402,11 @@ tmpfile_mod_own (const int fd, const char *path)
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) if (config.merr) perror (config.tmpfilename);
perror (config.tmpfilename);
if (fchmod (fd, s.st_mode) == -1) if (fchmod (fd, s.st_mode) == -1)
if (config.merr) if (config.merr) perror (config.tmpfilename);
perror (config.tmpfilename);
} }
else if (config.merr) else if (config.merr) perror (path);
perror (path);
} }
} }
@@ -312,127 +427,3 @@ tmpfile_create (void)
} }
return fd; return fd;
} }
void
mbox_lock (int fd, const char *path, const mbox_mode_t mbox_mode)
{
#ifdef HAVE_FLOCK
int op;
if (mbox_mode == r)
op = LOCK_SH;
else
op = LOCK_EX;
if (-1 == flock (fd, op))
#else
memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET;
if (mode[0] == 'r')
lck.l_type = F_RDLCK;
else
lck.l_type = F_WRLCK;
if (-1 == fcntl (fd, F_SETLK, &lck))
#endif /* HAVE_FLOCK */
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
exit (2);
}
}
}
void *
mbox_fdopen (int fd, const char *path, const mbox_mode_t mbox_mode)
{
void *f;
char *file_mode;
if (mbox_mode == w)
file_mode = xstrdup("wb");
else
file_mode = xstrdup("rb");
if (config.format == FORMAT_MBOX)
f = (FILE *) m_fdopen (fd, file_mode);
#ifdef HAVE_LIBZ
else if (config.format == FORMAT_ZMBOX)
f = (gzFile *) m_gzdopen (fd, file_mode);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX)
f = (BZFILE *) BZ2_bzdopen (fd, file_mode);
#endif /* HAVE_LIBBZ2 */
if (f == NULL)
{
if (config.merr)
{
fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL);
}
errno = 0;
close (fd);
return NULL;
}
return f;
}
char *
mbox_check_postmark(mbox_t *mp, const char *path)
{
char *buffer;
buffer = (char *) xmalloc (BUFSIZ * sizeof (char));
memset (buffer, 0, BUFSIZ);
if (config.format == FORMAT_MBOX)
fgets (buffer, BUFSIZ, mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == FORMAT_ZMBOX)
gzgets (mp->fp, buffer, BUFSIZ);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX)
{
char c[1] = "\0";
int n = 0;
while (c[0] != '\n' && n < BUFSIZ)
{
BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0];
n++;
}
buffer[n] = '\0';
}
#endif /* HAVE_LIBBZ2 */
if (0 != strncmp ("From ", buffer, 5))
{
if ((config.merr) && (buffer[0] != '\0'))
{
if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not an mbox folder\n",
APPNAME);
else
fprintf (stderr, "%s: %s: Not an mbox folder\n", APPNAME,
path);
}
if (config.format == FORMAT_MBOX)
fclose (mp->fp);
#ifdef HAVE_LIBZ
else if (config.format == FORMAT_ZMBOX)
gzclose (mp->fp);
#endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2
else if (config.format == FORMAT_BZ2MBOX)
BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */
return NULL;
}
return buffer;
}

View File

@@ -1,6 +1,6 @@
/* /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000 - 2004, 2023 - 2024 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
@@ -19,7 +19,9 @@
#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
@@ -29,14 +31,8 @@ typedef struct
char *postmark_cache; char *postmark_cache;
} mbox_t; } mbox_t;
typedef enum
{
r,
w,
} mbox_mode_t;
mbox_t *mbox_open (const char *path, const char *mode);
mbox_t *mbox_open (const char *path, const mbox_mode_t mbox_mode);
void tmpmbox_create (const char *path); void tmpmbox_create (const char *path);
void tmpfile_name (const char *path); void tmpfile_name (const char *path);
void tmpfile_mod_own (const int fd, const char *path); void tmpfile_mod_own (const int fd, const char *path);
@@ -44,8 +40,5 @@ 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);
void mbox_lock (int fd, const char *path, const mbox_mode_t mbox_mode);
void *mbox_fdopen (int fd, const char *path, const mbox_mode_t mbox_mode);
char *mbox_check_postmark(mbox_t *mp, const char *path);
#endif /* MBOX_H */ #endif /* MBOX_H */

View File

@@ -1,6 +1,6 @@
/* /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000 - 2003, 2006, 2023 - 2024 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,14 +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
*/ */
#ifndef MBOXGREP_H #ifndef MBOXGREP_H
#define MBOXGREP_H #define MBOXGREP_H
#define APPNAME "mboxgrep" #define APPNAME "mboxgrep"
#define VERSION "0.7.13" #define VERSION "0.7.10"
#define BUGREPORT_ADDR "dspiljar@datatipp.se" #define BUGREPORT_ADDR "dspiljar AT datatipp.se"
#define HOST_NAME_SIZE 256 #define HOST_NAME_SIZE 256
@@ -46,46 +47,34 @@
typedef enum typedef enum
{ {
FORMAT_UNDEF, MBOX,
FORMAT_MBOX, ZMBOX,
FORMAT_ZMBOX, MH,
FORMAT_MH, NNML,
FORMAT_NNML, NNMH,
FORMAT_NNMH, MAILDIR,
FORMAT_MAILDIR, BZ2MBOX
FORMAT_BZ2MBOX
} }
format_t; format_t;
typedef enum typedef enum
{ {
LOCK_UNDEF, NONE,
LOCK_NONE, FCNTL,
LOCK_FCNTL, FLOCK
LOCK_FLOCK
} }
lockmethod_t; lockmethod_t;
typedef enum typedef enum
{ {
ACTION_UNDEF, DISPLAY,
ACTION_DISPLAY, WRITE,
ACTION_WRITE, COUNT,
ACTION_COUNT, DELETE,
ACTION_DELETE, PIPE
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;
@@ -105,6 +94,9 @@ checksum_t;
typedef struct typedef struct
{ {
int extended;
int perl;
int body; int body;
int headers; int headers;
int dedup; int dedup;
@@ -120,13 +112,12 @@ typedef struct
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, *posix_pattern, *match_data; void *pcre_pattern, *pcre_hints, *posix_pattern;
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 -*- /* -*- 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, 2023 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003, 2006 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
@@ -29,16 +29,13 @@
# 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 # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <sys/types.h> #include <sys/types.h>
@@ -57,8 +54,7 @@
extern option_t config; extern option_t config;
DIR * DIR *mh_open (const char *path)
mh_open (const char *path)
{ {
DIR *dp; DIR *dp;
@@ -76,14 +72,12 @@ mh_open (const char *path)
return dp; return dp;
} /* mh_open */ } /* mh_open */
void void mh_close (DIR *dp)
mh_close (DIR * dp)
{ {
closedir (dp); closedir (dp);
} /* mh_close */ } /* mh_close */
message_t * message_t *mh_read_message (DIR *dp)
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;
@@ -100,8 +94,7 @@ mh_read_message (DIR * dp)
for(;;) for(;;)
{ {
d_content = readdir(dp); d_content = readdir(dp);
if (d_content == NULL) if (d_content == NULL) return NULL;
return NULL;
if (d_content->d_name[0] == '.') if (d_content->d_name[0] == '.')
continue; continue;
@@ -129,7 +122,7 @@ mh_read_message (DIR * dp)
fgets (buffer, BUFSIZ, fp); fgets (buffer, BUFSIZ, fp);
/* if (config.format == FORMAT_NNML || config.format == FORMAT_NNMH) */ /* if (config.format == NNML || config.format == NNMH) */
/* { */ /* { */
/* if (0 != strncmp ("X-From-Line: ", buffer, 13)) */ /* if (0 != strncmp ("X-From-Line: ", buffer, 13)) */
/* { */ /* { */
@@ -168,8 +161,7 @@ mh_read_message (DIR * dp)
message->headers = message->headers =
(char *) realloc (message->headers, (char *) realloc (message->headers,
((1 + s + ((1 + s + message->hbytes) * sizeof (char)));
message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer); strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s; message->hbytes += s;
} /* if */ } /* if */
@@ -177,8 +169,7 @@ mh_read_message (DIR * dp)
{ {
message->body = message->body =
(char *) realloc (message->body, (char *) realloc (message->body,
((1 + s + ((1 + s + message->bbytes) * sizeof (char)));
message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer); strcpy (message->body + message->bbytes, buffer);
message->bbytes += s; message->bbytes += s;
} /* else */ } /* else */
@@ -210,14 +201,12 @@ mh_read_message (DIR * dp)
} /* for */ } /* for */
} /* mh_read_message */ } /* mh_read_message */
void void mh_write_message (message_t *m, const char *path)
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; DIR *d; FILE *f;
FILE *f;
d = m_opendir (path); d = m_opendir (path);
rewinddir (d); rewinddir (d);

View File

@@ -27,18 +27,14 @@
#else #else
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */ #endif /* HAVE_DIRENT_H */
# endif
/* HAVE_DIRENT_H */
#include "mboxgrep.h" #include "mboxgrep.h"

View File

@@ -18,7 +18,7 @@
*/ */
#define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */ #define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */
#define _DEFAULT_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3) #define _BSD_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
* from string.h. */ * from string.h. */
#include <config.h> #include <config.h>
@@ -28,76 +28,61 @@
#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"
/* Determine the folder format passed to -m. */ format_t
folder_format (const char *name)
void
set_folder_format (const char *name)
{ {
if (config.format > 0) format_t f;
{
if (config.merr)
fprintf (stderr, "%s: multiple mailbox types specified\n", APPNAME);
exit (2);
}
if (0 == strncasecmp (name, "mbox", 4)) if (0 == strncasecmp (name, "mbox", 4))
config.format = FORMAT_MBOX; f = MBOX;
else if (0 == strncasecmp (name, "zmbox", 5)) else if (0 == strncasecmp (name, "zmbox", 5))
config.format = FORMAT_ZMBOX; f = ZMBOX;
else if (0 == strncasecmp (name, "gzmbox", 6)) else if (0 == strncasecmp (name, "gzmbox", 6))
config.format = FORMAT_ZMBOX; f = ZMBOX;
else if (0 == strncasecmp (name, "bzmbox", 5)) else if (0 == strncasecmp (name, "bzmbox", 5))
config.format = FORMAT_BZ2MBOX; f = BZ2MBOX;
else if (0 == strncasecmp (name, "bz2mbox", 5)) else if (0 == strncasecmp (name, "bz2mbox", 5))
config.format = FORMAT_BZ2MBOX; f = BZ2MBOX;
else if (0 == strncasecmp (name, "mh", 2)) else if (0 == strncasecmp (name, "mh", 2))
config.format = FORMAT_MH; f = MH;
else if (0 == strncasecmp (name, "nnml", 4)) else if (0 == strncasecmp (name, "nnml", 4))
config.format = FORMAT_NNML; f = NNML;
else if (0 == strncasecmp (name, "nnmh", 4)) else if (0 == strncasecmp (name, "nnmh", 4))
config.format = FORMAT_NNMH; f = NNMH;
else if (0 == strncasecmp (name, "maildir", 7)) else if (0 == strncasecmp (name, "maildir", 7))
config.format = FORMAT_MAILDIR; f = MAILDIR;
else else
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: unknown folder type\n", APPNAME, name); fprintf (stderr, "%s: %s: unknown folder type\n", APPNAME, name);
exit (2); exit (2);
} }
return f;
} }
/* Determine the file locking method passed to -l. */ lockmethod_t lock_method (const char *name)
void
set_lock_method (const char *name)
{ {
if (config.lock > 0) lockmethod_t l;
{
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))
config.lock = LOCK_NONE; l = NONE;
else if (0 == strncasecmp (name, "off", 3)) else if (0 == strncasecmp (name, "off", 3))
config.lock = LOCK_NONE; l = NONE;
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
else if (0 == strncasecmp (name, "fcntl", 5)) else if (0 == strncasecmp (name, "fcntl", 5))
config.lock = LOCK_FCNTL; l = 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))
config.lock = LOCK_FLOCK; l = FLOCK;
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
else else
{ {
@@ -105,9 +90,9 @@ set_lock_method (const char *name)
fprintf (stderr, "mboxgrep: %s: unknown file locking method\n", name); fprintf (stderr, "mboxgrep: %s: unknown file locking method\n", name);
exit (2); exit (2);
} }
}
/* Dead code */ return l;
}
/* /*
time_t parse_date(char *datestr) time_t parse_date(char *datestr)
@@ -137,8 +122,7 @@ time_t parse_date(char *datestr)
} }
*/ */
char * char * parse_return_path(char *rpath)
parse_return_path (char *rpath)
{ {
char *blah1, blah2[BUFSIZ]; char *blah1, blah2[BUFSIZ];
@@ -148,8 +132,7 @@ parse_return_path (char *rpath)
return blah1; return blah1;
} }
void * void * allocate_message (void)
allocate_message (void)
{ {
message_t *message; message_t *message;
@@ -168,8 +151,7 @@ allocate_message (void)
return message; return message;
} }
void void postmark_print (message_t *msg)
postmark_print (message_t * msg)
{ {
time_t tt; time_t tt;
struct tm *ct; struct tm *ct;
@@ -184,29 +166,26 @@ 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
init_options (void) set_default_options (void)
{ {
config.regextype = REGEX_UNDEF; config.perl = 0;
config.extended = 1;
config.invert = 0; config.invert = 0;
config.headers = 0; config.headers = 0;
config.body = 0; config.body = 0;
config.action = ACTION_UNDEF; config.action = DISPLAY;
config.dedup = 0; config.dedup = 0;
config.recursive = 0; config.recursive = 0;
config.ignorecase = 0; config.ignorecase = 0;
config.format = FORMAT_UNDEF; config.format = MBOX; /* default mailbox format */
config.lock = LOCK_UNDEF; /* default file locking method */ config.lock = FCNTL; /* default file locking method */
config.merr = 1; /* report errors by default */ config.merr = 1; /* report errors by default */
config.debug = 0; config.debug = 0;
} }
/* Parse command-line arguments and assign values to option_t. */
void void
get_options (int *argc, char **argv, struct option *long_options) get_runtime_options (int *argc, char **argv, struct option *long_options)
{ {
int option_index = 0, c; int option_index = 0, c;
@@ -223,26 +202,35 @@ get_options (int *argc, char **argv, struct option *long_options)
case '?': case '?':
usage(); usage();
case 'c': case 'c':
set_option_action (ACTION_COUNT, NULL); config.action = COUNT;
break; break;
case 'd': case 'd':
set_option_action (ACTION_DELETE, NULL); config.action = DELETE;
break; break;
case 'e': case 'e':
config.regex_s = xstrdup (optarg); config.regex_s = xstrdup (optarg);
config.haveregex = 1; config.haveregex = 1;
break; break;
case 'o': case 'o':
set_option_action (ACTION_WRITE, optarg); config.outboxname = xstrdup (optarg);
config.action = WRITE;
break; break;
case 'E': case 'E':
set_option_regextype (REGEX_EXTENDED); config.extended = 1;
break; break;
case 'G': case 'G':
set_option_regextype (REGEX_BASIC); config.extended = 0;
break; break;
case 'P': case 'P':
set_option_regextype (REGEX_PERL); #ifdef HAVE_LIBPCRE
config.extended = 0;
config.perl = 1;
#else
fprintf(stderr,
"%s: Support for Perl regular expressions not "
"compiled in\n", APPNAME);
exit(2);
#endif /* HAVE_LIBPCRE */
break; break;
case 'h': case 'h':
help (); help ();
@@ -251,13 +239,14 @@ get_options (int *argc, char **argv, struct option *long_options)
config.ignorecase = 1; config.ignorecase = 1;
break; break;
case 'm': case 'm':
set_folder_format (optarg); config.format = folder_format (optarg);
break; break;
case 'l': case 'l':
set_lock_method (optarg); config.lock = lock_method (optarg);
break; break;
case 'p': case 'p':
set_option_action (ACTION_PIPE, optarg); config.action = PIPE;
config.pipecmd = xstrdup (optarg);
break; break;
case 'V': case 'V':
version (); version ();
@@ -296,7 +285,7 @@ get_options (int *argc, char **argv, struct option *long_options)
config.dedup = 1; config.dedup = 1;
break; break;
case 'l': case 'l':
set_lock_method ("none"); config.lock = 0;
break; break;
default: default:
fprintf(stderr, "%s: invalid option -- n%c\n", fprintf(stderr, "%s: invalid option -- n%c\n",
@@ -307,80 +296,3 @@ get_options (int *argc, char **argv, struct option *long_options)
} /* 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

@@ -25,17 +25,13 @@
#include "message.h" #include "message.h"
/* #include <time.h> */ /* #include <time.h> */
void set_folder_format (const char *name); format_t folder_format (const char *name);
void set_lock_method (const char *name); lockmethod_t 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 * allocate_message (void); void * allocate_message (void);
void postmark_print (message_t *msg); void postmark_print (message_t *msg);
void init_options (void); void set_default_options (void);
void get_options (int *argc, char **argv, void get_runtime_options (int *argc, char **argv, struct option *long_options);
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

@@ -21,58 +21,55 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <regex.h> #include <regex.h>
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
# define PCRE2_CODE_UNIT_WIDTH 32 #include <pcre.h>
# include <pcre2.h> #endif /* HAVE_LIBPCRE */
#endif /* HAVE_LIBPCRE2 */
#include "mboxgrep.h" #include "mboxgrep.h"
#include "message.h" #include "message.h"
#include "wrap.h" /* xcalloc() et cetera */ #include "wrap.h" /* xcalloc() et cetera */
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
void void
pcre_init (void) pcre_init (void)
{ {
int errornumber; int errptr;
PCRE2_SIZE erroroffset; const char *error;
config.pcre_pattern = config.pcre_pattern =
(pcre2_code *) pcre2_compile ((PCRE2_SPTR) config.regex_s, (PCRE2_SIZE) strlen (config.regex_s), (pcre *) pcre_compile (config.regex_s,
(config.ignorecase ? PCRE2_CASELESS : 0), (config.ignorecase ? PCRE_CASELESS : 0),
&errornumber, &erroroffset, NULL); &error, &errptr, 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,
PCRE2_UCHAR buffer[256]; error);
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); 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 =
pcre2_match ((pcre2_code *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(PCRE2_SPTR) msg->headers, (int) strlen (msg->headers), 0, 0, config.match_data, NULL); (pcre_extra *) config.pcre_hints,
msg->headers,
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
if (config.body) if (config.body)
config.res2 = config.res2 =
pcre2_match ((pcre2_code *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(PCRE2_SPTR) msg->body, (int) strlen (msg->body), 0, 0, config.match_data, NULL); (pcre_extra *) config.pcre_hints,
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_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
void void
regex_init (void) regex_init (void)
@@ -83,7 +80,7 @@ regex_init (void)
if (config.ignorecase) if (config.ignorecase)
flag1 = REG_ICASE; flag1 = REG_ICASE;
if (config.regextype == REGEX_EXTENDED) if (config.extended)
flag2 = REG_EXTENDED; flag2 = REG_EXTENDED;
config.posix_pattern = (regex_t *) xmalloc (sizeof (regex_t)); config.posix_pattern = (regex_t *) xmalloc (sizeof (regex_t));
@@ -93,8 +90,7 @@ regex_init (void)
{ {
if (config.merr) if (config.merr)
{ {
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf); fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf);
} }
exit (2); exit (2);

View File

@@ -19,9 +19,9 @@
#include "mboxgrep.h" #include "mboxgrep.h"
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
void pcre_init (void); void pcre_init (void);
void pcre_match (message_t *msg); void pcre_match (message_t *msg);
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
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 @@
/* /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000 - 2004, 2006, 2023 - 2024 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
@@ -32,16 +32,13 @@
# 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 # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#include <time.h> #include <time.h>
@@ -64,16 +61,14 @@
#else #else
# ifdef HAVE_FTW # ifdef HAVE_FTW
# include <ftw.h> # include <ftw.h>
# endif # endif /* HAVE_FTW */
/* 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 void scan_mailbox (char path[])
scan_mailbox (char path[])
{ {
static FILE *outf; static FILE *outf;
static mbox_t *mbox, *out; static mbox_t *mbox, *out;
@@ -83,7 +78,7 @@ scan_mailbox (char path[])
int delete = 0; int delete = 0;
int isdup = 0; int isdup = 0;
if (config.format == FORMAT_MAILDIR && config.action == ACTION_WRITE) if (config.format == MAILDIR && config.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)
@@ -101,24 +96,22 @@ scan_mailbox (char path[])
} }
runtime.count = 0; runtime.count = 0;
if (config.action == ACTION_DELETE) if (config.action == DELETE)
delete = 1; delete = 1;
if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX) if ((config.format == MBOX) || (config.format == ZMBOX) ||
|| (config.format == FORMAT_BZ2MBOX)) (config.format == BZ2MBOX))
{ {
mbox = (mbox_t *) mbox_open (path, r); mbox = (mbox_t *) mbox_open (path, "r");
if (mbox == NULL) if (mbox == NULL) return;
return;
} }
else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH) else if ((config.format == MH) || (config.format == NNMH) ||
|| (config.format == FORMAT_NNML)) (config.format == NNML))
{ {
boxd = mh_open (path); boxd = mh_open (path);
if (boxd == NULL) if (boxd == NULL) return;
return;
} }
else if (config.format == FORMAT_MAILDIR) else if (config.format == MAILDIR)
{ {
maildird = maildir_open (path); maildird = maildir_open (path);
@@ -131,26 +124,24 @@ scan_mailbox (char path[])
config.res1 = 1; config.res1 = 1;
config.res2 = 1; config.res2 = 1;
if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX) if ((config.format == MBOX) || (config.format == ZMBOX) ||
|| (config.format == FORMAT_BZ2MBOX)) (config.format == BZ2MBOX))
msg = (message_t *) mbox_read_message (mbox); msg = (message_t *) mbox_read_message (mbox);
else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH) else if ((config.format == MH) || (config.format == NNMH) ||
|| (config.format == FORMAT_NNML)) (config.format == NNML))
msg = (message_t *) mh_read_message (boxd); msg = (message_t *) mh_read_message (boxd);
else if (config.format == FORMAT_MAILDIR) else if (config.format == MAILDIR)
msg = (message_t *) maildir_read_message (maildird); msg = (message_t *) maildir_read_message (maildird);
if (msg == NULL) if (msg == NULL) break;
break;
if (msg->from == NULL) if (msg->from == NULL) msg->from = (char *) xstrdup ("nobody");
msg->from = (char *) xstrdup ("nobody");
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
if (config.regextype == REGEX_PERL) if (config.perl)
pcre_match (msg); pcre_match (msg);
else else
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
regex_match (msg); regex_match (msg);
if (config.dedup) if (config.dedup)
@@ -160,32 +151,32 @@ scan_mailbox (char path[])
((config.invert ^ delete)) && ((config.invert ^ delete)) &&
((config.dedup && !isdup) || !config.dedup)) ((config.dedup && !isdup) || !config.dedup))
{ {
if (config.action == ACTION_DISPLAY) if (config.action == DISPLAY)
{ {
if (config.format != FORMAT_MBOX && config.format != FORMAT_ZMBOX if (config.format != MBOX && config.format != ZMBOX
&& config.format != FORMAT_BZ2MBOX && config.format != BZ2MBOX
&& 0 != strncmp ("From ", msg->headers, 5)) && 0 != strncmp ("From ", msg->headers, 5))
postmark_print (msg); postmark_print (msg);
fprintf (stdout, "%s\n%s", msg->headers, msg->body); fprintf (stdout, "%s\n%s", msg->headers, msg->body);
} }
else if (config.action == ACTION_WRITE) else if (config.action == WRITE)
{ {
if (config.format == FORMAT_MAILDIR) if (config.format == MAILDIR)
maildir_write_message (msg, config.outboxname); maildir_write_message (msg, config.outboxname);
else if (config.format == FORMAT_MH || config.format == FORMAT_NNMH else if (config.format == MH || config.format == NNMH ||
|| config.format == FORMAT_NNML) config.format == NNML)
mh_write_message (msg, config.outboxname); mh_write_message (msg, config.outboxname);
else if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX) else if ((config.format == MBOX) || (config.format == ZMBOX) ||
|| (config.format == FORMAT_BZ2MBOX)) (config.format == BZ2MBOX))
{ {
out = mbox_open (config.outboxname, w); out = mbox_open (config.outboxname, "w");
/* fprintf (out->fp, "%s\n%s", msg->headers, msg->body); */ /* fprintf (out->fp, "%s\n%s", msg->headers, msg->body); */
mbox_write_message (msg, out); mbox_write_message (msg, out);
mbox_close (out); mbox_close (out);
} }
} }
else if (config.action == ACTION_PIPE) else if (config.action == PIPE)
{ {
outf = popen (config.pipecmd, "w"); outf = popen (config.pipecmd, "w");
if (outf == NULL) if (outf == NULL)
@@ -200,19 +191,17 @@ scan_mailbox (char path[])
fprintf (outf, "%s\n%s", msg->headers, msg->body); fprintf (outf, "%s\n%s", msg->headers, msg->body);
pclose (outf); pclose (outf);
} }
else if (config.action == ACTION_COUNT) else if (config.action == COUNT)
runtime.count++; runtime.count++;
else if (config.action == ACTION_DELETE && else if (config.action == DELETE &&
((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX) ((config.format == MBOX) || (config.format == ZMBOX) ||
|| (config.format == FORMAT_BZ2MBOX))) (config.format == BZ2MBOX)))
mbox_write_message (msg, runtime.tmp_mbox); mbox_write_message (msg, runtime.tmp_mbox);
} }
else else if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert) && delete) &&
if (((((config.res1 == 0) | (config.res2 == 0)) ^ config.invert) ((config.format == MH) || (config.format == NNMH) ||
&& delete) && ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH) (config.format == NNML) || (config.format == MAILDIR)))
|| (config.format == FORMAT_NNML)
|| (config.format == FORMAT_MAILDIR)))
m_unlink(msg->filename); m_unlink(msg->filename);
free(msg->body); free(msg->body);
@@ -220,16 +209,15 @@ scan_mailbox (char path[])
free(msg); free(msg);
} /* for */ } /* for */
if ((config.format == FORMAT_MBOX) || (config.format == FORMAT_ZMBOX) if ((config.format == MBOX) || (config.format == ZMBOX) ||
|| (config.format == FORMAT_BZ2MBOX)) (config.format == BZ2MBOX))
mbox_close (mbox); mbox_close (mbox);
else if ((config.format == FORMAT_MH) || (config.format == FORMAT_NNMH) else if ((config.format == MH) || (config.format == NNMH) ||
|| (config.format == FORMAT_NNML)) (config.format == NNML))
mh_close(boxd); mh_close(boxd);
} }
void void recursive_scan (char path[])
recursive_scan (char path[])
{ {
#ifdef HAVE_FTS_OPEN #ifdef HAVE_FTS_OPEN
FTS *ftsfoo; FTS *ftsfoo;
@@ -262,8 +250,7 @@ recursive_scan (char path[])
#endif /* HAVE_FTS_OPEN */ #endif /* HAVE_FTS_OPEN */
} }
int int md5_check_message (char *body, checksum_t *chksum)
md5_check_message (char *body, checksum_t * chksum)
{ {
struct md5_ctx a; struct md5_ctx a;
char b[16]; char b[16];
@@ -284,8 +271,7 @@ md5_check_message (char *body, checksum_t * chksum)
return 1; return 1;
} }
chksum->md5 = chksum->md5 = (char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
(char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
chksum->md5[chksum->n] = xstrdup (b); chksum->md5[chksum->n] = xstrdup (b);

View File

@@ -31,16 +31,13 @@
# 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 # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */
#endif /* HAVE_DIRENT_H */ #endif /* HAVE_DIRENT_H */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> #include <zlib.h>
@@ -62,8 +59,7 @@
#define BUFLEN 16384 #define BUFLEN 16384
int int m_open (const char *pathname, int flags, mode_t mode)
m_open (const char *pathname, int flags, mode_t mode)
{ {
int blah; int blah;
@@ -82,8 +78,7 @@ m_open (const char *pathname, int flags, mode_t mode)
return blah; return blah;
} }
FILE * FILE *m_fopen (const char *path, const char *mode)
m_fopen (const char *path, const char *mode)
{ {
FILE *blah; FILE *blah;
@@ -101,8 +96,7 @@ m_fopen (const char *path, const char *mode)
return blah; return blah;
} }
FILE * FILE *m_fdopen (int fildes, const char *mode)
m_fdopen (int fildes, const char *mode)
{ {
FILE *blah; FILE *blah;
@@ -117,8 +111,7 @@ m_fdopen (int fildes, const char *mode)
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
gzFile gzFile m_gzdopen (int fildes, const char *mode)
m_gzdopen (int fildes, const char *mode)
{ {
gzFile blah; gzFile blah;
@@ -133,8 +126,7 @@ m_gzdopen (int fildes, const char *mode)
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
DIR * DIR *m_opendir (const char *name)
m_opendir (const char *name)
{ {
DIR *blah; DIR *blah;
@@ -152,8 +144,7 @@ m_opendir (const char *name)
#ifndef HAVE_LIBDMALLOC #ifndef HAVE_LIBDMALLOC
void * void *xmalloc (size_t size)
xmalloc (size_t size)
{ {
void *foo; void *foo;
@@ -167,8 +158,7 @@ xmalloc (size_t size)
return foo; return foo;
} }
void * void *xrealloc (void *ptr, size_t size)
xrealloc (void *ptr, size_t size)
{ {
void *foo; void *foo;
@@ -182,8 +172,7 @@ xrealloc (void *ptr, size_t size)
return foo; return foo;
} }
void * void *xcalloc (size_t nmemb, size_t size)
xcalloc (size_t nmemb, size_t size)
{ {
void *foo; void *foo;
@@ -197,8 +186,7 @@ xcalloc (size_t nmemb, size_t size)
return foo; return foo;
} }
char * char *xstrdup (const char *s)
xstrdup (const char *s)
{ {
char *foo; char *foo;
@@ -214,8 +202,7 @@ xstrdup (const char *s)
#endif /* HAVE_LIBDMALLOC */ #endif /* HAVE_LIBDMALLOC */
int int m_unlink (const char *pathname)
m_unlink (const char *pathname)
{ {
int baz; int baz;
@@ -233,8 +220,7 @@ m_unlink (const char *pathname)
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
void void gzwrite_loop (void *fp, char *str)
gzwrite_loop (void *fp, char *str)
{ {
int quux, len, baz; int quux, len, baz;
@@ -254,8 +240,7 @@ gzwrite_loop (void *fp, char *str)
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
void void bzwrite_loop (void *fp, char *str)
bzwrite_loop (void *fp, char *str)
{ {
int quux, len, baz; int quux, len, baz;

View File

@@ -33,29 +33,23 @@
#else #else
# ifdef HAVE_SYS_NDIR_H # ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h> # include <sys/ndir.h>
# endif # endif /* HAVE_SYS_NDIR_H */
/* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H # ifdef HAVE_SYS_DIR_H
# include <sys/dir.h> # include <sys/dir.h>
# endif # endif /* HAVE_SYS_DIR_H */
/* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H # ifdef HAVE_NDIR_H
# include <ndir.h> # include <ndir.h>
# endif # endif /* HAVE_NDIR_H */
/* HAVE_NDIR_H */ #endif /* HAVE_DIRENT_H */
# endif
/* HAVE_DIRENT_H */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> #include <zlib.h>
# endif #endif /* HAVE_LIBZ */
/* HAVE_LIBZ */
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_LIBDMALLOC #ifdef HAVE_LIBDMALLOC
# include <dmalloc.h> # include <dmalloc.h>
# endif #endif /* HAVE_LIBDMALLOC */
/* HAVE_LIBDMALLOC */
int m_open (const char *pathname, int flags, mode_t mode); int m_open (const char *pathname, int flags, mode_t mode);
@@ -64,12 +58,10 @@ 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 #endif /* HAVE_LIBZ */
/* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
void bzwrite_loop (void *fp, char *str); void bzwrite_loop (void *fp, char *str);
# endif #endif /* HAVE_LIBBZ2 */
/* HAVE_LIBBZ2 */
DIR *m_opendir (const char *name); DIR *m_opendir (const char *name);
@@ -78,8 +70,7 @@ 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 #endif /* HAVE_LIBDMALLOC */
/* HAVE_LIBDMALLOC */
int m_unlink (const char *pathname); int m_unlink (const char *pathname);