00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "Mailinst.h"
00023
00024
00025 namespace db {
00026
00027
00028 Mailinst::Mailinst(Database& db) :
Table(db)
00029 {
00030 m_new =
true;
00031
m_host_spam =
false;
00032
m_mail_spam =
false;
00033
m_from_spam =
false;
00034
m_subject_spam =
false;
00035 }
00036
00037
00038 Mailinst::Mailinst(Database& db,
long id) :
Table(db)
00039 {
00040 std::string sql;
00041 sql =
"select * from mailinst where id=" + Utility::l2string(
id);
00042
Spawn(sql);
00043 }
00044
00045
00046 Mailinst::Mailinst(Database& db,
const std::string& sql) :
Table(db)
00047 {
00048
Spawn(sql);
00049 }
00050
00051
00052 Mailinst::Mailinst(Database& db,
const std::string& host,
00053
const std::string& mail,
00054
const std::string& rcpt,
00055
const std::string& h_from,
00056
const std::string& h_to,
00057
const std::string& h_subject) :
Table(db)
00058 {
00059 std::string sql;
00060 sql =
"select * from mailinst where host='" + sqlsafe(host) +
"' and ";
00061 sql +=
"mail='" + sqlsafe(mail) +
"' and ";
00062 sql +=
"rcpt='" + sqlsafe(rcpt) +
"' and ";
00063 sql +=
"h_from='" + sqlsafe(h_from) +
"' and ";
00064 sql +=
"h_to='" + sqlsafe(h_to) +
"' and ";
00065 sql +=
"h_subject='" + sqlsafe(h_subject) +
"'";
00066
Spawn(sql);
00067
m_host = host;
00068
m_mail = mail;
00069
m_rcpt = rcpt;
00070
m_h_from = h_from;
00071
m_h_to = h_to;
00072
m_h_subject = h_subject;
00073 }
00074
00075
00076 Mailinst::~Mailinst()
00077 {
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void Mailinst::Spawn(
const std::string& sql)
00096 {
00097 Query q(
GetDatabase());
00098 m_new =
true;
00099
m_host_spam =
false;
00100
m_mail_spam =
false;
00101
m_from_spam =
false;
00102
m_subject_spam =
false;
00103 q.get_result(sql);
00104
if (q.fetch_row())
00105 {
00106
m_id = q.getval();
00107
m_host = q.getstr();
00108
m_mail = q.getstr();
00109
m_rcpt = q.getstr();
00110
m_h_from = q.getstr();
00111
m_h_to = q.getstr();
00112
m_h_subject = q.getstr();
00113
m_host_spam = q.getval() ?
true :
false;
00114
m_mail_spam = q.getval() ?
true :
false;
00115
m_from_spam = q.getval() ?
true :
false;
00116
m_subject_spam = q.getval() ?
true :
false;
00117 m_new =
false;
00118 }
00119 q.free_result();
00120 }
00121
00122
00123 void Mailinst::save()
00124 {
00125 Query q(
GetDatabase());
00126 std::string sql;
00127
if (m_new)
00128 {
00129 sql =
"insert into mailinst values(NULL"
00130
",'" + sqlsafe(
m_host) +
"'"
00131
",'" + sqlsafe(
m_mail) +
"'"
00132
",'" + sqlsafe(
m_rcpt) +
"'"
00133
",'" + sqlsafe(
m_h_from) +
"'"
00134
",'" + sqlsafe(
m_h_to) +
"'"
00135
",'" + sqlsafe(
m_h_subject) +
"'";
00136 sql +=
m_host_spam ?
",1" :
",0";
00137 sql +=
m_mail_spam ?
",1" :
",0";
00138 sql +=
m_from_spam ?
",1" :
",0";
00139 sql +=
m_subject_spam ?
",1" :
",0";
00140 sql +=
")";
00141 printf(
"SQL: '%s'\n",sql.c_str());
00142 q.execute(sql);
00143
m_id = q.insert_id();
00144 }
00145
else
00146 {
00147 sql =
"update mailinst set "
00148
"host='" + sqlsafe(
m_host) +
"',"
00149
"mail='" + sqlsafe(
m_mail) +
"',"
00150
"rcpt='" + sqlsafe(
m_rcpt) +
"',"
00151
"h_from='" + sqlsafe(
m_h_from) +
"',"
00152
"h_to='" + sqlsafe(
m_h_to) +
"',"
00153
"h_subject='" + sqlsafe(
m_h_subject) +
"',";
00154 sql +=
m_host_spam ?
"host_spam=1," :
"host_spam=0,";
00155 sql +=
m_mail_spam ?
"mail_spam=1," :
"mail_spam=0,";
00156 sql +=
m_from_spam ?
"from_spam=1," :
"from_spam=0,";
00157 sql +=
m_subject_spam ?
"subject_spam=1 " :
"subject_spam=0 ";
00158 sql = sql +
"where id=" + Utility::l2string(
m_id);
00159 printf(
"SQL: '%s'\n",sql.c_str());
00160 q.execute(sql);
00161 }
00162 }
00163
00164
00165 }