[2016-05-10 16:34] markus schnalke <mei...@marmaro.de>
> 
> Yet, I have a simpler solution (sorry for being so late with it!):
> 
>       #!/bin/sh
>       #
>       # remove From_ lines from MH messages in-place
> 
>       for i do
>               ed - "$i" <<\!
>       1,/^$/g/^From /d
>       w
>       !
>       done

This code isn't good enough. It cannot handle header-only messages,
nor does it check for read-only files. This is a better version:

        for i do
                if [ ! -w "$i" ] ; then
                        echo "$i: not writeable"
                        continue
                fi
                if grep -q '^$' "$i" ; then
                        range='1,/^$/'
                else
                        range='1,$'
                fi
                ed - "$i" <<! || echo "$i: editing failed"
        $range g/^From /d
        w
        !
        done

I used this version to convert my whole mail storage (5.8 GB).
It took about 9 minutes.

There was one message with wrong permissions (had to fix that
manually) and about 40 messages without a trailing newline
(they are correct according to RFC 822, IIRC, but not according
to Unix style; ed(1) informs that it appended a newline
automatically).


meillo

Reply via email to