Thread View: comp.mail.misc
2 messages
2 total messages
Started by Keith Ford
Fri, 24 Jul 1992 18:40
extract adding address
Author: Keith Ford
Date: Fri, 24 Jul 1992 18:40
Date: Fri, 24 Jul 1992 18:40
13 lines
895 bytes
895 bytes
I would like to pipe a RFC 822 message into a program and have it return the return address. The Reply-To: line should take precedence (sp?) over the From: line. I'm using a UNIX box with System V. A shell script or C program would be nice. I don't use perl, but I guess I could learn. Thanks for your time... -- Keith Ford __ 73s, KA4ZDG Intergraph Corp / \ Micro Magic BBS 1:373/12 Rush/Opus Archive +1 205 730-8614 \__/ sysop@umagic.fidonet.org server@ingr.com fordke@ingr.com [__] 830-2362 HST/V32bis 9600 "Subject: HELP"
Re: extract adding address
Author: Larry Wall
Date: Mon, 27 Jul 1992 16:42
Date: Mon, 27 Jul 1992 16:42
33 lines
1857 bytes
1857 bytes
In article <1992Jul24.184037.15528@infonode.ingr.com> fordke@infonode.ingr.com (Keith Ford) writes:
:
: I would like to pipe a RFC 822 message into a program and have
: it return the return address. The Reply-To: line should take
: precedence (sp?) over the From: line. I'm using a UNIX box
: with System V. A shell script or C program would be nice.
: I don't use perl, but I guess I could learn.
Here's the usual Perl incantation for such things. It relies on two
subtle tricks: first, if you split a string using a pattern with
parens, it returns the corresponding portions of the delimiters as well
as the fields between delimiters, and second, if you assign a list to
an associative array, each pair of strings becomes one key-value pair.
Once you've done that you can look at the entries in any order you please.
#!/usr/bin/perl
$/ = ""; # paragraph mode
$* = 1; # multi-line pattern matching
$_ = <>; # read one paragraph
%head = ('PRESTUFF', split(/^(\S+):\s*/)); # split on entry names
print $head{'Reply-To'} || $head{'From'}; # print the one you want
You can even get at the uucp-style colon-less From line if you so desire
since that will be part of PRESTUFF, if the article contains such a line.
Also, if you're allergic to answers with embedded newlines, you can say
s/\n[ \t]+/ /g; # join multi-line entries
just before the split line.
Larry Wall
lwall@netlabs.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads