Kevin -- After reading David Tamkin's post I'm going to have to unearth my sed book; sed's man pages and info pages are all quite lame... So... More Perl!!! ;-) Ah, I was thrown off by the "X_COMMAND" and "__END" tokens somewhere in this thread. Here is what I come up with -- not that there is a shortage of good solutions -- I'm mainly just enjoying hacking on it. FWIW, This could be easily hacked to allow X-Commands to start on *any* body line, not just the first, which would deal with MIME lossage... (ick) Aaaaanyhow, unless there's a good reason, I promise to stop flogging this expired equine. After this last time. --- cut here --- # X-Commands, if they appear in the body of a message, # must be the first line, and must be followed by a # blank line before the rest of the body of the message, # or be the only thing in the message. If there's more # than one X-Command in the body, they must not be # separated by a blank line. # Each X-Command: must start at the beginning of a line. # Each X-Command: blah blah blah can be across multiple lines. # This is expensive, but X-Commands should be somewhat rare. :0 Bw * ^^X-Command:.* { # Perl in slurp/print mode; # Zap header; # Zap secondary paras; # flatten to one line; # put each cmd on own line: XCMD=`perl -p -0077 -e \ 's/.*?[\n\r]{2,}//s; \ s/[\n\r]{2,}.*//s; \ s/[\n\r\s]+/ /sg; \ s/ (X-Command:)/\n$1/g;'` :0 af * XCMD ?? ^X-Command: .+ |formail -i "$XCMD" } # End of recipe --- cut here --- Regards, Pete. On Fri, 19 Jul 2002, KEVIN ZEMBOWER wrote:
Peter, the only criticism I have of this method is that it requires the person sending the X-Command to know in advance that it's going to be wrapped, and to put the magic "_END" at the end of this. This was not my situation; the X-Commands just suddenly stopped working (for only long email addresses, we discovered later) and no one knew why.
I prefer a solution which says: "X-Commands, if they appear in the body of a message, must be the first line, and must be followed by a blank line before the rest of the body of the message, or be the only thing in the message. If there's more than one X-Command in the body, they must not be separated by a blank line."
I think that this would work more intuitively and naturally. It should also work for automatic word wrapping which occurs without the author's knowledge or consent.
Unfortunately, I don't know how to write the perl code for this. Sorry.
Thank you for your efforts to update the FAQ. I've found it very valuable.
-Kevin Zembower
Peter Hartzler <pete@hartzler.net> 07/18/02 07:59PM >>> Hmm...
I'm interested in updating the FAQ, but the code seems to be a bit crazy yet. (Ironically, the word-wrapping doesn't help. ;-)
Now, I could be way off on this one, so don't go jumping up to place this into production; there are some dark corners to this stuff that I'm sure I don't know about!
If the goal here is to pick out and unwrap text from a message and inject that text as a header using perl, then I'm thinking this might be saner:
--- cut here --- # Allow embedding a single X-Command on multiple lines # within the body of an email. (Lines will be joined.) # Look for FIRST magic X_CMD: token. If found, # take from there to __END and add to message header. # Like this: X_CMD: X-Command: blah blah blah __END # (X-Command: blah blah blah..) can be across multiple lines... # Note that this is kind of expensive, but X-Commands should # be somewhat rare. :0 Bw * X_CMD: * __END { XCMD=`perl -p -0077 -e \ 's/[\n\r\s]+/ /sg; \ s/^.*?X_CMD:\s*(.*?)\s*__END.*/$1/;'`
:0 f |formail -i "$XCMD" } # End of recipe --- cut here ---
Please let me know if I'm out to lunch on this one.
Check out the SmartList FAQ at http://www.hartzler.net/smartlist/
Regards,
Pete.
Smartlist mailing list Smartlist@lists.RWTH-Aachen.DE http://MailMan.RWTH-Aachen.DE/mailman/listinfo/smartlist