Compare commits
No commits in common. "5cc84ca1bd62225ccaf70fe13c11a1a98cad18f1" and "7dd6f3d69db0e8b80540b8edeee8e2ac8c26f201" have entirely different histories.
5cc84ca1bd
...
7dd6f3d69d
@ -1,4 +1,5 @@
|
|||||||
.TH MBOXGREP 1 "17 Feb 2023"
|
.Id $Id: mboxgrep.1,v 1.16 2006-01-18 00:09:58 dspiljar Exp $
|
||||||
|
.TH MBOXGREP 1 "26 Jan 2023"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
mboxgrep \- displays email messages matching a pattern
|
mboxgrep \- displays email messages matching a pattern
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -85,10 +86,6 @@ Ignore duplicate messages.
|
|||||||
Select input and output mailbox TYPE. TYPE can be either `mbox' (default),
|
Select input and output mailbox TYPE. TYPE can be either `mbox' (default),
|
||||||
`zmbox' (gzip compressed mbox), `bz2mbox' (bzip2 compressed mbox), `mh', `nnml',
|
`zmbox' (gzip compressed mbox), `bz2mbox' (bzip2 compressed mbox), `mh', `nnml',
|
||||||
`nnmh' or `maildir'.
|
`nnmh' or `maildir'.
|
||||||
.IP "-s, --no-messages"
|
|
||||||
Suppress most error messages.
|
|
||||||
.IP "--debug"
|
|
||||||
Print messages useful for debugging.
|
|
||||||
.SH EXAMPLES
|
.SH EXAMPLES
|
||||||
.TP
|
.TP
|
||||||
\(bu
|
\(bu
|
||||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
@set EDITION 0.7
|
@set EDITION 0.7
|
||||||
@set VERSION 0.7.10
|
@set VERSION 0.7.10
|
||||||
@set UPDATED 17 Feb 2023
|
@set UPDATED 26 Jan 2023
|
||||||
|
|
||||||
@dircategory Mail
|
@dircategory Mail
|
||||||
@direntry
|
@direntry
|
||||||
@ -188,9 +188,6 @@ instance of COMMAND.
|
|||||||
@itemx -s
|
@itemx -s
|
||||||
Suppress error messages.
|
Suppress error messages.
|
||||||
|
|
||||||
@item --debug
|
|
||||||
Print messages useful for debugging.
|
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Search scope selection, Mailbox type selection, Output control, Invoking
|
@node Search scope selection, Mailbox type selection, Output control, Invoking
|
||||||
|
@ -120,8 +120,7 @@ help (void)
|
|||||||
" -nd, --no-duplicates\t\tIgnore duplicate messages\n"
|
" -nd, --no-duplicates\t\tIgnore duplicate messages\n"
|
||||||
" -o, --output=MAILBOX\t\tWrite messages to MAILBOX\n"
|
" -o, --output=MAILBOX\t\tWrite messages to MAILBOX\n"
|
||||||
" -p, --pipe=COMMAND\t\tPipe each found message to COMMAND\n"
|
" -p, --pipe=COMMAND\t\tPipe each found message to COMMAND\n"
|
||||||
" -s, --no-messages\t\tSuppress most error messages\n"
|
" -s, --no-messages\t\tSuppress most error messages\n\n"
|
||||||
" --debug\t\t\tPrint messages useful for debugging\n\n"
|
|
||||||
"Matching criteria:\n\n"
|
"Matching criteria:\n\n"
|
||||||
" -E, --extended-regexp\tPATTERN is an extended regular expression\n"
|
" -E, --extended-regexp\tPATTERN is an extended regular expression\n"
|
||||||
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
|
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
|
||||||
|
76
src/main.c
76
src/main.c
@ -48,6 +48,8 @@ runtime_t runtime;
|
|||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
{
|
{
|
||||||
int havemailbox = 0;
|
int havemailbox = 0;
|
||||||
int singlefile = 0;
|
int singlefile = 0;
|
||||||
@ -55,6 +57,8 @@ main (int argc, char **argv)
|
|||||||
runtime.maildir_count = 0;
|
runtime.maildir_count = 0;
|
||||||
|
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
{
|
{
|
||||||
{"count", 0, 0, 'c'},
|
{"count", 0, 0, 'c'},
|
||||||
{"delete", 0, 0, 'd'},
|
{"delete", 0, 0, 'd'},
|
||||||
@ -76,12 +80,13 @@ main (int argc, char **argv)
|
|||||||
{"output", 1, 0, 'o'},
|
{"output", 1, 0, 'o'},
|
||||||
{"no-duplicates", 0, 0, 200},
|
{"no-duplicates", 0, 0, 200},
|
||||||
{"no-file-lock", 0, 0, 201},
|
{"no-file-lock", 0, 0, 201},
|
||||||
{"debug", 0, 0, 202},
|
|
||||||
{"file-lock", 1, 0, 'l'},
|
{"file-lock", 1, 0, 'l'},
|
||||||
{"recursive", 0, 0, 'r'},
|
{"recursive", 0, 0, 'r'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
set_default_options ();
|
set_default_options ();
|
||||||
|
|
||||||
get_runtime_options (&argc, argv, long_options);
|
get_runtime_options (&argc, argv, long_options);
|
||||||
@ -107,17 +112,17 @@ main (int argc, char **argv)
|
|||||||
config.regex_s = xstrdup (argv[optind]);
|
config.regex_s = xstrdup (argv[optind]);
|
||||||
config.haveregex = 1;
|
config.haveregex = 1;
|
||||||
++optind;
|
++optind;
|
||||||
}
|
} /* if */
|
||||||
|
|
||||||
if (config.haveregex)
|
if (config.haveregex)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBPCRE
|
#ifdef HAVE_LIBPCRE
|
||||||
if (config.perl)
|
if (config.perl)
|
||||||
pcre_init ();
|
pcre_init ();
|
||||||
else
|
else
|
||||||
#endif /* HAVE_LIBPCRE */
|
#endif /* HAVE_LIBPCRE */
|
||||||
regex_init ();
|
regex_init ();
|
||||||
}
|
} /* if */
|
||||||
else
|
else
|
||||||
usage ();
|
usage ();
|
||||||
|
|
||||||
@ -125,49 +130,56 @@ main (int argc, char **argv)
|
|||||||
singlefile = 1;
|
singlefile = 1;
|
||||||
|
|
||||||
while (optind < argc)
|
while (optind < argc)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
{
|
{
|
||||||
if (config.action == DELETE)
|
if (config.action == DELETE) {
|
||||||
{
|
tmpmbox_create (argv[optind]);
|
||||||
tmpmbox_create (argv[optind]);
|
runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, "w");
|
||||||
runtime.tmp_mbox = (mbox_t *) mbox_open (config.tmpfilename, "w");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
config.boxname = xstrdup (argv[optind]);
|
config.boxname = xstrdup (argv[optind]);
|
||||||
|
|
||||||
if (config.recursive)
|
if (config.recursive)
|
||||||
recursive_scan (argv[optind]);
|
recursive_scan (argv[optind]);
|
||||||
else
|
else
|
||||||
scan_mailbox (argv[optind]);
|
scan_mailbox (argv[optind]);
|
||||||
|
|
||||||
havemailbox = 1;
|
havemailbox = 1;
|
||||||
|
|
||||||
if (config.action == COUNT)
|
if (config.action == COUNT)
|
||||||
{
|
{
|
||||||
if (singlefile)
|
if (singlefile)
|
||||||
fprintf (stdout, "%i\n", runtime.count);
|
fprintf (stdout, "%i\n", runtime.count);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (0 == strcmp ("-", argv[optind]))
|
if (0 == strcmp ("-", argv[optind]))
|
||||||
fprintf (stdout, "(standard input):%i\n", runtime.count);
|
fprintf (stdout, "(standard input):%i\n", runtime.count);
|
||||||
else
|
else
|
||||||
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
|
fprintf (stdout, "%s:%i\n", argv[optind], runtime.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.action == DELETE)
|
if (config.action == DELETE)
|
||||||
{
|
{
|
||||||
mbox_close (runtime.tmp_mbox);
|
mbox_close (runtime.tmp_mbox);
|
||||||
rename (config.tmpfilename, argv[optind]);
|
rename (config.tmpfilename, argv[optind]);
|
||||||
}
|
}
|
||||||
++optind;
|
++optind;
|
||||||
}
|
} /* while */
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
if (! havemailbox)
|
if (! havemailbox)
|
||||||
|
/* {{{ */
|
||||||
|
|
||||||
{
|
{
|
||||||
config.format = MBOX;
|
config.format = MBOX;
|
||||||
scan_mailbox ("-");
|
scan_mailbox ("-");
|
||||||
if (config.action == COUNT)
|
if (config.action == COUNT)
|
||||||
fprintf (stdout, "%i\n", runtime.count);
|
fprintf (stdout, "%i\n", runtime.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} /* main */
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
@ -107,7 +107,6 @@ typedef struct
|
|||||||
int merr;
|
int merr;
|
||||||
int pid;
|
int pid;
|
||||||
int haveregex;
|
int haveregex;
|
||||||
int debug;
|
|
||||||
|
|
||||||
char hostname[HOST_NAME_SIZE];
|
char hostname[HOST_NAME_SIZE];
|
||||||
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
|
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
|
||||||
|
249
src/misc.c
249
src/misc.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/* -*- C -*-
|
||||||
mboxgrep - scan mailbox for messages matching a regular expression
|
mboxgrep - scan mailbox for messages matching a regular expression
|
||||||
Copyright (C) 2000 - 2004, 2006, 2023 Daniel Spiljar
|
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar
|
||||||
|
|
||||||
Mboxgrep is free software; you can redistribute it and/or modify it
|
Mboxgrep is free software; you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published by
|
under the terms of the GNU General Public License as published by
|
||||||
@ -15,7 +15,8 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with mboxgrep; if not, write to the Free Software Foundation,
|
along with mboxgrep; if not, write to the Free Software Foundation,
|
||||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
|
||||||
|
$Id: misc.c,v 1.17 2006-07-06 10:53:49 dspiljar Exp $ */
|
||||||
|
|
||||||
#define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */
|
#define _XOPEN_SOURCE /* Pull in strptime(3) from time.h */
|
||||||
#define _BSD_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
|
#define _BSD_SOURCE /* Compensate for _XOPEN_SOURCE to pull in strdup(3)
|
||||||
@ -37,6 +38,7 @@
|
|||||||
|
|
||||||
format_t
|
format_t
|
||||||
folder_format (const char *name)
|
folder_format (const char *name)
|
||||||
|
/* {{{ */
|
||||||
{
|
{
|
||||||
format_t f;
|
format_t f;
|
||||||
|
|
||||||
@ -61,14 +63,16 @@ folder_format (const char *name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (config.merr)
|
if (config.merr)
|
||||||
fprintf (stderr, "%s: %s: unknown folder type\n", APPNAME, name);
|
fprintf (stderr, "mboxgrep: %s: unknown folder type\n", name);
|
||||||
exit (2);
|
exit (2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
lockmethod_t lock_method (const char *name)
|
lockmethod_t lock_method (const char *name)
|
||||||
|
/* {{{ */
|
||||||
{
|
{
|
||||||
lockmethod_t l;
|
lockmethod_t l;
|
||||||
|
|
||||||
@ -93,36 +97,38 @@ lockmethod_t lock_method (const char *name)
|
|||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/*
|
/* time_t parse_date(char *datestr) */
|
||||||
time_t parse_date(char *datestr)
|
/* {{{ */
|
||||||
{
|
/* { */
|
||||||
time_t t;
|
/* time_t t; */
|
||||||
const char *fmt = "%d%n%b%n%Y%n%T";
|
/* const char *fmt = "%d%n%b%n%Y%n%T"; */
|
||||||
int h, m;
|
/* int h, m; */
|
||||||
struct tm tm;
|
/* struct tm tm; */
|
||||||
char *str2, str1[BUFSIZ];
|
/* char *str2, str1[BUFSIZ]; */
|
||||||
|
|
||||||
sscanf (datestr, "Date: %[^\r\n]", str1);
|
/* sscanf (datestr, "Date: %[^\r\n]", str1); */
|
||||||
|
|
||||||
str2 = (char *) strptime (str1, "%d%n%b%n%Y%n%T", &tm);
|
/* str2 = (char *) strptime (str1, "%d%n%b%n%Y%n%T", &tm); */
|
||||||
if (str2 == NULL)
|
/* if (str2 == NULL) */
|
||||||
str2 = (char *) strptime (str1, "%a, %d%n%b%n%Y%n%T", &tm);
|
/* str2 = (char *) strptime (str1, "%a, %d%n%b%n%Y%n%T", &tm); */
|
||||||
if (str2 == NULL)
|
/* if (str2 == NULL) */
|
||||||
return (time_t) 0;
|
/* return (time_t) 0; */
|
||||||
|
|
||||||
if (sscanf (str2, "%3d%2d", &h, &m) == 2)
|
/* if (sscanf (str2, "%3d%2d", &h, &m) == 2) */
|
||||||
{
|
/* { */
|
||||||
tm.tm_hour -= h;
|
/* tm.tm_hour -= h; */
|
||||||
tm.tm_min -= (h >= 0 ? m : -m);
|
/* tm.tm_min -= (h >= 0 ? m : -m); */
|
||||||
t = (time_t) mktime (&tm);
|
/* t = (time_t) mktime (&tm); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
return t;
|
/* return t; */
|
||||||
}
|
/* } */
|
||||||
*/
|
/* }}} */
|
||||||
|
|
||||||
char * parse_return_path(char *rpath)
|
char * parse_return_path(char *rpath)
|
||||||
|
/* {{{ */
|
||||||
{
|
{
|
||||||
char *blah1, blah2[BUFSIZ];
|
char *blah1, blah2[BUFSIZ];
|
||||||
|
|
||||||
@ -131,6 +137,7 @@ char * parse_return_path(char *rpath)
|
|||||||
|
|
||||||
return blah1;
|
return blah1;
|
||||||
}
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
void * allocate_message (void)
|
void * allocate_message (void)
|
||||||
{
|
{
|
||||||
@ -181,7 +188,6 @@ set_default_options (void)
|
|||||||
config.format = MBOX; /* default mailbox format */
|
config.format = MBOX; /* default mailbox format */
|
||||||
config.lock = FCNTL; /* default file locking method */
|
config.lock = FCNTL; /* default file locking method */
|
||||||
config.merr = 1; /* report errors by default */
|
config.merr = 1; /* report errors by default */
|
||||||
config.debug = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -195,104 +201,103 @@ get_runtime_options (int *argc, char **argv, struct option *long_options)
|
|||||||
&option_index);
|
&option_index);
|
||||||
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
/* {{{ */
|
||||||
case '?':
|
|
||||||
usage();
|
{
|
||||||
case 'c':
|
case '?':
|
||||||
config.action = COUNT;
|
usage();
|
||||||
break;
|
case 'c':
|
||||||
case 'd':
|
config.action = COUNT;
|
||||||
config.action = DELETE;
|
break;
|
||||||
break;
|
case 'd':
|
||||||
case 'e':
|
config.action = DELETE;
|
||||||
config.regex_s = xstrdup (optarg);
|
break;
|
||||||
config.haveregex = 1;
|
case 'e':
|
||||||
break;
|
config.regex_s = xstrdup (optarg);
|
||||||
case 'o':
|
config.haveregex = 1;
|
||||||
config.outboxname = xstrdup (optarg);
|
break;
|
||||||
config.action = WRITE;
|
case 'o':
|
||||||
break;
|
config.outboxname = xstrdup (optarg);
|
||||||
case 'E':
|
config.action = WRITE;
|
||||||
config.extended = 1;
|
break;
|
||||||
break;
|
case 'E':
|
||||||
case 'G':
|
config.extended = 1;
|
||||||
config.extended = 0;
|
break;
|
||||||
break;
|
case 'G':
|
||||||
case 'P':
|
config.extended = 0;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
#ifdef HAVE_LIBPCRE
|
#ifdef HAVE_LIBPCRE
|
||||||
config.extended = 0;
|
config.extended = 0;
|
||||||
config.perl = 1;
|
config.perl = 1;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: Support for Perl regular expressions not "
|
"%s: Support for Perl regular expressions not "
|
||||||
"compiled in\n", APPNAME);
|
"compiled in\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
#endif /* HAVE_LIBPCRE */
|
#endif /* HAVE_LIBPCRE */
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help ();
|
help ();
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
config.ignorecase = 1;
|
config.ignorecase = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
config.format = folder_format (optarg);
|
config.format = folder_format (optarg);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
config.lock = lock_method (optarg);
|
config.lock = lock_method (optarg);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
config.action = PIPE;
|
config.action = PIPE;
|
||||||
config.pipecmd = xstrdup (optarg);
|
config.pipecmd = xstrdup (optarg);
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
version ();
|
version ();
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
config.invert = 1;
|
config.invert = 1;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
config.headers = 1;
|
config.headers = 1;
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
config.body = 1;
|
config.body = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
config.merr = 0;
|
config.merr = 0;
|
||||||
break;
|
break;
|
||||||
case 201:
|
case 201:
|
||||||
config.lock = 0;
|
config.lock = 0;
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 'r':
|
||||||
config.debug = 1;
|
config.recursive = 1;
|
||||||
fprintf (stderr, "%s: %s, line %d: enable debugging\n",
|
break;
|
||||||
APPNAME, __FILE__, __LINE__);
|
case 200:
|
||||||
break;
|
config.dedup = 1;
|
||||||
case 'r':
|
break;
|
||||||
config.recursive = 1;
|
case 'n':
|
||||||
break;
|
{
|
||||||
case 200:
|
switch (optarg[0])
|
||||||
config.dedup = 1;
|
{
|
||||||
break;
|
case 'd':
|
||||||
case 'n':
|
config.dedup = 1;
|
||||||
{
|
break;
|
||||||
switch (optarg[0])
|
case 'l':
|
||||||
{
|
config.lock = 0;
|
||||||
case 'd':
|
break;
|
||||||
config.dedup = 1;
|
default:
|
||||||
break;
|
fprintf(stderr, "%s: invalid option -- n%c\n",
|
||||||
case 'l':
|
APPNAME, optarg[0]);
|
||||||
config.lock = 0;
|
exit(2);
|
||||||
break;
|
}
|
||||||
default:
|
}
|
||||||
fprintf(stderr, "%s: invalid option -- n%c\n",
|
} /* switch */
|
||||||
APPNAME, optarg[0]);
|
|
||||||
exit(2);
|
/* }}} */
|
||||||
}
|
|
||||||
}
|
|
||||||
} /* switch */
|
|
||||||
} /* while */
|
} /* while */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user