Clean up some compile errors on Debian Etch.
[inoclam.git] / src / smtp.cxx
blobcfd832fb41106048a8e64680037794257317effc
1 /*
2 * inoclam - Inotify+ClamAV virus scanner
3 * Copyright (C) 2007, 2008 Vermont Department of Taxes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <exception>
20 #include "jwsmtp.hxx"
21 #include <libdaemon/dlog.h>
22 #include <stdlib.h>
23 #include <string>
24 #include <string.h>
25 #include "smtp.hxx"
27 /**
28 * Returns a banner to go at the bottom of e-mails. Remember to delete it when done.
29 * @return footer string
31 std::string * smtp_get_banner()
34 * " (o_ Powered by: inoclam v1.0 (Bender)\n"
35 * " //\ Homepage: http://www.inoclam.org/\n"
36 * " V_/_ Author: Vermont Department of Taxes\n"
39 std::string * banner;
40 banner = new std::string();
41 banner->append(" (o_ Powered by inoclam v");
43 std::string * version;
44 version = new std::string(VERSION);
45 banner->append(version->c_str());
46 delete version;
48 banner->append(" (");
50 std::string * codename;
51 codename = new std::string(CODENAME);
52 banner->append(codename->c_str());
53 delete codename;
55 banner->append(")\n");
57 banner->append(" //\\ Developed by the Vermont Department of Taxes\n");
58 banner->append(" V_/_ Project Homepage: http://www.inoclam.org/\n");
60 return banner;
63 /**
64 * Returns an RFC 2822 Compliant Date String
65 * @return timestamp
67 std::string * smtp_get_timestamp()
69 char *timestamp;
70 const struct tm *tm;
71 time_t now;
73 now = time(NULL);
74 tm = localtime(&now);
76 timestamp = (char *) malloc(sizeof(char) * 41);
77 if (!timestamp) {
78 daemon_log(LOG_ERR, "malloc() failed!");
79 return NULL;
82 memset(timestamp, '\0', 41); /* RFC 2822 Date */
83 strftime(timestamp, 40, "%a, %d %b %Y %H:%M:%S", tm);
85 std::string * tstamp;
86 tstamp = new std::string(timestamp);
88 if (timestamp) {
89 free(timestamp);
90 timestamp = NULL;
93 return tstamp;
96 /**
97 * Sends an E-Mail.
99 void smtp_send(char *subject, std::string * body, config * conf)
101 char *smtp_host = conf->getHost();
102 int smtp_port = conf->getPort();
103 char *smtp_from = conf->getFrom();
104 const char *smtp_body = body->c_str();
106 if (smtp_host == NULL || smtp_from == NULL || smtp_port < 1 || smtp_port > 65535 || subject == NULL || smtp_body == NULL) {
107 daemon_log(LOG_INFO, "Incomplete Configuration or Message -- Not Sending E-Mail");
108 return;
111 for (std::list < char *>::iterator itr = conf->getTo()->begin(); itr != conf->getTo()->end(); ++itr) {
112 char *smtp_to;
113 smtp_to = *itr;
115 daemon_log(LOG_INFO, "Mailing '%s' ", smtp_to);
117 /* Why are there no C libraries for sending mail that are this simple? */
118 jwsmtp::mailer * mail;
119 mail = new jwsmtp::mailer(smtp_to, smtp_from, subject, smtp_body, smtp_host, smtp_port, false);
120 mail->send();
121 delete mail;