| 40 |
MUNPACK=$HERE/munpack |
MUNPACK=$HERE/munpack |
| 41 |
UnpTmpD="/var/tmp/m-prts-$USER" |
UnpTmpD="/var/tmp/m-prts-$USER" |
| 42 |
TR_LIST='TTT.'$$ |
TR_LIST='TTT.'$$ |
| 43 |
TEMPDIR=/tmp/prc_emails |
TEMPDIR="/tmp/prc_emails_$USER" |
| 44 |
STDOUT=$TEMPDIR/'outp.'$$ |
STDOUT=$TEMPDIR/'outp.'$$ |
| 45 |
ERRMSG=/tmp/tmp.$$ |
ERRMSG=/tmp/tmp.$$ |
| 46 |
PRT=1 |
PRT=1 |
| 130 |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
| 131 |
|
|
| 132 |
all_msg=`ls -1 $INDIR` |
all_msg=`ls -1 $INDIR` |
| 133 |
nb_files=`echo "$all_msg" | grep -c '^msg\.'` |
nb_msg=`echo "$all_msg" | grep -c '^msg\.'` |
| 134 |
|
nb_tar=`echo "$all_msg" | grep -c '\.tar\.gz$'` |
| 135 |
|
nb_files=`expr $nb_msg + $nb_tar` |
| 136 |
|
|
| 137 |
if test $PRT = 2 ; then |
if test $PRT = 2 ; then |
| 138 |
echo "Using OUTDIR=\"$OUTDIR\"" |
echo "Using OUTDIR=\"$OUTDIR\"" |
| 139 |
echo "Using INDIR=\"$INDIR\"" |
echo "Using INDIR=\"$INDIR\"" |
| 140 |
echo -n "Unpacking $nb_files emails ("`date` |
echo -n "Unpacking $nb_msg msg + $nb_tar tar-file ("`date` |
| 141 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
| 142 |
echo -n ", err-msg: '$ADDRERR'" |
echo -n ", err: $ADDRERR" |
| 143 |
fi |
fi |
| 144 |
echo ")" |
echo ")" |
| 145 |
elif test $nb_files != 0 ; then |
elif test $nb_files != 0 ; then |
| 146 |
echo -n "Unpacking $nb_files emails ("`date` |
echo -n "Unpacking $nb_msg msg + $nb_tar tar-file ("`date` |
| 147 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
| 148 |
echo -n ", err-msg: '$ADDRERR'" |
echo -n ", err: $ADDRERR" |
| 149 |
fi |
fi |
| 150 |
echo ")" |
echo ")" |
| 151 |
echo " from '$INDIR' to '$OUTDIR'" |
echo " from '$INDIR' to '$OUTDIR'" |
| 162 |
do |
do |
| 163 |
in=`grep -c $xx $TR_LIST` |
in=`grep -c $xx $TR_LIST` |
| 164 |
if test $in = 0 ; then |
if test $in = 0 ; then |
| 165 |
np=`grep -c 'Content-Type: message/partial' $INDIR/$xx` |
it=`echo $xx | grep -c '\.tar\.gz$'` |
| 166 |
if test $np = 0 ; then |
if test $it = 1 ; then |
| 167 |
echo $xx >> $TR_LIST |
echo $xx >> $TR_LIST |
| 168 |
else |
else |
| 169 |
l=`sed -n '/Content-Type: message\/partial/=' $INDIR/$xx` |
np=`grep -c 'Content-Type: message/partial' $INDIR/$xx` |
| 170 |
lp=`expr $l + 1` |
if test $np = 0 ; then |
| 171 |
id=`sed -n "$lp p" $INDIR/$xx` |
echo $xx >> $TR_LIST |
| 172 |
partM=`( cd $INDIR ; grep -c "$id" msg.* | grep -v ':0$' | sed 's/:1$//' )` |
else |
| 173 |
echo $partM >> $TR_LIST |
l=`sed -n '/Content-Type: message\/partial/=' $INDIR/$xx` |
| 174 |
if test "x$ADDRERR" != x ; then flag=1 |
lp=`expr $l + 1` |
| 175 |
echo "multi-parts message:" $partM >> $ERRMSG |
id=`sed -n "$lp p" $INDIR/$xx` |
| 176 |
( cd $INDIR ; ls -l $partM ) >> $ERRMSG |
partM=`( cd $INDIR ; grep -c "$id" msg.* | grep -v ':0$' | sed 's/:1$//' )` |
| 177 |
|
echo $partM >> $TR_LIST |
| 178 |
|
if test "x$ADDRERR" != x ; then flag=1 |
| 179 |
|
echo "multi-parts message:" $partM >> $ERRMSG |
| 180 |
|
( cd $INDIR ; ls -l $partM ) >> $ERRMSG |
| 181 |
|
fi |
| 182 |
fi |
fi |
| 183 |
fi |
fi |
| 184 |
fi |
fi |
| 220 |
continue |
continue |
| 221 |
fi |
fi |
| 222 |
|
|
| 223 |
|
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
| 224 |
|
it=`echo $grpM | grep -c '\.tar\.gz$'` |
| 225 |
|
if test $it = 1 ; then |
| 226 |
|
#- nothing to do: already a tar file! |
| 227 |
|
trOutp=$grpM ; prcM=$grpM |
| 228 |
|
else |
| 229 |
|
|
| 230 |
#-check that we have all the parts |
#-check that we have all the parts |
| 231 |
if [ $PRT -ge 1 -a $nm -gt 1 ] ; then |
if [ $PRT -ge 1 -a $nm -gt 1 ] ; then |
| 232 |
echo " group (nm=$nm) of multi-parts msg: '$grpM'" |
echo " group (nm=$nm) of multi-parts msg: '$grpM'" |
| 375 |
if test -f $TEMPDIR/$trOutp ; then ls -l $TEMPDIR/$trOutp ; fi |
if test -f $TEMPDIR/$trOutp ; then ls -l $TEMPDIR/$trOutp ; fi |
| 376 |
fi |
fi |
| 377 |
|
|
| 378 |
|
fi |
| 379 |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
| 380 |
|
|
| 381 |
#-- un-tar |
#-- un-tar |
| 382 |
#( cd $TEMPDIR ; tar -xzvf $trOutp > $STDOUT ) |
#( cd $TEMPDIR ; tar -xzvf $trOutp > $STDOUT ) |
| 383 |
# to remove small files "._mydir" that some MAC OS are adding |
# to remove small files "._mydir" that some MAC OS are adding |
| 384 |
# (for each file or dir) to a tar-file, use option "--exclude=": |
# (for each file or dir) to a tar-file, use option "--exclude=": |
| 385 |
( cd $TEMPDIR ; tar -xzvf $trOutp --exclude="._*" > $STDOUT ) |
( cd $TEMPDIR ; tar -xzvf $trOutp --exclude="._*" > $STDOUT 2> $ERRMSG ) |
| 386 |
RETVAL=$? |
RETVAL=$? |
| 387 |
|
#echo "--- content of file $STDOUT (STDOUT):" |
| 388 |
|
#cat $STDOUT |
| 389 |
|
#echo "--- content of file $ERRMSG (ERRMSG):" |
| 390 |
|
#cat $ERRMSG |
| 391 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
| 392 |
echo "parsing email error" > $ERRMSG |
echo "parsing email error" >> $ERRMSG |
| 393 |
echo " - Error: tar -xzvf $trOutp returns:" $RETVAL | tee -a $ERRMSG |
echo " - Error: tar -xzvf $trOutp returns:" $RETVAL | tee -a $ERRMSG |
| 394 |
( cd $INDIR ; ls -l $prcM ) | tee -a $ERRMSG |
( cd $INDIR ; ls -l $prcM ) | tee -a $ERRMSG |
| 395 |
ls -l $TEMPDIR/$trOutp | tee -a $ERRMSG |
ls -l $TEMPDIR/$trOutp | tee -a $ERRMSG |
| 400 |
( cd $INDIR ; mv -f $grpM ../fail2process ) |
( cd $INDIR ; mv -f $grpM ../fail2process ) |
| 401 |
continue |
continue |
| 402 |
fi |
fi |
| 403 |
|
test -f $ERRMSG && rm -f $ERRMSG |
| 404 |
|
#-- |
| 405 |
tdir=`cat $STDOUT | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
tdir=`cat $STDOUT | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
| 406 |
if test -d $TEMPDIR/$tdir ; then |
if test -d $TEMPDIR/$tdir ; then |
| 407 |
rm -f $STDOUT |
rm -f $STDOUT |