Interface de gestion des catchalls

Données dans la base
This commit is contained in:
Alan Garcia 2012-10-20 14:41:45 +00:00
parent 4c206de62d
commit 26b6135699
3 changed files with 48 additions and 25 deletions

View File

@ -109,7 +109,7 @@ if (isset($error) && !empty($error)) {
<?php pager($offset,$count,$mail->total,"mail_list.php?domain_id=".$domain_id."&amp;count=".$count."&amp;search=".urlencode($search)."&amp;offset=%%offset%%"); ?> <?php pager($offset,$count,$mail->total,"mail_list.php?domain_id=".$domain_id."&amp;count=".$count."&amp;search=".urlencode($search)."&amp;offset=%%offset%%"); ?>
</td> </td>
<td style="text-align:center"> <td style="text-align:center">
<input type="checkbox" id="show_systemmails" name="show_systemmails" <?php if($show_systemmails) {echo "checked";}?> value="1"><label for="show_systemmails" onclick="document.getElementById('formlist1').submit();"><?php __("Show system emails");?></label> <input type="checkbox" id="show_systemmails" name="show_systemmails" <?php if($show_systemmails) {echo "checked";}?> value="1"onclick="document.getElementById('formlist1').submit();" ><label for="show_systemmails" ><?php __("Show system emails");?></label>
</td> </td>
</form> </form>
<td style="text-align:right"> <td style="text-align:right">

View File

@ -58,7 +58,6 @@ if (!is_null($target_type)) {
} }
$catch=$mail->catchall_getinfos($domain_id); $catch=$mail->catchall_getinfos($domain_id);
printvar($catch);
?> ?>
<h3><?php printf(_("Manage catch-all configuration of %s"),$catch["domain"]); ?></h3> <h3><?php printf(_("Manage catch-all configuration of %s"),$catch["domain"]); ?></h3>
@ -93,7 +92,7 @@ __("You can choose what to do with emails send to unexisting address of this dom
<td style="width: 50%; text-align: justify"><label for='target_type_domain'/><?php echo sprintf(_("Mails send to john.doe@%s will be redirect to john.doe@anotherdomain.tld"),$catch['domain']);?></label></td> <td style="width: 50%; text-align: justify"><label for='target_type_domain'/><?php echo sprintf(_("Mails send to john.doe@%s will be redirect to john.doe@anotherdomain.tld"),$catch['domain']);?></label></td>
<td> <td>
<p> <p>
<input type="text" id="target_domain" name="target_domain" value="<?php if($catch['type']=='domain') { echo $catch['target']; } ?>" placeholder="example.tld" /> <input type="text" id="target_domain" name="target_domain" value="<?php if($catch['type']=='domain') { echo substr($catch['target'],1); } ?>" placeholder="example.tld" />
<ul> <ul>
<?php foreach ( $dom->enum_domains() as $d) { echo "<li><a href=\"javascript:set_target_domain_value('".addslashes($d)."');\">$d</a></li>"; } ?> <?php foreach ( $dom->enum_domains() as $d) { echo "<li><a href=\"javascript:set_target_domain_value('".addslashes($d)."');\">$d</a></li>"; } ?>
</ul> </ul>
@ -126,6 +125,7 @@ __("You can choose what to do with emails send to unexisting address of this dom
<script type="text/javascript"> <script type="text/javascript">
function set_target_domain_value(value) { function set_target_domain_value(value) {
$('#target_domain').val(value); $('#target_domain').val(value);
$('#target_type_domain').prop('checked', true);
} }
</script> </script>

View File

@ -94,14 +94,16 @@ class m_mail {
function catchall_getinfos($domain_id) { function catchall_getinfos($domain_id) {
global $dom, $db; global $dom, $db;
$rr=array( $rr=array(
'mail_id'=>'',
'domain' =>$dom->get_domain_byid($domain_id), 'domain' =>$dom->get_domain_byid($domain_id),
'target' => '', 'target' => '',
'type' => '', 'type' => '',
); );
$db->query("select r.recipients as dst from address a, recipient r where a.domain_id = $domain_id and r.address_id = a.id and a.address='';"); $db->query("select r.recipients as dst, a.id mail_id from address a, recipient r where a.domain_id = $domain_id and r.address_id = a.id and a.address='';");
if ($db->next_record()) { if ($db->next_record()) {
$rr['target'] = $db->f('dst'); $rr['target'] = $db->f('dst');
$rr['mail_id'] = $db->f('mail_id');
} }
// Does it redirect to a specific mail or to a domain // Does it redirect to a specific mail or to a domain
@ -117,13 +119,28 @@ class m_mail {
} }
function catchall_del($domain_id) { function catchall_del($domain_id) {
//FIXME $catch = $this->catchall_getinfos($domain_id);
print("catchall_del $domain_id"); if (empty($catch['mail_id'])) return false;
return $this->delete($catch['mail_id']);
} }
function catchall_set($domain_id, $target) { function catchall_set($domain_id, $target) {
//FIXME // target :
print("catchall_set $domain_id $target"); $target=rtrim($target);
if ( substr_count($target,'@') == 0 ) { // Pas de @
$target = '@'.$target;
}
if ( substr($target,0,1) == '@' ) { // le premier caractere est un @
// FIXME validate domain
} else { // ca doit être un mail
if (!filter_var($target,FILTER_VALIDATE_EMAIL)) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
}
$this->catchall_del($domain_id);
return $this->create_alias($domain_id, '', $target, "catchall", true);
} }
@ -231,7 +248,7 @@ print("catchall_set $domain_id $target");
$db->next_record(); $db->next_record();
$this->total=$db->f("total"); $this->total=$db->f("total");
if ($count!=-1) $limit="LIMIT $offset,$count"; else $limit=""; if ($count!=-1) $limit="LIMIT $offset,$count"; else $limit="";
$db->query("SELECT a.id, a.address, a.password, a.`enabled`, a.mail_action, d.domaine AS domain, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin $db->query("SELECT a.id, a.address, a.password, a.`enabled`, a.mail_action, d.domaine AS domain, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.domain_id
FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d
WHERE $where AND d.id=a.domain_id $limit ;"); WHERE $where AND d.id=a.domain_id $limit ;");
if (! $db->next_record()) { if (! $db->next_record()) {
@ -243,7 +260,7 @@ print("catchall_set $domain_id $target");
$details=$db->Record; $details=$db->Record;
// if necessary, fill the typedata with data from hooks ... // if necessary, fill the typedata with data from hooks ...
if ($details["type"]) { if ($details["type"]) {
$result=$hooks->invoke("hook_mail_get_details",array($details["id"])); // Will fill typedata if necessary $result=$hooks->invoke("hook_mail_get_details",array($details)); // Will fill typedata if necessary
$details["typedata"]=implode("<br />",$result); $details["typedata"]=implode("<br />",$result);
} }
$res[]=$details; $res[]=$details;
@ -252,6 +269,10 @@ print("catchall_set $domain_id $target");
} }
function hook_mail_get_details($detail) {
if ($detail['type']=='catchall') return _(sprintf("Special mail address for catch-all. <a href='mail_manage_catchall.php?domain_id=%s'>Click here to manage it.</a>",$detail['domain_id']));
}
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** Function used to insert a new mail into the db /** Function used to insert a new mail into the db
@ -266,7 +287,7 @@ print("catchall_set $domain_id $target");
* @return an hashtable containing the database id of the newly created mail, * @return an hashtable containing the database id of the newly created mail,
* or false if an error occured ($err is filled accordingly) * or false if an error occured ($err is filled accordingly)
*/ */
function create($dom_id, $mail,$type=""){ function create($dom_id, $mail,$type="",$dontcheck=false){
global $err,$db,$cuid,$quota,$dom,$hooks; global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","create",$mail); $err->log("mail","create",$mail);
@ -277,7 +298,7 @@ print("catchall_set $domain_id $target");
// Validate the email syntax: // Validate the email syntax:
$m=$mail."@".$domain; $m=$mail."@".$domain;
if (!filter_var($m,FILTER_VALIDATE_EMAIL)) { if (!filter_var($m,FILTER_VALIDATE_EMAIL) && !$dontcheck) {
$err->raise("mail",_("The email you entered is syntaxically incorrect")); $err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false; return false;
} }
@ -539,7 +560,7 @@ print("catchall_set $domain_id $target");
* @return true if the email has been properly edited * @return true if the email has been properly edited
* or false if an error occured ($err is filled accordingly) * or false if an error occured ($err is filled accordingly)
*/ */
function set_details($mail_id, $islocal, $quotamb, $recipients,$delivery="dovecot") { function set_details($mail_id, $islocal, $quotamb, $recipients,$delivery="dovecot",$dontcheck=false) {
global $err,$db,$cuid,$quota,$dom,$hooks; global $err,$db,$cuid,$quota,$dom,$hooks;
$delivery=mysql_escape_string($delivery); $delivery=mysql_escape_string($delivery);
$err->log("mail","set_details"); $err->log("mail","set_details");
@ -587,7 +608,7 @@ print("catchall_set $domain_id $target");
$red=""; $red="";
foreach($r as $m) { foreach($r as $m) {
$m=trim($m); $m=trim($m);
if ($m && filter_var($m,FILTER_VALIDATE_EMAIL) // Recipient Email is valid if ($m && ( filter_var($m,FILTER_VALIDATE_EMAIL) || $dontcheck) // Recipient Email is valid
&& $m!=($me["address"]."@".$me["domain"])) { // And not myself (no loop allowed easily ;) ) && $m!=($me["address"]."@".$me["domain"])) { // And not myself (no loop allowed easily ;) )
$red.=$m."\n"; $red.=$m."\n";
} }
@ -612,6 +633,7 @@ print("catchall_set $domain_id $target");
$mail_id=$mail->create($dom_id,$m,$delivery); $mail_id=$mail->create($dom_id,$m,$delivery);
$this->set_details($mail_id,1,0,'',$delivery); $this->set_details($mail_id,1,0,'',$delivery);
// FIXME return error code
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
@ -619,14 +641,15 @@ print("catchall_set $domain_id $target");
* @ param : $dom_id , the domain sql identifier * @ param : $dom_id , the domain sql identifier
* @ param : $m , the alias we want to create * @ param : $m , the alias we want to create
* @ param : $alias , the already existing aliased address * @ param : $alias , the already existing aliased address
* @ param : $delivery, the type of delivery of the alias created * @ param : $type, the type of the alias created
*/ */
function create_alias($dom_id,$m,$alias,$delivery) { function create_alias($dom_id,$m,$alias,$type="",$dontcheck=false) {
global $err,$db,$mail; global $err,$db,$mail;
$err->log("mail","create_alias","creating $delivery $m alias for $alias"); $err->log("mail","create_alias","creating $m alias for $alias type $type");
$mail_id=$mail->create($dom_id,$m,$delivery); $mail_id=$mail->create($dom_id,$m,$type,$dontcheck);
$this->set_details($mail_id,0,0,$alias,"mailman"); $this->set_details($mail_id,0,0,$alias,"dovecot",$dontcheck);
// FIXME return error code
} }