bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-mailutils] Is this a Bug? Readmsg Omits From Line


From: Sergey Poznyakoff
Subject: Re: [bug-mailutils] Is this a Bug? Readmsg Omits From Line
Date: Mon, 12 Feb 2007 10:40:35 +0200

Neil R. Ormos <address@hidden> wrote:

> In at least one historical version of readmsg, the -h
> option flag causes readmsg to copy the "^From .*"
> line to the output, as does the -w "From_" option.
> By the "^From .*" line I mean the line that signals
> the start of a new message in an mbox-format mailbox
> file, not the From: header line.

It is due to the basic differences between MU implementation of
readmsg and other versions.  First of all, MU readmsg is able to process 
mailboxes of different formats.  All of them, except UNIX mailboxes,
do not contain 'From ' line.  Secondly, -w is said to select *headers*
from the message, and the 'From ' marker in a UNIX mailbox is not a
header at all.

> I don't know whether this is intended behavior or a
> bug.  The manual page does not specify whether the
> "^From .*" line is supposed to be copied to the
> output

Mailutils readmsg was planned as a full-fledged replacement for
the elm implementation.  From this point of view, it surely must
support -w From_ notation (whenever it is possible).

The enclosed patch adds the `-w From_' functionality.  When there is
no `From ' marker (e.g. when reading a Maildir folder), readmsg
will attempt to construct one from the available data.  Notice that
this may not always be possible.

I will commit the improved version of this patch later.

Regards,
Sergey

Index: readmsg/readmsg.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/readmsg/readmsg.c,v
retrieving revision 1.25
diff -p -u -r1.25 readmsg.c
--- readmsg/readmsg.c   27 Aug 2005 11:37:43 -0000      1.25
+++ readmsg/readmsg.c   12 Feb 2007 08:18:01 -0000
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 1999, 2000, 2001, 2002, 2003, 
-   2004, 2005 Free Software Foundation, Inc.
+   2004, 2005, 2007 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -22,11 +22,12 @@
 #endif
 
 #include "readmsg.h"
+#include "xalloc.h"
 
 #define WEEDLIST_SEPARATOR " :,"
 
-static void print_header (mu_message_t, int no_header,
-                         int all_header, const char *weedlst);
+static void print_unix_header (mu_message_t);
+static void print_header (mu_message_t, int, int, char **);
 static void print_body (mu_message_t);
 static int  string_starts_with (const char * s1, const char *s2);
 
@@ -133,17 +134,42 @@ string_starts_with (const char * s1, con
 }
 
 static void
