Bump to version 0.7.10 and import of changes that have been made between
2003 and 2006 and haven't been tracked by any SCM. The changes are the following, in reverse order: * src/mboxgrep.h, src/main.c, src/mbox.c, src/mbox.h, src/scan.c: Temporary mbox file (used for deleting messages) is now created by tmpmbox_create(); tmpp global pointer is killed; portions of code in scan.c are replaced by single call of mbox_write_message(); scan.c no longer includes zlib.h and bzlib.h. * src/mboxgrep.h, src/main.c, src/maildir.c, src/scan.c: Got rid off tmpp and maildir_count global variables (code cleanup). * src/mboxgrep.h, src/main.c, src/scan.c: Introduction of the global runtime_t structure; mailbox counter, MD5 hash and other global variables are now part of it (code cleanup). * src/mboxgrep.h, src/re.c, src/re.h, src/scan.c: Portions of scan_mailbox() have been moved to new functions, pcre_match() and regex_match() (code cleanup). * src/main.c, src/mboxgrep.h, src/re.c, src/re.h, src/scan.c: main() has been partially uncluttered by moving portions of the code to functions pcre_init() and regex_init(). * src/main.c, src/mboxgrep.h, src/misc.c, src/misc.h: Variables regex_s and haveregex are now part of the option_t structure (code cleanup). * src/main.c, src/misc.c, src/misc.h: Parts of main() have been moved to set_default_options() and get_runtime_options() (code cleanup). * src/mbox.c, src/mbox.h: File mode and ownership-altering code has been moved to a separate function, tmpfile_mod_own (code cleanup). * src/mbox.c, src/mbox.h: Portions of the code from tmpfile_open moved to a new function, tmpfile_name (code cleanup). * src/maildir.c, src/mh.c: Removed some unused variables (have_return_path). * src/mboxgrep.h, src/maildir.c, src/mh.c, src/mbox.c, src/scan.c, src/main.c: boxname, outboxname, pipecmd and tmpfilename are now a part of the config_t structure and no longer global variables. * src/scan.c, src/misc.c, src/misc.h: Created postmark_print() to unclutter scan_mailbox(). * src/misc.c, src/misc.h, src/mbox.c, src/maildir.c, src/mh.c: Some repetitive code moved to malloc_message(). * src/mbox.c: Cleanup of mbox_write_message(); use of gzwrite_loop() and bzwrite_loop(). * src/scan.c, src/wrap.h, src/wrap.c: Wrote gzwrite_loop() and bzwrite_loop() to remove some repetitive code from scan.c. * src/scan.c: md5_check_message(): array b and cast in strncmp are no longer unsigned. * src/info.c, src/mboxgrep.h: Updated copyright information, changed author's email address to the one at Panix. * src/mbox.h, src/mbox.c, src/scan.c, src/main.c: mbox_write_message(); further fixes of message deletion code. * src/scan.c: Fixed deleting messages from mbox folders compressed with bzip2. * src/main.c, src/mbox.c: Moved James P. Dugal's ownership-preserving code from main() to tmpfile_open(). * src/info.c: If bzip2 support is compiled in, `--help' command should list `bz2mbox' as a valid option to `--mailbox-format='.
This commit is contained in:
parent
bd80cfbb4d
commit
0649ac9320
5
AUTHORS
5
AUTHORS
@ -1,2 +1,5 @@
|
||||
-*- text -*-
|
||||
|
||||
$Id: AUTHORS,v 1.2 2002/01/28 23:43:34 dspiljar Exp $
|
||||
mboxgrep is written and maintained by Daniel Spiljar.
|
||||
|
||||
$Id: AUTHORS,v 1.3 2005-11-16 01:37:18 dspiljar Exp $
|
||||
|
132
ChangeLog
132
ChangeLog
@ -1,3 +1,133 @@
|
||||
Mon Oct 23 01:29:07 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mboxgrep.h, src/main.c, src/mbox.c, src/mbox.h, src/scan.c:
|
||||
temporary mbox file (used for deleting messages) is now created
|
||||
by tmpmbox_create(), tmpp global pointer is killed; portions of
|
||||
code in scan.c are replaced by single call of mbox_write_message();
|
||||
scan.c no longer includes zlib.h and bzlib.h
|
||||
|
||||
Thu Oct 19 03:50:38 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mboxgrep.h, src/main.c, src/maildir.c, src/scan.c:
|
||||
got rid off tmpp and maildir_count global variables (code
|
||||
cleanup)
|
||||
|
||||
Thu Oct 19 03:38:24 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mboxgrep.h, src/main.c, src/scan.c:
|
||||
introduction of the global runtime_t structure; mailbox counter,
|
||||
MD5 hash and other global variables are now part of it (code
|
||||
cleanup)
|
||||
|
||||
Fri Jul 7 06:10:51 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
|
||||
portions of scan_mailbox() have been moved to new functions,
|
||||
pcre_match() and regex_match() (code cleanup)
|
||||
|
||||
Thu Jul 6 13:54:23 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/main.c, src/mboxgrep.h, src/re.c, src/re.h, src/scan.c:
|
||||
main() has been partially uncluttered by moving portions of the
|
||||
code to functions pcre_init() and regex_init()
|
||||
|
||||
Thu Jul 6 12:49:59 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/main.c, src/mboxgrep.h, src/misc.c, src/misc.h:
|
||||
variables regex_s and haveregex are now part of the option_t
|
||||
structure (code cleanup)
|
||||
|
||||
Thu Jul 6 10:26:57 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/main.c, src/misc.c, src/misc.h:
|
||||
parts of main() have been moved to set_default_options() and
|
||||
get_runtime_options() (code cleanup)
|
||||
|
||||
Sat Jul 1 13:06:37 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mbox.c, src/mbox.h:
|
||||
file mode and ownership-altering code has been moved to a separate
|
||||
function, tmpfile_mod_own (code cleanup)
|
||||
|
||||
Tue Jun 27 18:48:00 CEST 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mbox.c, src/mbox.h:
|
||||
portions of the code from tmpfile_open moved to a new function,
|
||||
tmpfile_name (code cleanup)
|
||||
|
||||
Mon Feb 20 18:09:59 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/maildir.c, src/mh.c:
|
||||
removed some unused variables (have_return_path)
|
||||
|
||||
Mon Jan 30 01:35:30 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mboxgrep.h, src/maildir.c, src/mh.c, src/mbox.c, src/scan.c, src/main.c:
|
||||
boxname, outboxname, pipecmd and tmpfilename are now a part of
|
||||
the config_t structure and no longer global variables
|
||||
|
||||
Sat Jan 21 08:18:29 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/scan.c, src/misc.c, src/misc.h:
|
||||
created postmark_print() to unclutter scan_mailbox()
|
||||
|
||||
Fri Jan 20 05:36:44 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/misc.c, src/misc.h, src/mbox.c, src/maildir.c, src/mh.c:
|
||||
some repetitive code moved to malloc_message()
|
||||
|
||||
Fri Jan 20 05:13:06 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/mbox.c:
|
||||
cleanup of mbox_write_message(); use of gzwrite_loop() and
|
||||
bzwrite_loop()
|
||||
|
||||
Fri Jan 20 03:57:28 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/scan.c, src/wrap.h, src/wrap.c:
|
||||
wrote gzwrite_loop() and bzwrite_loop() to remove some repetitive
|
||||
code from scan.c
|
||||
|
||||
Fri Jan 20 02:11:50 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/scan.c:
|
||||
md5_check_message(): array b and cast in strncmp are no longer
|
||||
unsigned
|
||||
|
||||
Wed Jan 18 01:48:56 CET 2006 Daniel Spiljar <dspiljar@panix.com>
|
||||
|
||||
* src/info.c, src/mboxgrep.h:
|
||||
updated copyright information, changed author's email address
|
||||
to the one at Panix
|
||||
|
||||
Mon Apr 12 19:30:52 CEST 2004 Daniel Spiljar <dspiljar@world.std.com>
|
||||
|
||||
* src/info.c:
|
||||
updated copyright information
|
||||
|
||||
Sun Apr 11 23:45:08 CEST 2004 Daniel Spiljar <dspiljar@world.std.com>
|
||||
|
||||
* src/mbox.h, src/mbox.c, src/scan.c, src/main.c:
|
||||
mbox_write_message(); further fixes of message deletion code
|
||||
|
||||
Thu Sep 18 00:10:13 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||
|
||||
* src/scan.c:
|
||||
fixed deleting messages from mbox folders compressed with
|
||||
bzip2
|
||||
|
||||
Thu Sep 18 00:08:36 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||
|
||||
* src/main.c, src/mbox.c:
|
||||
moved James P. Dugal's ownership-preserving code from main()
|
||||
to tmpfile_open()
|
||||
|
||||
Sat Aug 30 23:13:01 CEST 2003 Vid Strpic <vms@bofhlet.net>
|
||||
|
||||
* src/info.c:
|
||||
If bzip2 support is compiled in, `--help' command should list
|
||||
`bz2mbox' as a valid option to `--mailbox-format='.
|
||||
|
||||
Sun Aug 24 21:49:52 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||
|
||||
* doc/mboxgrep.1, doc/mboxgrep.texi:
|
||||
@ -251,4 +381,4 @@ Tue Mar 27 01:26:22 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||
|
||||
|
||||
|
||||
$Id: ChangeLog,v 1.37 2003/08/24 19:51:12 dspiljar Exp $
|
||||
$Id: ChangeLog,v 1.59 2006-10-22 23:34:47 dspiljar Exp $
|
||||
|
@ -15,7 +15,7 @@
|
||||
# along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id: Makefile.in,v 1.1 2001/10/26 13:07:28 dspiljar Exp $
|
||||
# $Id: Makefile.in,v 1.1 2001-10-26 13:07:28 dspiljar Exp $
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
|
6
NEWS
6
NEWS
@ -1,6 +1,10 @@
|
||||
Changes of mboxgrep
|
||||
===================
|
||||
|
||||
Changes since 0.7.9
|
||||
- fixed compile bug on FreeBSD and other systems
|
||||
- fixed deleting messages mbox folders compressed with bzip2
|
||||
|
||||
Changes since 0.7.8
|
||||
- implemented support for mbox folders compressed with bzip2 algorithm
|
||||
- improved detection of PCRE library; this also fixes a compilation bug
|
||||
@ -103,4 +107,4 @@ Changes since 0.1.0
|
||||
- added support for mailboxes generated by Gnus
|
||||
|
||||
|
||||
$Id: NEWS,v 1.21 2003/08/24 19:23:48 dspiljar Exp $
|
||||
$Id: NEWS,v 1.23 2004-04-11 21:48:53 dspiljar Exp $
|
||||
|
4
README
4
README
@ -7,7 +7,7 @@ which is provided both in manpage and texinfo format, to satisfy
|
||||
believers of both religions.
|
||||
|
||||
The author of mboxgrep is Daniel Spiljar, who can be reached via email
|
||||
at <dspiljar@world.std.com>. Bug reports, feature requests and flames
|
||||
at <dspiljar@panix.com>. Bug reports, feature requests and flames
|
||||
are welcome.
|
||||
|
||||
If you intend to bundle mboxgrep with an operating system (such as a
|
||||
@ -16,4 +16,4 @@ GNU/Linux distrubution, for example), please drop me a line about it.
|
||||
For build instructions, read the file `INSTALL', and run
|
||||
`./configure --help'
|
||||
|
||||
$Id: README,v 1.2 2002/12/02 20:53:07 dspiljar Exp $
|
||||
$Id: README,v 1.3 2006-01-18 00:09:56 dspiljar Exp $
|
||||
|
2
TODO
2
TODO
@ -23,4 +23,4 @@
|
||||
- add support for mail folder conversion [ ]
|
||||
|
||||
|
||||
$Id: TODO,v 1.16 2003/04/06 21:48:23 dspiljar Exp $
|
||||
$Id: TODO,v 1.16 2003-04-06 21:48:23 dspiljar Exp $
|
||||
|
@ -15,7 +15,7 @@
|
||||
# along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id: configure.ac,v 1.13 2003/08/10 22:45:45 dspiljar Exp $
|
||||
# $Id: configure.ac,v 1.13 2003-08-10 22:45:45 dspiljar Exp $
|
||||
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id: Makefile.in,v 1.1 2001/10/26 13:07:55 dspiljar Exp $
|
||||
# $Id: Makefile.in,v 1.1 2001-10-26 13:07:55 dspiljar Exp $
|
||||
|
||||
MANPAGE = mboxgrep.1
|
||||
INSTALL = @INSTALL@
|
||||
|
@ -1,4 +1,4 @@
|
||||
.Id $Id: mboxgrep.1,v 1.15 2003/08/24 19:51:14 dspiljar Exp $
|
||||
.Id $Id: mboxgrep.1,v 1.16 2006-01-18 00:09:58 dspiljar Exp $
|
||||
.TH MBOXGREP 1 "24 Aug 2003"
|
||||
.SH NAME
|
||||
mboxgrep \- displays email messages matching a pattern
|
||||
@ -119,4 +119,4 @@ well, little friend.
|
||||
.SH URL
|
||||
http://www.mboxgrep.org/
|
||||
.SH AUTHOR
|
||||
Daniel Spiljar <dspiljar@world.std.com>
|
||||
Daniel Spiljar <dspiljar@panix.com>
|
||||
|
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
\input texinfo @c -*-texinfo-*-
|
||||
@c $Id: mboxgrep.texi,v 1.19 2003/08/24 19:51:14 dspiljar Exp $
|
||||
@c $Id: mboxgrep.texi,v 1.20 2006-01-18 00:09:58 dspiljar Exp $
|
||||
@setfilename mboxgrep.info
|
||||
@settitle Grep through mailboxes
|
||||
@finalout
|
||||
@ -260,7 +260,7 @@ mboxgrep -nd -c . spam
|
||||
Shortly, if @code{mboxgrep} crashes and/or works differently than described
|
||||
in this manual, you've found a bug.
|
||||
|
||||
Please report bugs to @email{dspiljar@@world.std.com}.
|
||||
Please report bugs to @email{dspiljar@@panix.com}.
|
||||
Instructions how to reproduce the bug or output from a debugger would be
|
||||
highly appreciated. Don't, however, send any coredumps.
|
||||
|
||||
|
@ -10,8 +10,8 @@ Description: mboxgrep is a small utility that scans a mailbox for messages
|
||||
It supports mbox (both plain and compressed), MH, nnmh, nnml
|
||||
and maildir folders.
|
||||
Keywords: mail, mail-tools, mbox, MH, nnmh, nnml, maildir, regex
|
||||
Author: dspiljar@world.std.com (Daniel Spiljar)
|
||||
Maintained-by: dspiljar@world.std.com (Daniel Spiljar)
|
||||
Author: dspiljar@panix.com (Daniel Spiljar)
|
||||
Maintained-by: dspiljar@panix.com (Daniel Spiljar)
|
||||
Primary-site: http://www.mboxgrep.org/
|
||||
75k mboxgrep-0.7.9.tar.gz
|
||||
Alternate-site:
|
||||
|
@ -1,5 +1,5 @@
|
||||
# mboxgrep - scan mailbox for messages matching a regular expression
|
||||
# Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
# Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
#
|
||||
# Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
@ -15,15 +15,15 @@
|
||||
# along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id: Makefile.in,v 1.9 2003/03/30 23:07:10 dspiljar Exp $
|
||||
# $Id: Makefile.in,v 1.12 2006-07-07 04:38:53 dspiljar Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
|
||||
CC = @CC@
|
||||
OBJS = info.o main.o mh.o scan.o maildir.o mbox.o misc.o \
|
||||
wrap.o getopt.o getopt1.o md5.o
|
||||
wrap.o getopt.o getopt1.o md5.o re.o
|
||||
SRCS = info.c main.c mh.c scan.c maildir.c mbox.c misc.c \
|
||||
wrap.c getopt.c getopt1.c md5.c
|
||||
wrap.c getopt.c getopt1.c md5.c re.c
|
||||
TARGET = mboxgrep
|
||||
CFLAGS = @CFLAGS@
|
||||
LIBS = @LIBS@
|
||||
|
13
src/info.c
13
src/info.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000 - 2004, 2006, 2010 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: info.c,v 1.19 2003/04/13 19:15:58 dspiljar Exp $ */
|
||||
$Id: info.c,v 1.22 2006-01-18 00:44:36 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -48,7 +48,7 @@ version (void)
|
||||
int n = 0;
|
||||
|
||||
fprintf (stdout, "%s %s\n\n"
|
||||
"Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar\n"
|
||||
"Copyright (C) 2000 - 2004, 2006, 2010 Daniel Spiljar\n"
|
||||
"This program is free software; you can redistribute it and/or "
|
||||
"modify\nit under the terms of the GNU General Public License "
|
||||
"as published by\nthe Free Software Foundation; either version "
|
||||
@ -147,9 +147,12 @@ help (void)
|
||||
#ifdef HAVE_LIBZ
|
||||
fprintf(stdout, "`zmbox', ");
|
||||
#endif /* HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBBZ2
|
||||
fprintf(stdout, "`bz2mbox', ");
|
||||
#endif /* HAVE_LIBBZ2 */
|
||||
fprintf(stdout,
|
||||
"`mh', `nnml',\n"
|
||||
"\t\t\t\t`nnmh', or `maildir'.\n\n"
|
||||
"`mh',\n"
|
||||
"\t\t\t\t`nnml', `nnmh', or `maildir'.\n\n"
|
||||
"Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR);
|
||||
|
||||
exit(0);
|
||||
|
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: info.h,v 1.5 2003/04/13 19:15:58 dspiljar Exp $ */
|
||||
$Id: info.h,v 1.5 2003-04-13 19:15:58 dspiljar Exp $ */
|
||||
|
||||
#ifndef INFO_H
|
||||
#define INFO_H
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: maildir.c,v 1.21 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: maildir.c,v 1.25 2006-10-19 01:53:43 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -115,26 +115,15 @@ message_t *
|
||||
maildir_read_message (maildir_t *mdp)
|
||||
{
|
||||
int isheaders = 1;
|
||||
int have_from = 0, have_to = 0, have_message_id = 0, have_return_path = 0,
|
||||
have_sender = 0, have_date = 0;
|
||||
int have_from = 0, have_to = 0, have_message_id = 0, have_sender = 0,
|
||||
have_date = 0;
|
||||
static message_t *message;
|
||||
static struct dirent *d_content;
|
||||
char *filename, buffer[BUFSIZ];
|
||||
extern char *boxname;
|
||||
static FILE *fp;
|
||||
static int s;
|
||||
|
||||
message = (message_t *) xmalloc (sizeof (message_t));
|
||||
|
||||
message->headers = (char *) xmalloc (sizeof (char));
|
||||
message->headers[0] = '\0';
|
||||
message->hbytes = 0;
|
||||
|
||||
message->body = (char *) xmalloc (sizeof (char));
|
||||
message->body[0] = '\0';
|
||||
message->bbytes = 0;
|
||||
|
||||
message->from = NULL;
|
||||
message = malloc_message ();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
@ -169,17 +158,17 @@ maildir_read_message (maildir_t *mdp)
|
||||
|
||||
filename =
|
||||
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
|
||||
+ (strlen (boxname)) + 6)));
|
||||
+ (strlen (config.boxname)) + 6)));
|
||||
|
||||
/*
|
||||
filename =
|
||||
(char *) alloca((sizeof(char)*((strlen(d_content->d_name))
|
||||
+ (strlen(boxname)) + 2)));
|
||||
+ (strlen(config.boxname)) + 2)));
|
||||
*/
|
||||
if (mdp->new != NULL)
|
||||
sprintf (filename, "%s/new/%s", boxname, d_content->d_name);
|
||||
sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name);
|
||||
else
|
||||
sprintf (filename, "%s/cur/%s", boxname, d_content->d_name);
|
||||
sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name);
|
||||
message->filename = (char *) xstrdup (filename);
|
||||
free (filename);
|
||||
|
||||
@ -210,10 +199,7 @@ maildir_read_message (maildir_t *mdp)
|
||||
if (0 == strncasecmp ("Message-ID: ", buffer, 12))
|
||||
have_message_id = 1;
|
||||
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
|
||||
{
|
||||
have_return_path = 1;
|
||||
message->from = parse_return_path(buffer);
|
||||
}
|
||||
|
||||
message->headers =
|
||||
(char *) xrealloc (message->headers,
|
||||
@ -248,15 +234,15 @@ maildir_read_message (maildir_t *mdp)
|
||||
void
|
||||
maildir_write_message (message_t *m, const char *path)
|
||||
{
|
||||
extern int maildir_count;
|
||||
char bla[BUFSIZ], *s1, *s2;
|
||||
int t;
|
||||
static FILE *f1;
|
||||
|
||||
maildir_count++;
|
||||
runtime.maildir_count++;
|
||||
t = (int) time (NULL);
|
||||
|
||||
sprintf (bla, "%i.%i_%i.%s", t, config.pid, maildir_count, config.hostname);
|
||||
sprintf (bla, "%i.%i_%i.%s",
|
||||
t, config.pid, runtime.maildir_count, config.hostname);
|
||||
s1 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char));
|
||||
sprintf(s1, "%s/tmp/%s", path, bla);
|
||||
s2 = (char *) xmalloc ((strlen (path) + strlen (bla) + 6) * sizeof (char));
|
||||
|
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: maildir.h,v 1.6 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: maildir.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
|
||||
|
||||
#ifndef MAILDIR_H
|
||||
#define MAILDIR_H
|
||||
|
244
src/main.c
244
src/main.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: main.c,v 1.32 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||
$Id: main.c,v 1.41 2006-10-22 23:34:49 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -24,12 +24,8 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <regex.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_LIBPCRE
|
||||
#include <pcre.h>
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
#ifdef HAVE_LIBZ
|
||||
#include <zlib.h>
|
||||
#endif /* HAVE_LIBZ */
|
||||
@ -42,39 +38,21 @@
|
||||
#include "mh.h"
|
||||
#include "scan.h"
|
||||
#include "wrap.h" /* xcalloc() et cetera */
|
||||
#include "re.h"
|
||||
|
||||
#ifdef HAVE_LIBDMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif /* HAVE_LIBDMALLOC */
|
||||
|
||||
regex_t posix_pattern;
|
||||
#ifdef HAVE_LIBPCRE
|
||||
pcre *pcre_pattern;
|
||||
pcre_extra *hints;
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
char *boxname, *outboxname, *pipecmd, *tmpfilename;
|
||||
int maildir_count = 0;
|
||||
int count = 0;
|
||||
void *tmpp;
|
||||
checksum_t *cs;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
int option_index = 0;
|
||||
int c;
|
||||
#ifdef HAVE_LIBPCRE
|
||||
int errptr;
|
||||
const char *error;
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
int haveregex = 0, havemailbox = 0;
|
||||
static char *regex_s;
|
||||
int havemailbox = 0;
|
||||
int singlefile = 0;
|
||||
|
||||
int errcode = 0;
|
||||
char errbuf[BUFSIZ];
|
||||
runtime.count = 0;
|
||||
runtime.maildir_count = 0;
|
||||
|
||||
static struct option long_options[] =
|
||||
/* {{{ */
|
||||
@ -107,124 +85,9 @@ main (int argc, char **argv)
|
||||
|
||||
/* }}} */
|
||||
|
||||
config.perl = 0;
|
||||
config.extended = 1;
|
||||
config.invert = 0;
|
||||
config.headers = 0;
|
||||
config.body = 0;
|
||||
config.action = DISPLAY;
|
||||
config.dedup = 0;
|
||||
config.recursive = 0;
|
||||
config.ignorecase = 0;
|
||||
config.format = MBOX; /* default mailbox format */
|
||||
config.lock = FCNTL; /* default file locking method */
|
||||
config.merr = 1; /* report errors by default */
|
||||
set_default_options ();
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt_long (argc, argv, "BcdEe:GHhil:m:n:o:Pp:rsVv", long_options,
|
||||
&option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
case '?':
|
||||
usage();
|
||||
case 'c':
|
||||
config.action = COUNT;
|
||||
break;
|
||||
case 'd':
|
||||
config.action = DELETE;
|
||||
break;
|
||||
case 'e':
|
||||
regex_s = xstrdup (optarg);
|
||||
haveregex = 1;
|
||||
break;
|
||||
case 'o':
|
||||
outboxname = xstrdup (optarg);
|
||||
config.action = WRITE;
|
||||
break;
|
||||
case 'E':
|
||||
config.extended = 1;
|
||||
break;
|
||||
case 'G':
|
||||
config.extended = 0;
|
||||
break;
|
||||
case 'P':
|
||||
#ifdef HAVE_LIBPCRE
|
||||
config.extended = 0;
|
||||
config.perl = 1;
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"%s: Support for Perl regular expressions not "
|
||||
"compiled in\n");
|
||||
exit(2);
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
break;
|
||||
case 'h':
|
||||
help ();
|
||||
break;
|
||||
case 'i':
|
||||
config.ignorecase = 1;
|
||||
break;
|
||||
case 'm':
|
||||
config.format = folder_format (optarg);
|
||||
break;
|
||||
case 'l':
|
||||
config.lock = lock_method (optarg);
|
||||
break;
|
||||
case 'p':
|
||||
config.action = PIPE;
|
||||
pipecmd = xstrdup (optarg);
|
||||
break;
|
||||
case 'V':
|
||||
version ();
|
||||
break;
|
||||
case 'v':
|
||||
config.invert = 1;
|
||||
break;
|
||||
case 'H':
|
||||
config.headers = 1;
|
||||
break;
|
||||
case 'B':
|
||||
config.body = 1;
|
||||
break;
|
||||
case 's':
|
||||
config.merr = 0;
|
||||
break;
|
||||
case 201:
|
||||
config.lock = 0;
|
||||
break;
|
||||
case 'r':
|
||||
config.recursive = 1;
|
||||
break;
|
||||
case 200:
|
||||
config.dedup = 1;
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
switch (optarg[0])
|
||||
{
|
||||
case 'd':
|
||||
config.dedup = 1;
|
||||
break;
|
||||
case 'l':
|
||||
config.lock = 0;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: invalid option -- n%c\n",
|
||||
APPNAME, optarg[0]);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
/* }}} */
|
||||
} /* while */
|
||||
get_runtime_options (&argc, argv, long_options);
|
||||
|
||||
if ((config.body == 0) && (config.headers == 0))
|
||||
{
|
||||
@ -238,62 +101,25 @@ main (int argc, char **argv)
|
||||
config.pid = (int) getpid ();
|
||||
}
|
||||
|
||||
cs = (checksum_t *) xmalloc (sizeof (checksum_t));
|
||||
cs->md5 = (char **) xcalloc (1, sizeof (char **));
|
||||
cs->n = 0;
|
||||
runtime.cs = (checksum_t *) xmalloc (sizeof (checksum_t));
|
||||
runtime.cs->md5 = (char **) xcalloc (1, sizeof (char **));
|
||||
runtime.cs->n = 0;
|
||||
|
||||
if (optind < argc && ! haveregex)
|
||||
if (optind < argc && ! config.haveregex)
|
||||
{
|
||||
regex_s = xstrdup (argv[optind]);
|
||||
haveregex = 1;
|
||||
config.regex_s = xstrdup (argv[optind]);
|
||||
config.haveregex = 1;
|
||||
++optind;
|
||||
} /* if */
|
||||
|
||||
if (haveregex)
|
||||
if (config.haveregex)
|
||||
{
|
||||
#ifdef HAVE_LIBPCRE
|
||||
if (config.perl)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
pcre_pattern = pcre_compile (regex_s,
|
||||
(config.ignorecase ? PCRE_CASELESS : 0),
|
||||
&error, &errptr, NULL);
|
||||
if (pcre_pattern == NULL)
|
||||
{
|
||||
if (config.merr)
|
||||
fprintf (stderr, "%s: %s: %s\n", APPNAME, regex_s, error);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
pcre_init ();
|
||||
else
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
int flag1 = 0, flag2 = 0;
|
||||
|
||||
if (config.ignorecase)
|
||||
flag1 = REG_ICASE;
|
||||
if (config.extended)
|
||||
flag2 = REG_EXTENDED;
|
||||
|
||||
errcode = regcomp (&posix_pattern, regex_s,
|
||||
(flag1 | flag2 | REG_NEWLINE ));
|
||||
if (0 != errcode)
|
||||
{
|
||||
if (config.merr)
|
||||
{
|
||||
regerror (errcode, &posix_pattern, errbuf, BUFSIZ);
|
||||
fprintf (stderr, "%s: %s: %s\n", APPNAME, regex_s, errbuf);
|
||||
}
|
||||
exit (2);
|
||||
} /* if */
|
||||
} /* if */
|
||||
|
||||
/* }}} */
|
||||
regex_init ();
|
||||
} /* if */
|
||||
else
|
||||
usage ();
|
||||
@ -306,24 +132,11 @@ main (int argc, char **argv)
|
||||
|
||||
{
|
||||
if (config.action == DELETE) {
|
||||
tmpp = tmpfile_open (argv[optind]);
|
||||
|
||||
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
|
||||
* so rename() will thus retain the original's ownership & permissions.
|
||||
*/
|
||||
if (geteuid() == 0) {
|
||||
struct stat s;
|
||||
if (stat(argv[optind], &s) != -1) {
|
||||
if (fchown(fileno(tmpp), s.st_uid, s.st_gid) == -1)
|
||||
if (config.merr) perror(tmpfilename);
|
||||
if (fchmod(fileno(tmpp), s.st_mode) == -1)
|
||||
if (config.merr) perror(tmpfilename);
|
||||
}
|
||||
else if (config.merr) perror(argv[optind]);
|
||||
}
|
||||
tmpmbox_create (argv[optind]);
|
||||
runtime.tmp_mbox = mbox_open (config.tmpfilename, "w");
|
||||
}
|
||||
|
||||
boxname = xstrdup (argv[optind]);
|
||||
config.boxname = xstrdup (argv[optind]);
|
||||
|
||||
if (config.recursive)
|
||||
recursive_scan (argv[optind]);
|
||||
@ -333,24 +146,19 @@ main (int argc, char **argv)
|
||||
if (config.action == COUNT)
|
||||
{
|
||||
if (singlefile)
|
||||
fprintf (stdout, "%i\n", count);
|
||||
fprintf (stdout, "%i\n", runtime.count);
|
||||
else
|
||||
{
|
||||
if (0 == strcmp ("-", argv[optind]))
|
||||
fprintf (stdout, "(standard input):%i\n", count);
|
||||
fprintf (stdout, "(standard input):%i\n", runtime.count);
|
||||
else
|
||||
fprintf (stdout, "%s:%i\n", argv[optind], count);
|
||||
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
|
||||
}
|
||||
}
|
||||
if (config.action == DELETE)
|
||||
{
|
||||
#ifdef HAVE_LIBZ
|
||||
if (config.format == ZMBOX)
|
||||
gzclose (tmpp);
|
||||
#endif /* HAVE_LIBZ */
|
||||
if (config.format == MBOX)
|
||||
fclose (tmpp);
|
||||
rename (tmpfilename, argv[optind]);
|
||||
mbox_close (runtime.tmp_mbox);
|
||||
rename (config.tmpfilename, argv[optind]);
|
||||
}
|
||||
++optind;
|
||||
} /* while */
|
||||
@ -364,7 +172,7 @@ main (int argc, char **argv)
|
||||
config.format = MBOX;
|
||||
scan_mailbox ("-");
|
||||
if (config.action == COUNT)
|
||||
fprintf (stdout, "%i\n", count);
|
||||
fprintf (stdout, "%i\n", runtime.count);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
130
src/mbox.c
130
src/mbox.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: mbox.c,v 1.26 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||
$Id: mbox.c,v 1.34 2006-10-22 23:34:49 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#ifdef HAVE_LIBBZ2
|
||||
#include <bzlib.h>
|
||||
#endif /* HAVE_LIBBZ2 */
|
||||
#define BUFLEN 16384
|
||||
|
||||
#include "mboxgrep.h"
|
||||
#include "mbox.h"
|
||||
@ -243,17 +244,7 @@ mbox_read_message (mbox_t * mp)
|
||||
char buffer[BUFSIZ];
|
||||
message_t *message;
|
||||
|
||||
message = (message_t *) xmalloc (sizeof (message_t));
|
||||
|
||||
message->headers = (char *) xmalloc (sizeof (char));
|
||||
message->headers[0] = '\0';
|
||||
message->hbytes = 0;
|
||||
|
||||
message->body = (char *) xmalloc (sizeof (char));
|
||||
message->body[0] = '\0';
|
||||
message->bbytes = 0;
|
||||
|
||||
message->from = NULL;
|
||||
message = malloc_message ();
|
||||
|
||||
s = strlen (mp->postmark_cache);
|
||||
message->headers =
|
||||
@ -348,53 +339,112 @@ mbox_read_message (mbox_t * mp)
|
||||
|
||||
/* }}} */
|
||||
|
||||
void *
|
||||
tmpfile_open (const char *path)
|
||||
void
|
||||
tmpmbox_create (const char *path)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
extern char *tmpfilename;
|
||||
char *fname;
|
||||
char *tmpdir;
|
||||
int foo;
|
||||
|
||||
if (path == NULL) { /* no path prefix given, use /tmp or TMPDIR */
|
||||
tmpfile_name (path);
|
||||
foo = tmpfile_create ();
|
||||
tmpfile_mod_own (foo, path);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
void
|
||||
tmpfile_name (const char *path)
|
||||
/* {{{ */
|
||||
{
|
||||
char *fname, *tmpdir;
|
||||
|
||||
if (path == NULL) /* no path prefix given, use /tmp or TMPDIR */
|
||||
{
|
||||
tmpdir = getenv ("TMPDIR");
|
||||
if (tmpdir == NULL)
|
||||
tmpdir = xstrdup ("/tmp");
|
||||
fname = xstrdup ("/mboxgrepXXXXXX");
|
||||
}
|
||||
else {
|
||||
tmpdir = (char *)path;
|
||||
else
|
||||
{
|
||||
tmpdir = xstrdup (path);
|
||||
fname = xstrdup (".XXXXXX");
|
||||
}
|
||||
|
||||
tmpfilename = (char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
|
||||
config.tmpfilename =
|
||||
(char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
|
||||
* sizeof (char));
|
||||
sprintf (tmpfilename, "%s%s", tmpdir, fname);
|
||||
foo = mkstemp (tmpfilename);
|
||||
if (-1 == foo)
|
||||
sprintf (config.tmpfilename, "%s%s", tmpdir, fname);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
void
|
||||
mbox_write_message (message_t *msg, mbox_t *mbox)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
if (config.format == MBOX)
|
||||
fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body);
|
||||
#ifdef HAVE_LIBZ
|
||||
else if (config.format == ZMBOX)
|
||||
{
|
||||
gzwrite_loop (mbox->fp, msg->headers);
|
||||
gzwrite(mbox->fp, "\n", 1);
|
||||
gzwrite_loop (mbox->fp, msg->body);
|
||||
}
|
||||
#endif /* HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBBZ2
|
||||
else if (config.format == BZ2MBOX)
|
||||
{
|
||||
bzwrite_loop (mbox->fp, msg->headers);
|
||||
BZ2_bzwrite (mbox->fp, "\n", 1);
|
||||
bzwrite_loop (mbox->fp, msg->body);
|
||||
}
|
||||
#endif /* HAVE_LIBBZ2 */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void
|
||||
tmpfile_mod_own (const int fd, const char *path)
|
||||
/* {{{ */
|
||||
{
|
||||
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
|
||||
* so rename() will thus retain the original's ownership & permissions.
|
||||
*/
|
||||
if (geteuid () == 0)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
if (stat (path, &s) != -1)
|
||||
{
|
||||
if (fchown (fd, s.st_uid, s.st_gid) == -1)
|
||||
if (config.merr) perror (config.tmpfilename);
|
||||
if (fchmod (fd, s.st_mode) == -1)
|
||||
if (config.merr) perror (config.tmpfilename);
|
||||
}
|
||||
else if (config.merr) perror (path);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
int
|
||||
tmpfile_create (void)
|
||||
/* {{{ */
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = mkstemp (config.tmpfilename);
|
||||
if (-1 == fd)
|
||||
{
|
||||
if (config.merr)
|
||||
{
|
||||
fprintf (stderr, "%s: %s: ", APPNAME, tmpfilename);
|
||||
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
|
||||
perror (NULL);
|
||||
}
|
||||
exit (2);
|
||||
}
|
||||
|
||||
if (config.format == MBOX)
|
||||
return (m_fdopen (foo, "w"));
|
||||
#ifdef HAVE_LIBZ
|
||||
else if (config.format == ZMBOX)
|
||||
return (m_gzdopen (foo, "wb"));
|
||||
#endif /* HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBBZ2
|
||||
else if (config.format == BZ2MBOX)
|
||||
return (BZ2_bzdopen (foo, "wb"));
|
||||
#endif /* HAVE_LIBZ */
|
||||
|
||||
return NULL; /* not reached */
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
14
src/mbox.h
14
src/mbox.h
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: mbox.h,v 1.9 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||
$Id: mbox.h,v 1.13 2006-10-22 23:34:49 dspiljar Exp $ */
|
||||
|
||||
#ifndef MBOX_H
|
||||
#define MBOX_H 1
|
||||
@ -34,8 +34,14 @@ typedef struct
|
||||
|
||||
|
||||
mbox_t *mbox_open (const char *path, const char *mode);
|
||||
void *tmpfile_open (const char *path);
|
||||
void tmpmbox_create (const char *path);
|
||||
void tmpfile_name (const char *path);
|
||||
void tmpfile_mod_own (const int fd, const char *path);
|
||||
int tmpfile_create (void);
|
||||
void mbox_close (mbox_t * mbp);
|
||||
message_t *mbox_read_message (mbox_t * mbp);
|
||||
/* FIXME -- it doesn't compile with this portion uncommented
|
||||
message_t *mbox_read_message (mbox_t * mp);
|
||||
void mbox_write_message (message_t *m, mbox_t *mbox);
|
||||
*/
|
||||
|
||||
#endif /* MBOX_H */
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,14 +16,14 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: mboxgrep.h,v 1.21 2003/04/06 21:01:49 dspiljar Exp $ */
|
||||
$Id: mboxgrep.h,v 1.31 2006-10-22 23:34:49 dspiljar Exp $ */
|
||||
|
||||
#ifndef MBOXGREP_H
|
||||
#define MBOXGREP_H
|
||||
|
||||
#define APPNAME "mboxgrep"
|
||||
#define VERSION "0.7.9"
|
||||
#define BUGREPORT_ADDR "dspiljar@world.std.com"
|
||||
#define VERSION "0.7.10"
|
||||
#define BUGREPORT_ADDR "dspiljar@panix.com"
|
||||
|
||||
#define HOST_NAME_SIZE 256
|
||||
|
||||
@ -45,6 +45,7 @@
|
||||
# endif /* HAVE_NDIR_H */
|
||||
#endif /* HAVE_DIRENT_H */
|
||||
|
||||
#include "mbox.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -120,15 +121,30 @@ typedef struct
|
||||
int ignorecase;
|
||||
int merr;
|
||||
int pid;
|
||||
int haveregex;
|
||||
|
||||
char hostname[HOST_NAME_SIZE];
|
||||
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
|
||||
|
||||
void *pcre_pattern, *pcre_hints, *posix_pattern;
|
||||
int res1, res2;
|
||||
|
||||
action_t action;
|
||||
format_t format;
|
||||
lockmethod_t lock;
|
||||
}
|
||||
option_t;
|
||||
option_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int count;
|
||||
int maildir_count;
|
||||
checksum_t *cs;
|
||||
mbox_t *tmp_mbox;
|
||||
}
|
||||
runtime_t;
|
||||
|
||||
option_t config;
|
||||
runtime_t runtime;
|
||||
|
||||
#endif /* MBOXGREP_H */
|
||||
|
25
src/mh.c
25
src/mh.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: mh.c,v 1.15 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: mh.c,v 1.18 2006-02-20 17:12:22 dspiljar Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -80,24 +80,14 @@ void mh_close (DIR *dp)
|
||||
message_t *mh_read_message (DIR *dp)
|
||||
{
|
||||
int isheaders = 1;
|
||||
int have_from = 0, have_return_path = 0,
|
||||
have_date = 0, have_sender = 0;
|
||||
int have_from = 0, have_date = 0, have_sender = 0;
|
||||
static int s;
|
||||
message_t *message;
|
||||
struct dirent *d_content;
|
||||
char buffer[BUFSIZ], *filename;
|
||||
FILE *fp;
|
||||
extern char *boxname;
|
||||
|
||||
message = (message_t *) xmalloc (sizeof (message_t));
|
||||
|
||||
message->headers = NULL;
|
||||
message->hbytes = 0;
|
||||
|
||||
message->body = NULL;
|
||||
message->bbytes = 0;
|
||||
|
||||
message->from = NULL;
|
||||
message = malloc_message ();
|
||||
|
||||
filename = NULL;
|
||||
|
||||
@ -110,7 +100,7 @@ message_t *mh_read_message (DIR *dp)
|
||||
|
||||
filename = (char *) xrealloc
|
||||
(filename, ((strlen (d_content->d_name)) +
|
||||
(strlen (boxname)) + 2));
|
||||
(strlen (config.boxname)) + 2));
|
||||
|
||||
/* message->headers = (char *) xrealloc (message->headers, 0); */
|
||||
/* message->hbytes = 0; */
|
||||
@ -118,7 +108,7 @@ message_t *mh_read_message (DIR *dp)
|
||||
/* message->bbytes = 0; */
|
||||
|
||||
filename[0] = '\0';
|
||||
sprintf (filename, "%s/%s", boxname, d_content->d_name);
|
||||
sprintf (filename, "%s/%s", config.boxname, d_content->d_name);
|
||||
fp = m_fopen (filename, "r");
|
||||
isheaders = 1;
|
||||
if (fp == NULL)
|
||||
@ -167,10 +157,7 @@ message_t *mh_read_message (DIR *dp)
|
||||
if (0 == strncasecmp ("Date: ", buffer, 6))
|
||||
have_date = 1;
|
||||
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
|
||||
{
|
||||
have_return_path = 1;
|
||||
message->from = parse_return_path (buffer);
|
||||
}
|
||||
|
||||
message->headers =
|
||||
(char *) realloc (message->headers,
|
||||
|
2
src/mh.h
2
src/mh.h
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: mh.h,v 1.6 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: mh.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
|
||||
|
||||
#ifndef MH_H
|
||||
#define MH_H 1
|
||||
|
168
src/misc.c
168
src/misc.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: misc.c,v 1.13 2003/04/06 21:01:49 dspiljar Exp $ */
|
||||
$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 _BSD_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
|
||||
@ -32,6 +32,7 @@
|
||||
|
||||
#include "mboxgrep.h"
|
||||
#include "wrap.h"
|
||||
#include "getopt.h"
|
||||
|
||||
format_t
|
||||
folder_format (const char *name)
|
||||
@ -135,3 +136,166 @@ char * parse_return_path(char *rpath)
|
||||
return blah1;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void * malloc_message (void)
|
||||
{
|
||||
message_t *message;
|
||||
|
||||
message = (message_t *) xmalloc (sizeof (message_t));
|
||||
|
||||
message->headers = (char *) xmalloc (sizeof (char));
|
||||
message->headers[0] = '\0';
|
||||
message->hbytes = 0;
|
||||
|
||||
message->body = (char *) xmalloc (sizeof (char));
|
||||
message->body[0] = '\0';
|
||||
message->bbytes = 0;
|
||||
|
||||
message->from = NULL;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void postmark_print (message_t *msg)
|
||||
{
|
||||
time_t tt;
|
||||
struct tm *ct;
|
||||
char date_str[80];
|
||||
|
||||
tt = time (NULL);
|
||||
ct = localtime (&tt);
|
||||
strftime (date_str, 80, "%a %b %d %H:%M:%S %Y", ct);
|
||||
if (msg->from)
|
||||
fprintf (stdout, "From %s %s\n", msg->from, date_str);
|
||||
else
|
||||
fprintf (stdout, "From nobody %s\n", date_str);
|
||||
}
|
||||
|
||||
void
|
||||
set_default_options (void)
|
||||
{
|
||||
config.perl = 0;
|
||||
config.extended = 1;
|
||||
config.invert = 0;
|
||||
config.headers = 0;
|
||||
config.body = 0;
|
||||
config.action = DISPLAY;
|
||||
config.dedup = 0;
|
||||
config.recursive = 0;
|
||||
config.ignorecase = 0;
|
||||
config.format = MBOX; /* default mailbox format */
|
||||
config.lock = FCNTL; /* default file locking method */
|
||||
config.merr = 1; /* report errors by default */
|
||||
}
|
||||
|
||||
void
|
||||
get_runtime_options (int *argc, char **argv, struct option *long_options)
|
||||
{
|
||||
int option_index = 0, c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt_long (*argc, argv, "BcdEe:GHhil:m:n:o:Pp:rsVv", long_options,
|
||||
&option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
/* {{{ */
|
||||
|
||||
{
|
||||
case '?':
|
||||
usage();
|
||||
case 'c':
|
||||
config.action = COUNT;
|
||||
break;
|
||||
case 'd':
|
||||
config.action = DELETE;
|
||||
break;
|
||||
case 'e':
|
||||
config.regex_s = xstrdup (optarg);
|
||||
config.haveregex = 1;
|
||||
break;
|
||||
case 'o':
|
||||
config.outboxname = xstrdup (optarg);
|
||||
config.action = WRITE;
|
||||
break;
|
||||
case 'E':
|
||||
config.extended = 1;
|
||||
break;
|
||||
case 'G':
|
||||
config.extended = 0;
|
||||
break;
|
||||
case 'P':
|
||||
#ifdef HAVE_LIBPCRE
|
||||
config.extended = 0;
|
||||
config.perl = 1;
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"%s: Support for Perl regular expressions not "
|
||||
"compiled in\n");
|
||||
exit(2);
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
break;
|
||||
case 'h':
|
||||
help ();
|
||||
break;
|
||||
case 'i':
|
||||
config.ignorecase = 1;
|
||||
break;
|
||||
case 'm':
|
||||
config.format = folder_format (optarg);
|
||||
break;
|
||||
case 'l':
|
||||
config.lock = lock_method (optarg);
|
||||
break;
|
||||
case 'p':
|
||||
config.action = PIPE;
|
||||
config.pipecmd = xstrdup (optarg);
|
||||
break;
|
||||
case 'V':
|
||||
version ();
|
||||
break;
|
||||
case 'v':
|
||||
config.invert = 1;
|
||||
break;
|
||||
case 'H':
|
||||
config.headers = 1;
|
||||
break;
|
||||
case 'B':
|
||||
config.body = 1;
|
||||
break;
|
||||
case 's':
|
||||
config.merr = 0;
|
||||
break;
|
||||
case 201:
|
||||
config.lock = 0;
|
||||
break;
|
||||
case 'r':
|
||||
config.recursive = 1;
|
||||
break;
|
||||
case 200:
|
||||
config.dedup = 1;
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
switch (optarg[0])
|
||||
{
|
||||
case 'd':
|
||||
config.dedup = 1;
|
||||
break;
|
||||
case 'l':
|
||||
config.lock = 0;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: invalid option -- n%c\n",
|
||||
APPNAME, optarg[0]);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
/* }}} */
|
||||
} /* while */
|
||||
}
|
||||
|
13
src/misc.h
13
src/misc.h
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,17 +16,22 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: misc.h,v 1.5 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: misc.h,v 1.9 2006-07-06 10:53:49 dspiljar Exp $ */
|
||||
|
||||
#ifndef MISC_H
|
||||
#define MISC_H 1
|
||||
|
||||
#include "mboxgrep.h"
|
||||
#include <time.h>
|
||||
#include "getopt.h"
|
||||
/* #include <time.h> */
|
||||
|
||||
format_t folder_format (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);
|
||||
void * malloc_message (void);
|
||||
void postmark_print (message_t *msg);
|
||||
void set_default_options (void);
|
||||
void get_runtime_options (int *argc, char **argv, struct option *long_options);
|
||||
|
||||
#endif /* MISC_H */
|
||||
|
108
src/re.c
Executable file
108
src/re.c
Executable file
@ -0,0 +1,108 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 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: re.c,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <regex.h>
|
||||
#ifdef HAVE_LIBPCRE
|
||||
#include <pcre.h>
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
#include "mboxgrep.h"
|
||||
|
||||
#ifdef HAVE_LIBPCRE
|
||||
void
|
||||
pcre_init (void)
|
||||
{
|
||||
int errptr;
|
||||
const char *error;
|
||||
|
||||
config.pcre_pattern =
|
||||
(pcre *) pcre_compile (config.regex_s,
|
||||
(config.ignorecase ? PCRE_CASELESS : 0),
|
||||
&error, &errptr, NULL);
|
||||
if (config.pcre_pattern == NULL)
|
||||
{
|
||||
if (config.merr)
|
||||
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
|
||||
error);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pcre_match (message_t *msg)
|
||||
{
|
||||
int of[BUFSIZ];
|
||||
|
||||
if (config.headers)
|
||||
config.res1 =
|
||||
pcre_exec ((pcre *) config.pcre_pattern,
|
||||
(pcre_extra *) config.pcre_hints,
|
||||
msg->headers,
|
||||
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
|
||||
if (config.body)
|
||||
config.res2 =
|
||||
pcre_exec ((pcre *) config.pcre_pattern,
|
||||
(pcre_extra *) config.pcre_hints,
|
||||
msg->body,
|
||||
(int) strlen (msg->body), 0, 0, of, BUFSIZ);
|
||||
|
||||
config.res1 = config.res1 ^ 1;
|
||||
config.res2 = config.res2 ^ 1;
|
||||
}
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
|
||||
void
|
||||
regex_init (void)
|
||||
{
|
||||
int flag1 = 0, flag2 = 0;
|
||||
int errcode = 0;
|
||||
char errbuf[BUFSIZ];
|
||||
|
||||
if (config.ignorecase)
|
||||
flag1 = REG_ICASE;
|
||||
if (config.extended)
|
||||
flag2 = REG_EXTENDED;
|
||||
|
||||
errcode = regcomp ((regex_t *) config.posix_pattern, config.regex_s,
|
||||
(flag1 | flag2 | REG_NEWLINE ));
|
||||
if (0 != errcode)
|
||||
{
|
||||
if (config.merr)
|
||||
{
|
||||
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
|
||||
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
|
||||
errbuf);
|
||||
}
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
regex_match (message_t *msg)
|
||||
{
|
||||
if (config.headers)
|
||||
config.res1 = regexec ((regex_t *) config.posix_pattern,
|
||||
msg->headers, 0, NULL, 0);
|
||||
if (config.body)
|
||||
config.res2 = regexec ((regex_t *) config.posix_pattern,
|
||||
msg->body, 0, NULL, 0);
|
||||
}
|
28
src/re.h
Executable file
28
src/re.h
Executable file
@ -0,0 +1,28 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 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: re.h,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
|
||||
|
||||
#include "mboxgrep.h"
|
||||
|
||||
#ifdef HAVE_LIBPCRE
|
||||
void pcre_init (void);
|
||||
void pcre_match (message_t *msg);
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
void regex_init (void);
|
||||
void regex_match (message_t *msg);
|
139
src/scan.c
139
src/scan.c
@ -1,6 +1,6 @@
|
||||
/* -*- C -*-
|
||||
mboxgrep - scan mailbox for messages matching a regular expression
|
||||
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar
|
||||
|
||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
@ -16,13 +16,12 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: scan.c,v 1.21 2003/04/06 21:01:49 dspiljar Exp $ */
|
||||
$Id: scan.c,v 1.32 2006-10-22 23:34:49 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <regex.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -46,20 +45,17 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_LIBZ
|
||||
# include <zlib.h>
|
||||
#define BUFLEN 16384
|
||||
#endif /* HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBPCRE
|
||||
# include <pcre.h>
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
|
||||
#include "mboxgrep.h"
|
||||
#include "scan.h"
|
||||
#include "mbox.h"
|
||||
#include "mh.h"
|
||||
#include "maildir.h"
|
||||
#include "wrap.h"
|
||||
#include "md5.h"
|
||||
#include "misc.h"
|
||||
#include "re.h"
|
||||
#ifdef HAVE_FTS_OPEN
|
||||
# include <sys/stat.h>
|
||||
# include <fts.h>
|
||||
@ -77,46 +73,30 @@ void scan_mailbox (char path[])
|
||||
/* {{{ */
|
||||
{
|
||||
static FILE *outf;
|
||||
extern FILE *tmpp;
|
||||
static mbox_t *mbox, *out;
|
||||
#ifdef HAVE_LIBPCRE
|
||||
extern pcre *pcre_pattern;
|
||||
extern pcre_extra *hints;
|
||||
int of[BUFSIZ];
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
static DIR *boxd, *foo;
|
||||
static maildir_t *maildird;
|
||||
static message_t *msg;
|
||||
extern regex_t posix_pattern;
|
||||
extern char *pipecmd, *outboxname;
|
||||
extern int count;
|
||||
int delete = 0;
|
||||
char date_str[80];
|
||||
int isdup = 0;
|
||||
time_t tt;
|
||||
struct tm *ct;
|
||||
extern checksum_t *cs;
|
||||
|
||||
extern option_t config;
|
||||
|
||||
|
||||
if (config.format == MAILDIR && config.action == WRITE)
|
||||
{
|
||||
foo = opendir (outboxname); /* do NOT change this to m_opendir! */
|
||||
foo = opendir (config.outboxname); /* do NOT change this to m_opendir! */
|
||||
if (foo == NULL && errno == ENOENT)
|
||||
maildir_create (outboxname);
|
||||
maildir_create (config.outboxname);
|
||||
else closedir (foo);
|
||||
|
||||
if (-1 == maildir_check (outboxname))
|
||||
if (-1 == maildir_check (config.outboxname))
|
||||
{
|
||||
if (config.merr)
|
||||
fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME,
|
||||
outboxname);
|
||||
config.outboxname);
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
count = 0;
|
||||
runtime.count = 0;
|
||||
if (config.action == DELETE)
|
||||
delete = 1;
|
||||
|
||||
@ -140,7 +120,8 @@ void scan_mailbox (char path[])
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int res1 = 1, res2 = 1;
|
||||
config.res1 = 1;
|
||||
config.res2 = 1;
|
||||
|
||||
if ((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||
(config.format == BZ2MBOX))
|
||||
@ -157,30 +138,16 @@ void scan_mailbox (char path[])
|
||||
|
||||
#ifdef HAVE_LIBPCRE
|
||||
if (config.perl)
|
||||
{
|
||||
if (config.headers)
|
||||
res1 = pcre_exec (pcre_pattern, hints, msg->headers,
|
||||
(int) strlen (msg->headers), 0, 0, of, BUFSIZ);
|
||||
if (config.body)
|
||||
res2 = pcre_exec (pcre_pattern, hints, msg->body,
|
||||
(int) strlen (msg->body), 0, 0, of, BUFSIZ);
|
||||
|
||||
res1 = res1 ^ 1;
|
||||
res2 = res2 ^ 1;
|
||||
}
|
||||
pcre_match (msg);
|
||||
else
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
{
|
||||
if (config.headers)
|
||||
res1 = regexec (&posix_pattern, msg->headers, 0, NULL, 0);
|
||||
if (config.body)
|
||||
res2 = regexec (&posix_pattern, msg->body, 0, NULL, 0);
|
||||
}
|
||||
regex_match (msg);
|
||||
|
||||
if (config.dedup)
|
||||
isdup = md5_check_message (msg->body, cs);
|
||||
isdup = md5_check_message (msg->body, runtime.cs);
|
||||
|
||||
if (((res1 == 0) | (res2 == 0)) ^ ((config.invert ^ delete)) &&
|
||||
if (((config.res1 == 0) | (config.res2 == 0)) ^
|
||||
((config.invert ^ delete)) &&
|
||||
((config.dedup && !isdup) || !config.dedup))
|
||||
{
|
||||
if (config.action == DISPLAY)
|
||||
@ -188,39 +155,33 @@ void scan_mailbox (char path[])
|
||||
if (config.format != MBOX && config.format != ZMBOX
|
||||
&& config.format != BZ2MBOX
|
||||
&& 0 != strncmp ("From ", msg->headers, 5))
|
||||
{
|
||||
tt = time (NULL);
|
||||
ct = localtime (&tt);
|
||||
strftime (date_str, 80, "%a %b %d %H:%M:%S %Y", ct);
|
||||
if (msg->from)
|
||||
fprintf (stdout, "From %s %s\n", msg->from, date_str);
|
||||
else
|
||||
fprintf (stdout, "From nobody %s\n", date_str);
|
||||
}
|
||||
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, outboxname);
|
||||
maildir_write_message (msg, config.outboxname);
|
||||
else if (config.format == MH || config.format == NNMH ||
|
||||
config.format == NNML)
|
||||
mh_write_message (msg, outboxname);
|
||||
else if (config.format == MBOX)
|
||||
mh_write_message (msg, config.outboxname);
|
||||
else if ((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||
(config.format == BZ2MBOX))
|
||||
{
|
||||
out = mbox_open (outboxname, "w");
|
||||
fprintf (out->fp, "%s\n%s", msg->headers, msg->body);
|
||||
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 (pipecmd, "w");
|
||||
outf = popen (config.pipecmd, "w");
|
||||
if (outf == NULL)
|
||||
{
|
||||
if (config.merr)
|
||||
{
|
||||
fprintf (stderr, "%s: %s: ", APPNAME, pipecmd);
|
||||
fprintf (stderr, "%s: %s: ", APPNAME, config.pipecmd);
|
||||
perror (NULL);
|
||||
}
|
||||
exit (2);
|
||||
@ -229,41 +190,15 @@ void scan_mailbox (char path[])
|
||||
pclose (outf);
|
||||
}
|
||||
else if (config.action == COUNT)
|
||||
++count;
|
||||
else if (config.action == DELETE && config.format == MBOX)
|
||||
fprintf (tmpp, "%s\n%s", msg->headers, msg->body);
|
||||
#ifdef HAVE_LIBZ
|
||||
else if (config.action == DELETE && config.format == ZMBOX)
|
||||
{
|
||||
int quux, len, baz;
|
||||
runtime.count++;
|
||||
else if (config.action == DELETE &&
|
||||
((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||
(config.format == BZ2MBOX)))
|
||||
mbox_write_message (msg, runtime.tmp_mbox);
|
||||
}
|
||||
|
||||
quux = 0;
|
||||
baz = strlen (msg->headers);
|
||||
for (;;)
|
||||
{
|
||||
len = gzwrite (tmpp, (msg->headers+quux),
|
||||
(((quux + BUFLEN) < baz) ? BUFLEN :
|
||||
(baz - quux)));
|
||||
quux += len;
|
||||
if (quux == baz)
|
||||
break;
|
||||
}
|
||||
gzwrite(tmpp, "\n", 1);
|
||||
quux = 0;
|
||||
baz = strlen(msg->body);
|
||||
for (;;)
|
||||
{
|
||||
len = gzwrite(tmpp, (msg->body+quux),
|
||||
(((quux + BUFLEN) < baz) ? BUFLEN :
|
||||
(baz - quux)));
|
||||
quux += len;
|
||||
if (quux == baz)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_LIBZ */
|
||||
} /* if */
|
||||
else if (((((res1 == 0) | (res2 == 0)) ^ config.invert) && delete) &&
|
||||
else if (((((config.res1 == 0) | (config.res2 == 0)) ^
|
||||
config.invert) && delete) &&
|
||||
((config.format == MH) || (config.format == NNMH) ||
|
||||
(config.format == NNML) || (config.format == MAILDIR)))
|
||||
m_unlink(msg->filename);
|
||||
@ -322,7 +257,7 @@ int md5_check_message (char *body, checksum_t *chksum)
|
||||
/* {{{ */
|
||||
{
|
||||
struct md5_ctx a;
|
||||
unsigned char b[16];
|
||||
char b[16];
|
||||
int i;
|
||||
|
||||
md5_init_ctx (&a);
|
||||
@ -334,7 +269,7 @@ int md5_check_message (char *body, checksum_t *chksum)
|
||||
|
||||
for (i = 0; i < chksum->n; i++)
|
||||
{
|
||||
if (0 == strncmp (chksum->md5[i], b, 16))
|
||||
if (0 == strncmp ((char *)chksum->md5[i], b, 16))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: scan.h,v 1.7 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||
$Id: scan.h,v 1.7 2003-03-30 23:07:10 dspiljar Exp $ */
|
||||
|
||||
#ifndef SCAN_H
|
||||
#define SCAN_H 1
|
||||
|
43
src/wrap.c
43
src/wrap.c
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: wrap.c,v 1.12 2003/04/06 23:24:04 dspiljar Exp $ */
|
||||
$Id: wrap.c,v 1.13 2006-01-20 03:00:39 dspiljar Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <unistd.h>
|
||||
@ -55,6 +55,8 @@
|
||||
#define APPNAME "mboxgrep"
|
||||
#endif
|
||||
|
||||
#define BUFLEN 16384
|
||||
|
||||
int m_open (const char *pathname, int flags, mode_t mode)
|
||||
{
|
||||
int blah;
|
||||
@ -214,3 +216,42 @@ int m_unlink (const char *pathname)
|
||||
return baz;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
|
||||
void gzwrite_loop (void *fp, char *str)
|
||||
{
|
||||
int quux, len, baz;
|
||||
|
||||
quux = 0;
|
||||
baz = strlen (str);
|
||||
for (;;)
|
||||
{
|
||||
len = gzwrite (fp, (str+quux),
|
||||
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
|
||||
quux += len;
|
||||
if (quux == baz)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
|
||||
#ifdef HAVE_LIBBZ2
|
||||
|
||||
void bzwrite_loop (void *fp, char *str)
|
||||
{
|
||||
int quux, len, baz;
|
||||
|
||||
quux = 0;
|
||||
baz = strlen (str);
|
||||
for (;;)
|
||||
{
|
||||
len = BZ2_bzwrite (fp, (str+quux),
|
||||
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
|
||||
quux += len;
|
||||
if (quux == baz)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBBZ2 */
|
||||
|
@ -16,7 +16,7 @@
|
||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: wrap.h,v 1.11 2003/04/06 23:24:04 dspiljar Exp $ */
|
||||
$Id: wrap.h,v 1.12 2006-01-20 03:00:39 dspiljar Exp $ */
|
||||
|
||||
/* This file is part of mboxgrep. */
|
||||
|
||||
@ -58,7 +58,11 @@ FILE *m_fopen (const char *path, const char *mode);
|
||||
FILE *m_fdopen (int fildes, const char *mode);
|
||||
#ifdef HAVE_LIBZ
|
||||
gzFile *m_gzdopen (int fildes, const char *mode);
|
||||
void gzwrite_loop (void *fp, char *str);
|
||||
#endif /* HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBBZ2
|
||||
void bzwrite_loop (void *fp, char *str);
|
||||
#endif /* HAVE_LIBBZ2 */
|
||||
|
||||
DIR *m_opendir (const char *name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user