"Fossies" - the Fresh Open Source Software Archive

Member "sarg-2.4.0/email.c" (24 Dec 2019, 2922 Bytes) of package /linux/privat/sarg-2.4.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "email.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.11_vs_2.4.0.

    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     format_path(__FILE__, __LINE__, 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     format_path(__FILE__, __LINE__, 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 }