Просто он немного забавный.
#!/bin/sh
#
# $1 is the mail account
[ -n "$1" ] && {
MAIL_PATH="/Mail/$1/mbox"
OUTPUT_MAIL_PATH="/mnt/flash/save/email/inbox/"
mkdir -p $OUTPUT_MAIL_PATH
mv /var/spool/mail/root/* $MAIL_PATH
for j in `find $MAIL_PATH -name "msg.*"`
do
MAIL_NAME=`basename $j`.eml
NEW_MAIL="$OUTPUT_MAIL_PATH/$MAIL_NAME"
mkdir -p "$OUTPUT_MAIL_PATH"
[ ! -f "$NEW_MAIL" ] && {
grep "^From:" $j | head -n 1 > $NEW_MAIL
if grep "^Cc:" $j ; then
grep "^Cc:" $j | head -n 1 >> $NEW_MAIL
fi
grep "^To:" $j | head -n 1 >> $NEW_MAIL
grep "^Subject:" $j | head -n 1 >> $NEW_MAIL
grep "^Date:" $j | head -n 1 >> $NEW_MAIL
if grep "^Content-Type: text/plain;" $j ; then
LINE_NUM=`grep -n "^Content-Type: text/plain;" $j | cut -d: -f1`
if grep "^Content-Type: text/plain;" $j | grep "charset=" ; then
TYPE=`grep "Content-Type: text/plain;" $j | cut -d";" -f1`
echo "$TYPE" >> $NEW_MAIL
CHAR="charset="`grep "Content-Type: text/plain;" $j | cut -d= -f2`
echo "$CHAR" >> $NEW_MAIL
else
grep "^Content-Type: text/plain;" $j >> $NEW_MAIL
x=$(($LINE_NUM+1))
sed -n "$x"p $j >> $NEW_MAIL
fi
x=$(($LINE_NUM-1))
BOUNDARY=`sed -n "$x"p $j`
for i in `sed "/$BOUNDARY/s/.*/ffffuuuucccckkkk/" $j | grep -n "ffffuuuucccckkkk" | cut -d: -f1`
do
if [ "$i" -gt "$LINE_NUM" ] ; then
i=$(($i-1))
y=$(($LINE_NUM+3))
echo "Mail content start:" >> $NEW_MAIL
sed -n "$y,$i"p $j >> $NEW_MAIL
break
fi
done
if ! grep "Mail content start:" $NEW_MAIL ; then
echo "Mail content start:" >> $NEW_MAIL
y=$(($LINE_NUM+3))
x=`grep -c "^" $j`
sed -n "$y,$x"p $j >> $NEW_MAIL
fi
else
echo "Fuck....."
fi
}
done
}