예제 #1
0
파일: server.cpp 프로젝트: elff1/myCodes
int server::attachment(char *buf){
	//发送附件
	int attid=0;//初始化附件id
	FILE *fat,*fatt;
	char *buff;
	char attname[15];
	char sendbuf[Max_buf];//待发送内容
	int eattid,eattnum,mattid,ininum;
	ininum=-1;//邮件未发送时,引用次数为-1
	if(file_exists("att_info.ini")){
		//非第一次发附件
		fat=fopen("att_info.ini","r+");//记录附件ID与引用次数
		mattid=0;//存最大附件id
		while(!feof(fat)){
			fscanf(fat,"%d %d",&eattid,&eattnum);
			if(mattid<=eattid)
				mattid=eattid;//找到已存在的最大id
		}
		attid=mattid+1;//设置当前附件id
		while(!feof(fat)) fgetc(fat);
		fprintf(fat,"%d %d\n",attid,ininum);//加入附件列表
		fclose(fat);
	}
	else{
		//全服第一次发附件
		fat=fopen("att_info.ini","w");
		fprintf(fat,"%d %d\n",attid,ininum);//写入第一个附件名
		fclose(fat);
	}
	attname[0]=(char)(attid/100000000)%10+48;
	attname[1]=(char)(attid/10000000)%10+48;
	attname[2]=(char)(attid/1000000)%10+48;
	attname[3]=(char)(attid/100000)%10+48;
	attname[4]=(char)(attid/10000)%10+48;
	attname[5]=(char)(attid/1000)%10+48;
	attname[6]=(char)(attid/100)%10+48;
	attname[7]=(char)(attid/10)%10+48;
	attname[8]=(char)attid%10+48;
	attname[9]='\0';
	//附件ID转换为字符串
	fatt=fopen(attname,"w");//存储附件
	buff=getsubstr(buf+10,buf+strlen(buf));
	fprintf(fatt,buff);
	fclose(fatt);
	//strcpy_s(sendbuf,"ATTID\n\0");
	strcpy_s(sendbuf,attname);//返回文件ID的字符串格式
	senddata(sendbuf);
	
	return 0;
}
예제 #2
0
파일: events.c 프로젝트: zkl/reminder
const char * event_em_analise(struct event_em_t * em, const char * buf)
{
	int ret = 0;
	int year, month, day, hour, minute, index, find;
	const char * weekday[] = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fir", "Sat"};
	const char * monthstr[]= {"Jan", "Feb", "Mar", "Apl", "May", "Jnu", "Jul",
		"Aug", "Sep", "Oct", "Nov", "Dec"};
	
	char words[100];

	/* 初始化 */
	em->hour = -1;
	em->day  = -1;
	em->year = -1;
	em->minute = -1;
	em->second = 0;
	
	for(index=0; index < 12; index++)
		em->mounth[index] = 0;
	
	for(index=0; index < 7; index++)
		em->week[index] = 0;
	
	for(index=0; 1; index++)
	{
		buf = getsubstr(words, 100, buf, 0, ' ');
		if(buf == 0 || strlen(buf) == 0)
			return 0;

		if(stricmp(words, "RUN") == 0)
			break;

		ret = sscanf(words, "%d:%d", &hour, &minute);
		if(ret == 2)
		{
			em->hour = hour;
			em->minute = minute;
			continue;
		}

		ret = sscanf(words, "%d-%d-%d", &year, &month, &day);
		if(ret == 3 && month < 13 && day < 32)
		{
			em->year = year;
			em->mounth[month-1] = 1;
			em->day = day;
			continue;
		}

		ret = sscanf(words, "%d", &day);
		if(ret == 1 && strlen(words) <=2 && nums(words) == strlen(words))
		{
			if(em->day != -1)
			{
				printf("重复设置日期,使用最后一次设置(%d)为准\n", day);
			}
			em->day = day;
			continue;
		}

		ret = sscanf(words, "%d", &year);
		if(ret == 1 && strlen(words) <= 4 && nums(words) == strlen(words))
		{
			if(em->year != -1)
				printf("重复设置年份,使用最后一次设置(%d)为准\n", year);
			
			em->year = year;
			continue;
		}

		find = 0;
		for(index = 0;index<12; index++)
		{
			if(stricmp(words, monthstr[index]) == 0)
			{
				find = 1;
				em->mounth[index] = 1;
			}
		}

		if(find)
			continue;

		find = 0;
		for(index = 0;index<7; index++)
		{
			if(stricmp(words, weekday[index]) == 0)
			{
				find = 1;
				em->week[index] = 1;
			}
		}

		if(find)
			continue;

		/* 未知的时间格式 */
		return 0;
	}

	find = 0;
	for(index = 0;index<12; index++)
	{
		if(em->mounth[index] == 1)
		{
			find = 1;
			break;
		}
	}

	if(!find)
	{
		for(index=0; index < 12; index++)
			em->mounth[index] = 1;
	}

	find = 0;
	for(index = 0;index<7; index++)
	{
		if(em->week[index] == 1)
		{
			find = 1;
			break;
		}
	}

	if(!find)
	{
		for(index=0; index < 7; index++)
			em->week[index] = 1;
	}

	return buf;
}
예제 #3
0
파일: server.cpp 프로젝트: elff1/myCodes
int server::mail(char *buf){
	//  MAIL receiver sender (datatime) attachment topic text
	//拆分收件人
	char *reciever,*sender,*attachment,*topic,*text;
	char *p1,*p2,*p3,*p4,*p5,*p6;
	char tag[2],time[10],data[10],datatime[20];
	p1=strchr(buf,'\n');*p1=' ';
	p2=strchr(buf,'\n');*p2=' ';
	p3=strchr(buf,'\n');*p3=' ';
	p4=strchr(buf,'\n');*p4=' ';
	p5=strchr(buf,'\n');*p5=' ';
	p6=buf+strlen(buf);
	reciever=getsubstr(p1,p2);
	sender=getsubstr(p2,p3);
	attachment=getsubstr(p3,p4);
	topic=getsubstr(p4,p5);
	text=getsubstr(p5,p6);
	_strtime(time);
	_strdate(data);
	strcpy(datatime,data);
	strcat_s(datatime,"/\0");
	strcat_s(datatime,time);
	setchar(datatime,'/','-');
	setchar(datatime,':',';');
	strcpy_s(tag,"0\0");//得到收件人、发件人、日期、信箱、主题、正文


	FILE *fp;     
	char temp[30],file_name[40],buff[150],sendbuf[Max_buf];
	int i,j=0,NUM=0;

	strcpy(buff,sender);
	strcat_s(buff,"\n\0");
	strcat_s(buff,datatime);
	strcat_s(buff,"\n\0");
	strcat_s(buff,tag);
	strcat_s(buff,"\n\0");
	strcat_s(buff,attachment);
	strcat_s(buff,"\n\0");
	strcat_s(buff,topic);
	strcat_s(buff,"\n\0");//用户信箱中存放的数据,发件人、日期、tag、主题,用回车隔开

	strcpy_s(sendbuf,"SEND_MAIL\n\0");

	for (i=0;i<strlen(reciever);i++)//有多个收件人,分离收件人
	{
		if(reciever[i]==';'){
			temp[i-j]='\0';
			j=i+1;
			NUM++;//记录收件人个数,每得到一个收件人+1
			strcpy_s(file_name,temp);
			strcat_s(file_name,".txt");
			fp=fopen(file_name,"r+");
			if(fp==NULL){//收件人不存在
				strcat_s(sendbuf,"FAIL\0");
				senddata(sendbuf);
				return 0;
			}
			fseek(fp,0,SEEK_END);//文件指针移动到文件末尾
			for (int k=0;k<strlen(buff);k++)  fputc(buff[k],fp);//写入邮件内容文件中
			fclose(fp);
		}
		else temp[i-j]=reciever[i];
	}

	strcat_s(sendbuf,"DONE\0");
	senddata(sendbuf);

	//向正文文件中写数据
	strcpy_s(file_name,sender);
	strcat_s(file_name,"+");
	strcat_s(file_name,datatime);
	strcat_s(file_name,".ini");

	fp=fopen(file_name,"w");
	fprintf(fp,"%d\n",NUM);
	for (i=0;i<strlen(text);i++)  fputc(text[i],fp);//写入邮件内容文件中
	fclose(fp);//邮件列表中修改

	//修改附件引用次数
	if(attachment[0]!='0'){//有附件
		p1=strchr(attachment,';');
		p2=attachment+strlen(attachment);
		p3=getsubstr(p1,p2);//附件编号
		fp=fopen("att_info.ini","r+");
		int a,b,c;
		c=atoi(p3);
		while(!feof(fp)){
			fscanf(fp,"%d %d",&a,&b);
			if(a==c){
				fseek(fp,-2,SEEK_CUR);
				fputs("  ",fp);
				fseek(fp,-2,SEEK_CUR);
				fprintf(fp,"%d",NUM);
				fclose(fp);
				break;
			}
		}
	}
	//修改邮件列表中发件箱内容
	strcpy_s(file_name,sender);
	strcat_s(file_name,".txt\0");
	fp=fopen(file_name,"r+");
	fseek(fp,0,SEEK_END);
	fprintf(fp,"%s",reciever);
	fputc('\n',fp);
	fprintf(fp,"%s",datatime);
	fputc('\n',fp);
	fprintf(fp,"%s","4\0");
	fputc('\n',fp);
	fprintf(fp,"%s",attachment);
	fputc('\n',fp);
	fprintf(fp,"%s",topic);
	fputc('\n',fp);
	fclose(fp);
	return 0;
}