|
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include<sys/types.h>
- #include<sys/stat.h>
- int fcopy(char *p,char *p2)
- {
- char cub[1024];
- int readi;
- FILE *fp,*fp1;
- chmod(p,S_IROTH | S_IWOTH | S_IWGRP | S_IRGRP);
- fp=fopen(p,"r");
- fp1=fopen(p2,"w");
- while(!feof(fp))
- {
- readi=fread(cub,sizeof(char),1024,fp);
- fwrite(cub,sizeof(char),readi,fp1);
- }
- fclose(fp);
- fclose(fp1);
- return 0;
- }
- int main(int argc, char *argv[])
- {
- FILE *fp,*fplog;
- char cub[1024],*usermail, sTiff[1024],sDtmf[4],newdir[2000],webdir[1024]="/home/billyz/data/user";
- char userdir[1024];
- char *mailcmd1,*tmpstr;
- int CodeType,j;
- if (argc <2 )
- return EXIT_SUCCESS;
- chmod(argv[2],S_IROTH | S_IWOTH | S_IWGRP | S_IRGRP);
- fp=fopen(argv[2],"r");
- fseek(fp,0,SEEK_END);
- if (ftell(fp)<1024)
- {
- fclose(fp);
- printf("file is smal");
- return EXIT_SUCCESS;
- }
- fclose(fp);
- mailcmd1=malloc(2024);
- tmpstr=malloc(2024);
- usermail=malloc(1024);
- memset(sTiff,'\0',1024);
- memset(sDtmf,'\0',4);
- memset(usermail,'\0',1024);
- memset(userdir,'\0',1024);
- strcpy(sDtmf,argv[1]);
- strcpy(sTiff,argv[2]);
- //SMTP邮件设置
- fp=fopen("/home/billyz/data/sendEmail","r");
- if(fp==NULL)
- {
- printf("open file err");
- }
- fgets(mailcmd1,2024,fp);
- //traceServer("mailcmd:%s",mailcmd );
- fclose(fp);
-
- fplog=fopen("/home/billyz/data/sendmail.log","a+");
- fp=fopen("/home/billyz/data/CodeType","r");
- CodeType=fgetc(fp)-48;
- //traceServer("CodeType:%d",CodeType );
- fclose(fp);
- fp=fopen("/home/billyz/data/user.dat", "r");
- do
- {
- memset(cub,'\0',1024);
- fgets(cub,1024,fp);
- if(strlen(cub)>0)
- if(strcmp(strtok(cub,":"),sDtmf)==0)
- {
- strtok(NULL,":");
- strcpy(userdir,strtok(NULL,":"));
- strtok(NULL,":");
- strtok(NULL,":");
- strtok(NULL,":");
- strcpy(usermail,strtok(NULL,":"));
- printf("%s:%s\n",userdir,usermail);
- }
- }
- while(!feof(fp));
- fclose(fp);
- if(strlen(userdir)>0)
- {
- sprintf(newdir,"%s/%s/inbox/NEW%d.tiff",webdir,userdir,time((time_t*)NULL));
- //sendmail1(usermail,newdir);
-
- printf("mail: %s\n",usermail);
- fcopy(sTiff,newdir);
- j=strlen(usermail);
- printf("%c\nj:%d",mailcmd1[0],j);
- printf("\nd:%d", j);
- //执行到这里时会出错了
- if (mailcmd1[0]!='0' && j!=0)
- {
-
- printf("d");
- memset(tmpstr,'\0',2024);
- sprintf(tmpstr,"%s -t "%s" -u "you have a new fax" -m "%d" -a %s > /tmp/%d.log",mailcmd1,usermail,time((time_t*)NULL),newdir,time((time_t*)NULL));
- printf("%s",tmpstr);
- j=0;
- do
- {
- memset(cub,'\0',1024);
- system(tmpstr);
- j++;
- fp=fopen("/tmp/sendmail.log","r");
- fgets(cub,1024,fp);
- fclose(fp);
- sprintf(tmpstr,"%s:%s:%s:%s",time((time_t*)NULL),userdir,usermail,cub);
- fputs(tmpstr,fplog);
- printf("%s\n%s",tmpstr,cub);
- }
- while(!(strstr(cub,"Email was sent successfully!")!=0) && j<10);
- }
- chmod("/home/billyz/data/sendmail.log",S_IROTH | S_IWOTH | S_IWGRP | S_IRGRP);
- fclose(fplog);
-
-
- }
- else
- {
- switch(CodeType)
- {
- case 1:
- fp=fopen("/home/billyz/data/default","r");
- fgets(usermail,1024,fp);
- strcpy(userdir,strtok(NULL,":"));
- strcpy(usermail,strtok(NULL,":"));
- fclose(fp);
- sprintf(newdir,"%s/%s",webdir,userdir);
- fcopy(sTiff,newdir);
- j=strlen(usermail);
- if (mailcmd1[0]!='0' &&j!=0)
- {
- sprintf(tmpstr,"%s -t "%s" -u "you have a new fax" -m "%d" -a %s > /tmp/sendmail.log",mailcmd1,usermail,time((time_t*)NULL),newdir);
- j=0;
- do
- {
- memset(cub,'\0',2024);
- system(tmpstr);
- j++;
- fp=fopen("/tmp/sendmail.log","r");
- fgets(cub,2024,fp);
- fclose(fp);
- sprintf(tmpstr,"%s:%s:%s:%s",time((time_t*)NULL),userdir,usermail,cub);
- fputs(tmpstr,fplog);
- printf("%s\n%s",tmpstr,cub);
- }
- while(!(strstr(cub,"Email was sent successfully!")!=0) && j<10);
- }
- chmod("/home/billyz/data/sendmail.log",S_IROTH | S_IWOTH | S_IWGRP | S_IRGRP);
- fclose(fplog);
- break;
- case 2:
- fp=fopen("/home/billyz/data/user.dat", "r");
- do
- {
- memset(cub,'\0',1024);
- fgets(cub,1024,fp);
- if(strlen(cub)>0)
- if(strcmp(strtok(cub,":"),"1")!=0)
- {
- strtok(NULL,":");
- strcpy(userdir,strtok(NULL,":"));
- strtok(NULL,":");
- strtok(NULL,":");
- strtok(NULL,":");
- strcpy(usermail,strtok(NULL,":"));
- sprintf(newdir,"%s/%s/inbox/NEW%d.tiff",webdir,userdir,time((time_t*)NULL));
- fcopy(sTiff,newdir);
- //sendmail1(usermail,newdir,userdir);
- j=strlen(usermail);
- if (mailcmd1[0]!='0' &&j!=0)
- {
- sprintf(tmpstr,"%s -t "%s" -u "you have a new fax" -m "%d" -a %s > /tmp/sendmail.log",mailcmd1,usermail,time((time_t*)NULL),newdir);
- j=0;
- do
- {
- memset(cub,'\0',2024);
- system(tmpstr);
- j++;
- fp=fopen("/tmp/sendmail.log","r");
- fgets(cub,2024,fp);
- fclose(fp);
- sprintf(tmpstr,"%s:%s:%s:%s",time((time_t*)NULL),userdir,usermail,cub);
- fputs(tmpstr,fplog);
- printf("%s\n%s",tmpstr,cub);
- }
- while(!(strstr(cub,"Email was sent successfully!")!=0) && j<10);
- }
- chmod("/home/billyz/data/sendmail.log",S_IROTH | S_IWOTH | S_IWGRP | S_IRGRP);
- fclose(fplog);
- }
- }
- while(!feof(fp));
- fclose(fp);
- break;
- }
- }
- free(mailcmd1);
- free(tmpstr);
- free(usermail);
- return EXIT_SUCCESS;
- }
复制代码 运行./copytiffto 806 /var/spool/fax/recvq/fax000000026.tif
的以下提示
--------
billyz:pzblwxjj@163.com
mail: pzblwxjj@163.com
s
j:16
段错误 |
|