Re: format and output all received: lines in an e-mail message

2019-11-24 Thread Ralph Corderoy
Hi kre,

>   case "$#" in
>   0)  set -- cur;;
>   esac

If this is bash(1) then

(($#)) || set cur

also works.  ((...)) is arithmetic evaluation.

-- 
Cheers, Ralph.



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Greg Minshall
dear Big I Down Under,

> It is this kind of thing that makes MH so nice.

indeed!



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Robert Elz
Date:Sat, 23 Nov 2019 20:26:27 +0530
From:Greg Minshall 
Message-ID:  <374462.1574520...@apollo2.minshall.org>

  | combined with (new-fangled) bash "process substitution",

If you're planning on using this much, I'd suggest avoiding making bash
do all that work (and making things work with shells that don't have this)
by simply creating a one line file in your $(mhparam path) directory,
and using that file name (in that dir no path is needed)

echo received:split,compress,nowrap > "$HOME/$(mhparam path)/received-only"

(pick your own file name), just once, and then

   mhl -form received-only $(mhpath +inbox 794)

(the switch from `` to $() is simply because the latter is in general better
to use, though for a simple case like this it makes no difference really)

and if you're going to do this often, put the one line in a script, ane
replace "+inbox 794" there with "$@" (including the quotes), insert before
that line

case "$#" in
0)  set -- cur;;
esac

(use an "if" instead of case if you prefer, and you can make it fancier
by appending "cur" any time there are no message args, rather than only when
there are no args at all if you want), and you end up with something
that feels and acts just like any other MH command.

It is this kind of thing that makes MH so nice.

kre




Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Andy Bradford
Thus said Ralph Corderoy on Sat, 23 Nov 2019 12:03:42 +:

> Andy is correct.  Mailman has a `nodupes' flag  for every subscription
> and it's set for Andy's subscription.

Not any longer. :-)

I didn't realize I had control over this.

Andy
-- 
TAI64 timestamp: 40005dd9a302





Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Steffen Nurpmeso
Valdis Klētnieks wrote in <235182.1574454918@turing-police>:
 |On Fri, 22 Nov 2019 20:51:52 +0100, Steffen Nurpmeso said:
 |
 |> I prefer people using Mail-Followup-To: instead of some ML
 |> software modifying the address lists, they could as well just
 |> avoid resending the mail!?!  Yes, i mean, well.
 |> I really like looking into old archives and i hope what i see is
 |> the real original thing, which i think is a value by itself.
 |> But the world does not seem to cherish this.
 |
 |A bigger issue is GMail's handling of Message-Id:
 |
 |If you post to a mailing list, it notes the Message-Id: on the way out,
 |and when the list sends its copy to you, it gets silently munched by the
 |duplicate suppressor.  So unless you are careful with Fcc: and have
 |nmh save a copy in the appropriate folder, your comments in a thread
 |go poof.

Poof also in use to spring out of existence.
To me such situations happen regulary even without GMail ._.

Before the upcoming release of my MUA i will have to add
a reply-to-swapin variable so one can use the address in Reply-To:
not only as an exclusive receiver override (as with M-F-T:), but
only to replace the one address in From: (or Sender:) with it.
This is the only idea i have to work with DKIM++ the way it is in
use on those lists which use the "x via y" syntax.
(Even if noone wants to hear just about any critics regarding
DKIM / DMARC / ARC, neither here nor on other lists.)

 --End of <235182.1574454918@turing-police>

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Greg Minshall
thanks to everyone for all the replies!

Ken suggested mhl. conveniently combined with (new-fangled) bash
"process substitution", the following does exactly what i want:

mhl -form <(echo received:split,compress,nowrap) `mhpath +inbox 794`


cheers, Greg



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Greg Minshall
oof, ships crossing in the night -- thanks!  (and for the
"-nomoreproc".)

> Hi Greg,
> 
> > yes, awk and sed are in my repertoire, but, well, i was wondering if i
> > could avoid those in this case.
> 
> For list's archive's completeness, the nmh way, using mhl(1) as Ken
> suggested, is
> 
> /usr/lib/nmh/mhl -nomoreproc \
> -form <(echo received:compress,nowrap,split) \
> `mhpath .`
> 
> -- 
> Cheers, Ralph.
> 



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Ralph Corderoy
Hi Ken,

> Andy Bradford wrote:
> > Curiously, the email you sent me appears to have never arrived via
> > the MLM that nmh-workers uses---I suspect it has one of those fancy
> > features that thinks an email that was sent to one address shouldn't
> > be also sent to another address (i.e. if the address of the To/Cc
> > recipient is also a member of the MLM exclude one of them).

Andy is correct.  Mailman has a `nodupes' flag for every subscription and
it's set for Andy's subscription.  Mailman says

nodupes -- Does the member want to avoid duplicates of the same
message?

> I see double-replies of messages and my own messages sent to me on the
> mailing list.

That same nodupes flag is set for your subscription too, so that's odd.
Only two subscribers do not have the flag set.

-- 
Cheers, Ralph.



Re: format and output all received: lines in an e-mail message

2019-11-23 Thread Ralph Corderoy
Hi Greg,

> yes, awk and sed are in my repertoire, but, well, i was wondering if i
> could avoid those in this case.

For list's archive's completeness, the nmh way, using mhl(1) as Ken
suggested, is

/usr/lib/nmh/mhl -nomoreproc \
-form <(echo received:compress,nowrap,split) \
`mhpath .`

-- 
Cheers, Ralph.



Re: format and output all received: lines in an e-mail message

2019-11-22 Thread Valdis Klētnieks
On Fri, 22 Nov 2019 20:51:52 +0100, Steffen Nurpmeso said:

> I prefer people using Mail-Followup-To: instead of some ML
> software modifying the address lists, they could as well just
> avoid resending the mail!?!  Yes, i mean, well.
> I really like looking into old archives and i hope what i see is
> the real original thing, which i think is a value by itself.
> But the world does not seem to cherish this.

A bigger issue is GMail's handling of Message-Id:

If you post to a mailing list, it notes the Message-Id: on the way out,
and when the list sends its copy to you, it gets silently munched by the
duplicate suppressor.  So unless you are careful with Fcc: and have
nmh save a copy in the appropriate folder, your comments in a thread
go poof.


pgpGvEg27G0Er.pgp
Description: PGP signature


Re: format and output all received: lines in an e-mail message

2019-11-22 Thread Ken Hornstein
>Curiously, the email  you sent me appears to have  never arrived via the
>MLM that nmh-workers uses---I suspect it has one of those fancy features
>that thinks an email that was sent to one address shouldn't be also sent
>to another address (i.e. if the address of the To/Cc recipient is also a
>member  of  the MLM  exclude  one  of  them).

As far as I know our mailing list software (hosted by savannah) does
not have such a feature; I see double-replies of messages and my own
messages sent to me on the mailing list.

--Ken



Re: format and output all received: lines in an e-mail message

2019-11-22 Thread Steffen Nurpmeso
Andy Bradford wrote in <20191122084003.18170.qmail@angmar.bradfordfamily\
.org>:
 |Thus said Steffen Nurpmeso on Thu, 21 Nov 2019 23:14:29 +0100:
 |> I have heared someone revived qmail  and wants to include some patches
 |> for builtin TLS etc. That sounded very much interesting, especially if
 |> its mailing-list manager would be maintained again!
 |
 |There has been some momentum around  creating a newer version that has a
 |forward path. I imagine there are  still some diehards out there like me
 |who  just continue  to  use  the original  software  (mine is  minimally
 |patched for example) because it "just works."

It was notqmail..  Not touched in a few months.  Well.

 |I  still use  unpatched ezmlm  for  my own  personal uses  for the  same
 |reasons,  though I  have added  an  extra binary;  but the  rest of  the
 |additional things that were added to it I haven't needed.

I was thinking about that when i practically had to move away from
Sourceforge, since Unicode.org used it for many years, and i had
no rememberance of any issue (except seeing never seen From_ quoting
via space not >).  (Not that i remember any issues after their
switch to Mailman.)  I did not dare to go that route by then.

 |Curiously, the email  you sent me appears to have  never arrived via the
 |MLM that nmh-workers uses---I suspect it has one of those fancy features
 |that thinks an email that was sent to one address shouldn't be also sent
 |to another address (i.e. if the address of the To/Cc recipient is also a
 |member  of  the MLM  exclude  one  of  them).  Personally, I  prefer  to
 |distinguish between direct  replies and replies via MLM so  I don't mind
 |the extra because my filters funnel things appropriately.

That must be your very personal Mailman config then, or?
Well, hmmm ..
I prefer people using Mail-Followup-To: instead of some ML
software modifying the address lists, they could as well just
avoid resending the mail!?!  Yes, i mean, well.
I really like looking into old archives and i hope what i see is
the real original thing, which i think is a value by itself.
But the world does not seem to cherish this.
A nice weekend!

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



Re: format and output all received: lines in an e-mail message

2019-11-22 Thread Andy Bradford
Thus said Steffen Nurpmeso on Thu, 21 Nov 2019 23:14:29 +0100:

> I have heared someone revived qmail  and wants to include some patches
> for builtin TLS etc. That sounded very much interesting, especially if
> its mailing-list manager would be maintained again!

There has been some momentum around  creating a newer version that has a
forward path. I imagine there are  still some diehards out there like me
who  just continue  to  use  the original  software  (mine is  minimally
patched for example) because it "just works."

I  still use  unpatched ezmlm  for  my own  personal uses  for the  same
reasons,  though I  have added  an  extra binary;  but the  rest of  the
additional things that were added to it I haven't needed.

Curiously, the email  you sent me appears to have  never arrived via the
MLM that nmh-workers uses---I suspect it has one of those fancy features
that thinks an email that was sent to one address shouldn't be also sent
to another address (i.e. if the address of the To/Cc recipient is also a
member  of  the MLM  exclude  one  of  them).  Personally, I  prefer  to
distinguish between direct  replies and replies via MLM so  I don't mind
the extra because my filters funnel things appropriately.

Andy
-- 
TAI64 timestamp: 40005dd80178





Re: format and output all received: lines in an e-mail message

2019-11-21 Thread Steffen Nurpmeso
Andy Bradford wrote in <20191121072709.1303.qm...@angmar.bradfordfamily.org>:
 |Thus said Greg Minshall on Wed, 20 Nov 2019 10:41:34 +0530:
 |> then, i'd like  to use something like fmttest(1) to  print out all the
 |> "Received:" lines in an e-mail message. ideally, each "Received:" line
 |> would come  out on a  separate line; less  ideally, but i'm  sure very
 |> practical, a very  long line would come out, with  some odd ascii code
 |> separating the individual lines.
 |
 |I usually use  822field (from mess822 [1]) for this  kind of thing which
 |takes all received lines and reformats them one per line (odd ascii code
 |separating them is a newline).
 |
 |For example, your message looks like:
 |
 |$ 822field received < `mhpath cur` | tail -6   
 | from eggs.gnu.org ([2001:470:142:3::10]:33280) by lists.gnu.org with \
 ...

Well, yes, it is a bit restricted, but you could also use S-nail
v14.9.11 or later:

  $ printf 'dig c 25 -;dig 25 h s received;digmsg r 25' |\
s-nail -#Rf +download
  212 Received
  from lists.gnu.org (lists.gnu.org [209.51.188.17]) by sdaoden.eu (Postfix) 
with ESMTPS id 977431604A for ; Thu, 21 Nov 2019 15:28:01 
+0100 (CET)
  from localhost ([::1]:41250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp 
(Exim 4.90_1) (envelope-from 
) id 1iXnR9-000318-IA for 
stef...@sdaoden.eu; Thu, 21 Nov 2019 09:27:59 -0500
  from eggs.gnu.org ([2001:470:142:3::10]:39911) by lists.gnu.org with esmtp 
(Exim 4.90_1) (envelope-from ) id 1iXnQr-0002zm-Am for 
nmh-workers@nongnu.org; Thu, 21 Nov 2019 09:27:42 -0500
  from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from 
) id 1iXnQq-0007yp-1j for nmh-workers@nongnu.org; Thu, 
21 Nov 2019 09:27:41 -0500
  from pellegrino.bradfordfamily.org ([208.53.44.231]:50897) by eggs.gnu.org 
with smtp (Exim 4.71) (envelope-from ) id 
1iXnQp-0007uL-NM for nmh-workers@nongnu.org; Thu, 21 Nov 2019 09:27:39 -0500
  (qmail 73392 invoked from network); 21 Nov 2019 14:27:26 -
  from localhost (HELO arnor.bradfordfamily.org) (127.0.0.1) by localhost with 
SMTP; 21 Nov 2019 14:27:26 -
  (qmail 71469 invoked from network); 21 Nov 2019 14:27:10 -
  from localhost (HELO edoras.bradfordfamily.org) (127.0.0.1) by localhost with 
SMTP; 21 Nov 2019 14:27:10 -
  (qmail 50445 invoked from network); 21 Nov 2019 14:27:10 -
  from angmar.bradfordfamily.org (50.77.44.21) by edoras.bradfordfamily.org 
with SMTP; 21 Nov 2019 14:27:10 -
  (qmail 27684 invoked by uid 1000); 21 Nov 2019 14:27:10 -

Where dig is actually digmsg, c is create, h is header, s is show,
and r is remove.  String matching etc. via the csop and vexpr
commands.
I have heared someone revived qmail and wants to include some
patches for builtin TLS etc.  That sounded very much interesting,
especially if its mailing-list manager would be maintained again!

 |Andy
 |
 |[1] https://cr.yp.to/mess822.html
 ...

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



Re: format and output all received: lines in an e-mail message

2019-11-21 Thread Andy Bradford
Thus said Greg Minshall on Wed, 20 Nov 2019 10:41:34 +0530:

> then, i'd like  to use something like fmttest(1) to  print out all the
> "Received:" lines in an e-mail message. ideally, each "Received:" line
> would come  out on a  separate line; less  ideally, but i'm  sure very
> practical, a very  long line would come out, with  some odd ascii code
> separating the individual lines.

I usually use  822field (from mess822 [1]) for this  kind of thing which
takes all received lines and reformats them one per line (odd ascii code
separating them is a newline).

For example, your message looks like:

$ 822field received < `mhpath cur` | tail -6   
 from eggs.gnu.org ([2001:470:142:3::10]:33280) by lists.gnu.org with esmtp 
(Exim 4.90_1) (envelope-from ) id 1iXIOr-0005CP-UD for 
nmh-workers@nongnu.org; Wed, 20 Nov 2019 00:19:34 -0500
 from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from 
) id 1iXIOq-00089z-NS for nmh-workers@nongnu.org; Wed, 20 Nov 
2019 00:19:33 -0500
 from hiwela.pair.com ([209.68.5.201]:21038) by eggs.gnu.org with esmtp (Exim 
4.71) (envelope-from ) id 1iXIOq-00088d-K6 for 
nmh-workers@nongnu.org; Wed, 20 Nov 2019 00:19:32 -0500
 from hiwela.pair.com (localhost [127.0.0.1]) by hiwela.pair.com (Postfix) with 
ESMTP id 001419805E3 for ; Wed, 20 Nov 2019 00:11:43 
-0500 (EST)
 from minshall-entroware-apollo.cliq.com (unknown [59.95.74.169]) (using 
TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client 
certificate requested) by hiwela.pair.com (Postfix) with ESMTPSA id 89AEF8F084C 
for ; Wed, 20 Nov 2019 00:11:43 -0500 (EST)
 from apollo2.minshall.org (localhost [IPv6:::1]) by 
minshall-entroware-apollo.cliq.com (Postfix) with ESMTP id E305D6089A for 
; Wed, 20 Nov 2019 10:41:34 +0530 (IST)

Andy

[1] https://cr.yp.to/mess822.html
-- 
TAI64 timestamp: 40005dd69ee2





Re: format and output all received: lines in an e-mail message

2019-11-21 Thread Paul Fox
greg wrote:
 > ps -- the goal is a little "blame" script for e-mail that tells you how
 > long a given message spent moving from A to B.  (this relies, of course,
 > on globally synchronized clocks, but that seems much more likely to be
 > true today than it did when Received: lines were first introduced.)

Oh, why didn't you say so. :-)  Don't know if he's still on the list,
but I cribbed this from Chris Garrigues many many years ago.  Takes a
raw message on stdin.

paul

#!/usr/bin/perl -w
#
# mailroute by Chris Garrigues 
#
# Reads an email message on stdin and pretty prints the contents of the
# recieved headers.
#
# When given an email message as it's argument will parse out the received
# headers and display the route it took to get to you and the times it
# arrived at each of the locations in your local timezone.
#
# It also tries to be clever in how it displays things:  (1) It only shows
# what changed in the date/time rather than the entire date/time each time. 
# (2) It breaks the line before the keywords "from", "by", and "with"
# unless they appear in comments.

# Changes by Mikko H�nninen 
#
# - match non-numeric timezones, as well as more liberal number checking
# - allow for two digit years as well as four digits (actually, any number
#   of digits)
# - also display Delivered-To: lines amidst Received: information
# - timezone conversion works even with timezones like +0745
# - somewhat prettier output (split at by/with/from) for non-recognised
#   date lines
# - print time difference from first entry
# - print time different always, even if it's the same as previous time
#   (so you can see where each hop is)
# - added "id" and "for" to keywords before which a linebreak is added
# - print date information on a separate line, so there's no need to reserve
#   columns for it on every line
# - print malformed received lines (cannot parse date) "as-is" with no
#   offset


use Time::Local;

# Global variable for date parsing
%mon = ('jan' => 0,
'feb' => 1,
'mar' => 2,
'apr' => 3,
'may' => 4,
'jun' => 5,
'jul' => 6,
'aug' => 7,
'sep' => 8,
'oct' => 9,
'nov' => 10,
'dec' => 11);

# Initialize some variables to keep -w quiet
($owd, $om, $od, $ot, $oy) = ("", "", "", "", "");


# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}


# Read the headers into $_
($_ = "\n" . join("", <>)) =~ s/\n\n.*$//sg;

# Parse the contents of the received headers into an array
@rec = ();
while (/\n(received|delivered-to):(.*?)(\n\S)/gis) {
unshift(@rec, "$1:$2");
#print "Adding $1: $2\n";
$_ = "$3$'";
}
#while (/\nreceived:(.*?)(\n\S)/gis) {
#unshift(@rec, $1);
#print "Adding Received: $1\n";
#$_ = "$2$'";
#}


for (@rec) {
if (/^delivered-to:/i) {
  s/^delivered-to://i;  # strip Delivered-To:
  s/\s+/ /gs;
  s/^\s+//;
  print "   Delivered-To: $_\n";
}
else {
  s/^received://i;  # strip Received:
  s/\s+/ /gs;

  # Format is "information; date"
  ($line, $date) = /^\s*(.*?)\s*;\s*(.*?)$/;
  if (!$date) {
# no date, must be malformed? simscan will produce these
# just print it out and go to next
print "   ", trim($_), "\n";
next;
  }

  $date =~ s/\(.*\)//g;
  $date =~ s/\s+/ /gs;
  # Parse the sucker
  if ($date =~ /(\d+) (jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) 
(\d+) (\d+):(\d\d):(\d\d) ([+-]?\d+|\w+)/i) {
# Coerce the date into something we can give to timegm
$d = $1;
($m = $2) =~ tr/A-Z/a-z/;
$y = $3;
$h = $4;
$mi = $5;
$s = $6;
$tz = $7;
if ($tz =~ /[+-]?\d+/) { ($zs, $zh, $zm) = $tz =~ 
/^([-+])(\d\d)(\d\d)$/; }
  else { $zs = "+"; $zh = $zm = 0; }  # word tz def, assume GMT
$m = $mon{$m};
if ($y > 1900) { $y -= 1900; } elsif ($y < 70) { $y += 100; }  # Y2K fix
if ($zs eq "+") { $zs = 1; } else { $zs = -1; }
$ts = timegm($s, $mi, $h, $d, $m, $y) -
 $zs * ($zh*60*60 + $zm*60);
$begints = $ts unless ($begints);
($wd, $m, $d, $t, $y) = split(' ', localtime($ts));
$d = " $d" if ($d < 10);
# Insert line breaks
$line =~ s/\b(by|with|from|id|for)\b/\n   $1/g;
# But take them back out if they're in a comment
while ($line =~ s/\(([^()]*?)\s\s+?(.*?)\)/\($1 $2\)/gs) {};
$line =~ s/\( /\(/g;
$line =~ s/^\s*//s;
# Figure out what parts of the date we want to display
($pwd, $pm, $pd, $pt, $py) = ($wd, $m, $d, $t, $y);
$pwd = "" if ($wd eq $owd);
$pm = "" if ($d eq $od);
#$pm = "" if ($m eq $om);
$pd = "" if ($d eq $od);
$pt = "" if ($t eq 

Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Greg Minshall
hi, Valdis!

ah, formail -- awesome!  yes, that does great.

Ken and Ralph -- thanks for your replies.  yes, awk and sed are in my
repertoire, but, well, i was wondering if i could avoid those in this
case.

cheers, Greg

ps -- the goal is a little "blame" script for e-mail that tells you how
long a given message spent moving from A to B.  (this relies, of course,
on globally synchronized clocks, but that seems much more likely to be
true today than it did when Received: lines were first introduced.)



Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Valdis Klētnieks
On Wed, 20 Nov 2019 10:41:34 +0530, Greg Minshall said:
> hi.  i'd like first, of course, to thank you all for nmh!
>
> then, i'd like to use something like fmttest(1) to print out all the
> "Received:" lines in an e-mail message.  ideally, each "Received:" line
> would come out on a separate line; less ideally, but i'm sure very
> practical, a very long line would come out, with some odd ascii code
> separating the individual lines.

Well in the "not using mh tools at all" category, if you have procmail
installed, you can just use:

[~] cat Mail/inbox/1 | formail -c -x Received
 from localhost (localhost [127.0.0.1]) by turing-police.cc.vt.edu 
(8.12.6.Beta1/8.12.6.Beta1) with ESMTP id g86N6Pbs020540 for 
; Fri, 6 Sep 2002 19:06:25 -0400
 from fan.cc.vt.edu [198.82.161.8]  by localhost with POP3 
(fetchmail-5.9.0)for valdis@localhost (single-drop); Fri, 06 Sep 2002 
19:06:25 -0400 (EDT)
 from dagger.cc.vt.edu ([10.1.1.11])  by gkar.cc.vt.edu (Sun Internet Mail 
Server sims.3.5.2001.05.04.11.50.p10)  with ESMTP id 
<0h210069rhg...@gkar.cc.vt.edu> for valdis@sims-ms-daemon; Fri,  6 Sep 2002 
19:05:21 -0400 (EDT)
 from mail01.corp.tellme.com (mail01.corp.tellme.com [209.157.157.98])  by 
dagger.cc.vt.edu (Mirapoint Messaging Server MOS 3.2.0-GA)  with ESMTP id 
AQM10446; Fri, 06 Sep 2002 19:05:20 -0400 (EDT)
 from mail01.corp.tellme.com (localhost [127.0.0.1])  by localhost.tellme.com 
(Postfix) with ESMTP id 1EE5744BDD for  ; Fri, 06 Sep 
2002 16:05:19 -0700 (PDT)
 from dhcp157-180.corp.tellme.com  (dhcp157-180.corp.tellme.com 
[209.157.157.180]) by mail01.corp.tellme.com  (Postfix) with ESMTP id 
A6F5444BDA for ; Fri,  06 Sep 2002 16:05:18 -0700 (PDT)

(Note that this returns the *values* of the lines, not the line.
 | sed -e 's/^/Received: /'  if that matters to you.


pgpfZqsSToygm.pgp
Description: PGP signature


Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Ralph Corderoy
Hi Paul,

> greg wrote:
> > then, i'd like to use something like fmttest(1) to print out all the
> > "Received:" lines in an e-mail message.  ideally, each "Received:"
> > line would come out on a separate line; less ideally, but i'm sure
> > very
>
> Is strict use of only MH tools a requirement for some reason?  Because
> if not, then this does a pretty good job:
> show -noshowproc |sed -n -e '/^$/q' -e '/^Received:/p' 

Fields can be continued by starting the next line with white-space,
and Received fields are often continued.  :-)

-- 
Cheers, Ralph.



Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Paul Fox
greg wrote:
 > then, i'd like to use something like fmttest(1) to print out all the
 > "Received:" lines in an e-mail message.  ideally, each "Received:" line
 > would come out on a separate line; less ideally, but i'm sure very

Is strict use of only MH tools a requirement for some reason?  Because
if not, then this does a pretty good job:
show -noshowproc |sed -n -e '/^$/q' -e '/^Received:/p' 

paul
=--
paul fox, p...@foxharp.boston.ma.us (arlington, ma, where it's 35.2 degrees)




Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Ralph Corderoy
Hi Greg,

> That's all I've time for at the moment, but others may chip in and this
> saves them covering some of the ground.

Ken's mhl(1) suggestion is what I would have tried.  But there's also
non-nmh solutions, e.g. sed or awk if you're familiar with those.
This prints all the Foo fields, each on a line, joining continuation lines.

#! /usr/bin/gawk -bf

BEGIN {
IGNORECASE = 1
}

pending {
if (/^[ \t]/) {
printf " %s", $0
} else {
print ""
pending = 0
}
}

/^foo[ \t]*:/ {
printf "%s:%s", FILENAME, $0
pending = 1
next
}

/^$/ {
nextfile
}

END {
if (pending)
print ""
}

-- 
Cheers, Ralph.



Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Ken Hornstein
>then, i'd like to use something like fmttest(1) to print out all the
>"Received:" lines in an e-mail message.  ideally, each "Received:" line
>would come out on a separate line; less ideally, but i'm sure very
>practical, a very long line would come out, with some odd ascii code
>separating the individual lines.

The format engine may not be the best tool for this job.

It is really optimized for dealing with header fields that appear only
once (e.g., Subject) or ones that can be combined in a reasonable
way (like header fields that contain address).  So when you refer to
%{received}, you're getting everything folded together.  There's no loop
processing that you could use to say, "Run these commands for every
instance of the Received header", which is really wnat you want.  That's
not to say it wouldn't be useful, but it would require some serious
rethinking of the format engine.

But, have you considered using mhl with a custom mhl format file?  That's
a tool designed to deal with each invidiual header, and I think that
would do exactly what you want.

--Ken



Re: format and output all received: lines in an e-mail message

2019-11-20 Thread Ralph Corderoy
Hi Greg,

Keeping you CC'd.

> context: the problem is there are (typically) multiple "Received:"
> header in an e-mail messages; can try either of these
> 
> bash% fmttest -outsize max +SOMEFOLDER 660 -format "%(putstr{received});"
> bash% fmttest -outsize max +SOMEFOLDER 660 -format "%(putlit{received});"
> 
> and get either a long line, or a number of lines, but without any real
> indication of how to separate the output into individual "Received"
> lines.

Here's my input test file.

$ sed -n l mail
foo: a aa$
foo: b bb$
foo: c$
 cc$
foo:$
 dd$
foo: e$
\tee$
$

Obvious approach, as you found, gives all the values of the Received
fields in one go.

$ fmttest -outsize max -format '%{foo}' -file mail
a aa b bb c cc dd e ee
$

-dump and -trace can be useful for more insight.

$ fmttest -dump -trace -outsize max -format '%{foo}' -file mail
Instruction dump of format string: 
%{foo}
COMP, comp "foo"
DONE
COMP, comp "foo", c_flags 0x8
num=0 str=
outbuf="a aa b bb c cc dd e ee"
DONE
a aa b bb c cc dd e ee
$

Using %(putstr) shows the string register being set to the values with a
tab inserted to join them together.

$ fmttest -dump -trace -outsize max -format '%(putstr{foo})' -file mail
Instruction dump of format string: 
%(putstr{foo})
LS_COMP, comp "foo"
STR
DONE
LS_COMP, comp "foo", c_flags 0x8
num=0 str=" a aa\n\t b bb\n\t c\n cc\n\t\n dd\n\t e\n\tee"
STR
outbuf="a aa b bb c cc dd e ee"
DONE
a aa b bb c cc dd e ee
$

Using %(putlit) preserves those tabs.

$ fmttest -dump -trace -outsize max -format '%(putlit{foo})' -file mail
Instruction dump of format string: 
%(putlit{foo})
LS_COMP, comp "foo"
STRLIT
DONE
LS_COMP, comp "foo", c_flags 0x8
num=0 str=" a aa\n\t b bb\n\t c\n cc\n\t\n dd\n\t e\n\tee"
STRLIT
outbuf=" a aa\n\t b bb\n\t c\n cc\n\t\n dd\n\t e\n\tee"
DONE
 a aa
 b bb
 c
 cc

 dd
 e
ee
$

But \n\t can't be used to split them back into the original distinct
field values because that may occur within a value, as with my ee test
input.

That's all I've time for at the moment, but others may chip in and this
saves them covering some of the ground.

-- 
Cheers, Ralph.



format and output all received: lines in an e-mail message

2019-11-20 Thread Greg Minshall
hi.  i'd like first, of course, to thank you all for nmh!

then, i'd like to use something like fmttest(1) to print out all the
"Received:" lines in an e-mail message.  ideally, each "Received:" line
would come out on a separate line; less ideally, but i'm sure very
practical, a very long line would come out, with some odd ascii code
separating the individual lines.

any hints?

cheers, Greg


context: the problem is there are (typically) multiple "Received:"
header in an e-mail messages; can try either of these

bash% fmttest -outsize max +SOMEFOLDER 660 -format "%(putstr{received});"
bash% fmttest -outsize max +SOMEFOLDER 660 -format "%(putlit{received});"

and get either a long line, or a number of lines, but without any real
indication of how to separate the output into individual "Received"
lines.