-print_header (mu_message_t message, int no_header, int all_headers,
-             const char *weedlist)
+print_unix_header (mu_message_t message)
+{
+  static size_t bufsize;
+  static char *buf;
+  size_t size;
+  mu_envelope_t envelope = NULL;
+
+  mu_message_get_envelope (message, &envelope);
+  mu_envelope_sender (envelope, NULL, 0, &size);
+  if (size > bufsize)
+    {
+      bufsize = size + 1;
+      buf = xrealloc (buf, bufsize);
+    }
+      
+  mu_envelope_sender (envelope, buf, bufsize, 0);
+  printf ("From %s ", buf);
+  
+  mu_envelope_date (envelope, NULL, 0, &size);
+  if (size > bufsize)
+    {
+      bufsize = size + 1;
+      buf = xrealloc (buf, bufsize);
+    }
+  mu_envelope_date (envelope, buf, bufsize, NULL);
+  printf ("%s", buf);
+}
+    
+static void
+print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
 {
   mu_header_t header = NULL;
 
-  if (no_header)
-    return;
-
   mu_message_get_header (message, &header);
 
-  if (all_headers)
+  if (weedc == 0)
     {
       mu_stream_t stream = NULL;
       off_t offset = 0;
@@ -161,25 +187,27 @@ print_header (mu_message_t message, int 
     }
   else
     {
-      size_t count = 0;
-      const char *delim = WEEDLIST_SEPARATOR;
+      size_t count;
       size_t i;
 
       mu_header_get_field_count (header, &count);
 
       for (i = 1; i <= count; i++)
        {
+         int j;
          char *name = NULL;
          char *value = NULL;
-         char *weedcopy = strdup (weedlist);
-         char *token, *s;
 
          mu_header_aget_field_name (header, i, &name);
          mu_header_aget_field_value (header, i, &value);
-         for (token = strtok_r (weedcopy, delim, &s); token;
-              token = strtok_r (NULL, delim, &s)) 
+         for (j = 0; j < weedc; j++)
            {
-             if (string_starts_with (name, token))
+             if (weedv[j][0] == '!')
+               {
+                 if (string_starts_with (name, weedv[j]+1))
+                   break;
+               }
+             else if (string_starts_with (name, weedv[j]))
                {
                  /* Check if mu_header_aget_value return an empty string.  */
                  if (value && *value)
@@ -188,7 +216,6 @@ print_header (mu_message_t message, int 
            }
          free (value);
          free (name);
-         free (weedcopy);
        }
       putchar ('\n');
     }
@@ -228,7 +255,10 @@ main (int argc, char **argv)
   int i;
   int index;
   mu_mailbox_t mbox = NULL;
-
+  char **weedv;
+  int weedc;
+  int unix_header = 0;
+  
   /* Native Language Support */
   mu_init_nls ();
 
@@ -269,14 +299,43 @@ main (int argc, char **argv)
       mu_url_t url = NULL;
 
       mu_mailbox_get_url (mbox, &url);
-      fprintf (stderr, _("Could not open mailbox `%s': %s\n"),
-              mu_url_to_string (url), mu_strerror(status));
+      mu_error (_("Could not open mailbox `%s': %s\n"),
+               mu_url_to_string (url), mu_strerror (status));
       exit (2);
     }
 
   if (weedlist == NULL)
     weedlist = "Date To Cc Subject From Apparently-";
 
+  status = mu_argcv_get (weedlist, WEEDLIST_SEPARATOR, NULL,
+                        &weedc, &weedv);
+  if (status)
+    {
+      mu_error (_("Cannot parse weedlist: %s"), mu_strerror (status));
+      exit (2);
+    }
+
+  for (i = 0; i < weedc; i++)
+    {
+      if (strcasecmp (weedv[i], "From_") == 0)
+       {
+         int j;
+         unix_header = 1;
+         free (weedv[i]);
+         for (j = i; j < weedc; j++)
+           weedv[j] = weedv[j+1];
+         weedc--;
+         if (weedc == 0 && !all_header)
+           no_header = 1;
+       }
+    }
+  
+  if (all_header)
+    {
+      weedc = 0;
+      weedv = NULL;
+    }
+
   /* Build an array containing the message number.  */
   argc -= index;
   if (argc > 0)
@@ -294,7 +353,12 @@ main (int argc, char **argv)
          exit (2);
        }
 
-      print_header (msg, no_header, all_header, weedlist);
+      if (unix_header)
+       print_unix_header (msg);
+      
+      if (!no_header)
+       print_header (msg, unix_header, weedc, weedv);
+      
       print_body (msg);
       if (form_feed)
        putchar ('\f');
Index: readmsg/readmsg.h
===================================================================
RCS file: /cvsroot/mailutils/mailutils/readmsg/readmsg.h,v
retrieving revision 1.17
diff -p -u -r1.17 readmsg.h
--- readmsg/readmsg.h   14 Nov 2005 21:58:39 -0000      1.17
+++ readmsg/readmsg.h   12 Feb 2007 08:18:01 -0000
@@ -47,6 +47,8 @@
 #include <mailutils/tls.h>
 #include <mailutils/argp.h>
 #include <mailutils/error.h>
+#include <mailutils/envelope.h>
+#include <mailutils/argcv.h>
 
 int msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, int 
**set, int *n);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]