| 13 | echo "Usage:  $0 [OPTIONS]" | echo "Usage:  $0 [OPTIONS]" | 
| 14 | echo | echo | 
| 15 | echo "where possible OPTIONS are:" | echo "where possible OPTIONS are:" | 
| 16 | echo "  (-help|-h)           print usage" | echo "  (-h|-help)           print usage" | 
| 17 | echo "  (-ind |-i )DIR       get mpack-created emails from DIR" | echo "  (-s|-silent)         silent mode" | 
| 18 |  | echo "  (-v|-verbose)        verbose mode" | 
| 19 |  | echo "  (-i |-ind )DIR       get mpack-created emails from DIR" | 
| 20 | echo "                         [def=\"$INDIR\"]" | echo "                         [def=\"$INDIR\"]" | 
| 21 | echo "  (-outd |-o )DIR      write the data to DIR" | echo "  (-o |-outd )DIR      write the data to DIR" | 
| 22 | echo "                         [def=\"$OUTDIR\"]" | echo "                         [def=\"$OUTDIR\"]" | 
| 23 | echo "  (-tempd |-t )DIR     use temporary directory DIR" | echo "  (-t |-tempd )DIR     use temporary directory DIR" | 
| 24 | echo "                         [def=\"$TEMPDIR\"]" | echo "                         [def=\"$TEMPDIR\"]" | 
| 25 | echo | echo | 
| 26 | exit 1 | exit 1 | 
| 31 | OUTDIR= | OUTDIR= | 
| 32 | TEMPDIR=./ptmp | TEMPDIR=./ptmp | 
| 33 | MUNPACK=/u/edhill/local/bin/munpack | MUNPACK=/u/edhill/local/bin/munpack | 
| 34 |  | PRT=1 | 
| 35 |  |  | 
| 36 | #  Parse options | #  Parse options | 
| 37 | ac_prev= | ac_prev= | 
| 50 |  |  | 
| 51 | -help | --help | -h | --h) | -help | --help | -h | --h) | 
| 52 | usage ;; | usage ;; | 
| 53 |  | -s | --s | -silent | --silent) | 
| 54 |  | PRT=0 ;; | 
| 55 |  | -v | --v | -verbose | --verbose) | 
| 56 |  | PRT=2 ;; | 
| 57 |  |  | 
| 58 | -ind | --ind | -i | --i) | -ind | --ind | -i | --i) | 
| 59 | ac_prev=INDIR ;; | ac_prev=INDIR ;; | 
| 94 | chmod 775 $OUTDIR | chmod 775 $OUTDIR | 
| 95 | fi | fi | 
| 96 |  |  | 
|  | echo "Using OUTDIR=\"$OUTDIR\"" |  | 
|  | echo "Using INDIR=\"$INDIR\"" |  | 
|  |  |  | 
| 97 | all_files=`ls -1 $INDIR` | all_files=`ls -1 $INDIR` | 
| 98 |  | nb_files=`echo $all_files | grep -c '^msg\.'` | 
| 99 |  |  | 
| 100 |  | if test $PRT = 1 ; then | 
| 101 |  | echo "Using OUTDIR=\"$OUTDIR\"" | 
| 102 |  | echo "Using INDIR=\"$INDIR\"" | 
| 103 |  | echo -n "Unpacking the emails ..." | 
| 104 |  | elif test $nb_files != 0 ; then | 
| 105 |  | echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'" | 
| 106 |  | if test $PRT = 2 ; then echo -n " dir:" ; fi | 
| 107 |  | fi | 
| 108 |  |  | 
|  | echo -n "Unpacking the emails ..." |  | 
| 109 | for file in $all_files ; do | for file in $all_files ; do | 
| 110 |  |  | 
| 111 | #  create local copy | #  create local copy | 
| 137 | rm -f $TEMPDIR"/out" | rm -f $TEMPDIR"/out" | 
| 138 |  |  | 
| 139 | #  copy to $OUTDIR and rename if necessary | #  copy to $OUTDIR and rename if necessary | 
| 140 |  | sdir=$tdir | 
| 141 | if test -e $OUTDIR"/"$tdir ; then | if test -e $OUTDIR"/"$tdir ; then | 
| 142 | ad=0 | ad=0 | 
| 143 | while test -e $OUTDIR"/"$tdir"_"$ad ; do | while test -e $OUTDIR"/"$tdir"_"$ad ; do | 
| 144 | ad=$(( $ad + 1 )) | ad=$(( $ad + 1 )) | 
| 145 | done | done | 
| 146 | mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1 | sdir=$tdir"_"$ad | 
|  | chmod -R a+rx $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1 |  | 
|  | #       gzip $OUTDIR"/"$tdir"_"$ad"/output.txt" |  | 
|  | else |  | 
|  | mv $TEMPDIR"/"$tdir $OUTDIR > /dev/null 2>&1 |  | 
|  | chmod -R a+rx $OUTDIR"/"$tdir > /dev/null 2>&1 |  | 
|  | #       gzip $OUTDIR"/"$tdir"/output.txt" |  | 
| 147 | fi | fi | 
| 148 |  | if test $PRT = 2 ; then echo -n " '$sdir'" ; fi | 
| 149 |  | mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 | 
| 150 |  | chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 | 
| 151 |  | #   gzip $OUTDIR"/"$sdir"/output.txt" | 
| 152 |  |  | 
| 153 | #  remove the original file | #  remove the original file | 
| 154 | rm -f $INDIR"/"$file | rm -f $INDIR"/"$file | 
| 155 |  |  | 
| 156 | done | done | 
| 157 | echo "  done" | if test $PRT = 1 ; then echo "  done" ; fi | 
| 158 |  | if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi | 
| 159 |  |  | 
| 160 | # echo -n "gzipping all the \"output.txt\" files ..." | # echo -n "gzipping all the \"output.txt\" files ..." | 
| 161 | # ( | # ( |