Initial import into the new git repository. Back from the dead!
This commit is contained in:
commit
bd80cfbb4d
2
AUTHORS
Normal file
2
AUTHORS
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
$Id: AUTHORS,v 1.2 2002/01/28 23:43:34 dspiljar Exp $
|
341
COPYING
Normal file
341
COPYING
Normal file
@ -0,0 +1,341 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) 19yy <name of author>
|
||||||
|
|
||||||
|
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; see the file COPYING. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Library General
|
||||||
|
Public License instead of this License.
|
254
ChangeLog
Normal file
254
ChangeLog
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
Sun Aug 24 21:49:52 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* doc/mboxgrep.1, doc/mboxgrep.texi:
|
||||||
|
small updates
|
||||||
|
|
||||||
|
Sat Aug 23 20:56:39 CEST 2003 James P. Dugal <jpd@louisiana.edu>
|
||||||
|
|
||||||
|
* src/main.c, src/mbox.h, src/mbox.c
|
||||||
|
If we are to use rename() to move a temp file (resulting from
|
||||||
|
deletions done in a mailbox) back over the original mailbox, we
|
||||||
|
must be sure the temp file is on the same file system. Also,
|
||||||
|
we should try to preserve the same ownership and permissions.
|
||||||
|
|
||||||
|
Mon Aug 11 00:39:14 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
look for pcre-config(1) script; this effectively fixes a
|
||||||
|
compilation bug on recent RedHat Linux systems
|
||||||
|
|
||||||
|
Sun Apr 13 21:16:25 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* src/info.c, src/info.h:
|
||||||
|
print_wrap(); list of compile-time options is now printed wrapped
|
||||||
|
|
||||||
|
Mon Apr 7 01:24:20 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* src/mbox.c, src/wrap.c, src/wrap.h:
|
||||||
|
m_gzdopen()
|
||||||
|
|
||||||
|
Sun Apr 6 23:04:19 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* src/mbox.c, src/mbox.h, src/mboxgrep.h, src/misc.c, src/scan.c:
|
||||||
|
support for bzip2 compressed mailboxes
|
||||||
|
|
||||||
|
Fri Apr 4 00:14:01 CEST 2003 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
check for libbz2
|
||||||
|
|
||||||
|
Sun Oct 27 23:57:31 CET 2002 Daniel Spiljar <dspiljar@world.std.com>
|
||||||
|
|
||||||
|
* src/mbox.c:
|
||||||
|
mbox_open() should now complain if called with an unknown argument
|
||||||
|
mode. Shouldn't normally happen, but...
|
||||||
|
|
||||||
|
Sun Aug 25 22:43:38 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/mbox.c, src/mbox.h, src/scan.c:
|
||||||
|
removed the gzmbox* functions in order to avoid code duplication;
|
||||||
|
as a side effect, mboxgrep can now read compressed mbox folders
|
||||||
|
from standard input
|
||||||
|
|
||||||
|
Sun Aug 11 01:36:02 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
AC_HEADER_STDC, which fixed another compiler warning
|
||||||
|
|
||||||
|
Sat Aug 10 22:03:31 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/mbox.c, src/mh.c, src/scan.c, src/misc.c, src/maildir.c, src/mboxgrep.h:
|
||||||
|
made various code cleanups: got rid of a couple of global variables,
|
||||||
|
fixed compiler warnings and things like that
|
||||||
|
|
||||||
|
Sat Aug 10 00:35:21 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mh.h, src/wrap.h, src/mboxgrep.h:
|
||||||
|
removed some unnecessary #defines that have been causing compiler
|
||||||
|
errors
|
||||||
|
|
||||||
|
Sun Aug 4 20:11:29 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/scan.c, src/scan.h:
|
||||||
|
code clean up: moved recursive scan code from main()
|
||||||
|
to recursive_scan()
|
||||||
|
|
||||||
|
Wed Jul 24 00:20:59 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/maildir.c:
|
||||||
|
same thing with maildir as with MH below
|
||||||
|
|
||||||
|
Sat Jul 6 22:51:45 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mh.c:
|
||||||
|
MH module doesn't read files which aren't RFC 2822 messages anymore
|
||||||
|
|
||||||
|
Sat Jun 29 01:43:36 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* configure.in, src/maildir.c, src/main.c, src/mbox.c, src/mh.c, src/scan.c:
|
||||||
|
added debugging with dmalloc library
|
||||||
|
|
||||||
|
Sat Jun 29 01:39:21 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mbox.c, src/maildir.c:
|
||||||
|
fixed potential problem as with MH folders (below)
|
||||||
|
|
||||||
|
Sat Jun 29 01:28:30 CEST 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mh.c, src/scan.c:
|
||||||
|
(hopefully) fixed crashes on MH folders
|
||||||
|
|
||||||
|
Sat Feb 23 22:22:12 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mbox.c, src/maildir.c, src/mh.c, src/misc.c:
|
||||||
|
removed useless code that required strptime ()
|
||||||
|
|
||||||
|
Sat Feb 23 15:43:05 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/mbox.h, src/mbox.c, src/scan.c:
|
||||||
|
mboxgrep can now read mbox folders from standard input
|
||||||
|
|
||||||
|
Fri Feb 8 02:15:36 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c:
|
||||||
|
fixed a bug which prevented mboxgrep from being compiled;
|
||||||
|
this happened because I've put some assignments *before*
|
||||||
|
declarations
|
||||||
|
|
||||||
|
Wed Feb 6 23:11:50 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/maildir.c, src/main.c, src/mbox.c, src/mboxgrep.h, src/mh.c, src/mh.h, src/misc.c, src/scan.c, src/wrap.c
|
||||||
|
code cleanups; many global variables have been replaced with
|
||||||
|
a single option_t structure
|
||||||
|
|
||||||
|
Fri Feb 1 00:31:05 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/maildir.c:
|
||||||
|
fixed a bug which occured on recursive search of maildirs
|
||||||
|
|
||||||
|
Wed Jan 2 00:32:37 CET 2002 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/misc.c, src/wrap.h:
|
||||||
|
applied a patch (kindly submitted by John R. Daily
|
||||||
|
<jdaily@progeny.com>), which fixes missing prototypes that might
|
||||||
|
cause mboxgrep to coredump on IA64 platform
|
||||||
|
|
||||||
|
Sat Dec 15 20:12:40 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/scan.c, src/scan.h:
|
||||||
|
recursive search through directories has been reimplemented
|
||||||
|
|
||||||
|
Sat Dec 8 22:13:54 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/main.c, src/maildir.c:
|
||||||
|
replaced remaining occurences of malloc() with xmalloc()
|
||||||
|
|
||||||
|
Sat Dec 8 21:21:58 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/maildir.c, src/main.c, src/mbox.c, src/mh.c, src/misc.c, src/scan.c, src/wrap.c, src/wrap.h:
|
||||||
|
wrote xstrdup(), an error-checking wrapper around strdup() and
|
||||||
|
replaced all occurences of strdup() with xstrdup()
|
||||||
|
|
||||||
|
Sun Dec 2 18:05:57 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/Makefile.in, src/info.c, src/main.c, src/mboxgrep.h, src/md5.c, src/md5.h, src/scan.c, src/scan.h, doc/mboxgrep.texi:
|
||||||
|
mboxgrep can now ignore duplicate messages, thanks to the MD5
|
||||||
|
algorithm
|
||||||
|
|
||||||
|
* src/maildir.c, src/main.c, src/scan.c, src/wrap.c, src/wrap.h:
|
||||||
|
wrote xcalloc() and renamed m_realloc() to xrealloc()
|
||||||
|
|
||||||
|
Sat Nov 17 22:57:57 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mbox.c, src/mh.c, src/maildir.c
|
||||||
|
message->headers and message->body pointers are now initially malloc'd
|
||||||
|
to size of one character in order to prevent NULL pointers from being
|
||||||
|
passed to regexec()
|
||||||
|
|
||||||
|
Wed Nov 7 22:47:34 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* configure.ac, src/mboxgrep.h, src/main.c, src/misc.h, src/misc.c, src/info.c, src/config.h, src/mbox.c:
|
||||||
|
file locking method can now be selected at run time
|
||||||
|
|
||||||
|
* src/info.c, src/maildir.c, src/main.c, src/mbox.h, src/misc.c, src/scan.c, src/Makefile.in
|
||||||
|
changed `#include "config.h"' to `#include <config.h>', and fixed
|
||||||
|
other bugs with #including
|
||||||
|
|
||||||
|
Sat Nov 3 16:08:22 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* configure.ac, src/config.h.in, src/info.c, src/mbox.c
|
||||||
|
files can be locked with flock() instead of fcntl(), if
|
||||||
|
enabled at compile time
|
||||||
|
|
||||||
|
Sun Oct 28 19:01:44 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/Makefile.in:
|
||||||
|
forgot to mention getopt.c and getopt1.c
|
||||||
|
|
||||||
|
Sun Oct 28 16:06:28 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/mh.c, src/main.c, src/scan.c:
|
||||||
|
#included certain neccessary files
|
||||||
|
|
||||||
|
Sun Oct 28 14:43:21 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/maildir.c, src/maildir.h, src/scan.c:
|
||||||
|
wrote functions maildir_check and maildir_create;
|
||||||
|
if the target maildir doesn't exist, mboxgrep creates one;
|
||||||
|
if it does exist, mboxgrep checks its consistency and refuses to
|
||||||
|
write to it unless `tmp', `new' and `cur' subdirectories exist
|
||||||
|
|
||||||
|
Sun Oct 28 13:02:10 CET 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/info.c, doc/mboxgrep.texi, doc/mboxgrep.1
|
||||||
|
the "--regexp" command was implemented in version 0.7.0, but I
|
||||||
|
forgot to document it
|
||||||
|
|
||||||
|
Sat Oct 27 21:48:36 CEST 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/scan.c:
|
||||||
|
if the input is a non-mbox folder, a proper postmark line (with
|
||||||
|
date) is put on top of each message written to stdout
|
||||||
|
|
||||||
|
Mon Oct 8 22:53:34 CEST 2001 Daniel Spiljar <dspiljar@bofhlet.net>
|
||||||
|
|
||||||
|
* src/*:
|
||||||
|
source code now completely rewritten
|
||||||
|
|
||||||
|
Sun May 27 00:19:52 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* doc/mboxgrep.1:
|
||||||
|
updated the manual page -- it now refers to RFC 2822, instead
|
||||||
|
of the obsoleted 822
|
||||||
|
|
||||||
|
Tue May 1 15:06:03 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* configure.in, doc/Makefile.in, src/Makefile.in, Makefile.in:
|
||||||
|
moved manpage to the `doc' subdirectory; changed files above
|
||||||
|
accordingly
|
||||||
|
|
||||||
|
Sun Apr 15 23:00:08 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* src/mboxgrep.h, src/main.c, src/file.c, src/scan.c, src/info.c:
|
||||||
|
added support for writing messages to another mail folder
|
||||||
|
|
||||||
|
Mon Apr 9 21:55:15 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* src/file.c, src/scan.c: all calls of malloc() are now checked
|
||||||
|
and mboxgrep exits with code 2 if it fails to allocate memory
|
||||||
|
|
||||||
|
Sun Apr 8 19:40:33 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* src/mboxgrep.h, src/main.c: wrote mboxgrep_stat()
|
||||||
|
|
||||||
|
Sun Apr 8 16:58:36 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* src/mboxgrep.h, src/main.c: wrote mboxgrep_error()
|
||||||
|
|
||||||
|
Tue Mar 27 01:26:22 CEST 2001 Daniel Spiljar <dspiljar@public.srce.hr>
|
||||||
|
|
||||||
|
* configure.in: check for gethostname()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$Id: ChangeLog,v 1.37 2003/08/24 19:51:12 dspiljar Exp $
|
37
Makefile.in
Normal file
37
Makefile.in
Normal 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:
|
106
NEWS
Normal file
106
NEWS
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
Changes of mboxgrep
|
||||||
|
===================
|
||||||
|
|
||||||
|
Changes since 0.7.8
|
||||||
|
- implemented support for mbox folders compressed with bzip2 algorithm
|
||||||
|
- improved detection of PCRE library; this also fixes a compilation bug
|
||||||
|
on recent RedHat Linux systems
|
||||||
|
- fixed a problem with message deletion, which used to occur if an mbox
|
||||||
|
folder and temporary directory were on different filesystems;
|
||||||
|
thanks to James P. Dugal <jpd@louisiana.edu> for providing a patch
|
||||||
|
|
||||||
|
Changes since 0.7.7
|
||||||
|
- fixed crashes on MH folders, as well as a potential problem with mbox
|
||||||
|
and maildir folders with the same cause
|
||||||
|
- debugging with dmalloc library
|
||||||
|
- MH and maildir functions no longer read files which aren't RFC 2822 messages
|
||||||
|
- mboxgrep can now read gzip compressed mbox folders from standard input
|
||||||
|
(which is a side effect of a code cleanup!)
|
||||||
|
|
||||||
|
Changes since 0.7.6a
|
||||||
|
- mboxgrep can now read mbox folders from standard input
|
||||||
|
|
||||||
|
Changes since 0.7.6
|
||||||
|
- fixed a bug which prevented mboxgrep from being compiled
|
||||||
|
|
||||||
|
Changes since 0.7.5
|
||||||
|
- fixed a bug which caused mboxgrep to coredump on recursive search of
|
||||||
|
maildirs
|
||||||
|
- code cleanups
|
||||||
|
|
||||||
|
Changes since 0.7.4
|
||||||
|
- recursive search through directories has been reimplemented
|
||||||
|
|
||||||
|
Changes since 0.7.3
|
||||||
|
- mboxgrep can now ignore messages with identical bodies
|
||||||
|
|
||||||
|
Changes since 0.7.2
|
||||||
|
- file locking method can be selected at runtime
|
||||||
|
- mboxgrep used to coredump on messages with empty headers; the problem is
|
||||||
|
now hopefully fixed
|
||||||
|
- mboxgrep now compiles on FreeBSD
|
||||||
|
|
||||||
|
Changes since 0.7.1
|
||||||
|
- file locking with flock() instead of fcntl() is now supported
|
||||||
|
- mboxgrep should now compile on systems which don't have getopt_long()
|
||||||
|
- other minor bugfixes
|
||||||
|
|
||||||
|
Changes since 0.7.0
|
||||||
|
- bugfixes
|
||||||
|
|
||||||
|
Changes since 0.5.3
|
||||||
|
- NOTE: there was no stable version between 0.5.x and 0.7.x
|
||||||
|
- mboxgrep is almost completely rewritten
|
||||||
|
- implemented message deleting feature (--delete)
|
||||||
|
- implemented piping messages to a command (--pipe) (using this option,
|
||||||
|
each selected message is piped to a separate instance of the specified
|
||||||
|
command)
|
||||||
|
- added support for compressed mbox folders
|
||||||
|
|
||||||
|
Changes since 0.5.2
|
||||||
|
- implemented ability to write found messages to another folder (instead
|
||||||
|
of stdout)
|
||||||
|
- started writing *real* changelog (while this file has been renamed to
|
||||||
|
"NEWS")
|
||||||
|
- wrote a manual in Texinfo format
|
||||||
|
|
||||||
|
Changes since 0.5.1
|
||||||
|
- implemented message counting (-c, --count)
|
||||||
|
- fixed manual page installation target in src/Makefile.in -- manual page
|
||||||
|
is now installed in $(manpath)/man1/ rather than in $(prefix)/man/man1/
|
||||||
|
- added `--without-sense-of-humor' switch to the configure script, which
|
||||||
|
disables checking whether Garfield still hates Mondays
|
||||||
|
- short version of `--version' switch is now `-V' instead of `-v',
|
||||||
|
because `-v' will be used for inverted matching
|
||||||
|
- implemented inverted matching (-v, --invert-match)
|
||||||
|
- implemented recursive search through directories (-r, --recursive)
|
||||||
|
- config.h[.in] is now wrapped (#ifndef CONFIG_H and stuff)
|
||||||
|
|
||||||
|
Changes since 0.5.0
|
||||||
|
- added support for qmail-style maildir folders
|
||||||
|
|
||||||
|
Changes since 0.4.0
|
||||||
|
- source of getopt_long() is now included, so long options are also available
|
||||||
|
on platforms that don't use GNU libc
|
||||||
|
- file locking is now performed on mbox folders only
|
||||||
|
|
||||||
|
Changes since 0.2.0
|
||||||
|
- added support for MH mailboxes
|
||||||
|
- added scope selection switches `-B' (or `--body') and `-H' (or `--headers')
|
||||||
|
- getopt() (or getopt_long(), if available) is now used to parse command line
|
||||||
|
arguments, instead of my own lousy routine
|
||||||
|
- configure script now looks for PCRE by default, unless `--with-pcre=no' or
|
||||||
|
`--without-pcre' is specified
|
||||||
|
- the feature of reading from standard input is gone
|
||||||
|
- added `-v' (or `--version') switch
|
||||||
|
|
||||||
|
Changes since 0.1.1
|
||||||
|
- mboxgrep now puts a shared lock on a mailbox before reading it
|
||||||
|
- various code cleanups
|
||||||
|
|
||||||
|
Changes since 0.1.0
|
||||||
|
- fixed install target in Makefile (`install' is now used instead of `cp')
|
||||||
|
- added support for mailboxes generated by Gnus
|
||||||
|
|
||||||
|
|
||||||
|
$Id: NEWS,v 1.21 2003/08/24 19:23:48 dspiljar Exp $
|
19
README
Normal file
19
README
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
-*- text -*-
|
||||||
|
|
||||||
|
mboxgrep - displays e-mail messages matching a pattern
|
||||||
|
|
||||||
|
Full description of mboxgrep is contained in the documentation,
|
||||||
|
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
|
||||||
|
are welcome.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
For build instructions, read the file `INSTALL', and run
|
||||||
|
`./configure --help'
|
||||||
|
|
||||||
|
$Id: README,v 1.2 2002/12/02 20:53:07 dspiljar Exp $
|
26
TODO
Normal file
26
TODO
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
-*- text -*-
|
||||||
|
|
||||||
|
- ignore .overview when grepping Gnus folders [X]
|
||||||
|
- implement inverted matching [X]
|
||||||
|
- (re)implement recursive search through directories [X]
|
||||||
|
- implement literal date matching [ ]
|
||||||
|
- write Texinfo documentation [X]
|
||||||
|
- implement writing selected messages to a new folder [X]
|
||||||
|
- implement deleting selected messages [X]
|
||||||
|
- add support for config files [ ]
|
||||||
|
- add support for reading messages from stdin [X]
|
||||||
|
- add support for compressed mbox folders [X]
|
||||||
|
- make use of lockfile library [ ]
|
||||||
|
- make use of Solaris' maillock library [ ]
|
||||||
|
- provide possibility to use flock() instead of fcntl() [X]
|
||||||
|
- provide national language support with gettext() [ ]
|
||||||
|
- allow run-time selection of file locking method [X]
|
||||||
|
- make mboxgrep understand MIME [ ]
|
||||||
|
- enable removing duplicate messages w/ MD5 checksums [X]
|
||||||
|
- add checking for conflicting command-line options [ ]
|
||||||
|
- add support for GnuPG [ ]
|
||||||
|
- add support for bzip2 compression [X]
|
||||||
|
- add support for mail folder conversion [ ]
|
||||||
|
|
||||||
|
|
||||||
|
$Id: TODO,v 1.16 2003/04/06 21:48:23 dspiljar Exp $
|
98
configure.ac
Normal file
98
configure.ac
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
# mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
# Copyright (C) 2000, 2001, 2002, 2003 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: configure.ac,v 1.13 2003/08/10 22:45:45 dspiljar Exp $
|
||||||
|
|
||||||
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
|
# Yawn.
|
||||||
|
AC_INIT
|
||||||
|
AC_LANG(C)
|
||||||
|
AC_CONFIG_HEADER([src/config.h])
|
||||||
|
|
||||||
|
# Checks for programs.
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
|
||||||
|
# Checks for standard (sp?) header files
|
||||||
|
AC_HEADER_STDC
|
||||||
|
AC_HEADER_DIRENT
|
||||||
|
|
||||||
|
# Checks for libraries.
|
||||||
|
|
||||||
|
# Check for PCRE library
|
||||||
|
AC_ARG_WITH(pcre, [ --without-pcre Compile without Perl regexp support],,
|
||||||
|
[
|
||||||
|
AC_PATH_PROG(PCRE_CONFIG, pcre-config)
|
||||||
|
|
||||||
|
if test "$PCRE_CONFIG"; then
|
||||||
|
CFLAGS="$CFLAGS `$PCRE_CONFIG --cflags`"
|
||||||
|
LIBS="$LIBS `$PCRE_CONFIG --libs`"
|
||||||
|
|
||||||
|
AC_LINK_IFELSE(
|
||||||
|
[
|
||||||
|
#include <pcre.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
AC_DEFINE(HAVE_LIBPCRE),
|
||||||
|
[
|
||||||
|
AC_MSG_NOTICE(found pcre-config but could not compile test program.)
|
||||||
|
AC_MSG_FAILURE(is PCRE properly installed?)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else
|
||||||
|
AC_MSG_NOTICE(pcre-config not found)
|
||||||
|
AC_MSG_NOTICE(trying to find PCRE anyway)
|
||||||
|
AC_CHECK_LIB(pcre, main)
|
||||||
|
fi
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check for zlib
|
||||||
|
AC_ARG_WITH(z, [ --without-zlib Compile without suport for gzip compressed mailboxes],,
|
||||||
|
AC_CHECK_LIB(z, gzopen))
|
||||||
|
|
||||||
|
# Check for bzlib
|
||||||
|
AC_ARG_WITH(z, [ --without-bzlib Compile without suport for bzip2 compressed mailboxes],,
|
||||||
|
AC_CHECK_LIB(bz2, BZ2_bzopen))
|
||||||
|
|
||||||
|
# Check for dmalloc
|
||||||
|
AC_ARG_WITH(dmalloc, [ --with-dmalloc Compile with dmalloc library],
|
||||||
|
AC_CHECK_LIB(dmalloc, main))
|
||||||
|
|
||||||
|
# Check for our favorite sarcastic cat's sanity. 8)
|
||||||
|
AC_ARG_WITH(sense-of-humor, [ --without-sense-of-humor If you have no sense of humor],,
|
||||||
|
AC_CHECK_LIB(garfield, like_monday))
|
||||||
|
|
||||||
|
# AC_ARG_WITH(lockfile, [ --without-lockfile Blah],,
|
||||||
|
# AC_CHECK_LIB(lockfile, maillock))
|
||||||
|
|
||||||
|
AC_CHECK_FUNCS(fcntl)
|
||||||
|
AC_CHECK_FUNCS([flock])
|
||||||
|
AC_CHECK_FUNCS([regcomp])
|
||||||
|
AC_CHECK_FUNCS([strptime])
|
||||||
|
AC_CHECK_FUNCS(ftw)
|
||||||
|
AC_CHECK_FUNCS(fts_open)
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([Makefile
|
||||||
|
doc/Makefile
|
||||||
|
src/Makefile])
|
||||||
|
AC_OUTPUT
|
5
contrib/README
Normal file
5
contrib/README
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
This directory is intended to hold third-party contributions.
|
||||||
|
|
||||||
|
- mboxgrep.spec is an RPM spec file, kindly contributed by
|
||||||
|
Vaclav Slavik <v.slavik@volny.cz>
|
||||||
|
|
46
contrib/mboxgrep.spec
Normal file
46
contrib/mboxgrep.spec
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
Summary: Grep for mailboxes
|
||||||
|
Name: mboxgrep
|
||||||
|
Version: 0.5.3
|
||||||
|
Release: 1
|
||||||
|
Epoch: 1
|
||||||
|
License: GPL
|
||||||
|
Group: Applications/Internet
|
||||||
|
Source: http://public.srce.hr/~dspiljar/mboxgrep-%{version}.tar.gz
|
||||||
|
URL: http://public.srce.hr/~dspiljar/mboxgrep.html
|
||||||
|
BuildRoot: %{_tmppath}/%{name}-%{version}-root
|
||||||
|
|
||||||
|
%description
|
||||||
|
mboxgrep is a small utility that scans a mailbox for messages
|
||||||
|
matching a basic, extended, or Perl-compatible regular
|
||||||
|
expression. Found messages can be either displayed on
|
||||||
|
standard output, counted or written to another mailbox.
|
||||||
|
It supports mbox, MH, nnmh, nnml and maildir folders.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
|
||||||
|
%build
|
||||||
|
%configure
|
||||||
|
%make
|
||||||
|
|
||||||
|
%install
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
%makeinstall
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
|
%post
|
||||||
|
/sbin/install-info %{_infodir}/mboxgrep.info* %{_infodir}/dir
|
||||||
|
|
||||||
|
%preun
|
||||||
|
if [ $1 = 0 ]; then
|
||||||
|
/sbin/install-info --delete %{_infodir}/mboxgrep.info* %{_infodir}/dir
|
||||||
|
fi
|
||||||
|
|
||||||
|
%files
|
||||||
|
%defattr(-,root,root)
|
||||||
|
%doc COPYING INSTALL NEWS README
|
||||||
|
%{_bindir}/*
|
||||||
|
%{_infodir}/*
|
||||||
|
%{_mandir}/*/*
|
41
doc/Makefile.in
Normal file
41
doc/Makefile.in
Normal 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:
|
122
doc/mboxgrep.1
Normal file
122
doc/mboxgrep.1
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
.Id $Id: mboxgrep.1,v 1.15 2003/08/24 19:51:14 dspiljar Exp $
|
||||||
|
.TH MBOXGREP 1 "24 Aug 2003"
|
||||||
|
.SH NAME
|
||||||
|
mboxgrep \- displays email messages matching a pattern
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B mboxgrep
|
||||||
|
.RI [ OPTIONS ]
|
||||||
|
.RI PATTERN
|
||||||
|
.RI [ MAILBOX ]
|
||||||
|
.SH DESCRIPTION
|
||||||
|
This manual page refers to
|
||||||
|
.B mboxgrep
|
||||||
|
version
|
||||||
|
.BR 0.7.9 .
|
||||||
|
.PP
|
||||||
|
.B mboxgrep
|
||||||
|
scans a
|
||||||
|
.I MAILBOX
|
||||||
|
and displays messages matching
|
||||||
|
.I PATTERN.
|
||||||
|
.PP
|
||||||
|
If a mailbox name is ommited, or a single dash (-) is given instead,
|
||||||
|
it reads from standard input.
|
||||||
|
It can read mbox folders or output from another
|
||||||
|
.B mboxgrep
|
||||||
|
process from standard input.
|
||||||
|
.PP
|
||||||
|
.B mboxgrep
|
||||||
|
understands POSIX regular expressions, as well as Perl compatible regular
|
||||||
|
expressions (if enabled at compile time).
|
||||||
|
.I MAILBOX
|
||||||
|
can be either a:
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
mbox folder (either plain or compressed)
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
MH folder
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
Gnus nnmh or nnml folder
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
qmail-style maildir folder
|
||||||
|
.SH OPTIONS
|
||||||
|
.PP
|
||||||
|
.IP "-h, --help"
|
||||||
|
Display a help screen and exit.
|
||||||
|
.IP "-V, --version"
|
||||||
|
Display version and copyright information and exit.
|
||||||
|
.IP "-r, --recursive"
|
||||||
|
Descend into directories recursively.
|
||||||
|
.IP "-E, --extended-regexp"
|
||||||
|
PATTERN is an extended regular expression. This is default.
|
||||||
|
.IP "-G, --basic-regexp "
|
||||||
|
PATTERN is a basic regular expression.
|
||||||
|
.IP "-P, --perl-regexp"
|
||||||
|
PATTERN is a Perl regular expression. Works only if enabled at compile time.
|
||||||
|
.IP "-e, --regexp=PATTERN"
|
||||||
|
Use PATTERN as a regular expression.
|
||||||
|
.IP "-i, --ignore-case"
|
||||||
|
Ignore case distinctions.
|
||||||
|
.IP "-v, --invert-match"
|
||||||
|
Select messages which don't match PATTERN.
|
||||||
|
.IP "-H, --headers"
|
||||||
|
Match PATTERN against message headers.
|
||||||
|
.IP "-B, --body"
|
||||||
|
Match PATTERN against message body.
|
||||||
|
.IP "-l, --file-lock=METHOD"
|
||||||
|
Select file locking METHOD. METHOD is `fcntl', `flock', or `none'.
|
||||||
|
.IP "-nl, --no-file-lock"
|
||||||
|
Do not lock files. This option is meaningful only if a mbox folder (see below)
|
||||||
|
is scanned.
|
||||||
|
.IP "-c, --count"
|
||||||
|
Suppress normal output and print a count of matching messages.
|
||||||
|
.IP "-o, --output=FOLDER"
|
||||||
|
Suppress normal output and write messages to destination folder FOLDER instead.
|
||||||
|
.IP "-p, --pipe=COMMAND"
|
||||||
|
Pipe each found message to COMMAND
|
||||||
|
.IP "-d, --delete"
|
||||||
|
Suppress normal output and delete selected messages instead. Use with
|
||||||
|
caution.
|
||||||
|
.IP "-nd, --no-duplicates"
|
||||||
|
Ignore duplicate messages.
|
||||||
|
.IP "-m, --mailbox-format=TYPE"
|
||||||
|
Select input and output mailbox TYPE. TYPE can be either `mbox' (default),
|
||||||
|
`zmbox' (meaning `gzip compressed mbox'), `bz2mbox' (meaning `bzip2
|
||||||
|
compressed mbox'), `mh', `nnml', `nnmh' or `maildir'.
|
||||||
|
.SH EXAMPLES
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
Search $MAIL for messages from Dirty Harry:
|
||||||
|
.PP
|
||||||
|
mboxgrep '^From:.*callahan@homicide\\.SFPD\\.gov' $MAIL
|
||||||
|
.TP
|
||||||
|
\(bu
|
||||||
|
Display all messages contained in folder ~/Mail/incoming, except those
|
||||||
|
that appear to originate from AOL:
|
||||||
|
.PP
|
||||||
|
mboxgrep -v 'Received:.*aol\\.com' ~/Mail/incoming
|
||||||
|
.SH BUGS
|
||||||
|
Report them to address below.
|
||||||
|
.SH NOTICE
|
||||||
|
Mboxgrep was alomost completely rewritten since version 0.5.3. Additionally,
|
||||||
|
there was no stable 0.6.x branch between 0.5.3 and 0.7.0.
|
||||||
|
.SH SEE ALSO
|
||||||
|
grep(1),
|
||||||
|
regex(7),
|
||||||
|
perlre(1),
|
||||||
|
mbox(5),
|
||||||
|
RFC 2822
|
||||||
|
.SH DEDICATION
|
||||||
|
Mboxgrep is dedicated in loving memory of Vicky, my cat who died of
|
||||||
|
tumor on Sep 12, 2002.
|
||||||
|
.PP
|
||||||
|
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
|
||||||
|
well, little friend.
|
||||||
|
.SH URL
|
||||||
|
http://www.mboxgrep.org/
|
||||||
|
.SH AUTHOR
|
||||||
|
Daniel Spiljar <dspiljar@world.std.com>
|
BIN
doc/mboxgrep.info
Normal file
BIN
doc/mboxgrep.info
Normal file
Binary file not shown.
279
doc/mboxgrep.texi
Normal file
279
doc/mboxgrep.texi
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
\input texinfo @c -*-texinfo-*-
|
||||||
|
@c $Id: mboxgrep.texi,v 1.19 2003/08/24 19:51:14 dspiljar Exp $
|
||||||
|
@setfilename mboxgrep.info
|
||||||
|
@settitle Grep through mailboxes
|
||||||
|
@finalout
|
||||||
|
@setchapternewpage odd
|
||||||
|
|
||||||
|
@set EDITION 0.7
|
||||||
|
@set VERSION 0.7.9
|
||||||
|
@set UPDATED 24 Aug 2003
|
||||||
|
|
||||||
|
@dircategory Mail
|
||||||
|
@direntry
|
||||||
|
* mboxgrep: (mboxgrep). A mail folder scanning utility.
|
||||||
|
@end direntry
|
||||||
|
|
||||||
|
@node Top, , , (dir)
|
||||||
|
|
||||||
|
@ifinfo
|
||||||
|
This file documents @code{mboxgrep} (version @value{VERSION}), a
|
||||||
|
mailbox scanning utility.
|
||||||
|
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar
|
||||||
|
@end ifinfo
|
||||||
|
|
||||||
|
@menu
|
||||||
|
* Introduction:: A short preface.
|
||||||
|
* Invoking:: Command-line arguments.
|
||||||
|
* Examples:: A few examples of usage.
|
||||||
|
* Bugs:: What to do with bugs and similar vermin.
|
||||||
|
|
||||||
|
* To Vicky:: Author's dedication.
|
||||||
|
@end menu
|
||||||
|
|
||||||
|
@node Introduction, Invoking, , Top
|
||||||
|
@chapter Introduction
|
||||||
|
|
||||||
|
@cindex introduction
|
||||||
|
@cindex preface
|
||||||
|
|
||||||
|
@code{mboxgrep} is a small, non-interactive utility that scans mail folders
|
||||||
|
for messages matching regular expressions.
|
||||||
|
|
||||||
|
It supports basic and extended POSIX regular expressions. @code{Perl}-style
|
||||||
|
regular expressions are supported as well, if @code{mboxgrep} is linked with
|
||||||
|
PCRE library.
|
||||||
|
|
||||||
|
Found messages can be either displayed on standard output, counted, deleted,
|
||||||
|
piped to a specified command, or copied to another mailbox.
|
||||||
|
|
||||||
|
It can read and write a variety of folder formats:
|
||||||
|
|
||||||
|
@itemize @bullet
|
||||||
|
@item
|
||||||
|
mbox folders, either plain or compressed
|
||||||
|
@item
|
||||||
|
MH folders
|
||||||
|
@item nnml and nnmh folders used by Gnus
|
||||||
|
@item @code{qmail}-style maildirs
|
||||||
|
@end itemize
|
||||||
|
|
||||||
|
Additionally, it can read mbox folders or output from another @code{mboxgrep}
|
||||||
|
process from standard input. It does so if a single dash (-) is given
|
||||||
|
as a file name.
|
||||||
|
|
||||||
|
@node Invoking, Examples, Introduction, Top
|
||||||
|
@chapter Command-Line Arguments
|
||||||
|
@cindex arguments
|
||||||
|
|
||||||
|
The syntax of @code{mboxgrep} invocation is:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep [OPTIONS] PATTERN [MAILBOX]
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@menu
|
||||||
|
* Miscellaneous::
|
||||||
|
* File locking::
|
||||||
|
* Regexp selection::
|
||||||
|
* Output control::
|
||||||
|
* Search scope selection::
|
||||||
|
* Mailbox type selection::
|
||||||
|
@end menu
|
||||||
|
|
||||||
|
@node Miscellaneous, File locking, , Invoking
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
@item --help
|
||||||
|
@itemx -h
|
||||||
|
Display a brief help screen and exit.
|
||||||
|
|
||||||
|
@item --version
|
||||||
|
@itemx -V
|
||||||
|
Display program version and copyright information and exit.
|
||||||
|
|
||||||
|
@item --recursive
|
||||||
|
@itemx -r
|
||||||
|
Descend into directories recursively.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node File locking, Regexp selection, Miscellaneous, Invoking
|
||||||
|
|
||||||
|
When accessing mbox folders, @code{mboxgrep} puts a shared lock on
|
||||||
|
files by default. Note that mbox folders normally should not be accessed
|
||||||
|
without locking.
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
|
||||||
|
@item --file-lock=METHOD
|
||||||
|
@itemx -l METHOD
|
||||||
|
Specify file locking METHOD. @code{mboxgrep} supports @code{flock} and
|
||||||
|
@code{fcntl} file locking. However, one of these methods may be
|
||||||
|
unimplemented on your operating system and thus not available in
|
||||||
|
@code{mboxgrep} at run time. To disable file locking, specify @code{none}.
|
||||||
|
|
||||||
|
@item --no-file-lock
|
||||||
|
@itemx -nl
|
||||||
|
Do not attempt to lock mbox folder files.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node Regexp selection, Output control, File locking, Invoking
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
|
||||||
|
@item --extended-regexp
|
||||||
|
@itemx -E
|
||||||
|
PATTERN is an extended regular expression.
|
||||||
|
|
||||||
|
@item --basic-regexp
|
||||||
|
@itemx -G
|
||||||
|
PATTERN is a basic regular expression.
|
||||||
|
|
||||||
|
@item --perl-regexp
|
||||||
|
@itemx -P
|
||||||
|
PATTERN is a Perl regular expression.
|
||||||
|
|
||||||
|
@item --regexp=PATTERN
|
||||||
|
@itemx -e PATTERN
|
||||||
|
Use PATTERN as a regular expression.
|
||||||
|
|
||||||
|
@item --ignore-case
|
||||||
|
@itemx -i
|
||||||
|
Perform case-insensitive search.
|
||||||
|
|
||||||
|
@item --invert-match
|
||||||
|
@itemx -v
|
||||||
|
Invert the sense of matching, i.e. select only non-matching messages.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node Output control, Search scope selection, Regexp selection, Invoking
|
||||||
|
|
||||||
|
By default, @code{mboxgrep} writes found messages to standard output.
|
||||||
|
The options below change such behavior.
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
|
||||||
|
@item --count
|
||||||
|
@itemx -c
|
||||||
|
Suppress normal output and print the count of matching (or non-matching,
|
||||||
|
if used with the @code{-v} option) messages.
|
||||||
|
|
||||||
|
@item --delete
|
||||||
|
@itemx -d
|
||||||
|
Suppress normal output and delete selected messages.
|
||||||
|
|
||||||
|
Use with extreme caution.
|
||||||
|
|
||||||
|
@item --no-duplicates
|
||||||
|
@itemx -nd
|
||||||
|
Ignore duplicate messages.
|
||||||
|
|
||||||
|
@item --output=FOLDER
|
||||||
|
@itemx -o FOLDER
|
||||||
|
Suppress normal output and write messages to destination folder FOLDER
|
||||||
|
instead.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
@item --pipe=COMMAND
|
||||||
|
@itemx -p COMMAND
|
||||||
|
Suppress normal output and pipe each selected message to a separate
|
||||||
|
instance of COMMAND.
|
||||||
|
|
||||||
|
@item --no-messages
|
||||||
|
@itemx -s
|
||||||
|
Suppress error messages.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node Search scope selection, Mailbox type selection, Output control, Invoking
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
|
||||||
|
@item --headers
|
||||||
|
@itemx -H
|
||||||
|
Match PATTERN against message headers.
|
||||||
|
|
||||||
|
@item --body
|
||||||
|
@itemx -B
|
||||||
|
Match PATTERN against message body.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node Mailbox type selection, , Search scope selection, Invoking
|
||||||
|
|
||||||
|
@table @samp
|
||||||
|
|
||||||
|
@item --mailbox-format=FORMAT
|
||||||
|
@itemx -m FORMAT
|
||||||
|
Specify mailbox FORMAT. Supported formats are @code{mbox} (default),
|
||||||
|
@code{zmbox} (gzip compressed mbox), @code{bz2mbox} (bzip2 compressed
|
||||||
|
mbox) @code{mh}, @code{nnml}, @code{nnmh}, and @code{maildir}.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@node Examples, Bugs, Invoking, Top
|
||||||
|
@chapter Examples
|
||||||
|
@cindex example
|
||||||
|
|
||||||
|
Scan @env{$MAIL} for messages from Dirty Harry:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep -H '^From:.*callahan@@homicide\.SFPD\.gov' $MAIL
|
||||||
|
@end example
|
||||||
|
|
||||||
|
Re-mail to George messages that mention his name:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep --pipe="/usr/lib/sendmail george" --ignore-case george ~/Mail/*
|
||||||
|
@end example
|
||||||
|
|
||||||
|
Display all messages in folder @file{~/Mail/incoming}, except those that
|
||||||
|
appear to originate from AOL:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep -v -H '^Received:.*aol\.com' ~/Mail/incoming
|
||||||
|
@end example
|
||||||
|
|
||||||
|
Do a case-insensitive scan of @file{~/Mail/incoming} for messages with subject
|
||||||
|
``Weekly News'' and write them to folder @file{~/Mail/archive}:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep -o ~/Mail/archive -H -i '^Subject: Weekly News' ~/Mail/incoming
|
||||||
|
@end example
|
||||||
|
|
||||||
|
Count @emph{all} messages stored in folder @file{spam}, ignoring duplicates:
|
||||||
|
|
||||||
|
@example
|
||||||
|
mboxgrep -nd -c . spam
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@node Bugs, To Vicky, Examples, Top
|
||||||
|
@chapter Detecting Vermin
|
||||||
|
@cindex bug, insect, vermin, bugreport
|
||||||
|
|
||||||
|
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}.
|
||||||
|
Instructions how to reproduce the bug or output from a debugger would be
|
||||||
|
highly appreciated. Don't, however, send any coredumps.
|
||||||
|
|
||||||
|
@node To Vicky, , Bugs, Top
|
||||||
|
@chapter Author's Dedication
|
||||||
|
@cindex vicky, cat, memory, love
|
||||||
|
|
||||||
|
@code{Mboxgrep} is dedicated in loving memory of Vicky, my cat who died
|
||||||
|
of tumor on Sep 12, 2002.
|
||||||
|
|
||||||
|
You haven't been long with us, but you gave us a lot of joy and all
|
||||||
|
your big heart that stopped ticking too early. I will never forget
|
||||||
|
you. Sleep well, little friend.
|
||||||
|
|
||||||
|
|
||||||
|
@bye @c cruel world
|
251
install-sh
Executable file
251
install-sh
Executable 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
|
21
mboxgrep.lsm
Normal file
21
mboxgrep.lsm
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
Begin4
|
||||||
|
Title: mboxgrep
|
||||||
|
Version: 0.7.9
|
||||||
|
Entered-date: 2003-08-24
|
||||||
|
Description: mboxgrep is a small utility that scans a mailbox for messages
|
||||||
|
matching a basic, extended, or Perl-compatible regular
|
||||||
|
expression. Selected messages can be either displayed on
|
||||||
|
standard output, counted, piped to a command or written to
|
||||||
|
another mailbox.
|
||||||
|
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)
|
||||||
|
Primary-site: http://www.mboxgrep.org/
|
||||||
|
75k mboxgrep-0.7.9.tar.gz
|
||||||
|
Alternate-site:
|
||||||
|
Original-site:
|
||||||
|
Platforms:
|
||||||
|
Copying-policy: GPL
|
||||||
|
End
|
57
src/Makefile.in
Normal file
57
src/Makefile.in
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
# Copyright (C) 2000, 2001, 2002, 2003 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.9 2003/03/30 23:07:10 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
|
||||||
|
SRCS = info.c main.c mh.c scan.c maildir.c mbox.c misc.c \
|
||||||
|
wrap.c getopt.c getopt1.c md5.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
67
src/config.h.in
Normal 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
|
731
src/getopt.c
Normal file
731
src/getopt.c
Normal file
@ -0,0 +1,731 @@
|
|||||||
|
/* Getopt for GNU.
|
||||||
|
NOTE: getopt is now part of the C library, so if you don't know what
|
||||||
|
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
|
||||||
|
before changing it!
|
||||||
|
|
||||||
|
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||||
|
|
||||||
|
/* NOTE!!! AIX requires this to be the first thing in the file.
|
||||||
|
Do not put ANYTHING before it! */
|
||||||
|
#if !defined (__GNUC__) && defined (_AIX)
|
||||||
|
#pragma alloca
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define alloca __builtin_alloca
|
||||||
|
#else /* not __GNUC__ */
|
||||||
|
#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
|
||||||
|
#include <alloca.h>
|
||||||
|
#else
|
||||||
|
#ifndef _AIX
|
||||||
|
char *alloca ();
|
||||||
|
#endif
|
||||||
|
#endif /* alloca.h */
|
||||||
|
#endif /* not __GNUC__ */
|
||||||
|
|
||||||
|
#if !__STDC__ && !defined(const) && IN_GCC
|
||||||
|
#define const
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. */
|
||||||
|
#ifndef _NO_PROTO
|
||||||
|
#define _NO_PROTO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||||
|
actually compiling the library itself. This code is part of the GNU C
|
||||||
|
Library, but also included in many other GNU distributions. Compiling
|
||||||
|
and linking in this code is a waste when using the GNU C library
|
||||||
|
(especially if it is a shared library). Rather than having every GNU
|
||||||
|
program understand `configure --with-gnu-libc' and omit the object files,
|
||||||
|
it is simpler to just do this in the source for each such file. */
|
||||||
|
|
||||||
|
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
|
||||||
|
|
||||||
|
|
||||||
|
/* This needs to come after some library #include
|
||||||
|
to get __GNU_LIBRARY__ defined. */
|
||||||
|
#ifdef __GNU_LIBRARY__
|
||||||
|
#undef alloca
|
||||||
|
/* Don't include stdlib.h for non-GNU C libraries because some of them
|
||||||
|
contain conflicting prototypes for getopt. */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#else /* Not GNU C library. */
|
||||||
|
#define __alloca alloca
|
||||||
|
#endif /* GNU C library. */
|
||||||
|
|
||||||
|
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
|
||||||
|
long-named option. Because this is not POSIX.2 compliant, it is
|
||||||
|
being phased out. */
|
||||||
|
/* #define GETOPT_COMPAT */
|
||||||
|
|
||||||
|
/* This version of `getopt' appears to the caller like standard Unix `getopt'
|
||||||
|
but it behaves differently for the user, since it allows the user
|
||||||
|
to intersperse the options with the other arguments.
|
||||||
|
|
||||||
|
As `getopt' works, it permutes the elements of ARGV so that,
|
||||||
|
when it is done, all the options precede everything else. Thus
|
||||||
|
all application programs are extended to handle flexible argument order.
|
||||||
|
|
||||||
|
Setting the environment variable POSIXLY_CORRECT disables permutation.
|
||||||
|
Then the behavior is completely standard.
|
||||||
|
|
||||||
|
GNU application programs can use a third alternative mode in which
|
||||||
|
they can distinguish the relative order of options and other arguments. */
|
||||||
|
|
||||||
|
#include "getopt.h"
|
||||||
|
|
||||||
|
/* For communication from `getopt' to the caller.
|
||||||
|
When `getopt' finds an option that takes an argument,
|
||||||
|
the argument value is returned here.
|
||||||
|
Also, when `ordering' is RETURN_IN_ORDER,
|
||||||
|
each non-option ARGV-element is returned here. */
|
||||||
|
|
||||||
|
char *optarg = 0;
|
||||||
|
|
||||||
|
/* Index in ARGV of the next element to be scanned.
|
||||||
|
This is used for communication to and from the caller
|
||||||
|
and for communication between successive calls to `getopt'.
|
||||||
|
|
||||||
|
On entry to `getopt', zero means this is the first call; initialize.
|
||||||
|
|
||||||
|
When `getopt' returns EOF, this is the index of the first of the
|
||||||
|
non-option elements that the caller should itself scan.
|
||||||
|
|
||||||
|
Otherwise, `optind' communicates from one call to the next
|
||||||
|
how much of ARGV has been scanned so far. */
|
||||||
|
|
||||||
|
/* XXX 1003.2 says this must be 1 before any call. */
|
||||||
|
int optind = 0;
|
||||||
|
|
||||||
|
/* The next char to be scanned in the option-element
|
||||||
|
in which the last option character we returned was found.
|
||||||
|
This allows us to pick up the scan where we left off.
|
||||||
|
|
||||||
|
If this is zero, or a null string, it means resume the scan
|
||||||
|
by advancing to the next ARGV-element. */
|
||||||
|
|
||||||
|
static char *nextchar;
|
||||||
|
|
||||||
|
/* Callers store zero here to inhibit the error message
|
||||||
|
for unrecognized options. */
|
||||||
|
|
||||||
|
int opterr = 1;
|
||||||
|
|
||||||
|
/* Set to an option character which was unrecognized.
|
||||||
|
This must be initialized on some systems to avoid linking in the
|
||||||
|
system's own getopt implementation. */
|
||||||
|
|
||||||
|
int optopt = '?';
|
||||||
|
|
||||||
|
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||||
|
|
||||||
|
If the caller did not specify anything,
|
||||||
|
the default is REQUIRE_ORDER if the environment variable
|
||||||
|
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||||
|
|
||||||
|
REQUIRE_ORDER means don't recognize them as options;
|
||||||
|
stop option processing when the first non-option is seen.
|
||||||
|
This is what Unix does.
|
||||||
|
This mode of operation is selected by either setting the environment
|
||||||
|
variable POSIXLY_CORRECT, or using `+' as the first character
|
||||||
|
of the list of option characters.
|
||||||
|
|
||||||
|
PERMUTE is the default. We permute the contents of ARGV as we scan,
|
||||||
|
so that eventually all the non-options are at the end. This allows options
|
||||||
|
to be given in any order, even with programs that were not written to
|
||||||
|
expect this.
|
||||||
|
|
||||||
|
RETURN_IN_ORDER is an option available to programs that were written
|
||||||
|
to expect options and other ARGV-elements in any order and that care about
|
||||||
|
the ordering of the two. We describe each non-option ARGV-element
|
||||||
|
as if it were the argument of an option with character code 1.
|
||||||
|
Using `-' as the first character of the list of option characters
|
||||||
|
selects this mode of operation.
|
||||||
|
|
||||||
|
The special argument `--' forces an end of option-scanning regardless
|
||||||
|
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||||
|
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
|
||||||
|
|
||||||
|
static enum
|
||||||
|
{
|
||||||
|
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
|
||||||
|
} ordering;
|
||||||
|
|
||||||
|
#ifdef __GNU_LIBRARY__
|
||||||
|
/* We want to avoid inclusion of string.h with non-GNU libraries
|
||||||
|
because there are many ways it can cause trouble.
|
||||||
|
On some systems, it contains special magic macros that don't work
|
||||||
|
in GCC. */
|
||||||
|
#include <string.h>
|
||||||
|
#define my_index strchr
|
||||||
|
#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* Avoid depending on library functions or files
|
||||||
|
whose names are inconsistent. */
|
||||||
|
|
||||||
|
char *getenv ();
|
||||||
|
|
||||||
|
static char *
|
||||||
|
my_index (str, chr)
|
||||||
|
const char *str;
|
||||||
|
int chr;
|
||||||
|
{
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
if (*str == chr)
|
||||||
|
return (char *) str;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
my_bcopy (from, to, size)
|
||||||
|
const char *from;
|
||||||
|
char *to;
|
||||||
|
int size;
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
to[i] = from[i];
|
||||||
|
}
|
||||||
|
#endif /* GNU C library. */
|
||||||
|
|
||||||
|
/* Handle permutation of arguments. */
|
||||||
|
|
||||||
|
/* Describe the part of ARGV that contains non-options that have
|
||||||
|
been skipped. `first_nonopt' is the index in ARGV of the first of them;
|
||||||
|
`last_nonopt' is the index after the last of them. */
|
||||||
|
|
||||||
|
static int first_nonopt;
|
||||||
|
static int last_nonopt;
|
||||||
|
|
||||||
|
/* Exchange two adjacent subsequences of ARGV.
|
||||||
|
One subsequence is elements [first_nonopt,last_nonopt)
|
||||||
|
which contains all the non-options that have been skipped so far.
|
||||||
|
The other is elements [last_nonopt,optind), which contains all
|
||||||
|
the options processed since those non-options were skipped.
|
||||||
|
|
||||||
|
`first_nonopt' and `last_nonopt' are relocated so that they describe
|
||||||
|
the new indices of the non-options in ARGV after they are moved. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
exchange (argv)
|
||||||
|
char **argv;
|
||||||
|
{
|
||||||
|
int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
|
||||||
|
char **temp = (char **) __alloca (nonopts_size);
|
||||||
|
|
||||||
|
/* Interchange the two blocks of data in ARGV. */
|
||||||
|
|
||||||
|
my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
|
||||||
|
my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
|
||||||
|
(optind - last_nonopt) * sizeof (char *));
|
||||||
|
my_bcopy ((char *) temp,
|
||||||
|
(char *) &argv[first_nonopt + optind - last_nonopt],
|
||||||
|
nonopts_size);
|
||||||
|
|
||||||
|
/* Update records for the slots the non-options now occupy. */
|
||||||
|
|
||||||
|
first_nonopt += (optind - last_nonopt);
|
||||||
|
last_nonopt = optind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scan elements of ARGV (whose length is ARGC) for option characters
|
||||||
|
given in OPTSTRING.
|
||||||
|
|
||||||
|
If an element of ARGV starts with '-', and is not exactly "-" or "--",
|
||||||
|
then it is an option element. The characters of this element
|
||||||
|
(aside from the initial '-') are option characters. If `getopt'
|
||||||
|
is called repeatedly, it returns successively each of the option characters
|
||||||
|
from each of the option elements.
|
||||||
|
|
||||||
|
If `getopt' finds another option character, it returns that character,
|
||||||
|
updating `optind' and `nextchar' so that the next call to `getopt' can
|
||||||
|
resume the scan with the following option character or ARGV-element.
|
||||||
|
|
||||||
|
If there are no more option characters, `getopt' returns `EOF'.
|
||||||
|
Then `optind' is the index in ARGV of the first ARGV-element
|
||||||
|
that is not an option. (The ARGV-elements have been permuted
|
||||||
|
so that those that are not options now come last.)
|
||||||
|
|
||||||
|
OPTSTRING is a string containing the legitimate option characters.
|
||||||
|
If an option character is seen that is not listed in OPTSTRING,
|
||||||
|
return '?' after printing an error message. If you set `opterr' to
|
||||||
|
zero, the error message is suppressed but we still return '?'.
|
||||||
|
|
||||||
|
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
|
||||||
|
so the following text in the same ARGV-element, or the text of the following
|
||||||
|
ARGV-element, is returned in `optarg'. Two colons mean an option that
|
||||||
|
wants an optional arg; if there is text in the current ARGV-element,
|
||||||
|
it is returned in `optarg', otherwise `optarg' is set to zero.
|
||||||
|
|
||||||
|
If OPTSTRING starts with `-' or `+', it requests different methods of
|
||||||
|
handling the non-option ARGV-elements.
|
||||||
|
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
|
||||||
|
|
||||||
|
Long-named options begin with `--' instead of `-'.
|
||||||
|
Their names may be abbreviated as long as the abbreviation is unique
|
||||||
|
or is an exact match for some defined option. If they have an
|
||||||
|
argument, it follows the option name in the same ARGV-element, separated
|
||||||
|
from the option name by a `=', or else the in next ARGV-element.
|
||||||
|
When `getopt' finds a long-named option, it returns 0 if that option's
|
||||||
|
`flag' field is nonzero, the value of the option's `val' field
|
||||||
|
if the `flag' field is zero.
|
||||||
|
|
||||||
|
The elements of ARGV aren't really const, because we permute them.
|
||||||
|
But we pretend they're const in the prototype to be compatible
|
||||||
|
with other systems.
|
||||||
|
|
||||||
|
LONGOPTS is a vector of `struct option' terminated by an
|
||||||
|
element containing a name which is zero.
|
||||||
|
|
||||||
|
LONGIND returns the index in LONGOPT of the long-named option found.
|
||||||
|
It is only valid when a long-named option has been found by the most
|
||||||
|
recent call.
|
||||||
|
|
||||||
|
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
|
||||||
|
long-named options. */
|
||||||
|
|
||||||
|
int
|
||||||
|
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
||||||
|
int argc;
|
||||||
|
char *const *argv;
|
||||||
|
const char *optstring;
|
||||||
|
const struct option *longopts;
|
||||||
|
int *longind;
|
||||||
|
int long_only;
|
||||||
|
{
|
||||||
|
int option_index;
|
||||||
|
|
||||||
|
optarg = 0;
|
||||||
|
|
||||||
|
/* Initialize the internal data when the first call is made.
|
||||||
|
Start processing options with ARGV-element 1 (since ARGV-element 0
|
||||||
|
is the program name); the sequence of previously skipped
|
||||||
|
non-option ARGV-elements is empty. */
|
||||||
|
|
||||||
|
if (optind == 0)
|
||||||
|
{
|
||||||
|
first_nonopt = last_nonopt = optind = 1;
|
||||||
|
|
||||||
|
nextchar = NULL;
|
||||||
|
|
||||||
|
/* Determine how to handle the ordering of options and nonoptions. */
|
||||||
|
|
||||||
|
if (optstring[0] == '-')
|
||||||
|
{
|
||||||
|
ordering = RETURN_IN_ORDER;
|
||||||
|
++optstring;
|
||||||
|
}
|
||||||
|
else if (optstring[0] == '+')
|
||||||
|
{
|
||||||
|
ordering = REQUIRE_ORDER;
|
||||||
|
++optstring;
|
||||||
|
}
|
||||||
|
else if (getenv ("POSIXLY_CORRECT") != NULL)
|
||||||
|
ordering = REQUIRE_ORDER;
|
||||||
|
else
|
||||||
|
ordering = PERMUTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextchar == NULL || *nextchar == '\0')
|
||||||
|
{
|
||||||
|
if (ordering == PERMUTE)
|
||||||
|
{
|
||||||
|
/* If we have just processed some options following some non-options,
|
||||||
|
exchange them so that the options come first. */
|
||||||
|
|
||||||
|
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||||
|
exchange ((char **) argv);
|
||||||
|
else if (last_nonopt != optind)
|
||||||
|
first_nonopt = optind;
|
||||||
|
|
||||||
|
/* Now skip any additional non-options
|
||||||
|
and extend the range of non-options previously skipped. */
|
||||||
|
|
||||||
|
while (optind < argc
|
||||||
|
&& (argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||||
|
#ifdef GETOPT_COMPAT
|
||||||
|
&& (longopts == NULL
|
||||||
|
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||||
|
#endif /* GETOPT_COMPAT */
|
||||||
|
)
|
||||||
|
optind++;
|
||||||
|
last_nonopt = optind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Special ARGV-element `--' means premature end of options.
|
||||||
|
Skip it like a null option,
|
||||||
|
then exchange with previous non-options as if it were an option,
|
||||||
|
then skip everything else like a non-option. */
|
||||||
|
|
||||||
|
if (optind != argc && !strcmp (argv[optind], "--"))
|
||||||
|
{
|
||||||
|
optind++;
|
||||||
|
|
||||||
|
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||||
|
exchange ((char **) argv);
|
||||||
|
else if (first_nonopt == last_nonopt)
|
||||||
|
first_nonopt = optind;
|
||||||
|
last_nonopt = argc;
|
||||||
|
|
||||||
|
optind = argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we have done all the ARGV-elements, stop the scan
|
||||||
|
and back over any non-options that we skipped and permuted. */
|
||||||
|
|
||||||
|
if (optind == argc)
|
||||||
|
{
|
||||||
|
/* Set the next-arg-index to point at the non-options
|
||||||
|
that we previously skipped, so the caller will digest them. */
|
||||||
|
if (first_nonopt != last_nonopt)
|
||||||
|
optind = first_nonopt;
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we have come to a non-option and did not permute it,
|
||||||
|
either stop the scan or describe it to the caller and pass it by. */
|
||||||
|
|
||||||
|
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||||
|
#ifdef GETOPT_COMPAT
|
||||||
|
&& (longopts == NULL
|
||||||
|
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||||
|
#endif /* GETOPT_COMPAT */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (ordering == REQUIRE_ORDER)
|
||||||
|
return EOF;
|
||||||
|
optarg = argv[optind++];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We have found another option-ARGV-element.
|
||||||
|
Start decoding its characters. */
|
||||||
|
|
||||||
|
nextchar = (argv[optind] + 1
|
||||||
|
+ (longopts != NULL && argv[optind][1] == '-'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longopts != NULL
|
||||||
|
&& ((argv[optind][0] == '-'
|
||||||
|
&& (argv[optind][1] == '-' || long_only))
|
||||||
|
#ifdef GETOPT_COMPAT
|
||||||
|
|| argv[optind][0] == '+'
|
||||||
|
#endif /* GETOPT_COMPAT */
|
||||||
|
))
|
||||||
|
{
|
||||||
|
const struct option *p;
|
||||||
|
char *s = nextchar;
|
||||||
|
int exact = 0;
|
||||||
|
int ambig = 0;
|
||||||
|
const struct option *pfound = NULL;
|
||||||
|
int indfound;
|
||||||
|
|
||||||
|
while (*s && *s != '=')
|
||||||
|
s++;
|
||||||
|
|
||||||
|
/* Test all options for either exact match or abbreviated matches. */
|
||||||
|
for (p = longopts, option_index = 0; p->name;
|
||||||
|
p++, option_index++)
|
||||||
|
if (!strncmp (p->name, nextchar, s - nextchar))
|
||||||
|
{
|
||||||
|
if (s - nextchar == strlen (p->name))
|
||||||
|
{
|
||||||
|
/* Exact match found. */
|
||||||
|
pfound = p;
|
||||||
|
indfound = option_index;
|
||||||
|
exact = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (pfound == NULL)
|
||||||
|
{
|
||||||
|
/* First nonexact match found. */
|
||||||
|
pfound = p;
|
||||||
|
indfound = option_index;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Second nonexact match found. */
|
||||||
|
ambig = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ambig && !exact)
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||||
|
argv[0], argv[optind]);
|
||||||
|
nextchar += strlen (nextchar);
|
||||||
|
optind++;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pfound != NULL)
|
||||||
|
{
|
||||||
|
option_index = indfound;
|
||||||
|
optind++;
|
||||||
|
if (*s)
|
||||||
|
{
|
||||||
|
/* Don't test has_arg with >, because some C compilers don't
|
||||||
|
allow it to be used on enums. */
|
||||||
|
if (pfound->has_arg)
|
||||||
|
optarg = s + 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
{
|
||||||
|
if (argv[optind - 1][1] == '-')
|
||||||
|
/* --option */
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: option `--%s' doesn't allow an argument\n",
|
||||||
|
argv[0], pfound->name);
|
||||||
|
else
|
||||||
|
/* +option or -option */
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: option `%c%s' doesn't allow an argument\n",
|
||||||
|
argv[0], argv[optind - 1][0], pfound->name);
|
||||||
|
}
|
||||||
|
nextchar += strlen (nextchar);
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pfound->has_arg == 1)
|
||||||
|
{
|
||||||
|
if (optind < argc)
|
||||||
|
optarg = argv[optind++];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
fprintf (stderr, "%s: option `%s' requires an argument\n",
|
||||||
|
argv[0], argv[optind - 1]);
|
||||||
|
nextchar += strlen (nextchar);
|
||||||
|
return optstring[0] == ':' ? ':' : '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nextchar += strlen (nextchar);
|
||||||
|
if (longind != NULL)
|
||||||
|
*longind = option_index;
|
||||||
|
if (pfound->flag)
|
||||||
|
{
|
||||||
|
*(pfound->flag) = pfound->val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return pfound->val;
|
||||||
|
}
|
||||||
|
/* Can't find it as a long option. If this is not getopt_long_only,
|
||||||
|
or the option starts with '--' or is not a valid short
|
||||||
|
option, then it's an error.
|
||||||
|
Otherwise interpret it as a short option. */
|
||||||
|
if (!long_only || argv[optind][1] == '-'
|
||||||
|
#ifdef GETOPT_COMPAT
|
||||||
|
|| argv[optind][0] == '+'
|
||||||
|
#endif /* GETOPT_COMPAT */
|
||||||
|
|| my_index (optstring, *nextchar) == NULL)
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
{
|
||||||
|
if (argv[optind][1] == '-')
|
||||||
|
/* --option */
|
||||||
|
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||||
|
argv[0], nextchar);
|
||||||
|
else
|
||||||
|
/* +option or -option */
|
||||||
|
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||||
|
argv[0], argv[optind][0], nextchar);
|
||||||
|
}
|
||||||
|
nextchar = (char *) "";
|
||||||
|
optind++;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look at and handle the next option-character. */
|
||||||
|
|
||||||
|
{
|
||||||
|
char c = *nextchar++;
|
||||||
|
char *temp = my_index (optstring, c);
|
||||||
|
|
||||||
|
/* Increment `optind' when we start to process its last character. */
|
||||||
|
if (*nextchar == '\0')
|
||||||
|
++optind;
|
||||||
|
|
||||||
|
if (temp == NULL || c == ':')
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
if (c < 040 || c >= 0177)
|
||||||
|
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||||
|
argv[0], c);
|
||||||
|
else
|
||||||
|
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
|
||||||
|
#else
|
||||||
|
/* 1003.2 specifies the format of this message. */
|
||||||
|
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
optopt = c;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
if (temp[1] == ':')
|
||||||
|
{
|
||||||
|
if (temp[2] == ':')
|
||||||
|
{
|
||||||
|
/* This is an option that accepts an argument optionally. */
|
||||||
|
if (*nextchar != '\0')
|
||||||
|
{
|
||||||
|
optarg = nextchar;
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
optarg = 0;
|
||||||
|
nextchar = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This is an option that requires an argument. */
|
||||||
|
if (*nextchar != '\0')
|
||||||
|
{
|
||||||
|
optarg = nextchar;
|
||||||
|
/* If we end this ARGV-element by taking the rest as an arg,
|
||||||
|
we must advance to the next element now. */
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
else if (optind == argc)
|
||||||
|
{
|
||||||
|
if (opterr)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
||||||
|
argv[0], c);
|
||||||
|
#else
|
||||||
|
/* 1003.2 specifies the format of this message. */
|
||||||
|
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||||
|
argv[0], c);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
optopt = c;
|
||||||
|
if (optstring[0] == ':')
|
||||||
|
c = ':';
|
||||||
|
else
|
||||||
|
c = '?';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* We already incremented `optind' once;
|
||||||
|
increment it again when taking next ARGV-elt as argument. */
|
||||||
|
optarg = argv[optind++];
|
||||||
|
nextchar = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
getopt (argc, argv, optstring)
|
||||||
|
int argc;
|
||||||
|
char *const *argv;
|
||||||
|
const char *optstring;
|
||||||
|
{
|
||||||
|
return _getopt_internal (argc, argv, optstring,
|
||||||
|
(const struct option *) 0,
|
||||||
|
(int *) 0,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _LIBC or not __GNU_LIBRARY__. */
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
/* Compile with -DTEST to make an executable for use in testing
|
||||||
|
the above definition of `getopt'. */
|
||||||
|
|
||||||
|
int
|
||||||
|
main (argc, argv)
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
int digit_optind = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int this_option_optind = optind ? optind : 1;
|
||||||
|
|
||||||
|
c = getopt (argc, argv, "abc:d:0123456789");
|
||||||
|
if (c == EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
|
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||||
|
printf ("digits occur in two different argv-elements.\n");
|
||||||
|
digit_optind = this_option_optind;
|
||||||
|
printf ("option %c\n", c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
printf ("option a\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
printf ("option b\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
printf ("option c with value `%s'\n", optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '?':
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
printf ("non-option ARGV-elements: ");
|
||||||
|
while (optind < argc)
|
||||||
|
printf ("%s ", argv[optind++]);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TEST */
|
129
src/getopt.h
Normal file
129
src/getopt.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/* Declarations for getopt.
|
||||||
|
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||||
|
|
||||||
|
#ifndef _GETOPT_H
|
||||||
|
#define _GETOPT_H 1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* For communication from `getopt' to the caller.
|
||||||
|
When `getopt' finds an option that takes an argument,
|
||||||
|
the argument value is returned here.
|
||||||
|
Also, when `ordering' is RETURN_IN_ORDER,
|
||||||
|
each non-option ARGV-element is returned here. */
|
||||||
|
|
||||||
|
extern char *optarg;
|
||||||
|
|
||||||
|
/* Index in ARGV of the next element to be scanned.
|
||||||
|
This is used for communication to and from the caller
|
||||||
|
and for communication between successive calls to `getopt'.
|
||||||
|
|
||||||
|
On entry to `getopt', zero means this is the first call; initialize.
|
||||||
|
|
||||||
|
When `getopt' returns EOF, this is the index of the first of the
|
||||||
|
non-option elements that the caller should itself scan.
|
||||||
|
|
||||||
|
Otherwise, `optind' communicates from one call to the next
|
||||||
|
how much of ARGV has been scanned so far. */
|
||||||
|
|
||||||
|
extern int optind;
|
||||||
|
|
||||||
|
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||||
|
for unrecognized options. */
|
||||||
|
|
||||||
|
extern int opterr;
|
||||||
|
|
||||||
|
/* Set to an option character which was unrecognized. */
|
||||||
|
|
||||||
|
extern int optopt;
|
||||||
|
|
||||||
|
/* Describe the long-named options requested by the application.
|
||||||
|
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||||
|
of `struct option' terminated by an element containing a name which is
|
||||||
|
zero.
|
||||||
|
|
||||||
|
The field `has_arg' is:
|
||||||
|
no_argument (or 0) if the option does not take an argument,
|
||||||
|
required_argument (or 1) if the option requires an argument,
|
||||||
|
optional_argument (or 2) if the option takes an optional argument.
|
||||||
|
|
||||||
|
If the field `flag' is not NULL, it points to a variable that is set
|
||||||
|
to the value given in the field `val' when the option is found, but
|
||||||
|
left unchanged if the option is not found.
|
||||||
|
|
||||||
|
To have a long-named option do something other than set an `int' to
|
||||||
|
a compiled-in constant, such as set a value from `optarg', set the
|
||||||
|
option's `flag' field to zero and its `val' field to a nonzero
|
||||||
|
value (the equivalent single-letter option character, if there is
|
||||||
|
one). For long options that have a zero `flag' field, `getopt'
|
||||||
|
returns the contents of the `val' field. */
|
||||||
|
|
||||||
|
struct option
|
||||||
|
{
|
||||||
|
#if __STDC__
|
||||||
|
const char *name;
|
||||||
|
#else
|
||||||
|
char *name;
|
||||||
|
#endif
|
||||||
|
/* has_arg can't be an enum because some compilers complain about
|
||||||
|
type mismatches in all the code that assumes it is an int. */
|
||||||
|
int has_arg;
|
||||||
|
int *flag;
|
||||||
|
int val;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||||
|
|
||||||
|
#define no_argument 0
|
||||||
|
#define required_argument 1
|
||||||
|
#define optional_argument 2
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
|
#if defined(__GNU_LIBRARY__)
|
||||||
|
/* Many other libraries have conflicting prototypes for getopt, with
|
||||||
|
differences in the consts, in stdlib.h. To avoid compilation
|
||||||
|
errors, only prototype getopt for the GNU C library. */
|
||||||
|
extern int getopt (int argc, char *const *argv, const char *shortopts);
|
||||||
|
#else /* not __GNU_LIBRARY__ */
|
||||||
|
extern int getopt ();
|
||||||
|
#endif /* not __GNU_LIBRARY__ */
|
||||||
|
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
|
||||||
|
const struct option *longopts, int *longind);
|
||||||
|
extern int getopt_long_only (int argc, char *const *argv,
|
||||||
|
const char *shortopts,
|
||||||
|
const struct option *longopts, int *longind);
|
||||||
|
|
||||||
|
/* Internal only. Users should not call this directly. */
|
||||||
|
extern int _getopt_internal (int argc, char *const *argv,
|
||||||
|
const char *shortopts,
|
||||||
|
const struct option *longopts, int *longind,
|
||||||
|
int long_only);
|
||||||
|
#else /* not __STDC__ */
|
||||||
|
extern int getopt ();
|
||||||
|
extern int getopt_long ();
|
||||||
|
extern int getopt_long_only ();
|
||||||
|
|
||||||
|
extern int _getopt_internal ();
|
||||||
|
#endif /* not __STDC__ */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _GETOPT_H */
|
176
src/getopt1.c
Normal file
176
src/getopt1.c
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||||
|
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "getopt.h"
|
||||||
|
|
||||||
|
#if !__STDC__ && !defined(const) && IN_GCC
|
||||||
|
#define const
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||||
|
actually compiling the library itself. This code is part of the GNU C
|
||||||
|
Library, but also included in many other GNU distributions. Compiling
|
||||||
|
and linking in this code is a waste when using the GNU C library
|
||||||
|
(especially if it is a shared library). Rather than having every GNU
|
||||||
|
program understand `configure --with-gnu-libc' and omit the object files,
|
||||||
|
it is simpler to just do this in the source for each such file. */
|
||||||
|
|
||||||
|
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
|
||||||
|
|
||||||
|
|
||||||
|
/* This needs to come after some library #include
|
||||||
|
to get __GNU_LIBRARY__ defined. */
|
||||||
|
#ifdef __GNU_LIBRARY__
|
||||||
|
#include <stdlib.h>
|
||||||
|
#else
|
||||||
|
char *getenv ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
getopt_long (argc, argv, options, long_options, opt_index)
|
||||||
|
int argc;
|
||||||
|
char *const *argv;
|
||||||
|
const char *options;
|
||||||
|
const struct option *long_options;
|
||||||
|
int *opt_index;
|
||||||
|
{
|
||||||
|
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||||
|
If an option that starts with '-' (not '--') doesn't match a long option,
|
||||||
|
but does match a short option, it is parsed as a short option
|
||||||
|
instead. */
|
||||||
|
|
||||||
|
int
|
||||||
|
getopt_long_only (argc, argv, options, long_options, opt_index)
|
||||||
|
int argc;
|
||||||
|
char *const *argv;
|
||||||
|
const char *options;
|
||||||
|
const struct option *long_options;
|
||||||
|
int *opt_index;
|
||||||
|
{
|
||||||
|
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _LIBC or not __GNU_LIBRARY__. */
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (argc, argv)
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
int digit_optind = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int this_option_optind = optind ? optind : 1;
|
||||||
|
int option_index = 0;
|
||||||
|
static struct option long_options[] =
|
||||||
|
{
|
||||||
|
{"add", 1, 0, 0},
|
||||||
|
{"append", 0, 0, 0},
|
||||||
|
{"delete", 1, 0, 0},
|
||||||
|
{"verbose", 0, 0, 0},
|
||||||
|
{"create", 0, 0, 0},
|
||||||
|
{"file", 1, 0, 0},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||||
|
long_options, &option_index);
|
||||||
|
if (c == EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
printf ("option %s", long_options[option_index].name);
|
||||||
|
if (optarg)
|
||||||
|
printf (" with arg %s", optarg);
|
||||||
|
printf ("\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
|
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||||
|
printf ("digits occur in two different argv-elements.\n");
|
||||||
|
digit_optind = this_option_optind;
|
||||||
|
printf ("option %c\n", c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
printf ("option a\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
printf ("option b\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
printf ("option c with value `%s'\n", optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
printf ("option d with value `%s'\n", optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '?':
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
printf ("non-option ARGV-elements: ");
|
||||||
|
while (optind < argc)
|
||||||
|
printf ("%s ", argv[optind++]);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TEST */
|
168
src/info.c
Normal file
168
src/info.c
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: info.c,v 1.19 2003/04/13 19:15:58 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
print_wrap (char *str, int len, int *n)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
*n += len;
|
||||||
|
fprintf (stdout, str);
|
||||||
|
if (*n >= 50)
|
||||||
|
{
|
||||||
|
fprintf (stdout, "\n");
|
||||||
|
*n = 0;
|
||||||
|
}
|
||||||
|
else fprintf (stdout, " ");
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void
|
||||||
|
version (void)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
fprintf (stdout, "%s %s\n\n"
|
||||||
|
"Copyright (C) 2000, 2001, 2002, 2003 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 "
|
||||||
|
"2 of the License, or\n(at your option) any later version.\n\n",
|
||||||
|
APPNAME, VERSION);
|
||||||
|
fprintf (stdout, "Compilation options:\n");
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
print_wrap ("HAVE_DIRENT_H", 13, &n);
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
#ifdef HAVE_FCNTL
|
||||||
|
print_wrap ("HAVE_FCNTL", 10, &n);
|
||||||
|
#endif /* HAVE_FCNTL */
|
||||||
|
#ifdef HAVE_FLOCK
|
||||||
|
print_wrap ("HAVE_FLOCK", 10, &n);
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
#ifdef HAVE_FTS_OPEN
|
||||||
|
print_wrap ("HAVE_FTS_OPEN", 13, &n);
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_FTW
|
||||||
|
print_wrap ("HAVE_FTW", 8, &n);
|
||||||
|
# endif /* HAVE_FTW */
|
||||||
|
#endif /* HAVE_FTS_OPEN */
|
||||||
|
/*
|
||||||
|
fprintf (stdout, "HAVE_LIBLOCKFILE ");
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_LIBPCRE
|
||||||
|
print_wrap ("HAVE_LIBPCRE", 12, &n);
|
||||||
|
#endif /* HAVE_LIBPCRE */
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
print_wrap ("HAVE_LIBZ", 9, &n);
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
#ifdef HAVE_LIBBZ2
|
||||||
|
print_wrap ("HAVE_LIBBZ2", 11, &n);
|
||||||
|
#endif /* HAVE_LIBBZ2 */
|
||||||
|
#ifdef HAVE_NDIR_H
|
||||||
|
print_wrap ("HAVE_NDIR_H", 11, &n);
|
||||||
|
#endif /* HAVE_NDIR_H */
|
||||||
|
#ifdef HAVE_SYS_DIR_H
|
||||||
|
print_wrap ("HAVE_SYS_DIR_H", 14, &n);
|
||||||
|
#endif /* HAVE_SYS_DIR_H */
|
||||||
|
#ifdef HAVE_SYS_NDIR_H
|
||||||
|
print_wrap ("HAVE_SYS_NDIR_H", 15, &n);
|
||||||
|
#endif
|
||||||
|
fprintf (stdout, "\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void
|
||||||
|
help (void)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
fprintf(stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n",
|
||||||
|
APPNAME, VERSION);
|
||||||
|
fprintf(stdout,
|
||||||
|
"Miscellaneous:\n\n"
|
||||||
|
" -h, --help\t\t\tThis help screen\n"
|
||||||
|
" -V, --version\t\tDisplay version, copyright and\n"
|
||||||
|
"\t\t\t\tcompile-time options information\n"
|
||||||
|
" -r, --recursive\t\tDescend into directories recursively\n\n"
|
||||||
|
"Output control:\n\n"
|
||||||
|
" -c, --count\t\t\tPrint a count of matching messages\n"
|
||||||
|
" -d, --delete\t\t\tDelete matching messages\n"
|
||||||
|
" -nd, --no-duplicates\t\tIgnore duplicate messages\n"
|
||||||
|
" -o, --output=MAILBOX\t\tWrite messages to MAILBOX\n"
|
||||||
|
" -p, --pipe=COMMAND\t\tPipe each found message to COMMAND\n"
|
||||||
|
" -s, --no-messages\t\tSuppress most error messages\n\n"
|
||||||
|
"Matching criteria:\n\n"
|
||||||
|
" -E, --extended-regexp\tPATTERN is an extended regular expression\n"
|
||||||
|
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
|
||||||
|
#ifdef HAVE_LIBPCRE
|
||||||
|
fprintf(stdout,
|
||||||
|
" -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n");
|
||||||
|
#endif /* HAVE_LIBPCRE */
|
||||||
|
fprintf(stdout,
|
||||||
|
" -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n"
|
||||||
|
" -i, --ignore-case\t\tIgnore case distinctions\n"
|
||||||
|
" -v, --invert-match\t\tSelect non-matching messages\n\n"
|
||||||
|
"Search scope selection:\n\n"
|
||||||
|
" -H, --headers\t\tMatch PATTERN against message headers\n"
|
||||||
|
" -B, --body\t\t\tMatch PATTERN against message body\n\n"
|
||||||
|
"File locking:\n\n"
|
||||||
|
" -nl, --no-file-lock\t\tDo not lock files\n"
|
||||||
|
" -l, --file-lock=METHOD\tSelect file locking METHOD\n"
|
||||||
|
"\t\t\t\tMETHOD is");
|
||||||
|
#ifdef HAVE_FCNTL
|
||||||
|
fprintf(stdout, " `fcntl',");
|
||||||
|
#endif /* HAVE_FCNTL */
|
||||||
|
#ifdef HAVE_FLOCK
|
||||||
|
fprintf(stdout, " `flock',");
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
fprintf(stdout, " or `none'\n\n"
|
||||||
|
"Mailbox type selection:\n\n"
|
||||||
|
" -m, --mailbox-format=TYPE\tSelect mailbox TYPE\n"
|
||||||
|
"\t\t\t\tTYPE is `mbox', ");
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
fprintf(stdout, "`zmbox', ");
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
fprintf(stdout,
|
||||||
|
"`mh', `nnml',\n"
|
||||||
|
"\t\t\t\t`nnmh', or `maildir'.\n\n"
|
||||||
|
"Mail bug reports and flames to <%s>.\n", BUGREPORT_ADDR);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void
|
||||||
|
usage (void)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n"
|
||||||
|
"Try `%s --help' for more information.\n", APPNAME, APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
29
src/info.h
Normal file
29
src/info.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: info.h,v 1.5 2003/04/13 19:15:58 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef INFO_H
|
||||||
|
#define INFO_H
|
||||||
|
|
||||||
|
void print_wrap (char *str, int len, int *n);
|
||||||
|
void version (void);
|
||||||
|
void help (void);
|
||||||
|
void usage (void);
|
||||||
|
|
||||||
|
#endif /* INFO_H */
|
339
src/maildir.c
Normal file
339
src/maildir.c
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: maildir.c,v 1.21 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "maildir.h"
|
||||||
|
#include "wrap.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBDMALLOC
|
||||||
|
#include <dmalloc.h>
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
maildir_t *
|
||||||
|
maildir_open (const char *path)
|
||||||
|
{
|
||||||
|
static maildir_t *mp;
|
||||||
|
char *dirname;
|
||||||
|
DIR *foo;
|
||||||
|
|
||||||
|
foo = m_opendir (path);
|
||||||
|
if (foo == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
closedir (foo);
|
||||||
|
|
||||||
|
if (-1 == maildir_check (path))
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME, path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dirname = (char *) xmalloc((sizeof (char) * (strlen (path) + 5)));
|
||||||
|
|
||||||
|
mp = (maildir_t *) xmalloc(sizeof (maildir_t));
|
||||||
|
sprintf (dirname, "%s/new", path);
|
||||||
|
mp->new = m_opendir (dirname);
|
||||||
|
if (mp->new == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
free (dirname);
|
||||||
|
errno = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf (dirname, "%s/cur", path);
|
||||||
|
mp->cur = m_opendir (dirname);
|
||||||
|
if (mp->cur == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, dirname);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
free (dirname);
|
||||||
|
errno = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (dirname);
|
||||||
|
return mp;
|
||||||
|
} /* maildir_open */
|
||||||
|
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
if (mdp->new != NULL)
|
||||||
|
{
|
||||||
|
d_content = readdir (mdp->new);
|
||||||
|
if (d_content == NULL)
|
||||||
|
{
|
||||||
|
closedir (mdp->new);
|
||||||
|
mdp->new = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mdp->new == NULL && mdp->cur != NULL)
|
||||||
|
{
|
||||||
|
d_content = readdir (mdp->cur);
|
||||||
|
if (d_content == NULL)
|
||||||
|
{
|
||||||
|
closedir (mdp->cur);
|
||||||
|
mdp->cur = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mdp->new == NULL && mdp->cur == NULL)
|
||||||
|
{
|
||||||
|
free (message->headers);
|
||||||
|
free (message->body);
|
||||||
|
free (message);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d_content->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
filename =
|
||||||
|
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
|
||||||
|
+ (strlen (boxname)) + 6)));
|
||||||
|
|
||||||
|
/*
|
||||||
|
filename =
|
||||||
|
(char *) alloca((sizeof(char)*((strlen(d_content->d_name))
|
||||||
|
+ (strlen(boxname)) + 2)));
|
||||||
|
*/
|
||||||
|
if (mdp->new != NULL)
|
||||||
|
sprintf (filename, "%s/new/%s", boxname, d_content->d_name);
|
||||||
|
else
|
||||||
|
sprintf (filename, "%s/cur/%s", boxname, d_content->d_name);
|
||||||
|
message->filename = (char *) xstrdup (filename);
|
||||||
|
free (filename);
|
||||||
|
|
||||||
|
isheaders = 1;
|
||||||
|
fp = m_fopen(message->filename, "r");
|
||||||
|
|
||||||
|
if (fp == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
while (fgets (buffer, BUFSIZ, fp) != NULL)
|
||||||
|
{
|
||||||
|
s = strlen (buffer);
|
||||||
|
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
|
||||||
|
{
|
||||||
|
isheaders = 0;
|
||||||
|
continue;
|
||||||
|
} /* if */
|
||||||
|
if (isheaders)
|
||||||
|
{
|
||||||
|
if (0 == strncasecmp ("From: ", buffer, 6))
|
||||||
|
have_from = 1;
|
||||||
|
if (0 == strncasecmp ("Sender: ", buffer, 8))
|
||||||
|
have_sender = 1;
|
||||||
|
if (0 == strncasecmp ("Date: ", buffer, 6))
|
||||||
|
have_date = 1;
|
||||||
|
if (0 == strncasecmp ("To: ", buffer, 4))
|
||||||
|
have_to = 1;
|
||||||
|
if (0 == strncasecmp ("Message-ID: ", buffer, 12))
|
||||||
|
have_message_id = 1;
|
||||||
|
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
|
||||||
|
{
|
||||||
|
have_return_path = 1;
|
||||||
|
message->from = parse_return_path(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
message->headers =
|
||||||
|
(char *) xrealloc (message->headers,
|
||||||
|
((1 + s + message->hbytes) * sizeof (char)));
|
||||||
|
strcpy (message->headers + message->hbytes, buffer);
|
||||||
|
message->hbytes += s;
|
||||||
|
} /* if */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message->body =
|
||||||
|
(char *) xrealloc (message->body,
|
||||||
|
((1 + s + message->bbytes) * sizeof (char)));
|
||||||
|
strcpy (message->body + message->bbytes, buffer);
|
||||||
|
message->bbytes += s;
|
||||||
|
} /* else */
|
||||||
|
} /* while */
|
||||||
|
/* if (!have_from || !have_to || !have_message_id) */
|
||||||
|
if ((!have_from && !have_sender)|| !have_date)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf(stderr, "%s: %s: Not a RFC 2822 message\n",
|
||||||
|
APPNAME, message->filename);
|
||||||
|
fclose(fp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return message;
|
||||||
|
} /* for */
|
||||||
|
} /* maildir_read_message */
|
||||||
|
|
||||||
|
void
|
||||||
|
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++;
|
||||||
|
t = (int) time (NULL);
|
||||||
|
|
||||||
|
sprintf (bla, "%i.%i_%i.%s", t, config.pid, 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));
|
||||||
|
sprintf(s2, "%s/new/%s", path, bla);
|
||||||
|
|
||||||
|
f1 = m_fopen (s1, "w");
|
||||||
|
fprintf (f1, "%s\n%s", m->headers, m->body);
|
||||||
|
fclose (f1);
|
||||||
|
rename (s1, s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
maildir_check (const char *path)
|
||||||
|
{
|
||||||
|
static struct stat fs;
|
||||||
|
static int i;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
s = (char *) xmalloc ((strlen (path) + 5) * sizeof (char));
|
||||||
|
|
||||||
|
sprintf (s, "%s/cur", path);
|
||||||
|
i = stat (s, &fs);
|
||||||
|
if (-1 == i) return -1;
|
||||||
|
if (! S_ISDIR (fs.st_mode)) return -1;
|
||||||
|
|
||||||
|
sprintf (s, "%s/new", path);
|
||||||
|
i = stat (s, &fs);
|
||||||
|
if (-1 == i) return -1;
|
||||||
|
if (! S_ISDIR (fs.st_mode)) return -1;
|
||||||
|
|
||||||
|
sprintf(s, "%s/tmp", path);
|
||||||
|
i = stat (s, &fs);
|
||||||
|
if (-1 == i) return -1;
|
||||||
|
if (! S_ISDIR (fs.st_mode)) return -1;
|
||||||
|
|
||||||
|
free (s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
maildir_create (const char *path)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
s = (char *) xmalloc ((strlen (path) + 4) * sizeof(char));
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
sprintf(s, "%s", path);
|
||||||
|
i = mkdir (s, S_IRWXU);
|
||||||
|
if (-1 == i)
|
||||||
|
break;
|
||||||
|
sprintf(s, "%s/new", path);
|
||||||
|
i = mkdir (s, S_IRWXU);
|
||||||
|
if (-1 == i)
|
||||||
|
break;
|
||||||
|
sprintf(s, "%s/cur", path);
|
||||||
|
i = mkdir (s, S_IRWXU);
|
||||||
|
if (-1 == i)
|
||||||
|
break;
|
||||||
|
sprintf(s, "%s/tmp", path);
|
||||||
|
i = mkdir (s, S_IRWXU);
|
||||||
|
if (-1 == i)
|
||||||
|
break;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errno != 0)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s:%s: ", APPNAME, s);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
src/maildir.h
Normal file
58
src/maildir.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: maildir.h,v 1.6 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef MAILDIR_H
|
||||||
|
#define MAILDIR_H
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
DIR *new;
|
||||||
|
DIR *cur;
|
||||||
|
} maildir_t;
|
||||||
|
|
||||||
|
maildir_t *maildir_open (const char *path);
|
||||||
|
int maildir_check (const char *path);
|
||||||
|
void maildir_create (const char *path);
|
||||||
|
void maildir_close (maildir_t *mdp);
|
||||||
|
message_t *maildir_read_message (maildir_t *mdp);
|
||||||
|
void maildir_write_message (message_t *m, const char *path);
|
||||||
|
|
||||||
|
#endif /* MAILDIR_H */
|
375
src/main.c
Normal file
375
src/main.c
Normal file
@ -0,0 +1,375 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: main.c,v 1.32 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#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 */
|
||||||
|
|
||||||
|
#include "getopt.h"
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "mbox.h"
|
||||||
|
#include "mh.h"
|
||||||
|
#include "scan.h"
|
||||||
|
#include "wrap.h" /* xcalloc() et cetera */
|
||||||
|
|
||||||
|
#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 singlefile = 0;
|
||||||
|
|
||||||
|
int errcode = 0;
|
||||||
|
char errbuf[BUFSIZ];
|
||||||
|
|
||||||
|
static struct option long_options[] =
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
{"count", 0, 0, 'c'},
|
||||||
|
{"delete", 0, 0, 'd'},
|
||||||
|
/* {"date", 1, 0, 'D'}, */
|
||||||
|
{"extended-regexp", 0, 0, 'E'},
|
||||||
|
{"basic-regexp", 0, 0, 'G'},
|
||||||
|
{"perl-regexp", 0, 0, 'P'},
|
||||||
|
{"help", 0, 0, 'h'},
|
||||||
|
{"ignore-case", 0, 0, 'i'},
|
||||||
|
{"mailbox-format", 1, 0, 'm'},
|
||||||
|
{"no", 1, 0, 'n' },
|
||||||
|
{"pipe", 1, 0, 'p'},
|
||||||
|
{"regexp", 1, 0, 'e'},
|
||||||
|
{"invert-match", 0, 0, 'v'},
|
||||||
|
{"version", 0, 0, 'V'},
|
||||||
|
{"headers", 0, 0, 'H'},
|
||||||
|
{"body", 0, 0, 'B'},
|
||||||
|
{"no-messages", 0, 0, 's'},
|
||||||
|
{"output", 1, 0, 'o'},
|
||||||
|
{"no-duplicates", 0, 0, 200},
|
||||||
|
{"no-file-lock", 0, 0, 201},
|
||||||
|
{"file-lock", 1, 0, 'l'},
|
||||||
|
{"recursive", 0, 0, 'r'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
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 */
|
||||||
|
|
||||||
|
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 */
|
||||||
|
|
||||||
|
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 ();
|
||||||
|
}
|
||||||
|
|
||||||
|
cs = (checksum_t *) xmalloc (sizeof (checksum_t));
|
||||||
|
cs->md5 = (char **) xcalloc (1, sizeof (char **));
|
||||||
|
cs->n = 0;
|
||||||
|
|
||||||
|
if (optind < argc && ! haveregex)
|
||||||
|
{
|
||||||
|
regex_s = xstrdup (argv[optind]);
|
||||||
|
haveregex = 1;
|
||||||
|
++optind;
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
if (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
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 */
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
} /* if */
|
||||||
|
else
|
||||||
|
usage ();
|
||||||
|
|
||||||
|
if (optind == (argc - 1))
|
||||||
|
singlefile = 1;
|
||||||
|
|
||||||
|
while (optind < argc)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boxname = xstrdup (argv[optind]);
|
||||||
|
|
||||||
|
if (config.recursive)
|
||||||
|
recursive_scan (argv[optind]);
|
||||||
|
else
|
||||||
|
scan_mailbox (argv[optind]);
|
||||||
|
havemailbox = 1;
|
||||||
|
if (config.action == COUNT)
|
||||||
|
{
|
||||||
|
if (singlefile)
|
||||||
|
fprintf (stdout, "%i\n", count);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 == strcmp ("-", argv[optind]))
|
||||||
|
fprintf (stdout, "(standard input):%i\n", count);
|
||||||
|
else
|
||||||
|
fprintf (stdout, "%s:%i\n", argv[optind], 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]);
|
||||||
|
}
|
||||||
|
++optind;
|
||||||
|
} /* while */
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
if (! havemailbox)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
config.format = MBOX;
|
||||||
|
scan_mailbox ("-");
|
||||||
|
if (config.action == COUNT)
|
||||||
|
fprintf (stdout, "%i\n", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} /* main */
|
||||||
|
|
||||||
|
/* }}} */
|
400
src/mbox.c
Normal file
400
src/mbox.c
Normal file
@ -0,0 +1,400 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: mbox.c,v 1.26 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#ifdef HAVE_FLOCK
|
||||||
|
#include <sys/file.h>
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
#include <zlib.h>
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
#ifdef HAVE_LIBBZ2
|
||||||
|
#include <bzlib.h>
|
||||||
|
#endif /* HAVE_LIBBZ2 */
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include "mbox.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "wrap.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBDMALLOC
|
||||||
|
#include <dmalloc.h>
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
mbox_t *
|
||||||
|
mbox_open (const char *path, const char *mode)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
mbox_t *mp;
|
||||||
|
static int fd;
|
||||||
|
#ifndef HAVE_FLOCK
|
||||||
|
struct flock lck;
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
|
||||||
|
mp = (mbox_t *) xmalloc (sizeof (mbox_t));
|
||||||
|
mp->postmark_cache = (char *) xmalloc (BUFSIZ * sizeof (char));
|
||||||
|
|
||||||
|
if (0 == strcmp ("-", path))
|
||||||
|
mp->fp = stdin;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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),
|
||||||
|
(S_IWUSR | S_IRUSR));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
|
||||||
|
"get this error...", APPNAME, mode[0]);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, path);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.lock)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_FLOCK
|
||||||
|
int op;
|
||||||
|
|
||||||
|
if (mode[0] == 'r')
|
||||||
|
op = LOCK_SH;
|
||||||
|
else
|
||||||
|
op = LOCK_EX;
|
||||||
|
if (-1 == flock (fd, op))
|
||||||
|
#else
|
||||||
|
memset (&lck, 0, sizeof (struct flock));
|
||||||
|
lck.l_whence = SEEK_SET;
|
||||||
|
if (mode[0] == 'r')
|
||||||
|
lck.l_type = F_RDLCK;
|
||||||
|
else
|
||||||
|
lck.l_type = F_WRLCK;
|
||||||
|
|
||||||
|
if (-1 == fcntl (fd, F_SETLK, &lck))
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, path);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
close (fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (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;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void
|
||||||
|
mbox_close (mbox_t * mp)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
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 */
|
||||||
|
|
||||||
|
free (mp->postmark_cache);
|
||||||
|
free (mp);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
message_t *
|
||||||
|
mbox_read_message (mbox_t * mp)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
int isheaders = 1, s;
|
||||||
|
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;
|
||||||
|
|
||||||
|
s = strlen (mp->postmark_cache);
|
||||||
|
message->headers =
|
||||||
|
(char *) realloc (message->headers,
|
||||||
|
((1 + s + message->hbytes) * sizeof (char)));
|
||||||
|
strcpy (message->headers + message->hbytes, mp->postmark_cache);
|
||||||
|
message->hbytes += s;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (config.format == MBOX)
|
||||||
|
{
|
||||||
|
if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
|
||||||
|
{
|
||||||
|
if (isheaders)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
else if (config.format == ZMBOX)
|
||||||
|
{
|
||||||
|
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
|
||||||
|
{
|
||||||
|
if (isheaders)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#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';
|
||||||
|
|
||||||
|
if (buffer[0] == '\0')
|
||||||
|
{
|
||||||
|
if (isheaders)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* HAVE_LIBBZ2 */
|
||||||
|
|
||||||
|
s = strlen (buffer);
|
||||||
|
|
||||||
|
if (buffer[0] == '\n' && isheaders == 1)
|
||||||
|
{
|
||||||
|
isheaders = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isheaders)
|
||||||
|
{
|
||||||
|
message->headers =
|
||||||
|
(char *) realloc (message->headers,
|
||||||
|
((1 + s + message->hbytes) * sizeof (char)));
|
||||||
|
strcpy (message->headers + message->hbytes, buffer);
|
||||||
|
message->hbytes += s;
|
||||||
|
} /* if */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 == strncmp (buffer, "From ", 5))
|
||||||
|
{
|
||||||
|
strcpy (mp->postmark_cache, buffer);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
message->body =
|
||||||
|
(char *) realloc (message->body,
|
||||||
|
((1 + s + message->bbytes) * sizeof (char)));
|
||||||
|
strcpy (message->body + message->bbytes, buffer);
|
||||||
|
message->bbytes += s;
|
||||||
|
|
||||||
|
}
|
||||||
|
} /* for */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void *
|
||||||
|
tmpfile_open (const char *path)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
extern char *tmpfilename;
|
||||||
|
char *fname;
|
||||||
|
char *tmpdir;
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
if (path == NULL) { /* no path prefix given, use /tmp or TMPDIR */
|
||||||
|
tmpdir = getenv ("TMPDIR");
|
||||||
|
if (tmpdir == NULL)
|
||||||
|
tmpdir = xstrdup ("/tmp");
|
||||||
|
fname = xstrdup ("/mboxgrepXXXXXX");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmpdir = (char *)path;
|
||||||
|
fname = xstrdup (".XXXXXX");
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpfilename = (char *) xmalloc ((strlen (tmpdir) + (strlen (fname) + 1))
|
||||||
|
* sizeof (char));
|
||||||
|
sprintf (tmpfilename, "%s%s", tmpdir, fname);
|
||||||
|
foo = mkstemp (tmpfilename);
|
||||||
|
if (-1 == foo)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, 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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
41
src/mbox.h
Normal file
41
src/mbox.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: mbox.h,v 1.9 2003/08/24 19:23:50 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef MBOX_H
|
||||||
|
#define MBOX_H 1
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "mboxgrep.h" /* for message_t structure */
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void *fp;
|
||||||
|
void *fp_raw;
|
||||||
|
char *postmark_cache;
|
||||||
|
} mbox_t;
|
||||||
|
|
||||||
|
|
||||||
|
mbox_t *mbox_open (const char *path, const char *mode);
|
||||||
|
void *tmpfile_open (const char *path);
|
||||||
|
void mbox_close (mbox_t * mbp);
|
||||||
|
message_t *mbox_read_message (mbox_t * mbp);
|
||||||
|
|
||||||
|
#endif /* MBOX_H */
|
134
src/mboxgrep.h
Normal file
134
src/mboxgrep.h
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: mboxgrep.h,v 1.21 2003/04/06 21:01: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 HOST_NAME_SIZE 256
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <time.h> /* for tm structure */
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MBOX,
|
||||||
|
ZMBOX,
|
||||||
|
MH,
|
||||||
|
NNML,
|
||||||
|
NNMH,
|
||||||
|
MAILDIR,
|
||||||
|
BZ2MBOX
|
||||||
|
}
|
||||||
|
format_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
FCNTL,
|
||||||
|
FLOCK
|
||||||
|
}
|
||||||
|
lockmethod_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
DISPLAY,
|
||||||
|
WRITE,
|
||||||
|
COUNT,
|
||||||
|
DELETE,
|
||||||
|
PIPE
|
||||||
|
}
|
||||||
|
action_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char *filename; /* used with directory formats, such as maildir or MH */
|
||||||
|
char *msgid;
|
||||||
|
char *from;
|
||||||
|
char *headers;
|
||||||
|
int hbytes;
|
||||||
|
char *body;
|
||||||
|
int bbytes;
|
||||||
|
time_t date;
|
||||||
|
}
|
||||||
|
message_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
DIR *dp;
|
||||||
|
DIR *newp;
|
||||||
|
DIR *curp;
|
||||||
|
char *path;
|
||||||
|
}
|
||||||
|
folder_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char **md5;
|
||||||
|
int n;
|
||||||
|
}
|
||||||
|
checksum_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int extended;
|
||||||
|
int perl;
|
||||||
|
|
||||||
|
int body;
|
||||||
|
int headers;
|
||||||
|
int dedup;
|
||||||
|
int recursive;
|
||||||
|
int invert;
|
||||||
|
int count;
|
||||||
|
int ignorecase;
|
||||||
|
int merr;
|
||||||
|
int pid;
|
||||||
|
|
||||||
|
char hostname[HOST_NAME_SIZE];
|
||||||
|
|
||||||
|
action_t action;
|
||||||
|
format_t format;
|
||||||
|
lockmethod_t lock;
|
||||||
|
}
|
||||||
|
option_t;
|
||||||
|
|
||||||
|
option_t config;
|
||||||
|
|
||||||
|
#endif /* MBOXGREP_H */
|
443
src/md5.c
Normal file
443
src/md5.c
Normal file
@ -0,0 +1,443 @@
|
|||||||
|
/* Functions to compute MD5 message digest of files or memory blocks.
|
||||||
|
according to the definition of MD5 in RFC 1321 from April 1992.
|
||||||
|
Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#if STDC_HEADERS || defined _LIBC
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <string.h>
|
||||||
|
#else
|
||||||
|
# ifndef HAVE_MEMCPY
|
||||||
|
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "md5.h"
|
||||||
|
|
||||||
|
#ifdef _LIBC
|
||||||
|
# include <endian.h>
|
||||||
|
# if __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
# define WORDS_BIGENDIAN 1
|
||||||
|
# endif
|
||||||
|
/* We need to keep the namespace clean so define the MD5 function
|
||||||
|
protected using leading __ . */
|
||||||
|
# define md5_init_ctx __md5_init_ctx
|
||||||
|
# define md5_process_block __md5_process_block
|
||||||
|
# define md5_process_bytes __md5_process_bytes
|
||||||
|
# define md5_finish_ctx __md5_finish_ctx
|
||||||
|
# define md5_read_ctx __md5_read_ctx
|
||||||
|
# define md5_stream __md5_stream
|
||||||
|
# define md5_buffer __md5_buffer
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
# define SWAP(n) \
|
||||||
|
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
|
||||||
|
#else
|
||||||
|
# define SWAP(n) (n)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* This array contains the bytes used to pad the buffer to the next
|
||||||
|
64-byte boundary. (RFC 1321, 3.1: Step 1) */
|
||||||
|
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize structure containing state of computation.
|
||||||
|
(RFC 1321, 3.3: Step 3) */
|
||||||
|
void
|
||||||
|
md5_init_ctx (ctx)
|
||||||
|
struct md5_ctx *ctx;
|
||||||
|
{
|
||||||
|
ctx->A = 0x67452301;
|
||||||
|
ctx->B = 0xefcdab89;
|
||||||
|
ctx->C = 0x98badcfe;
|
||||||
|
ctx->D = 0x10325476;
|
||||||
|
|
||||||
|
ctx->total[0] = ctx->total[1] = 0;
|
||||||
|
ctx->buflen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put result from CTX in first 16 bytes following RESBUF. The result
|
||||||
|
must be in little endian byte order.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
||||||
|
aligned for a 32 bits value. */
|
||||||
|
void *
|
||||||
|
md5_read_ctx (ctx, resbuf)
|
||||||
|
const struct md5_ctx *ctx;
|
||||||
|
void *resbuf;
|
||||||
|
{
|
||||||
|
((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
|
||||||
|
((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
|
||||||
|
((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
|
||||||
|
((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
|
||||||
|
|
||||||
|
return resbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process the remaining bytes in the internal buffer and the usual
|
||||||
|
prolog according to the standard and write the result to RESBUF.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
||||||
|
aligned for a 32 bits value. */
|
||||||
|
void *
|
||||||
|
md5_finish_ctx (ctx, resbuf)
|
||||||
|
struct md5_ctx *ctx;
|
||||||
|
void *resbuf;
|
||||||
|
{
|
||||||
|
/* Take yet unprocessed bytes into account. */
|
||||||
|
md5_uint32 bytes = ctx->buflen;
|
||||||
|
size_t pad;
|
||||||
|
|
||||||
|
/* Now count remaining bytes. */
|
||||||
|
ctx->total[0] += bytes;
|
||||||
|
if (ctx->total[0] < bytes)
|
||||||
|
++ctx->total[1];
|
||||||
|
|
||||||
|
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
|
||||||
|
memcpy (&ctx->buffer[bytes], fillbuf, pad);
|
||||||
|
|
||||||
|
/* Put the 64-bit file length in *bits* at the end of the buffer. */
|
||||||
|
*(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
|
||||||
|
*(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
|
||||||
|
(ctx->total[0] >> 29));
|
||||||
|
|
||||||
|
/* Process last bytes. */
|
||||||
|
md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
|
||||||
|
|
||||||
|
return md5_read_ctx (ctx, resbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute MD5 message digest for bytes read from STREAM. The
|
||||||
|
resulting message digest number will be written into the 16 bytes
|
||||||
|
beginning at RESBLOCK. */
|
||||||
|
int
|
||||||
|
md5_stream (stream, resblock)
|
||||||
|
FILE *stream;
|
||||||
|
void *resblock;
|
||||||
|
{
|
||||||
|
/* Important: BLOCKSIZE must be a multiple of 64. */
|
||||||
|
#define BLOCKSIZE 4096
|
||||||
|
struct md5_ctx ctx;
|
||||||
|
char buffer[BLOCKSIZE + 72];
|
||||||
|
size_t sum;
|
||||||
|
|
||||||
|
/* Initialize the computation context. */
|
||||||
|
md5_init_ctx (&ctx);
|
||||||
|
|
||||||
|
/* Iterate over full file contents. */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
|
||||||
|
computation function processes the whole buffer so that with the
|
||||||
|
next round of the loop another block can be read. */
|
||||||
|
size_t n;
|
||||||
|
sum = 0;
|
||||||
|
|
||||||
|
/* Read block. Take care for partial reads. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
|
||||||
|
|
||||||
|
sum += n;
|
||||||
|
}
|
||||||
|
while (sum < BLOCKSIZE && n != 0);
|
||||||
|
if (n == 0 && ferror (stream))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* If end of file is reached, end the loop. */
|
||||||
|
if (n == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Process buffer with BLOCKSIZE bytes. Note that
|
||||||
|
BLOCKSIZE % 64 == 0
|
||||||
|
*/
|
||||||
|
md5_process_block (buffer, BLOCKSIZE, &ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the last bytes if necessary. */
|
||||||
|
if (sum > 0)
|
||||||
|
md5_process_bytes (buffer, sum, &ctx);
|
||||||
|
|
||||||
|
/* Construct result in desired memory. */
|
||||||
|
md5_finish_ctx (&ctx, resblock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
||||||
|
result is always in little endian byte order, so that a byte-wise
|
||||||
|
output yields to the wanted ASCII representation of the message
|
||||||
|
digest. */
|
||||||
|
void *
|
||||||
|
md5_buffer (buffer, len, resblock)
|
||||||
|
const char *buffer;
|
||||||
|
size_t len;
|
||||||
|
void *resblock;
|
||||||
|
{
|
||||||
|
struct md5_ctx ctx;
|
||||||
|
|
||||||
|
/* Initialize the computation context. */
|
||||||
|
md5_init_ctx (&ctx);
|
||||||
|
|
||||||
|
/* Process whole buffer but last len % 64 bytes. */
|
||||||
|
md5_process_bytes (buffer, len, &ctx);
|
||||||
|
|
||||||
|
/* Put result in desired memory area. */
|
||||||
|
return md5_finish_ctx (&ctx, resblock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
md5_process_bytes (buffer, len, ctx)
|
||||||
|
const void *buffer;
|
||||||
|
size_t len;
|
||||||
|
struct md5_ctx *ctx;
|
||||||
|
{
|
||||||
|
//const void aligned_buffer = buffer;
|
||||||
|
|
||||||
|
/* When we already have some bits in our internal buffer concatenate
|
||||||
|
both inputs first. */
|
||||||
|
if (ctx->buflen != 0)
|
||||||
|
{
|
||||||
|
size_t left_over = ctx->buflen;
|
||||||
|
size_t add = 128 - left_over > len ? len : 128 - left_over;
|
||||||
|
|
||||||
|
/* Only put full words in the buffer. */
|
||||||
|
add -= add % __alignof__ (md5_uint32);
|
||||||
|
|
||||||
|
memcpy (&ctx->buffer[left_over], buffer, add);
|
||||||
|
ctx->buflen += add;
|
||||||
|
|
||||||
|
if (ctx->buflen > 64)
|
||||||
|
{
|
||||||
|
md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
|
||||||
|
|
||||||
|
ctx->buflen &= 63;
|
||||||
|
/* The regions in the following copy operation cannot overlap. */
|
||||||
|
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
|
||||||
|
ctx->buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = (const char *) buffer + add;
|
||||||
|
len -= add;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process available complete blocks. */
|
||||||
|
if (len > 64)
|
||||||
|
{
|
||||||
|
md5_process_block (buffer, len & ~63, ctx);
|
||||||
|
buffer = (const char *) buffer + (len & ~63);
|
||||||
|
len &= 63;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move remaining bytes in internal buffer. */
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
size_t left_over = ctx->buflen;
|
||||||
|
|
||||||
|
memcpy (&ctx->buffer[left_over], buffer, len);
|
||||||
|
left_over += len;
|
||||||
|
if (left_over >= 64)
|
||||||
|
{
|
||||||
|
md5_process_block (ctx->buffer, 64, ctx);
|
||||||
|
left_over -= 64;
|
||||||
|
memcpy (ctx->buffer, &ctx->buffer[64], left_over);
|
||||||
|
}
|
||||||
|
ctx->buflen = left_over;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* These are the four functions used in the four steps of the MD5 algorithm
|
||||||
|
and defined in the RFC 1321. The first function is a little bit optimized
|
||||||
|
(as found in Colin Plumbs public domain implementation). */
|
||||||
|
/* #define FF(b, c, d) ((b & c) | (~b & d)) */
|
||||||
|
#define FF(b, c, d) (d ^ (b & (c ^ d)))
|
||||||
|
#define FG(b, c, d) FF (d, b, c)
|
||||||
|
#define FH(b, c, d) (b ^ c ^ d)
|
||||||
|
#define FI(b, c, d) (c ^ (b | ~d))
|
||||||
|
|
||||||
|
/* Process LEN bytes of BUFFER, accumulating context into CTX.
|
||||||
|
It is assumed that LEN % 64 == 0. */
|
||||||
|
|
||||||
|
void
|
||||||
|
md5_process_block (buffer, len, ctx)
|
||||||
|
const void *buffer;
|
||||||
|
size_t len;
|
||||||
|
struct md5_ctx *ctx;
|
||||||
|
{
|
||||||
|
md5_uint32 correct_words[16];
|
||||||
|
const md5_uint32 *words = buffer;
|
||||||
|
size_t nwords = len / sizeof (md5_uint32);
|
||||||
|
const md5_uint32 *endp = words + nwords;
|
||||||
|
md5_uint32 A = ctx->A;
|
||||||
|
md5_uint32 B = ctx->B;
|
||||||
|
md5_uint32 C = ctx->C;
|
||||||
|
md5_uint32 D = ctx->D;
|
||||||
|
|
||||||
|
/* First increment the byte count. RFC 1321 specifies the possible
|
||||||
|
length of the file up to 2^64 bits. Here we only compute the
|
||||||
|
number of bytes. Do a double word increment. */
|
||||||
|
ctx->total[0] += len;
|
||||||
|
if (ctx->total[0] < len)
|
||||||
|
++ctx->total[1];
|
||||||
|
|
||||||
|
/* Process all bytes in the buffer with 64 bytes in each round of
|
||||||
|
the loop. */
|
||||||
|
while (words < endp)
|
||||||
|
{
|
||||||
|
md5_uint32 *cwp = correct_words;
|
||||||
|
md5_uint32 A_save = A;
|
||||||
|
md5_uint32 B_save = B;
|
||||||
|
md5_uint32 C_save = C;
|
||||||
|
md5_uint32 D_save = D;
|
||||||
|
|
||||||
|
/* First round: using the given function, the context and a constant
|
||||||
|
the next context is computed. Because the algorithms processing
|
||||||
|
unit is a 32-bit word and it is determined to work on words in
|
||||||
|
little endian byte order we perhaps have to change the byte order
|
||||||
|
before the computation. To reduce the work for the next steps
|
||||||
|
we store the swapped words in the array CORRECT_WORDS. */
|
||||||
|
|
||||||
|
#define OP(a, b, c, d, s, T) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
|
||||||
|
++words; \
|
||||||
|
CYCLIC (a, s); \
|
||||||
|
a += b; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
/* It is unfortunate that C does not provide an operator for
|
||||||
|
cyclic rotation. Hope the C compiler is smart enough. */
|
||||||
|
#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
|
||||||
|
|
||||||
|
/* Before we start, one word to the strange constants.
|
||||||
|
They are defined in RFC 1321 as
|
||||||
|
|
||||||
|
T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Round 1. */
|
||||||
|
OP (A, B, C, D, 7, 0xd76aa478);
|
||||||
|
OP (D, A, B, C, 12, 0xe8c7b756);
|
||||||
|
OP (C, D, A, B, 17, 0x242070db);
|
||||||
|
OP (B, C, D, A, 22, 0xc1bdceee);
|
||||||
|
OP (A, B, C, D, 7, 0xf57c0faf);
|
||||||
|
OP (D, A, B, C, 12, 0x4787c62a);
|
||||||
|
OP (C, D, A, B, 17, 0xa8304613);
|
||||||
|
OP (B, C, D, A, 22, 0xfd469501);
|
||||||
|
OP (A, B, C, D, 7, 0x698098d8);
|
||||||
|
OP (D, A, B, C, 12, 0x8b44f7af);
|
||||||
|
OP (C, D, A, B, 17, 0xffff5bb1);
|
||||||
|
OP (B, C, D, A, 22, 0x895cd7be);
|
||||||
|
OP (A, B, C, D, 7, 0x6b901122);
|
||||||
|
OP (D, A, B, C, 12, 0xfd987193);
|
||||||
|
OP (C, D, A, B, 17, 0xa679438e);
|
||||||
|
OP (B, C, D, A, 22, 0x49b40821);
|
||||||
|
|
||||||
|
/* For the second to fourth round we have the possibly swapped words
|
||||||
|
in CORRECT_WORDS. Redefine the macro to take an additional first
|
||||||
|
argument specifying the function to use. */
|
||||||
|
#undef OP
|
||||||
|
#define OP(f, a, b, c, d, k, s, T) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
a += f (b, c, d) + correct_words[k] + T; \
|
||||||
|
CYCLIC (a, s); \
|
||||||
|
a += b; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
/* Round 2. */
|
||||||
|
OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
|
||||||
|
OP (FG, D, A, B, C, 6, 9, 0xc040b340);
|
||||||
|
OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
|
||||||
|
OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
|
||||||
|
OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
|
||||||
|
OP (FG, D, A, B, C, 10, 9, 0x02441453);
|
||||||
|
OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
|
||||||
|
OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
|
||||||
|
OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
|
||||||
|
OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
|
||||||
|
OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
|
||||||
|
OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
|
||||||
|
OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
|
||||||
|
OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
|
||||||
|
OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
|
||||||
|
OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
|
||||||
|
|
||||||
|
/* Round 3. */
|
||||||
|
OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
|
||||||
|
OP (FH, D, A, B, C, 8, 11, 0x8771f681);
|
||||||
|
OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
|
||||||
|
OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
|
||||||
|
OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
|
||||||
|
OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
|
||||||
|
OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
|
||||||
|
OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
|
||||||
|
OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
|
||||||
|
OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
|
||||||
|
OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
|
||||||
|
OP (FH, B, C, D, A, 6, 23, 0x04881d05);
|
||||||
|
OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
|
||||||
|
OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
|
||||||
|
OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
|
||||||
|
OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
|
||||||
|
|
||||||
|
/* Round 4. */
|
||||||
|
OP (FI, A, B, C, D, 0, 6, 0xf4292244);
|
||||||
|
OP (FI, D, A, B, C, 7, 10, 0x432aff97);
|
||||||
|
OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
|
||||||
|
OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
|
||||||
|
OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
|
||||||
|
OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
|
||||||
|
OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
|
||||||
|
OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
|
||||||
|
OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
|
||||||
|
OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
|
||||||
|
OP (FI, C, D, A, B, 6, 15, 0xa3014314);
|
||||||
|
OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
|
||||||
|
OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
|
||||||
|
OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
|
||||||
|
OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
|
||||||
|
OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
|
||||||
|
|
||||||
|
/* Add the starting values of the context. */
|
||||||
|
A += A_save;
|
||||||
|
B += B_save;
|
||||||
|
C += C_save;
|
||||||
|
D += D_save;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put checksum in context given as argument. */
|
||||||
|
ctx->A = A;
|
||||||
|
ctx->B = B;
|
||||||
|
ctx->C = C;
|
||||||
|
ctx->D = D;
|
||||||
|
}
|
140
src/md5.h
Normal file
140
src/md5.h
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
/* md5.h - Declaration of functions and data types used for MD5 sum
|
||||||
|
computing library functions.
|
||||||
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||||
|
NOTE: The canonical source of this file is maintained with the GNU C
|
||||||
|
Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
||||||
|
|
||||||
|
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, 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. */
|
||||||
|
|
||||||
|
#ifndef _MD5_H
|
||||||
|
#define _MD5_H 1
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#if defined HAVE_LIMITS_H || _LIBC
|
||||||
|
# include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The following contortions are an attempt to use the C preprocessor
|
||||||
|
to determine an unsigned integral type that is 32 bits wide. An
|
||||||
|
alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
|
||||||
|
doing that would require that the configure script compile and *run*
|
||||||
|
the resulting executable. Locally running cross-compiled executables
|
||||||
|
is usually not possible. */
|
||||||
|
|
||||||
|
#ifdef _LIBC
|
||||||
|
# include <sys/types.h>
|
||||||
|
typedef u_int32_t md5_uint32;
|
||||||
|
#else
|
||||||
|
# if defined __STDC__ && __STDC__
|
||||||
|
# define UINT_MAX_32_BITS 4294967295U
|
||||||
|
# else
|
||||||
|
# define UINT_MAX_32_BITS 0xFFFFFFFF
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
|
||||||
|
This should be valid for all systems GNU cares about because
|
||||||
|
that doesn't include 16-bit systems, and only modern systems
|
||||||
|
(that certainly have <limits.h>) have 64+-bit integral types. */
|
||||||
|
|
||||||
|
# ifndef UINT_MAX
|
||||||
|
# define UINT_MAX UINT_MAX_32_BITS
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if UINT_MAX == UINT_MAX_32_BITS
|
||||||
|
typedef unsigned int md5_uint32;
|
||||||
|
# else
|
||||||
|
# if USHRT_MAX == UINT_MAX_32_BITS
|
||||||
|
typedef unsigned short md5_uint32;
|
||||||
|
# else
|
||||||
|
# if ULONG_MAX == UINT_MAX_32_BITS
|
||||||
|
typedef unsigned long md5_uint32;
|
||||||
|
# else
|
||||||
|
/* The following line is intended to evoke an error.
|
||||||
|
Using #error is not portable enough. */
|
||||||
|
"Cannot determine unsigned 32-bit data type."
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Structure to save state of computation between the single steps. */
|
||||||
|
struct md5_ctx
|
||||||
|
{
|
||||||
|
md5_uint32 A;
|
||||||
|
md5_uint32 B;
|
||||||
|
md5_uint32 C;
|
||||||
|
md5_uint32 D;
|
||||||
|
|
||||||
|
md5_uint32 total[2];
|
||||||
|
md5_uint32 buflen;
|
||||||
|
char buffer[128];
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following three functions are build up the low level used in
|
||||||
|
* the functions `md5_stream' and `md5_buffer'.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Initialize structure containing state of computation.
|
||||||
|
(RFC 1321, 3.3: Step 3) */
|
||||||
|
extern void md5_init_ctx (struct md5_ctx *ctx);
|
||||||
|
|
||||||
|
/* Starting with the result of former calls of this function (or the
|
||||||
|
initialization function update the context for the next LEN bytes
|
||||||
|
starting at BUFFER.
|
||||||
|
It is necessary that LEN is a multiple of 64!!! */
|
||||||
|
extern void md5_process_block (const void *buffer, size_t len,
|
||||||
|
struct md5_ctx *ctx);
|
||||||
|
|
||||||
|
/* Starting with the result of former calls of this function (or the
|
||||||
|
initialization function update the context for the next LEN bytes
|
||||||
|
starting at BUFFER.
|
||||||
|
It is NOT required that LEN is a multiple of 64. */
|
||||||
|
extern void md5_process_bytes (const void *buffer, size_t len,
|
||||||
|
struct md5_ctx *ctx);
|
||||||
|
|
||||||
|
/* Process the remaining bytes in the buffer and put result from CTX
|
||||||
|
in first 16 bytes following RESBUF. The result is always in little
|
||||||
|
endian byte order, so that a byte-wise output yields to the wanted
|
||||||
|
ASCII representation of the message digest.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
||||||
|
aligned for a 32 bits value. */
|
||||||
|
extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
|
||||||
|
|
||||||
|
|
||||||
|
/* Put result from CTX in first 16 bytes following RESBUF. The result is
|
||||||
|
always in little endian byte order, so that a byte-wise output yields
|
||||||
|
to the wanted ASCII representation of the message digest.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
||||||
|
aligned for a 32 bits value. */
|
||||||
|
extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
|
||||||
|
|
||||||
|
|
||||||
|
/* Compute MD5 message digest for bytes read from STREAM. The
|
||||||
|
resulting message digest number will be written into the 16 bytes
|
||||||
|
beginning at RESBLOCK. */
|
||||||
|
extern int md5_stream (FILE *stream, void *resblock);
|
||||||
|
|
||||||
|
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
||||||
|
result is always in little endian byte order, so that a byte-wise
|
||||||
|
output yields to the wanted ASCII representation of the message
|
||||||
|
digest. */
|
||||||
|
extern void *md5_buffer (const char *buffer, size_t len,
|
||||||
|
void *resblock);
|
||||||
|
|
||||||
|
#endif
|
239
src/mh.c
Normal file
239
src/mh.c
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: mh.c,v 1.15 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "mh.h"
|
||||||
|
#include "wrap.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBDMALLOC
|
||||||
|
# include <dmalloc.h>
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
extern option_t config;
|
||||||
|
|
||||||
|
DIR *mh_open (const char *path)
|
||||||
|
{
|
||||||
|
DIR *dp;
|
||||||
|
|
||||||
|
dp = opendir (path);
|
||||||
|
if (dp == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, path);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return dp;
|
||||||
|
} /* mh_open */
|
||||||
|
|
||||||
|
void mh_close (DIR *dp)
|
||||||
|
{
|
||||||
|
closedir (dp);
|
||||||
|
} /* mh_close */
|
||||||
|
|
||||||
|
message_t *mh_read_message (DIR *dp)
|
||||||
|
{
|
||||||
|
int isheaders = 1;
|
||||||
|
int have_from = 0, have_return_path = 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;
|
||||||
|
|
||||||
|
filename = NULL;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
d_content = readdir(dp);
|
||||||
|
if (d_content == NULL) return NULL;
|
||||||
|
if (d_content->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
filename = (char *) xrealloc
|
||||||
|
(filename, ((strlen (d_content->d_name)) +
|
||||||
|
(strlen (boxname)) + 2));
|
||||||
|
|
||||||
|
/* message->headers = (char *) xrealloc (message->headers, 0); */
|
||||||
|
/* message->hbytes = 0; */
|
||||||
|
/* message->body = (char *) xrealloc (message->body, 0); */
|
||||||
|
/* message->bbytes = 0; */
|
||||||
|
|
||||||
|
filename[0] = '\0';
|
||||||
|
sprintf (filename, "%s/%s", boxname, d_content->d_name);
|
||||||
|
fp = m_fopen (filename, "r");
|
||||||
|
isheaders = 1;
|
||||||
|
if (fp == NULL)
|
||||||
|
{
|
||||||
|
free (message->headers);
|
||||||
|
free (message->body);
|
||||||
|
message->hbytes = 0;
|
||||||
|
message->bbytes = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fgets (buffer, BUFSIZ, fp);
|
||||||
|
|
||||||
|
/* if (config.format == NNML || config.format == NNMH) */
|
||||||
|
/* { */
|
||||||
|
/* if (0 != strncmp ("X-From-Line: ", buffer, 13)) */
|
||||||
|
/* { */
|
||||||
|
/* if (config.merr) */
|
||||||
|
/* fprintf (stderr, "%s: %s: Not a Gnus folder message\n", */
|
||||||
|
/* APPNAME, filename); */
|
||||||
|
/* fclose (fp); */
|
||||||
|
/* free (message->headers); */
|
||||||
|
/* free (message->body); */
|
||||||
|
/* message->hbytes = 0; */
|
||||||
|
/* message->bbytes = 0; */
|
||||||
|
/* continue; */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
fseek (fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
while (fgets (buffer, BUFSIZ, fp) != NULL)
|
||||||
|
{
|
||||||
|
s = strlen (buffer);
|
||||||
|
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
|
||||||
|
{
|
||||||
|
isheaders = 0;
|
||||||
|
continue;
|
||||||
|
} /* if */
|
||||||
|
if (isheaders)
|
||||||
|
{
|
||||||
|
if (0 == strncasecmp ("From: ", buffer, 6))
|
||||||
|
have_from = 1;
|
||||||
|
if (0 == strncasecmp ("Sender: ", buffer, 8))
|
||||||
|
have_sender = 1;
|
||||||
|
if (0 == strncasecmp ("Date: ", buffer, 6))
|
||||||
|
have_date = 1;
|
||||||
|
if (0 == strncasecmp ("Return-Path: ", buffer, 13))
|
||||||
|
{
|
||||||
|
have_return_path = 1;
|
||||||
|
message->from = parse_return_path (buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
message->headers =
|
||||||
|
(char *) realloc (message->headers,
|
||||||
|
((1 + s + message->hbytes) * sizeof (char)));
|
||||||
|
strcpy (message->headers + message->hbytes, buffer);
|
||||||
|
message->hbytes += s;
|
||||||
|
} /* if */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message->body =
|
||||||
|
(char *) realloc (message->body,
|
||||||
|
((1 + s + message->bbytes) * sizeof (char)));
|
||||||
|
strcpy (message->body + message->bbytes, buffer);
|
||||||
|
message->bbytes += s;
|
||||||
|
} /* else */
|
||||||
|
} /* while */
|
||||||
|
|
||||||
|
if ((!have_from && !have_sender)|| !have_date)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf (stderr, "%s: %s: Not a RFC 2822 message\n",
|
||||||
|
APPNAME, filename);
|
||||||
|
fclose (fp);
|
||||||
|
free (message->headers);
|
||||||
|
message->headers = NULL;
|
||||||
|
free (message->body);
|
||||||
|
message->body = NULL;
|
||||||
|
message->hbytes = 0;
|
||||||
|
message->bbytes = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message->filename = (char *) xstrdup (filename);
|
||||||
|
fclose (fp);
|
||||||
|
free (filename);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
} /* for */
|
||||||
|
} /* mh_read_message */
|
||||||
|
|
||||||
|
void mh_write_message (message_t *m, const char *path)
|
||||||
|
{
|
||||||
|
struct dirent *dc;
|
||||||
|
int x, y = 0;
|
||||||
|
char s1[BUFSIZ];
|
||||||
|
DIR *d; FILE *f;
|
||||||
|
|
||||||
|
d = m_opendir (path);
|
||||||
|
rewinddir (d);
|
||||||
|
|
||||||
|
while ((dc = readdir (d)) != NULL)
|
||||||
|
{
|
||||||
|
x = strtol (dc->d_name, NULL, 10);
|
||||||
|
if (x > y)
|
||||||
|
y = x;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
sprintf (s1, "%s/%i", path, y);
|
||||||
|
|
||||||
|
f = m_fopen (s1, "w");
|
||||||
|
fprintf (f, "%s\n%s", m->headers, m->body);
|
||||||
|
fclose (f);
|
||||||
|
}
|
47
src/mh.h
Normal file
47
src/mh.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: mh.h,v 1.6 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef MH_H
|
||||||
|
#define MH_H 1
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
|
||||||
|
DIR *mh_open (const char *path);
|
||||||
|
void mh_close (DIR *dp);
|
||||||
|
message_t *mh_read_message (DIR *dp);
|
||||||
|
void mh_write_message (message_t *m, const char *path);
|
||||||
|
|
||||||
|
#endif /* MH_H */
|
137
src/misc.c
Normal file
137
src/misc.c
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: misc.c,v 1.13 2003/04/06 21:01: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)
|
||||||
|
* from string.h. */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include "wrap.h"
|
||||||
|
|
||||||
|
format_t
|
||||||
|
folder_format (const char *name)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
format_t f;
|
||||||
|
|
||||||
|
if (0 == strncasecmp (name, "mbox", 4))
|
||||||
|
f = MBOX;
|
||||||
|
else if (0 == strncasecmp (name, "zmbox", 5))
|
||||||
|
f = ZMBOX;
|
||||||
|
else if (0 == strncasecmp (name, "gzmbox", 6))
|
||||||
|
f = ZMBOX;
|
||||||
|
else if (0 == strncasecmp (name, "bzmbox", 5))
|
||||||
|
f = BZ2MBOX;
|
||||||
|
else if (0 == strncasecmp (name, "bz2mbox", 5))
|
||||||
|
f = BZ2MBOX;
|
||||||
|
else if (0 == strncasecmp (name, "mh", 2))
|
||||||
|
f = MH;
|
||||||
|
else if (0 == strncasecmp (name, "nnml", 4))
|
||||||
|
f = NNML;
|
||||||
|
else if (0 == strncasecmp (name, "nnmh", 4))
|
||||||
|
f = NNMH;
|
||||||
|
else if (0 == strncasecmp (name, "maildir", 7))
|
||||||
|
f = MAILDIR;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf (stderr, "mboxgrep: %s: unknown folder type\n", name);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
lockmethod_t lock_method (const char *name)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
lockmethod_t l;
|
||||||
|
|
||||||
|
if (0 == strncasecmp (name, "none", 4))
|
||||||
|
l = NONE;
|
||||||
|
else if (0 == strncasecmp (name, "off", 3))
|
||||||
|
l = NONE;
|
||||||
|
#ifdef HAVE_FCNTL
|
||||||
|
else if (0 == strncasecmp (name, "fcntl", 5))
|
||||||
|
l = FCNTL;
|
||||||
|
#endif /* HAVE_FCNTL */
|
||||||
|
#ifdef HAVE_FLOCK
|
||||||
|
else if (0 == strncasecmp (name, "flock", 5))
|
||||||
|
l = FLOCK;
|
||||||
|
#endif /* HAVE_FLOCK */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf (stderr, "mboxgrep: %s: unknown file locking method\n", name);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* time_t parse_date(char *datestr) */
|
||||||
|
/* {{{ */
|
||||||
|
/* { */
|
||||||
|
/* time_t t; */
|
||||||
|
/* const char *fmt = "%d%n%b%n%Y%n%T"; */
|
||||||
|
/* int h, m; */
|
||||||
|
/* struct tm tm; */
|
||||||
|
/* char *str2, str1[BUFSIZ]; */
|
||||||
|
|
||||||
|
/* sscanf (datestr, "Date: %[^\r\n]", str1); */
|
||||||
|
|
||||||
|
/* str2 = (char *) strptime (str1, "%d%n%b%n%Y%n%T", &tm); */
|
||||||
|
/* if (str2 == NULL) */
|
||||||
|
/* str2 = (char *) strptime (str1, "%a, %d%n%b%n%Y%n%T", &tm); */
|
||||||
|
/* if (str2 == NULL) */
|
||||||
|
/* return (time_t) 0; */
|
||||||
|
|
||||||
|
/* if (sscanf (str2, "%3d%2d", &h, &m) == 2) */
|
||||||
|
/* { */
|
||||||
|
/* tm.tm_hour -= h; */
|
||||||
|
/* tm.tm_min -= (h >= 0 ? m : -m); */
|
||||||
|
/* t = (time_t) mktime (&tm); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* return t; */
|
||||||
|
/* } */
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
char * parse_return_path(char *rpath)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
char *blah1, blah2[BUFSIZ];
|
||||||
|
|
||||||
|
sscanf(rpath, "Return-Path: <%[^\r\n>]>", blah2);
|
||||||
|
blah1 = xstrdup (blah2);
|
||||||
|
|
||||||
|
return blah1;
|
||||||
|
}
|
||||||
|
/* }}} */
|
32
src/misc.h
Normal file
32
src/misc.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: misc.h,v 1.5 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef MISC_H
|
||||||
|
#define MISC_H 1
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
format_t folder_format (const char *name);
|
||||||
|
lockmethod_t lock_method (const char *name);
|
||||||
|
time_t parse_date(char *datestr);
|
||||||
|
char * parse_return_path(char *rpath);
|
||||||
|
|
||||||
|
#endif /* MISC_H */
|
349
src/scan.c
Normal file
349
src/scan.c
Normal file
@ -0,0 +1,349 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: scan.c,v 1.21 2003/04/06 21:01:49 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <regex.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
|
||||||
|
#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 "scan.h"
|
||||||
|
#include "mbox.h"
|
||||||
|
#include "mh.h"
|
||||||
|
#include "maildir.h"
|
||||||
|
#include "wrap.h"
|
||||||
|
#include "md5.h"
|
||||||
|
#ifdef HAVE_FTS_OPEN
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <fts.h>
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_FTW
|
||||||
|
# include <ftw.h>
|
||||||
|
# endif /* HAVE_FTW */
|
||||||
|
#endif /* HAVE_FTS_OPEN */
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBDMALLOC
|
||||||
|
#include <dmalloc.h>
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
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! */
|
||||||
|
if (foo == NULL && errno == ENOENT)
|
||||||
|
maildir_create (outboxname);
|
||||||
|
else closedir (foo);
|
||||||
|
|
||||||
|
if (-1 == maildir_check (outboxname))
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
fprintf (stderr, "%s: %s: Not a maildir folder\n", APPNAME,
|
||||||
|
outboxname);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
if (config.action == DELETE)
|
||||||
|
delete = 1;
|
||||||
|
|
||||||
|
if ((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||||
|
(config.format == BZ2MBOX))
|
||||||
|
{
|
||||||
|
mbox = (mbox_t *) mbox_open (path, "r");
|
||||||
|
if (mbox == NULL) return;
|
||||||
|
}
|
||||||
|
else if ((config.format == MH) || (config.format == NNMH) ||
|
||||||
|
(config.format == NNML))
|
||||||
|
{
|
||||||
|
boxd = mh_open (path);
|
||||||
|
if (boxd == NULL) return;
|
||||||
|
}
|
||||||
|
else if (config.format == MAILDIR)
|
||||||
|
{
|
||||||
|
maildird = maildir_open (path);
|
||||||
|
if (maildird == NULL) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int res1 = 1, res2 = 1;
|
||||||
|
|
||||||
|
if ((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||||
|
(config.format == BZ2MBOX))
|
||||||
|
msg = (message_t *) mbox_read_message (mbox);
|
||||||
|
else if ((config.format == MH) || (config.format == NNMH) ||
|
||||||
|
(config.format == NNML))
|
||||||
|
msg = (message_t *) mh_read_message (boxd);
|
||||||
|
else if (config.format == MAILDIR)
|
||||||
|
msg = (message_t *) maildir_read_message (maildird);
|
||||||
|
|
||||||
|
if (msg == NULL) break;
|
||||||
|
|
||||||
|
if (msg->from == NULL) msg->from = (char *) xstrdup ("nobody");
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.dedup)
|
||||||
|
isdup = md5_check_message (msg->body, cs);
|
||||||
|
|
||||||
|
if (((res1 == 0) | (res2 == 0)) ^ ((config.invert ^ delete)) &&
|
||||||
|
((config.dedup && !isdup) || !config.dedup))
|
||||||
|
{
|
||||||
|
if (config.action == DISPLAY)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
fprintf (stdout, "%s\n%s", msg->headers, msg->body);
|
||||||
|
}
|
||||||
|
else if (config.action == WRITE)
|
||||||
|
{
|
||||||
|
if (config.format == MAILDIR)
|
||||||
|
maildir_write_message (msg, outboxname);
|
||||||
|
else if (config.format == MH || config.format == NNMH ||
|
||||||
|
config.format == NNML)
|
||||||
|
mh_write_message (msg, outboxname);
|
||||||
|
else if (config.format == MBOX)
|
||||||
|
{
|
||||||
|
out = mbox_open (outboxname, "w");
|
||||||
|
fprintf (out->fp, "%s\n%s", msg->headers, msg->body);
|
||||||
|
mbox_close (out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (config.action == PIPE)
|
||||||
|
{
|
||||||
|
outf = popen (pipecmd, "w");
|
||||||
|
if (outf == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, pipecmd);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
exit (2);
|
||||||
|
} /* if */
|
||||||
|
fprintf (outf, "%s\n%s", msg->headers, msg->body);
|
||||||
|
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;
|
||||||
|
|
||||||
|
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) &&
|
||||||
|
((config.format == MH) || (config.format == NNMH) ||
|
||||||
|
(config.format == NNML) || (config.format == MAILDIR)))
|
||||||
|
m_unlink(msg->filename);
|
||||||
|
|
||||||
|
free(msg->body);
|
||||||
|
free(msg->headers);
|
||||||
|
free(msg);
|
||||||
|
} /* for */
|
||||||
|
if ((config.format == MBOX) || (config.format == ZMBOX) ||
|
||||||
|
(config.format == BZ2MBOX))
|
||||||
|
mbox_close (mbox);
|
||||||
|
else if ((config.format == MH) || (config.format == NNMH) ||
|
||||||
|
(config.format == NNML))
|
||||||
|
mh_close(boxd);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
void recursive_scan (char path[])
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
|
{
|
||||||
|
#ifdef HAVE_FTS_OPEN
|
||||||
|
FTS *ftsfoo;
|
||||||
|
FTSENT *ftsbar;
|
||||||
|
#endif /* HAVE_FTS_OPEN */
|
||||||
|
|
||||||
|
#ifdef HAVE_FTS_OPEN
|
||||||
|
{
|
||||||
|
char *p[2];
|
||||||
|
|
||||||
|
p[0] = strdup (path);
|
||||||
|
p[1] = 0;
|
||||||
|
|
||||||
|
ftsfoo = fts_open (p, FTS_NOCHDIR, NULL);
|
||||||
|
|
||||||
|
if (ftsfoo == NULL)
|
||||||
|
{
|
||||||
|
/* fixme (?) */
|
||||||
|
perror(APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((ftsbar = fts_read (ftsfoo)))
|
||||||
|
scan_mailbox (ftsbar->fts_path);
|
||||||
|
|
||||||
|
fts_close (ftsfoo);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ftw (path, (void *) scan_mailbox, 1);
|
||||||
|
#endif /* HAVE_FTS_OPEN */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
int md5_check_message (char *body, checksum_t *chksum)
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
struct md5_ctx a;
|
||||||
|
unsigned char b[16];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
md5_init_ctx (&a);
|
||||||
|
if (body == NULL)
|
||||||
|
md5_process_bytes ("", 0, &a);
|
||||||
|
else
|
||||||
|
md5_process_bytes (body, strlen(body), &a);
|
||||||
|
md5_finish_ctx(&a, b);
|
||||||
|
|
||||||
|
for (i = 0; i < chksum->n; i++)
|
||||||
|
{
|
||||||
|
if (0 == strncmp (chksum->md5[i], b, 16))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
chksum->md5 =
|
||||||
|
(char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
|
||||||
|
chksum->md5[chksum->n] = xstrdup (b);
|
||||||
|
|
||||||
|
(chksum->n)++;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* }}} */
|
30
src/scan.h
Normal file
30
src/scan.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: scan.h,v 1.7 2003/03/30 23:07:10 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#ifndef SCAN_H
|
||||||
|
#define SCAN_H 1
|
||||||
|
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
|
||||||
|
void scan_mailbox (char path[]);
|
||||||
|
void recursive_scan (char path[]);
|
||||||
|
int md5_check_message (char *body, checksum_t *chksum);
|
||||||
|
|
||||||
|
#endif /* SCAN_H */
|
216
src/wrap.c
Normal file
216
src/wrap.c
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: wrap.c,v 1.12 2003/04/06 23:24:04 dspiljar Exp $ */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
#include <zlib.h>
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "wrap.h"
|
||||||
|
#include "mboxgrep.h"
|
||||||
|
|
||||||
|
#ifndef APPNAME
|
||||||
|
#define APPNAME "mboxgrep"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int m_open (const char *pathname, int flags, mode_t mode)
|
||||||
|
{
|
||||||
|
int blah;
|
||||||
|
|
||||||
|
blah = open (pathname, flags, mode);
|
||||||
|
if (blah == -1 && config.merr)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
/* failure to open a file for writing should be fatal */
|
||||||
|
if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR))
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *m_fopen (const char *path, const char *mode)
|
||||||
|
{
|
||||||
|
FILE *blah;
|
||||||
|
|
||||||
|
blah = fopen (path, mode);
|
||||||
|
if (blah == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, path);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
if (mode[0] == 'w')
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *m_fdopen (int fildes, const char *mode)
|
||||||
|
{
|
||||||
|
FILE *blah;
|
||||||
|
|
||||||
|
blah = fdopen (fildes, mode);
|
||||||
|
if (blah == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
}
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
|
||||||
|
gzFile *m_gzdopen (int fildes, const char *mode)
|
||||||
|
{
|
||||||
|
gzFile *blah;
|
||||||
|
|
||||||
|
blah = gzdopen (fildes, mode);
|
||||||
|
if (blah == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
}
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
|
||||||
|
DIR *m_opendir (const char *name)
|
||||||
|
{
|
||||||
|
DIR *blah;
|
||||||
|
|
||||||
|
blah = opendir (name);
|
||||||
|
if (blah == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, name);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBDMALLOC
|
||||||
|
|
||||||
|
void *xmalloc (size_t size)
|
||||||
|
{
|
||||||
|
void *foo;
|
||||||
|
|
||||||
|
foo = malloc (size);
|
||||||
|
if (foo == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *xrealloc (void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
void *foo;
|
||||||
|
|
||||||
|
foo = realloc (ptr, size);
|
||||||
|
if (foo == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *xcalloc (size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
void *foo;
|
||||||
|
|
||||||
|
foo = calloc (nmemb, size);
|
||||||
|
if (foo == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *xstrdup (const char *s)
|
||||||
|
{
|
||||||
|
char *foo;
|
||||||
|
|
||||||
|
foo = strdup (s);
|
||||||
|
if (foo == NULL)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
perror (APPNAME);
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
int m_unlink (const char *pathname)
|
||||||
|
{
|
||||||
|
int baz;
|
||||||
|
|
||||||
|
baz = unlink (pathname);
|
||||||
|
if (baz == -1)
|
||||||
|
{
|
||||||
|
if (config.merr)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: ", APPNAME, pathname);
|
||||||
|
perror (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return baz;
|
||||||
|
}
|
||||||
|
|
74
src/wrap.h
Normal file
74
src/wrap.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* -*- C -*-
|
||||||
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
|
Copyright (C) 2000, 2001, 2002, 2003 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: wrap.h,v 1.11 2003/04/06 23:24:04 dspiljar Exp $ */
|
||||||
|
|
||||||
|
/* This file is part of mboxgrep. */
|
||||||
|
|
||||||
|
/* wrappers around certain std functions */
|
||||||
|
|
||||||
|
#ifndef WRAP_H
|
||||||
|
#define WRAP_H
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif /* HAVE_SYS_NDIR_H */
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif /* HAVE_SYS_DIR_H */
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif /* HAVE_NDIR_H */
|
||||||
|
#endif /* HAVE_DIRENT_H */
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
#include <zlib.h>
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBDMALLOC
|
||||||
|
# include <dmalloc.h>
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
int m_open (const char *pathname, int flags, mode_t mode);
|
||||||
|
|
||||||
|
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);
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
|
||||||
|
DIR *m_opendir (const char *name);
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBDMALLOC
|
||||||
|
void *xmalloc (size_t size);
|
||||||
|
void *xrealloc (void *ptr, size_t size);
|
||||||
|
void *xcalloc (size_t nmemb, size_t size);
|
||||||
|
char *xstrdup (const char *s);
|
||||||
|
#endif /* HAVE_LIBDMALLOC */
|
||||||
|
|
||||||
|
int m_unlink (const char *pathname);
|
||||||
|
|
||||||
|
#endif /* WRAP_H */
|
Loading…
Reference in New Issue
Block a user