Hi there,
I looked into mailutils since I needed some command line utilities to
check mailboxes. (We actually want to check whether mails arrive where
they are expected to arrive.)
While I took a closer look at frm, I came across a bug - whenever I
specified "-s", it segfaulted. I'm no argp_parse expert and didn't
bother to look at the docs, but judging from what gdb displayed, optarg
was being used instead of arg and optarg was NULL. So I fixed that.
Later, I wanted frm to display all the fields I needed, not just one, so
I extended the -f syntax. It now supports the specification of multiple
fields, separated by comma, semicolon or spaces. Alternatively, the
option may be given multiple times.
Now I just need a way to mark a message read, so I don't need to compare
it again - does readmsg do this?
Bye, Tino.
PS: I used mailutils 0.6, so I may be not totally up to date...
--- frm/frm.c.orig 2004-06-02 09:30:51.000000000 +0200
+++ frm/frm.c 2005-07-28 22:16:40.157666184 +0200
@@ -45,7 +45,8 @@
#include <mailutils/mutil.h>
#include <mailutils/mime.h>
-static char *show_field;
+static char **show_fields = NULL;
+static int show_fields_count = 0;
static int show_to;
static int show_from = 1;
static int show_subject = 1;
@@ -181,6 +182,9 @@
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
+ int i, arglen, count;
+ char* lastfield;
+
switch (key)
{
case 'd':
@@ -188,7 +192,34 @@
break;
case 'f':
- show_field = arg;
+ if (strlen (arg) == 0)
+ break;
+
+ /* at first count new fields */
+ count = 1;
+ arglen = strlen (arg);
+ for (i = 0; i < arglen; i++)
+ {
+ if ((arg[i] == ',') || (arg[i] == ';') || (arg[i] == ' '))
+ count++;
+ }
+
+ show_fields = (char**)realloc (show_fields,
(show_fields_count+count)*(sizeof (char*)));
+
+ lastfield = arg;
+ for (i = 0; i < arglen; i++)
+ {
+ if ((arg[i] == ',') || (arg[i] == ';') || (arg[i] == ' '))
+ {
+ /* terminate field */
+ arg[i] = '\0';
+ show_fields[show_fields_count++] = lastfield;
+ lastfield = &(arg[i+1]);
+ }
+ }
+
+ show_fields[show_fields_count++] = lastfield;
+
show_from = 0;
show_subject = 0;
align = 0;
@@ -222,7 +253,7 @@
break;
case 's':
- select_attribute = decode_attr (optarg);
+ select_attribute = decode_attr (arg);
break;
case 't':
@@ -377,13 +408,20 @@
if (show_number)
printf ("%4lu: ", (u_long) counter.index);
- if (show_field)
+ if (show_fields != NULL)
{
char hfield[256];
- status = header_get_value_unfold (hdr, show_field, hfield,
- sizeof (hfield), NULL);
- if (status == 0)
- printf ("%s", hfield);
+ int i;
+
+ for (i = 0; i < show_fields_count; i++)
+ {
+ status = header_get_value_unfold (hdr, show_fields[i], hfield,
+ sizeof (hfield), NULL);
+ if (i > 0)
+ printf (" ");
+ if (status == 0)
+ printf ("%s", hfield);
+ }
}
if (show_to)
--- doc/texinfo/programs.texi.org 2004-12-06 13:33:05.000000000 +0100
+++ doc/texinfo/programs.texi 2005-07-28 21:34:02.909253944 +0200
@@ -494,8 +494,11 @@
@table @option
@item -f @var{string}
@itemx --field @var{string}
-Display the header named by @var{string} instead of @code{From}
[EMAIL PROTECTED] pair.
+Display the headers specified by @var{string} instead of @code{From}
[EMAIL PROTECTED] pair. Multiple header may be given, separated by comma,
+semicolon or spaces. Alternatively, the option may be given multiple
+times. Headers are output in the same order they are specified,
+separated by spaces.
@item -l
@itemx --to
Include the contents of @code{To} header to the output. The output field
_______________________________________________
Bug-mailutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-mailutils