]> git.ipfire.org Git - thirdparty/sarg.git/blame - email.c
Add support to decompress xz files
[thirdparty/sarg.git] / email.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
110ce984 3 * 1998, 2015
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
9dc20988
FM
30#ifdef ENABLE_DOUBLE_CHECK_DATA
31extern struct globalstatstruct globstat;
32#endif
33
6bbb47cf
FM
34//! Name of the file containing the e-mail to send.
35static char EmailFileName[MAXLEN]="";
9bd92830 36
6bbb47cf
FM
37/*!
38 * Generate a file name to write the e-mail and open the file.
39 *
40 * \param Module The module for which the e-mail is generated.
41 *
42 * \return The file to which the e-mail can be written.
43 */
44FILE *Email_OutputFile(const char *Module)
45{
46 FILE *fp;
9bd92830 47
6bbb47cf
FM
48 if(strcmp(email,"stdout") == 0) {
49 EmailFileName[0]='\0';
50 return(stdout);
9bd92830
FM
51 }
52
6bbb47cf
FM
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));
9bd92830
FM
56 exit(EXIT_FAILURE);
57 }
6bbb47cf
FM
58 return(fp);
59}
9bd92830 60
6bbb47cf
FM
61/*!
62 * Send the e-mail.
63 *
64 * \param fp The file opened by Email_OutputFile().
65 */
66void Email_Send(FILE *fp,const char *Subject)
67{
68 char warea[MAXLEN];
69 int cstatus;
9bd92830 70
6bbb47cf 71 if (fp==stdout) return;//to stdout
9bd92830 72
6bbb47cf
FM
73 if (fclose(fp)==EOF) {
74 debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),EmailFileName,strerror(errno));
9dc20988
FM
75 exit(EXIT_FAILURE);
76 }
9dc20988 77
6bbb47cf
FM
78 snprintf(warea,sizeof(warea),"%s -s \"%s\" \"%s\" <\"%s\"",MailUtility,Subject,email,EmailFileName);
79 if (debug)
80 debuga(__FILE__,__LINE__,_("Sending mail with command: %s\n"),warea);
81 cstatus=system(warea);
9bd92830 82 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
6bbb47cf
FM
83 debuga(__FILE__,__LINE__,_("command return status %d\n"),WEXITSTATUS(cstatus));
84 debuga(__FILE__,__LINE__,_("command: %s\n"),warea);
9bd92830
FM
85 exit(EXIT_FAILURE);
86 }
6bbb47cf
FM
87 if (!KeepTempLog && unlink(EmailFileName)) {
88 debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),EmailFileName,strerror(errno));
08f9b029
FM
89 exit(EXIT_FAILURE);
90 }
25697a35 91}