dir=/home1/tamblayo/mail/inhedo.com/informeges/cur
rm -r INFGES FILGES DATGES LINGES
mkdir INFGES FILGES DATGES LINGES

INFGES=`pwd`/
#echo $dir/1552434186.M403233P898282.host213.hostmonster.com,S=98944,W=100567:2,S
for i in $dir/*
do
#echo $dir/$i
file=`date +%Y%m%d%H%M%S%N`$$
awk ' { if(length==76 && substr($0,76,1)=="=")  print substr($0,1,length-1); else print   } ' $i >tmp/LINT
awk -F">" '
$0=="" { next  } 
/Delivery-date/ { print >"'"$INFGES/DATGES/$file"'" }
/^Subject/ && !/Domiciliaria/ { print >"'"$INFGES/DATGES/$file"'" }
/Content-Type: text\/html;/ { getline; getline; getline;r=1 }
r=="" { next }
NF==1 { printf "%s",$0 ;next }
{
	#print  "\n=====\nNF="NF"\n"$0"\n================="
	for (i=1;i<NF;i++) printf "%s>\n",$i 
	printf "%s",$NF
}


' tmp/LINT > $INFGES/LINGES/$file 
awk -F">" '
/div dir=3D\"auto\" style=3D\"background-color/   { getline 
if( index($0,"mailto")) getline
rt++
split($0,a,"<") ; print  "T^"rt"^"a[1] }
/selected/ { rs++;split($0,a,"\"") ; print  "S^"rs"^"a[2] }
/checked/ && /Ambulatorio/ { rc++;split($0,a,"\"") ; print "C^"rc"^Ambulatorio" }
/checked/ && /Domicilio/ { rc++;split($0,a,"\"") ; print "C^"rc"^Domicilio" }
/q-text/ { getline;
if( index($0,"mailto")) getline
rt++
split($0,a,"<") ; print  "T^"rt"^"a[1] }

' $INFGES/LINGES/$file > $INFGES/INFGES/$file
echo $i > $INFGES/FILGES/$file
#[ -s $INFGES/LINGES/$file ] || exit

[ -s $INFGES/INFGES/$file ] || sh v01 $INFGES/LINGES/$file> $INFGES/INFGES/$file
[ -s $INFGES/INFGES/$file ] || sh v02 $INFGES/LINGES/$file> $INFGES/INFGES/$file
done 
#sh v11
