csh alias hack
Mar. 10th, 2004 01:49 pmIt's rare I get to report a good hack! A bit of background first about Habeas and spam:
I'm getting a notable increase in spam that uses the Habeas warrant mark (and gets through SpamAssassin). This is a copyright law trick one group is using to greate a concept of "Sender Warranted Email". Any message with the Habeas header (including the copyrighted Habeas haiku, in full) is a violation of their copyright. *Unless* it's not spam, in which case they grant a license in return for the sender's warrant that it isn't spam. They have sued spammers and won judgments proportional to the number of violations.
If you read the Habeas header, it includes a website at which to report violations. I always do -- it's easy and satisfying.
With the rise of Habeas-violating email, I wanted it to be even easier to report them, so I made an alias to cat the current message. I use mh, which stores the current message number in the second field of the first line in .mh_sequences. This number is also the filename of the message.
Tricky alias! Smart aliases are hard because the command that defines the alias is parsed by the shell, which does immediately all the special things with ' and " and $ that you really want done when the alias is actually called. I was about to give up and write a script instead, but then the following worked.
#prints a string with a bunch of special characters.
alias cm0 echo '\{print \$2\}'
#gets the current message number
alias cm1 "cat ~/Mail/in/.mh_sequences | head -1 | awk '`cm0`'"
#cats that message
alias catm 'cat ~/Mail/in/`cm1`'
I'm getting a notable increase in spam that uses the Habeas warrant mark (and gets through SpamAssassin). This is a copyright law trick one group is using to greate a concept of "Sender Warranted Email". Any message with the Habeas header (including the copyrighted Habeas haiku, in full) is a violation of their copyright. *Unless* it's not spam, in which case they grant a license in return for the sender's warrant that it isn't spam. They have sued spammers and won judgments proportional to the number of violations.
If you read the Habeas header, it includes a website at which to report violations. I always do -- it's easy and satisfying.
With the rise of Habeas-violating email, I wanted it to be even easier to report them, so I made an alias to cat the current message. I use mh, which stores the current message number in the second field of the first line in .mh_sequences. This number is also the filename of the message.
Tricky alias! Smart aliases are hard because the command that defines the alias is parsed by the shell, which does immediately all the special things with ' and " and $ that you really want done when the alias is actually called. I was about to give up and write a script instead, but then the following worked.
#prints a string with a bunch of special characters.
alias cm0 echo '\{print \$2\}'
#gets the current message number
alias cm1 "cat ~/Mail/in/.mh_sequences | head -1 | awk '`cm0`'"
#cats that message
alias catm 'cat ~/Mail/in/`cm1`'
no subject
Date: 2004-03-10 12:57 pm (UTC)Another approach uses the "mhpath" command. "mhpath cur" prints the full pathname of the current message. (And "mhpath last" prints the full pathname of the next message, "mhpath last:-10" prints the full pathnames, one per line, of the last 10 messages in the folder, and "mhpath new" will give you a pathname to a new message that doesn't exist yet -- what "inc" would use next.) So "alias catm 'cat `mhpath cur`'" should work.
Alternatively, I presume you want this so you can get the Received: headers and that sort of thing. "show -noshow" will show the current message without doing any sort of processing on it at all, except for prepending a single line of the form "(Message inbox:1066)". So "alias catm 'show -noshow | sed 1d'" would be equivalent, if a little less efficient. (The sed command deletes the first line.)
no subject
Date: 2004-03-12 12:45 pm (UTC)no subject
Date: 2004-03-11 05:15 pm (UTC)| blah
and run your script and have it process your email and do the right thing. (TM)
:)
;)
no subject
Date: 2004-03-12 01:00 pm (UTC)(I almost never use Pine for anything but testing, though, 'cause I like MH's shell-command-per-action paradigm.)