2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 #ifdef ENABLE_DOUBLE_CHECK_DATA
31 extern struct globalstatstruct globstat
;
34 //! Name of the file containing the e-mail to send.
35 static char EmailFileName
[MAXLEN
]="";
38 * Generate a file name to write the e-mail and open the file.
40 * \param Module The module for which the e-mail is generated.
42 * \return The file to which the e-mail can be written.
44 FILE *Email_OutputFile(const char *Module
)
48 if(strcmp(email
,"stdout") == 0) {
49 EmailFileName
[0]='\0';
53 snprintf(EmailFileName
,sizeof(EmailFileName
),"%s/%s.int_unsort",tmp
,Module
);
54 if ((fp
=fopen(EmailFileName
,"w"))==NULL
) {
55 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),EmailFileName
,strerror(errno
));
64 * \param fp The file opened by Email_OutputFile().
66 void Email_Send(FILE *fp
,const char *Subject
)
71 if (fp
==stdout
) return;//to stdout
73 if (fclose(fp
)==EOF
) {
74 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),EmailFileName
,strerror(errno
));
78 snprintf(warea
,sizeof(warea
),"%s -s \"%s\" \"%s\" <\"%s\"",MailUtility
,Subject
,email
,EmailFileName
);
80 debuga(__FILE__
,__LINE__
,_("Sending mail with command: %s\n"),warea
);
81 cstatus
=system(warea
);
82 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
83 debuga(__FILE__
,__LINE__
,_("command return status %d\n"),WEXITSTATUS(cstatus
));
84 debuga(__FILE__
,__LINE__
,_("command: %s\n"),warea
);
87 if (!KeepTempLog
&& unlink(EmailFileName
)) {
88 debuga(__FILE__
,__LINE__
,_("Cannot delete \"%s\": %s\n"),EmailFileName
,strerror(errno
));