cd INFGES
dir=/home1/tamblayo/mail/inhedo.com/informeges/cur
for i in *
do
[ -s $i ] || {
x=`cat ../FILGES/$i`
#more $x
egrep base64 $x >/dev/null
[ $? = 0 ] && {
rm ../tmp/part*
echo  $i
echo =====================================
awk -F">" ' BEGIN { part=0 }
/X-Spam-Flag: NO/ { print >sprintf("../tmp/part%.2d",part)
r=""
print "Content-Type: text/html"
  getline
if(index($0,"Subject: [SPAM]")) getline
print >sprintf("../tmp/part%.2d",part)
print >sprintf("../tmp/part%.2d",part)
        part++
        while (r=="" && getline)
        {
                print >sprintf("../tmp/part%.2d.b64",part)
                if(length <76) r=1
        }
        part++


} 
/Content-Type: text\// { print >sprintf("../tmp/part%.2d",part) ; getline
if(index($0,"base64")) {
	r=""
	print >sprintf("../tmp/part%.2d",part)
	r=""
	getline
	print >sprintf("../tmp/part%.2d",part)
	part++
	while (r=="" && getline)
	{
		print >sprintf("../tmp/part%.2d.b64",part)
		if(length <76) r=1
	}
	part++
	
}
}
{ print >sprintf("../tmp/part%.2d",part)} 

' $x
for j in part00 part01 part02 part03 part04 part05 part06 part07
do
[ -s ../tmp/$j ] && cat ../tmp/$j
[ -s ../tmp/$j.b64 ] && base64 -d ../tmp/$j.b64 
done |
awk ' { if(length==76 && substr($0,76,1)=="=")  print substr($0,1,length-1); else print   } ' - >../tmp/LINT
awk -F">" '
$0=="" { next  } 
/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 > ../LINGES/$i 
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] }

' ../LINGES/$i > ../INFGES/$i
echo $x > ../FILGES/$i
[ -s ../INFGES/$i ] || sh ../v01 ../LINGES/$i > ../INFGES/$i
# [ -s ../INFGES/$i ] || sh ../v02 ../LINGES/$i > ../INFGES/$i
[ -s ../INFGES/$i ] || echo VACIO
#[ -s $INFGES/INFGES/$file ] || exit
}
}
done 
