enabled=variable_get('mail_alias_enabled',null); if (is_null($this->enabled)) { // if not configuration var, setup one (with a default value) variable_set('mail_alias_enabled',true,'To enable or disable the alias module in the mail edit page'); $this->enabled=true; } $this->advanced=variable_get('mail_alias_advanced',null); if (is_null($this->advanced)) { // if not configuration var, setup one (with a default value) variable_set('mail_alias_advanced',true,'To place the alias option in the advanced area'); $this->advanced=true; } } /* * function used to list every aliases ( aka local redirections ) of a given mail address * param: mail address aliased. * return : an array containing every alias of a given mail on every domain related to the current user. * */ function list_alias($mail_address) { global $db, $mail, $cuid,$err; $err->log("mail_alias","list_alias"); $db->query("SELECT r.id as id, r.address_id from recipient r,address a, domaines d where r.recipients REGEXP '^[[:space:]]*".mysql_real_escape_string($mail_address)."[[:space:]]*$'and r.address_id=a.id and a.domain_id=d.id and d.compte = $cuid;"); $rcp = Array(); while ($db->next_record()) { $rcp[$db->f("id")] = $db->f("address_id"); } foreach ($rcp as $k => $v) { $rcp[$k] = $mail->mail_get_details($v, false); } return $rcp; } function form($mail_id, $edit_id) { global $mail,$err; if ($edit_id) { //echo "";__("Edit");echo ""; echo "";__("Edit");echo ""; } else { include('mail_alias_create.inc.php'); } } /** *hooks called to list a given mail properties *@param: the id of the mail in question *@return: an hashtable of every information usefull to edit the mail if it is part of the class *including a url to the edition page of the propertie in question ( here local hosting of a mail) *if the mail cannot be a localbox because of some of it's properties the return is NULL, thus not *displayed in the properties listing page. */ function hooks_mail_properties_list($mail_id){ global $db, $mail, $err; $err->log("mail","mail_properties_list"); $val = array ( "label" => "alias", "short_desc" => _("Alias"), "human_desc" => _("To add an alias to this mail address.
You must have the domain's alias setup in your AlternC account."), "url" => "mail_alias_create.php?mail_id=$mail_id", "class" => "mail_alias", "form_param" => Array($mail_id,false), "advanced" => $this->advanced, "pass_required" => false ); if (!$details = $mail->mail_get_details($mail_id, true)) return Array(); $return=Array(); $return[]=$val; // To be able to add a new alias foreach ($details['alias'] as $k => $v ) { $tmp = $val; $tmp['url'] = "mail_redirection_edit.php?mail_id=".$v['address_id']; $tmp["form_param"] = Array($mail_id,$v['address_id']); $tmp['short_desc'] = sprintf(_("Alias of %s"),$v['address_full']); $tmp['human_desc'] = sprintf(_("All the mails sent to %s will be received here."),$v['address_full']); $return[] = $tmp; } return $return; } /* * Function inserting an alias in the recipient table * @param integer alias_id : unique id of the alias just inserted in address table. * @param string mail_arg : the mail being aliased. * @return true if the alias was inserted ,false if there is an error or if alias al* ready in the base */ function setalias($alias_id,$mail_arg){ global $db, $err; $err->log("mail","setalias"); $compare=$this->list_alias($mail_arg); $db->query("select address from address where id=$alias_id;"); $db->next_record(); $mail_left=$db->f('address'); foreach($compare as $k => $v){ if($v['address'] === $mail_left) return false; } $db->query("INSERT INTO recipient (address_id, recipients) VALUES ($alias_id,'$mail_arg');"); return true; } } ?>