#include <stdio.h>

int wap_ckm(char *mailboxpath,char *mailboxname,char *outbuf)
{
FILE *f;
char buf[500],*k,odkogo[500];
int head=0;
int maili=0,body=0,readed=0,nowy;

if(!(f=fopen(mailboxpath,"r")))
    return 0;
while(fgets(buf,501,f))
    {
    k=(char *)index(buf,10);
    if(k!=NULL)k[0]=0;
    k=(char *)index(buf,13);
    if(k!=NULL)k[0]=0;

    if(strncmp(buf,"From ",5)==0 && head==0)
	{
	head=1;
	maili++;
	sprintf(odkogo,"%s",buf+5);
	}
    else
    if(strlen(buf)==0 && head==1)
	{
	head=0;
	body++;
	if(nowy==1)
//	    printf("%s\n",odkogo);
	nowy=0;
	}
    else
    if(head==1 && strncmp(buf,"Status:",7)==0)
	{
	nowy=1;
	if(index(buf,'R')!=0)
	    {
	    readed++;
	    nowy=0;
	    }
	}
    }
fclose(f);

sprintf(outbuf,"%s: %d new %d",mailboxname,maili,maili-readed);

return 1;
}
