/* name : autoreply.c autoreply : un programme leger pour repondre automatiquement aux mails Copyright (C) 2008 Hugo Vandeputte This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #if !defined _AUTOREPLY_DIR #define _AUTOREPLY_DIR /etc/postfix/autoreply.d #endif #define xstr(s) str(s) #define str(s) #s #define tailleLigne 1024 void erreur(char * diag,char *msg){ syslog(LOG_NOTICE,"%s %s\n",diag,msg); exit(1); } char*buildPath(char* repBase,char*nom,char*suffixe) { char* path= (char*) malloc(strlen(repBase)+strlen(nom)+strlen(suffixe)+2); if(path==0) erreur("erreur malloc",""); strcpy(path,repBase); strcat(path,"/"); strcat(path,nom); strcat(path,suffixe); return path; } void envoiMessage(char* destinataire,int messageDesc){ int pid; char* cmd="/usr/sbin/sendmail"; char * option=(char*) malloc(strlen(destinataire)+4); if(option==0) erreur("echec malloc",""); strcpy(option,"-t "); strcat(option,destinataire); char *champTo=(char*)malloc(strlen(destinataire)+7); if(champTo==0) erreur("echec malloc",""); int pipefd[2]; pipe(pipefd); if(pid=fork() ==0){ // fils close(0);dup(pipefd[0]); close(pipefd[1]); execlp(cmd,cmd,destinataire,0); exit(0); } else { close(pipefd[0]); FILE*pipe=fdopen(pipefd[1],"w"); fprintf(pipe,"To: %s\n",destinataire); sprintf(champTo,"To: %s\n",destinataire); write(pipefd[1],champTo,strlen(champTo)); unsigned char buf[1024]; int lus,ecrits; while((lus=read(messageDesc,buf,1024))!=-1 && lus!=0){ ecrits=0; while((ecrits+=write(pipefd[1],buf+ecrits,lus-ecrits))