// smtpd/SmtpdDb.cc
// This file is part of Decimail; see http://decimail.org
// (C) 2004-2007 Philip Endecott
 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
#include "SmtpdDb.hh"

using namespace std;
using namespace pbe;


namespace Smtpd {

SmtpdDb::SmtpdDb(void):
  q_get_username_for_recipient
    (*this, "select username from incoming_addresses where $1 ilike address_pat"),
  q_test_username_and_recipient
    (*this, "select count(*)::int4 from incoming_addresses where username=$1 and $2 ilike address_pat"),
  q_get_msg_id_for_rfc822_messageid
    (*this, "select msg_id from messages where owner=$1 and rfc822_messageid=$2"),
  q_get_username_for_autoaddr
    (*this, "select username from auto_users where addr=$1"),
  q_get_custom_addr_for_username_recipient
    (*this, "select custom_addr from custom_addrs where username=$1 and $2 ilike correspondent_pat"), 
  q_get_random_template_for_username
    (*this, "select random_template from auto_users where username=$1"),
  q_insert_custom_recipient
    (*this, "insert into custom_recipients(username, recipient, custom_addr) values($1,$2,$3)"),
  q_insert_random_addr
    (*this, "insert into random_addrs(username, addr, description) values($1,$2,$3)")
{
}

};

