<?

/**
 * mail.mod.php
 * @package   Modules
 */

/**
 * Module name
 */
define("MOD_MAIL",$name);

/**
 * Recipient option
 */
define("RECIPIENT",0);
/**
 * Subject option
 */
define("SUBJECT",1);
/**
 * From option
 */
define("FROM",2);
/**
 * Carbon copy option
 */
define("CC",3);
/**
 * Blind carbon copy option
 */
define("BCC",4);
/**
 * Extra headers option
 */
define("HEADERS",5);

$modules[$name]= new MailModule();

/**
 * MailModule
 *
 * This module takes care of sending the mail.
 * to extend the mail feature, just extend this module and overwrite the
 * send_mail method
 * @package   Modules
 * @author    Herman Suijs
 */
class MailModule extends Module {
  var 
$name "MailModule";
  var 
$id MOD_MAIL;
  var 
$execlevel 22;

  
/**
   * Constructor
   *
   * Set options and call the superConstructor
   */
  
function MailModule() {
    
$this->options[RECIPIENT] = new Option("recipient:to",REGEX_MAIL,true,false,DEFAULT_MAIL);
    
$this->options[SUBJECT] = new Option("subject:onderwerp","",false,true,DEFAULT_SUBJECT);
    
$this->options[CC] = new Option("cc:copy",REGEX_MAIL);
    
$this->options[BCC] = new Option("bcc:blindcopy",REGEX_MAIL);
    
$this->options[FROM] = new Option("from:address","",false,true,DEFAULT_FROM);
    
$this->options[HEADERS] = new Option("mailheader:mailheaders");
    
$this->Module();
  } 
/* function MailModule() */
  
  /**
   * Before action
   *
   * Check options
   */
  
function before_action() {
    
$this->check_options();
  } 
/* function before_action() */

  //CMailFile($subject,$to,$from,$msg,$filename,$mimetype = "application/octet-stream", $mime_filename = false) {
  /**
   * Send mail routine
   */
  
function send_mail($recipient,$from,$subject,$content,$headers) {
    if (
$from$headers .= "From: $from\n";
    
mail($recipient,$subject,$content,$headers);
  } 
/* function send_mail($recipient,... */

  /**
   * Do action
   *
   * Call send mail routine
   */
  
function do_action() {
    global 
$formHandler,$debug;

    
$recipient $this->options[RECIPIENT]->value;
    
$subject $this->options[SUBJECT]->value;
    
$from $this->options[FROM]->value;
    
$cc $this->options[CC]->value;
    
$bcc $this->options[BCC]->value;
    
$mailheaders $this->options[HEADERS]->value;

    
// Get the content
    //$formHandler->convert_content($formHandler->get_vars(SHOW_VARS),MAIL_CONTENT);
    
$content=$formHandler->get_content(MAIL_CONTENT,true);

    
// Fillin the headers
    
$headers"";
    
//if ($from) $headers .= "From: $from\n";
    
if ($cc$headers .= "Cc: $cc\n";
    if (
$bcc$headers .= "Bcc: $bcc\n";
    if (
$mailheaders$headers .= "$mailheaders\n";
    if(
$this->action()) {
      
$this->send_mail($recipient,$from,$subject,$content,$headers);
      
$debug->add(DB_XFLOW,$this->name,"mail(%s,%s,%s,%s) is %s",$recipient,$subject,$content,$headers,"send");
      
//echo "Mail send <br>";
    
} elseif($debug->enabled) { /* if($this->action()) */
      
$debug->add(DB_XFLOW,$this->name,"mail(%s,%s,%s,%s) is %s",$recipient,$subject,$content,$headers,"not send");
      
//$debug->add_message("mail($recipient,$subject,$content,$headers) not send",$this->name);
   /* if($this->action()) { ... } el... */  
} else {
      
//echo "No mail send";
    
/* /* if($this->action()) { ... }... */
  
/* function do_action() */

  /**
   * After action
   *
   * Cleanup
   */
  
function after_action() {
    
$this->clean_up();
  } 
/* function after_action() */
/* //CMailFile($subject,$to,$from... */