]> git.ipfire.org Git - thirdparty/sarg.git/blob - email.c
Make b-tree cache functions static.
[thirdparty/sarg.git] / email.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2015
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 #ifdef ENABLE_DOUBLE_CHECK_DATA
31 extern struct globalstatstruct globstat;
32 #endif
33
34 //! Name of the file containing the e-mail to send.
35 static char EmailFileName[MAXLEN]="";
36
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 */
44 FILE *Email_OutputFile(const char *Module)
45 {
46 FILE *fp;
47
48 if(strcmp(email,"stdout") == 0) {
49 EmailFileName[0]='\0';
50 return(stdout);
51 }
52
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));
56 exit(EXIT_FAILURE);
57 }
58 return(fp);
59 }
60
61 /*!
62 * Send the e-mail.
63 *
64 * \param fp The file opened by Email_OutputFile().
65 */
66 void Email_Send(FILE *fp,const char *Subject)
67 {
68 char warea[MAXLEN];
69 int cstatus;
70
71 if (fp==stdout) return;//to stdout
72
73 if (fclose(fp)==EOF) {
74 debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),EmailFileName,strerror(errno));
75 exit(EXIT_FAILURE);
76 }
77
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);
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);
85 exit(EXIT_FAILURE);
86 }
87 if (!KeepTempLog && unlink(EmailFileName)) {
88 debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),EmailFileName,strerror(errno));
89 exit(EXIT_FAILURE);
90 }
91 }