Commit 25db453e 25db453e96894f1f8c7320ec49a8213b9a2cdd1f by Alain Magloire

* doc/texinfo/programs.texi: Descibe the readmsg utility.

	* configure.in: Enable readmsg.
	* Makefile.in: Enable readmsg.
	* readmsg/readmsg.c: Implementation.
	* readmsg/msglist.c: Implement Elm weird expansion.
1 parent 89287b76
2001-12-31 Alain Magloire
* doc/texinfo/programs.texi: Descibe the readmsg utility.
* configure.in: Enable readmsg.
* Makefile.in: Enable readmsg.
* readmsg/readmsg.c: Implementation.
* readmsg/msglist.c: Implement Elm weird expansion.
2001-12-29 Sergey Poznyakoff
* guimb/scm/numaddr.scm: (new) Implements "numaddr" extension
......
......@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = gnu 1.4
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = include doc m4 lib MySql argp mailbox frm from pop3d imap4d mail sieve \
scripts libmu_scm guimb messages comsat
scripts libmu_scm guimb messages comsat readmsg
EXTRA_DIST = mailutils.spec mailutils.spec.in README-alpha COPYING.FDL
......
......@@ -140,7 +140,7 @@ AC_FUNC_FNMATCH
if test "$ac_cv_func_fnmatch_works" = "no"; then
: LIBOBJS="$LIBOBJS fnmatch.o"
fi
AC_REPLACE_FUNCS(fgetpwent setenv snprintf strtok_r strncasecmp strcasecmp \
AC_REPLACE_FUNCS(fgetpwent getpass setenv snprintf strtok_r strncasecmp strcasecmp \
strsignal vasprintf)
AC_CHECK_FUNCS(mkstemp sigaction sysconf getdelim vsyslog)
......@@ -307,4 +307,5 @@ AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
mailbox/include/Makefile from/Makefile mail/Makefile pop3d/Makefile
frm/Makefile sieve/Makefile messages/Makefile scripts/Makefile
libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile
readmsg/Makefile
MySql/Makefile mh/Makefile comsat/Makefile)
......
......@@ -1444,7 +1444,71 @@ Output program version and exit.
@section readmsg --- Extract messages from a folder.
@pindex readmsg
The program is currently in development
The program, readmsg, extracts with the selection argument messages from
a mailbox. Selection can be specify by:
@enumerate
@item
A lone ``*'' means select all messages in the mailbox.
@item
A list of message numbers may be specified. Values
of ``0'' and ``$'' in the list both mean the last
message in the mailbox. For example:
@example
readmsg 1 3 0
@end example
extracts three messages from the folder: the first, the third, and the last.
@item
Finally, the selection may be some text to match. This will select a mail
message which exactly matches the specified text. For example,
@example
readmsg staff meeting
@end example
extracts the message which contains the words ``staff meeting.'' Note that it
will not match a message containing ``Staff Meeting'' - the matching is case
sensitive. Normally only the first message which matches the pattern will be
printed.
@end enumerate
@subheading Command line options
@table @samp
@item -a
@itemx --show-all
If a pattern is use for selection show all messages that match pattern
by default only the first one is presented.
@item -d
@itemx --debug
Display mailbox debuging information.
@item -f @var{MAILBOX}
@itemx --folder=@var{MAILBOX}
Specified the default mailbox.
@item -h
@itemx --header
Show the entire header and ignore the weedlist.
@item -n
@itemx --no-header
Do not print the message header.
@item -p
@itemx --form-feed
Put form-feed (Control-L) between messages instead of newline.
@item -w @var{weedlist}
@itemx --weedlist=@var{weedlist}
A whitespace or coma separated list of header names to show per message.
Default is --weedlist=''From Subject Date To CC Apparently-''
@end table
@page
@node sieve
......
......@@ -37,74 +37,104 @@ addset (int **set, int *n, unsigned val)
return 0;
}
static int
isnumber (const char *s)
{
int is_number = 1;
if (*s == '\0')
is_number = 0;
for (; *s; s++)
{
if (!isdigit ((unsigned char)*s))
{
is_number = 0;
break;
}
}
return is_number;
}
/*
According to ELM readmsg(1):
1. A lone ``*'' means select all messages in the mailbox.
2. A list of message numbers may be specified. Values of ``0'' and ``$'' in the
list both mean the last message in the mailbox. For example:
readmsg 1 3 0
extracts three messages from the folder: the first, the third, and the last.
3. Finally, the selection may be some text to match. This will select a mail
message which exactly matches the specified text. For example,
readmsg staff meeting
extracts the message which contains the words ``staff meeting.'' Note that it
will not match a message containing ``Staff Meeting'' - the matching is case
sensitive. Normally only the first message which matches the pattern will be
printed. The -a option discussed in a moment changes this.
*/
int
msgset (const int argc, char **argv, int **set, int *n)
msglist (mailbox_t mbox, int show_all, int argc, char **argv, int **set, int *n)
{
int i = 0, lc = 0;
int undelete = 0;
int *ret = NULL;
int i = 0;
size_t total = 0;
mailbox_messages_count (mbox, &total);
for (i = 0; i < argc; i++)
{
/* Last message */
if (!strcmp (argv[i], "$") || !strcmp (argv[i], "0"))
/* 1. A lone ``*'' means select all messages in the mailbox. */
if (!strcmp (argv[i], "*"))
{
addset (set, n, total);
size_t j;
/* all messages */
for (j = 1; j <= total; j++)
addset (set, n, j);
j = argc + 1;
}
else if (!strcmp (argv[i], "*"))
/* 2. A list of message numbers may be specified. Values of ``0'' and ``$'' in the
list both mean the last message in the mailbox. */
else if (!strcmp (argv[i], "$") || !strcmp (argv[i], "0"))
{
/* all messages */
for (i = 1; i <= total; i++)
addset (set, n, i);
i = argc + 1;
size_t j;
mailbox_messages_count (mbox, &total);
for (j = 1; j < total; j++)
addset (set, n, j);
}
else if (argv[i][0] == '/')
/* 3. Finally, the selection may be some text to match. This will select a mail
message which exactly matches the specified text. */
else if (!isnumber(argv[i]))
{
/* FIXME: all messages with pattern following / in
the subject line, case insensitive */
/* This currently appears to be quit b0rked */
message_t msg;
header_t hdr;
char subj[128];
int j = 1, k = 0, len2 = 0;
int len = strlen (&argv[i][1]);
size_t j;
int found = 0;
for (j = 1; j <= total; j++)
{
char buf[128];
size_t len = 0;
off_t offset = 0;
message_t msg = NULL;
stream_t stream = NULL;
mailbox_get_message (mbox, j, &msg);
message_get_header (msg, &hdr);
header_get_value (hdr, MU_HEADER_SUBJECT, subj, 128, NULL);
len2 = strlen (subj);
for (k = 0; i < strlen (subj); k++)
message_get_stream (msg, &stream);
while (stream_readline (stream, buf, sizeof buf, offset, &len) == 0 && len > 0)
{
if (len2 - k >= len
&& !strncasecmp (&argv[i][1], &subj[k], len))
if (strstr (buf, argv[i]) != NULL)
{
addset (set, n, j);
k = 128;
}
}
found = 1;
break;
}
offset += len;
}
else if (isalpha(argv[i][0]))
{
/* FIXME: all messages from sender argv[i] */
}
else if (strchr (argv[i], '-') != NULL)
{
/* message range */
int j, x, y;
char *arg = strdup (argv[i]);
for (j = 0; j < strlen (arg); j++)
if (arg[j] == '-')
if (found && !show_all)
break;
arg[j] = '\0';
x = strtol (arg, NULL, 10);
y = strtol (&(arg[j + 1]), NULL, 10);
for (; x <= y; x++)
addset (set, n, x);
free (arg);
}
else
}
else if (isdigit (argv[i][0]))
{
/* single message */
addset (set, n, strtol (argv[i], NULL, 10));
......
......@@ -22,9 +22,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <getopt.h>
#include <mailutils/mailbox.h>
#include <mailutils/header.h>
......@@ -32,7 +34,13 @@
#include <mailutils/filter.h>
#include <mailutils/registrar.h>
extern mailbox_t mbox;
extern size_t total;
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
int msglist __P ((mailbox_t mbox, int show_all, int argc, char **argv, int **set, int *n));
#endif
......