]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Send email report directly to stdout
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 12 Jul 2015 19:14:59 +0000 (21:14 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 12 Jul 2015 19:14:59 +0000 (21:14 +0200)
If the email report must be sent to stdout, do it directly. Don't use
another temporary file simply to output it later to stdout.

email.c

diff --git a/email.c b/email.c
index 6e4680731439a719af05073b597605c6822a1154..565c68a6dd212c9d14f4a2380bdce2de3bfa85eb 100644 (file)
--- a/email.c
+++ b/email.c
@@ -154,10 +154,14 @@ int geramail(const char *dirname, int debug, const char *email, const char *Temp
                exit(EXIT_FAILURE);
        }
 
-       snprintf(top3,sizeof(top3),"%s/report",dirname);
-       if((fp_top3=fopen(top3,"w"))==NULL) {
-               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno));
-               exit(EXIT_FAILURE);
+       if(strcmp(email,"stdout") == 0) {
+               fp_top3=stdout;
+       } else {
+               snprintf(top3,sizeof(top3),"%s/report",dirname);
+               if((fp_top3=fopen(top3,"w"))==NULL) {
+                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
 
        safe_strcpy(strip1,_("Squid User Access Report"),sizeof(strip1));
@@ -267,24 +271,12 @@ int geramail(const char *dirname, int debug, const char *email, const char *Temp
        local = localtime(&t);
        fprintf(fp_top3, "\n%s\n", asctime(local));
 
-       if (fclose(fp_top3)==EOF) {
-               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-
-       if(strcmp(email,"stdout") == 0) {
-               if((fp_top3=fopen(top3,"r"))==NULL) {
-                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno));
-                       exit(EXIT_FAILURE);
-               }
-
-               while(fgets(warea,sizeof(warea),fp_top3)!=NULL)
-                       fputs(warea,stdout);
+       if(strcmp(email,"stdout") != 0) {
                if (fclose(fp_top3)==EOF) {
-                       debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top3,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
                        exit(EXIT_FAILURE);
                }
-       } else {
+
                /* TRANSLATORS: The string is formatted using strftime. You can use
                   any string formatting marker allowed by strftime. */
                strftime(Subject,sizeof(Subject),_("SARG report, %c"),local);