00001 00007 /* 00008 COPYRIGHT (C) 2005-2006 RIVERDRUMS 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 00024 */ 00025 00319 #include "init.h" 00320 00321 #include <rd/log.h> 00322 #include <rd/conf.h> 00323 #include <rd/email.h> 00324 #include <rd/timer.h> 00325 #include <rd/daemon.h> 00326 00327 void VF__send_report(veldfire *v, struct rdtimer *t); 00328 00337 int main(int argc, char *argv[]) { 00338 veldfire *v = NULL; 00339 struct rdtimer t; 00340 int rc = 0; 00341 00342 if ( (v = VF__init(argc, argv)) == NULL) { 00343 return -1; 00344 } 00345 00346 if ( (v->msg = VF__get_msg(v)) == NULL) { 00347 VF__cleanup(v); 00348 return -1; 00349 } 00350 00351 if (v->debug == 0 && v->foreground == 0) { 00352 RD__daemon(1, v->printlog ? 1 : 0); 00353 } 00354 00355 RD__timer_start(&t); 00356 rc = RD__email(v->host, v->port, v->from, v->to, 00357 v->subject, v->msg, v->files, v->headers, 00358 v->sendtimeout, v->recvtimeout, 00359 v->maxconnection, v->log, &v->sent, &v->fail); 00360 RD__timer_stop(&t); 00361 00362 VF__send_report(v, &t); 00363 VF__cleanup(v); 00364 00365 return rc; 00366 } 00367 00374 void 00375 VF__send_report(veldfire *v, struct rdtimer *t) 00376 { 00377 char msg[256]; 00378 char *p = RD__error(); 00379 char *subj = "[veldfire] Email results"; 00380 00381 if (v == NULL || v->report == NULL || t == NULL) { 00382 return; 00383 } 00384 00385 RD__log(v->log, 3, "%s Sent: %d Fail: %d", t->time, v->sent, v->fail); 00386 00387 snprintf(msg, sizeof(msg), 00388 "Mail results\n------------\n\n%d Sent, %d Fail\nTime: %s\n%s%s\n", 00389 v->sent, v->fail, t->time, 00390 p && strlen(p) ? "Last error: " : "", 00391 p && strlen(p) ? p : ""); 00392 00393 RD__email_simple(v->host, v->from, v->report, subj, msg); 00394 } 00395