<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS 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
(at your option) any later version.

AthenaRMS 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
*/?>
<?php
require_once 'base_object.php';
require_once 'crypt.php';
require_once 'config.php';


class Mail extends Base_Object {

  function Mail () {
    $this->crypt = new Crypt ();
    $this->config = new Config ();

    $this->domain = $this->config->Get ('email_domain');
    $this->sig = $this->config->Get ('Email Sig');

    global $dbi;
    $this->db = &$dbi;
  }

  function send ($in_ary) {
    foreach ($in_ary as $k => $v) {
      $msg[strtoupper($k)] = $v;
    }

    foreach (array ('TO', 'SUBJECT', 'TICKET_ID', 'MESSAGE') as $req) {
      if (!$msg[$req]) {
        return $req;
      }
    }

    $return_email = $this->crypt->encrypt ($msg['TICKET_ID']).'@'.$this->domain;

    $headers = "From: \"{$this->sig}\" <$return_email>\n";
    $headers .= "Reply-To: \"{$this->sig}\" <$return_email>\n";
    $headers .= "Return-Path: \"{$this->sig}\" <$return_email>\n";

    mail ($msg['TO'], $msg['SUBJECT'], $msg['MESSAGE'], $headers);

    return 0;
  }
}
?>
