procmail
[Top] [All Lists]

Re: Help with filter recipe.

1998-12-11 08:16:52
On 11 Dec 1998 14:18:49 +0000, Nelson Jose dos Santos Ferreira
<Nelson(_dot_)Ferreira(_at_)inesc(_dot_)pt> wrote:
------
#! /bin/sh
/bin/sed 's/[        ]*^K[   ]*/\
/g' | /bin/sed 's/[  ]*^K[   ]*/\
/g'
exit 0
-----

(Parenthetically:

#!/bin/sed -f
s/[     ]*^K[   ]*/\
/g
s/[     ]*^K[   ]*/\
/g

You can pass several commands to sed from the command line too, with
the -e option: sed -e 's/[      ]*^K[   ]*/\
/g' -e 's/[     ]*^K[   ]*/\
/g' ... It is not clear to me why you are doing the same substitution
twice, assume there's a typo there. Oh, wait, one is a literal ctrl-k
and the other is the string caret-k. Is that why?)

sed is usually not very tolerant of control characters. Have you
verified that this works as intended from the command line, on the
host where Procmail runs? Also, I hope you are actually using real
ctrl-K:s in the script rather than the string caret-K. But like I
said, your sed might not be prepared to cope with that; if not,
investigate whether you can accomplish what you want with Perl (simple
-- Perl basically understands sed s/// syntax, but has a lot of regex
goodies and extensions, and of course a whole language to go with it);

    | perl -e 's/\s*\013\s*//g'

or perhaps something involving

    | tr '\013' '\012'  # this will not kill whitespace around ^K, of course

which you are of course free to elaborate on.

I call it on my .procmailrc like this:
:0 fw
*$ ${FROM_LIST}(@|\<)pilotgear
| $HOME/bin/pilotgear.strip.k
:0:
*$ ${FROM_LIST}(@|\<)pilotgear
mail.pilot-gear

If this only appears in this one list, you can do both in one fell
swoop:

    :0w:
    * $ ${FROM_LIST}\<pilotgear
    | strip-ctrl-ks >>mail.pilot-gear

\< already covers @ so you don't need the alternation you had there.

Alternatively, perhaps you want to make sure you only filter the body;
in that case, your original two-recipe script is better, but you need
a b flag -- and perhaps you want to make sure the message actually
contains a ^K before you go and spawn off the filter:

    :0bfw
    * B ?? ^K
    * $ ${FROM_LIST}\<pilotgear
    | strip-ctrl-ks

    # proceed as earlier ...

Throughout this message, I have used the string caret-K where you
should have a literal ^K character (ASCII 11).

still have Control-G in it, dispite the filter which I know 
                      ^
(Perhaps this is the big problem? You talked about ctrl-K earlier. :-)

Hope this helps,

/* era */

-- 
.obBotBait: It shouldn't even matter whether    <http://www.iki.fi/~era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>

<Prev in Thread] Current Thread [Next in Thread>