Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
m_mail Class Reference

This class handle emails (pop and/or aliases and even wrapper for internal classes) of hosted users. More...

Public Member Functions

 m_mail ()
 Constructeur.
 hook_menu ()
 get_total_size_for_domain ($domain)
 catchall_getinfos ($domain_id)
 catchall_del ($domain_id)
 catchall_set ($domain_id, $target)
 hook_quota_get ()
 get_quota (hook for quota class), returns the number of used service for a quota-bound service
 alternc_password_policy ()
 Password policy kind used in this class (hook for admin class)
 enum_domains ($uid=-1)
 Returns the list of mail-hosting domains for a user.
 available ($mail)
 available: tells if an email address can be installed in the server check the domain part (is it mine too), the syntax, and the availability.
 enum_domain_mails ($dom_id=null, $search="", $offset=0, $count=30, $show_systemmails=false)
 hook_mail_get_details ($detail)
 create ($dom_id, $mail, $type="", $dontcheck=false)
 Function used to insert a new mail into the db should be used by the web interface, not by third-party programs.
 get_details ($mail_id)
 function used to get every information we can on a mail
 is_it_my_mail ($mail_id)
 Check if an email is mine ...
 hook_dom_del_mx_domain ($dom_id)
 Hook called when the DOMAIN class will delete a domain.
 get_account_by_mail_id ($mail_id)
 delete ($mail_id)
 Function used to delete a mail from the db should be used by the web interface, not by third-party programs.
 undelete ($mail_id)
 Function used to undelete a pending deletion mail from the db should be used by the web interface, not by third-party programs.
 set_passwd ($mail_id, $pass)
 set the password of an email address.
 enable ($mail_id)
 Enables an email address.
 disable ($mail_id)
 Disables an email address.
 set_details ($mail_id, $islocal, $quotamb, $recipients, $delivery="dovecot", $dontcheck=false)
 Function used to update an email settings should be used by the web interface, not by third-party programs.
 add_wrapper ($dom_id, $m, $delivery)
 A wrapper used by mailman class to create it's needed addresses @ param : $dom_id , the domain id associated to a given address @ param : $m , the left part of the mail address being created @ param : $delivery , the delivery used to deliver the mail.
 create_alias ($dom_id, $m, $alias, $type="", $dontcheck=false)
 A function used to create an alias for a specific address @ param : $dom_id , the domain sql identifier @ param : $m , the alias we want to create @ param : $alias , the already existing aliased address @ param : $type, the type of the alias created.
 del_wrapper ($mail_id)
 A wrapper used by mailman class to create it's needed addresses @ param : $mail_id , the mysql id of the mail address we want to delete of the email for the current acccount.
 alternc_export_conf ()
 Export the mail information of an account.
 enum_slave_account ()
 Return the list of allowed slave accounts (secondary-mx)
 check_slave_account ($login, $pass)
 Check for a slave account (secondary mx)
 echo_domain_list ($format=null)
 Out (echo) the complete hosted domain list :
 add_slave_account ($login, $pass)
 Add a slave account that will be allowed to access the mxdomain list.
 del_slave_account ($login)
 Remove a slave account.
 hook_dom_add_slave_domain ($domain_id, $target_domain)
 hook function called by AlternC when a domain is created for the current user account using the SLAVE DOMAIN feature This function create a CATCHALL to the master domain
 hook_dom_add_mx_domain ($domain_id)
 hook function called by AlternC when a domain is created for the current user account This function create a postmaster mail which is an alias to LOGIN @ FQDN wich is a dynamic alias to the alternc's account mail
 hook_upnp_list ()
 hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests

Data Fields

 $domains
 domain list for this account private
 $specialchars = array('"',"'",'\\','/')
 If an email has those chars, 'not nice in shell env' ;) we don't store the email in $mail/u/{user}_domain, but in $mail/_/{address_id}_domain private.
 $forbiddenchars = array('"',"'",'\\','/','?','!','*','$','|','#','+')
 If an email has those chars, we will ONLY allow RECIPIENTS, NOT POP/IMAP for DOVECOT ! Since Dovecot doesn't allow those characters private.
 $total
 Number of results for a pager display public.
 $srv_submission
 $srv_smtp
 $srv_smtps
 $srv_imap
 $srv_imaps
 $srv_pop3
 $srv_pop3s
 $cache_domain_mail_size = array()

Private Attributes

 $isitmy_cache = array()

Detailed Description

This class handle emails (pop and/or aliases and even wrapper for internal classes) of hosted users.

Definition at line 36 of file m_mail.php.

Member Function Documentation

add_slave_account (   $login,
  $pass 
)

Add a slave account that will be allowed to access the mxdomain list.

Parameters
string$loginthe login to add
string$passthe password to add
Returns
boolean TRUE if the account has been created, or FALSE if an error occurred.

Definition at line 833 of file m_mail.php.

References $db, and $err.

{
global $db,$err;
$login=mysql_real_escape_string($login);
$pass=mysql_real_escape_string($pass);
$db->query("SELECT * FROM mxaccount WHERE login='$login'");
if ($db->next_record()) {
$err->raise("mail",_("The slave MX account was not found"));
return false;
}
$db->query("INSERT INTO mxaccount (login,pass) VALUES ('$login','$pass')");
return true;
}
add_wrapper (   $dom_id,
  $m,
  $delivery 
)

A wrapper used by mailman class to create it's needed addresses @ param : $dom_id , the domain id associated to a given address @ param : $m , the left part of the mail address being created @ param : $delivery , the delivery used to deliver the mail.

Definition at line 682 of file m_mail.php.

References $db, $err, $mail_id, and set_details().

{
global $err,$db,$mail;
$err->log("mail","add_wrapper","creating $delivery $m address");
$mail_id=$mail->create($dom_id,$m,$delivery);
$this->set_details($mail_id,1,0,'',$delivery);
// FIXME return error code
}
alternc_export_conf ( )

Export the mail information of an account.

Returns
: str, string containing the complete configuration of the email for the current acccount.

Definition at line 725 of file m_mail.php.

References $d, $db, $domain, $err, $key, $r, $val, enum_domain_mails(), enum_domains(), and get_details().

{
global $db,$err,$mail_localbox;
$err->log("mail","export");
$str="<mail>\n";
$onepop=false;
foreach ($domain as $d) {
$str.=" <domain>\n <name>".xml_entities($d["domain"])."</name>\n";
$s=$this->enum_domain_mails($d["id"]);
if (count($s)) {
while (list($key,$val)=each($s)){
$test=$this->get_details($val['id']);
$str.=" <address>\n";
$str.=" <name>".xml_entities($val["address"])."</name>\n";
$str.=" <enabled>".xml_entities($val["enabled"])."</enabled>\n";
if(is_array($val["islocal"])){
$str.=" <islocal>1</islocal>\n";
$str.=" <quota>".$val["quota"]."</quota>\n";
$str.=" <path>".$val["path"]."</path>\n";
}else{
$str.=" <islocal>0</islocal>\n";
}
if(!empty($val["recipients"])){
$r=explode("\n",$val["recipients"]);
foreach($r as $recip){
$str.=" <recipients>".$recip."<recipients>\n";
}
}
$str.=" </address>\n";
}
}
$str.=" </domain>\n";
}
$str.="</mail>\n";
return $str;
}
alternc_password_policy ( )

Password policy kind used in this class (hook for admin class)

Returns
array an array of policykey => "policy name (for humans)"

Definition at line 203 of file m_mail.php.

{
return array("pop"=>_("Email account password"));
}
available (   $mail)

available: tells if an email address can be installed in the server check the domain part (is it mine too), the syntax, and the availability.

Parameters
$mailstring email to check
Returns
boolean true if the email can be installed on the server

Definition at line 246 of file m_mail.php.

References $db, $dom, $domain, and $err.

{
global $db,$err,$dom;
$err->log("mail","available");
list($login,$domain)=explode("@",$mail,2);
// Validate the domain ownership & syntax
if (!($dom_id=$dom->get_domain_byname($domain))) {
return false;
}
// Validate the email syntax:
if (!filter_var($mail,FILTER_VALIDATE_EMAIL)) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Check the availability
$db->query("SELECT a.id FROM address a WHERE a.domain_id=".$dom_id." AND a.address='".addslashes($login)."';");
if ($db->next_record()) {
return false;
} else {
return true;
}
}
catchall_del (   $domain_id)

Definition at line 154 of file m_mail.php.

References $catch, and catchall_getinfos().

Referenced by catchall_set().

{
$catch = $this->catchall_getinfos($domain_id);
if (empty($catch['mail_id'])) return false;
return $this->delete($catch['mail_id']);
}
catchall_getinfos (   $domain_id)

Definition at line 127 of file m_mail.php.

References $db, and $dom.

Referenced by catchall_del().

{
global $dom, $db;
$rr=array(
'mail_id'=>'',
'domain' =>$dom->get_domain_byid($domain_id),
'target' => '',
'type' => '',
);
$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()) {
$rr['target'] = $db->f('dst');
$rr['mail_id'] = $db->f('mail_id');
}
// Does it redirect to a specific mail or to a domain
if (empty($rr['target'])) {
$rr['type']='none';
} elseif (substr($rr['target'],0,1)=='@') {
$rr['type']='domain';
} else {
$rr['type']='mail';
}
return $rr;
}
catchall_set (   $domain_id,
  $target 
)

Definition at line 160 of file m_mail.php.

References $err, catchall_del(), and create_alias().

Referenced by hook_dom_add_slave_domain().

{
// 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);
}
check_slave_account (   $login,
  $pass 
)

Check for a slave account (secondary mx)

Parameters
string$loginthe login to check
string$passthe password to check
Returns
boolean TRUE if the password is correct, or FALSE if an error occurred.

Definition at line 786 of file m_mail.php.

References $db, and $err.

{
global $db,$err;
$login=mysql_real_escape_string($login);
$pass=mysql_real_escape_string($pass);
$db->query("SELECT * FROM mxaccount WHERE login='$login' AND pass='$pass';");
if ($db->next_record()) {
return true;
}
return false;
}
create (   $dom_id,
  $mail,
  $type = "",
  $dontcheck = false 
)

Function used to insert a new mail into the db should be used by the web interface, not by third-party programs.

This function calls the hook "hooks_mail_cancreate" which must return FALSE if the user can't create this email, and raise and error accordingly

Parameters
$dom_idinteger A domain_id (owned by the user) (will be the part at the right of the @ in the email)
$mailstring the left part of the email to create (something)
Returns
an hashtable containing the database id of the newly created mail, or false if an error occured ($err is filled accordingly)

Definition at line 329 of file m_mail.php.

References $cuid, $db, $dom, $domain, $err, and $hooks.

{
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","create",$mail);
// Validate the domain id
if (!($domain=$dom->get_domain_byid($dom_id))) {
return false;
}
// Validate the email syntax:
$m=$mail."@".$domain;
if (!filter_var($m,FILTER_VALIDATE_EMAIL) && !$dontcheck) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Call other classes to check we can create it:
$cancreate=$hooks->invoke("hook_mail_cancreate",array($dom_id,$mail));
if (in_array(false,$cancreate,true)) {
return false;
}
// Check the quota:
if (!$quota->cancreate("mail")) {
$err->raise("mail",_("You cannot create email addresses: your quota is over"));
return false;
}
// Already exists?
$db->query("SELECT * FROM address WHERE domain_id=".$dom_id." AND address='".addslashes($mail)."';");
if ($db->next_record()) {
$err->raise("mail",_("This email address already exists"));
return false;
}
// Create it now
$db->query("INSERT INTO address (domain_id, address,type) VALUES ($dom_id, '".addslashes($mail)."','$type');");
if (!($id=$db->lastid())) {
$err->raise("mail",_("An unexpected error occured when creating the email"));
return false;
}
return $id;
}
create_alias (   $dom_id,
  $m,
  $alias,
  $type = "",
  $dontcheck = false 
)

A function used to create an alias for a specific address @ param : $dom_id , the domain sql identifier @ param : $m , the alias we want to create @ param : $alias , the already existing aliased address @ param : $type, the type of the alias created.

Definition at line 698 of file m_mail.php.

References $db, $err, $mail_id, and set_details().

Referenced by catchall_set(), and hook_dom_add_mx_domain().

{
global $err,$db,$mail;
$err->log("mail","create_alias","creating $m alias for $alias type $type");
$mail_id=$mail->create($dom_id,$m,$type,$dontcheck);
$this->set_details($mail_id,0,0,$alias,"dovecot",$dontcheck);
// FIXME return error code
}
del_slave_account (   $login)

Remove a slave account.

Parameters
string$loginthe login to delete

Definition at line 852 of file m_mail.php.

References $db, and $err.

{
global $db,$err;
$login=mysql_real_escape_string($login);
$db->query("DELETE FROM mxaccount WHERE login='$login'");
return true;
}
del_wrapper (   $mail_id)

A wrapper used by mailman class to create it's needed addresses @ param : $mail_id , the mysql id of the mail address we want to delete of the email for the current acccount.

Definition at line 714 of file m_mail.php.

References $db, $err, and $mail_id.

{
global $err,$db;
$err->log("mail","del_wrapper");
$this->delete($mail_id);
}
delete (   $mail_id)

Function used to delete a mail from the db should be used by the web interface, not by third-party programs.

Parameters
$mail_idinteger the number of the email to delete
Returns
true if the email has been properly deleted or false if an error occured ($err is filled accordingly)

Definition at line 461 of file m_mail.php.

References $cuid, $db, $dom, $err, $hooks, $mail_id, $mailinfos, get_details(), and is_it_my_mail().

{
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","delete");
$mail_id=intval($mail_id);
if (!$mail_id) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Validate that this email is owned by me...
if (!($mail=$this->is_it_my_mail($mail_id))) {
return false;
}
$hooks->invoke('hook_mail_delete', array($mail_id, $mailinfos['address'].'@'.$mailinfos['domain'] ));
// Search for that address:
$db->query("SELECT a.id, a.type, a.mail_action, m.mail_action AS mailbox_action, NOT ISNULL(m.id) AS islocal FROM address a LEFT JOIN mailbox m ON m.address_id=a.id WHERE a.id='$mail_id';");
if (!$db->next_record()) {
$err->raise("mail",_("The email %s does not exist, it can't be deleted"),$mail);
return false;
}
if ($db->f("mail_action")!="OK" || ($db->f("islocal") && $db->f("mailbox_action")!="OK")) { // will be deleted soon ...
$err->raise("mail",_("The email %s is already marked for deletion, it can't be deleted"),$mail);
return false;
}
$mail_id=$db->f("id");
if ($db->f("islocal")) {
// If it's a pop/imap mailbox, mark it for deletion
$db->query("UPDATE address SET mail_action='DELETE', enabled=0 WHERE id='$mail_id';");
$db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been marked for deletion"),$mail);
} else {
// If it's only aliases, delete it NOW.
$db->query("DELETE FROM address WHERE id='$mail_id';");
$db->query("DELETE FROM mailbox WHERE address_id='$mail_id';");
$db->query("DELETE FROM recipient WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been successfully deleted"),$mail);
}
return true;
}
disable (   $mail_id)

Disables an email address.

Parameters
$mail_idinteger Email ID
Returns
boolean true if the email has been enabled.

Definition at line 595 of file m_mail.php.

References $db, $err, $mail_id, and is_it_my_mail().

{
global $db,$err;
$err->log("mail","disable");
if (!($email=$this->is_it_my_mail($mail_id))) return false;
if (!$db->query("UPDATE address SET `enabled`=0 where id=$mail_id;")) return false;
return true;
}
echo_domain_list (   $format = null)

Out (echo) the complete hosted domain list :

Definition at line 801 of file m_mail.php.

References $db, and $err.

{
global $db,$err;
$db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
$lst=array();
$tt="";
while ($db->next_record()) {
$lst[]=$db->f("domaine");
$tt.=$db->f("domaine");
}
# Generate an integrity check
$obj=array('integrity'=>md5($tt),'items'=>$lst);
switch($format) {
case "json":
return json_encode($obj);
break;
default:
foreach ($lst as $l) { echo $l."\n"; }
return true;
break;
} // switch
}
enable (   $mail_id)

Enables an email address.

Parameters
$mail_idinteger Email ID
Returns
boolean true if the email has been enabled.

Definition at line 581 of file m_mail.php.

References $db, $err, $mail_id, and is_it_my_mail().

{
global $db,$err;
$err->log("mail","enable");
if (!($email=$this->is_it_my_mail($mail_id))) return false;
if (!$db->query("UPDATE address SET `enabled`=1 where id=$mail_id;")) return false;
return true;
}
enum_domain_mails (   $dom_id = null,
  $search = "",
  $offset = 0,
  $count = 30,
  $show_systemmails = false 
)

Definition at line 277 of file m_mail.php.

References $cuid, $db, $err, $hooks, and $res.

Referenced by alternc_export_conf(), and hook_dom_del_mx_domain().

{
global $db,$err,$cuid,$hooks;
$err->log("mail","enum_domains_mail");
$search=trim($search);
$where="a.domain_id=$dom_id";
if ($search) $where.=" AND (a.address LIKE '%".addslashes($search)."%' OR r.recipients LIKE '%".addslashes($search)."%')";
if (!$show_systemmails) $where.=" AND type='' ";
$db->query("SELECT count(a.id) AS total FROM address a LEFT JOIN recipient r ON r.address_id=a.id WHERE $where;");
$db->next_record();
$this->total=$db->f("total");
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, 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
WHERE $where AND d.id=a.domain_id $limit ;");
if (! $db->next_record()) {
$err->raise("mail",_("No email found for this query"));
return false;
}
$res=array();
do {
$details=$db->Record;
// if necessary, fill the typedata with data from hooks ...
if ($details["type"]) {
$result=$hooks->invoke("hook_mail_get_details",array($details)); // Will fill typedata if necessary
$details["typedata"]=implode("<br />",$result);
}
$res[]=$details;
} while ($db->next_record());
return $res;
}
enum_domains (   $uid = -1)

Returns the list of mail-hosting domains for a user.

Returns
array indexed array of hosted domains

Definition at line 212 of file m_mail.php.

References $cuid, $db, $err, and $uid.

Referenced by alternc_export_conf(), and hook_menu().

{
global $db,$err,$cuid;
$err->log("mail","enum_domains");
if ($uid == -1) { $uid = $cuid; }
$db->query("
SELECT
d.id,
d.domaine,
IFNULL( COUNT(a.id), 0) as nb_mail
FROM
domaines d LEFT JOIN address a ON (d.id=a.domain_id AND a.type='')
WHERE
d.compte = $uid
and d.gesmx = 1
GROUP BY
d.id
ORDER BY
d.domaine
;
");
$this->enum_domains=array();
while($db->next_record()){
$this->enum_domains[]=$db->Record;
}
return $this->enum_domains;
}
enum_slave_account ( )

Return the list of allowed slave accounts (secondary-mx)

Returns
array

Definition at line 768 of file m_mail.php.

References $db, $err, and $res.

{
global $db,$err;
$db->query("SELECT login,pass FROM mxaccount;");
$res=array();
while ($db->next_record()) {
$res[]=$db->Record;
}
if (!count($res)) return false;
return $res;
}
get_account_by_mail_id (   $mail_id)

Definition at line 443 of file m_mail.php.

References $db, and $err.

{
global $db,$err;
$db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = $mail_id");
if ( !$db->next_record()) {
return false;
}
return $db->f('uid');
}
get_details (   $mail_id)

function used to get every information we can on a mail

Parameters
$mail_idinteger
Returns
array a hashtable with all the informations for that email

Definition at line 377 of file m_mail.php.

References $cuid, $db, $err, $hooks, $mail_id, and is_it_my_mail().

Referenced by alternc_export_conf(), delete(), and set_details().

{
global $db, $err, $cuid, $hooks;
$err->log("mail","get_details");
$mail_id=intval($mail_id);
// Validate that this email is owned by me...
if (!($mail=$this->is_it_my_mail($mail_id))) {
return false;
}
// We fetch all the informations for that email: these will fill the hastable :
$db->query("SELECT a.id, a.address, a.password, a.enabled, d.domaine AS domain, m.path, 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.mail_action, m.mail_action AS mailbox_action 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 a.id=".$mail_id." AND d.id=a.domain_id;");
if (! $db->next_record()) return false;
$details=$db->Record;
// if necessary, fill the typedata with data from hooks ...
if ($details["type"]) {
$result=$hooks->invoke("hook_mail_get_details",array($mail_id)); // Will fill typedata if necessary
$details["typedata"]=implode("<br />",$result);
}
return $details;
}
get_total_size_for_domain (   $domain)

Definition at line 113 of file m_mail.php.

References $db, $domain, and isset.

{
global $db;
if (empty($this->cache_domain_mail_size)) {
$db->query("SELECT SUBSTRING_INDEX(user,'@', -1) as domain, SUM(quota_dovecot) AS sum FROM dovecot_view group by domain ;");
while ($db->next_record() ) {
$dd = $db->f('domain');
$this->cache_domain_mail_size[ $dd ] = $db->f('sum');
}
}
if ( isset( $this->cache_domain_mail_size[$domain]) ) return $this->cache_domain_mail_size[$domain];
return 0;
}
hook_dom_add_mx_domain (   $domain_id)

hook function called by AlternC when a domain is created for the current user account This function create a postmaster mail which is an alias to LOGIN @ FQDN wich is a dynamic alias to the alternc's account mail

Parameters
string$domain_idDomain that has just been created private

Definition at line 882 of file m_mail.php.

References $db, $err, $mem, and create_alias().

{
global $err, $mem, $L_FQDN,$db;
$err->log("mail","hook_dom_add_mx_domain",$domain_id);
$db->query("SELECT value FROM variable where name='mailname_bounce';");
if (!$db->next_record()) {
$err->raise("mail",_("The email %s does not exist, it can't be deleted"),$mail);
return false;
}
$mailname=$db->f("value");
return $this->create_alias($domain_id, 'postmaster', $mem->user['login'].'@'.$mailname );
}
hook_dom_add_slave_domain (   $domain_id,
  $target_domain 
)

hook function called by AlternC when a domain is created for the current user account using the SLAVE DOMAIN feature This function create a CATCHALL to the master domain

Parameters
string$domain_idDomain that has just been created
string$target_domainMaster domain private

Definition at line 867 of file m_mail.php.

References $err, and catchall_set().

{
global $err;
$err->log("mail","hook_dom_add_slave_domain",$domain_id);
$this->catchall_set($domain_id,'@'.$target_domain);
return true;
}
hook_dom_del_mx_domain (   $dom_id)

Hook called when the DOMAIN class will delete a domain.

Parameters
$dominteger the number of the email to delete
Returns
true if the email has been properly deleted or false if an error occured ($err is filled accordingly)

Definition at line 432 of file m_mail.php.

References $list, and enum_domain_mails().

{
$list=$this->enum_domain_mails($dom_id,"",0,-1);
if (is_array($list)) {
foreach($list as $one) {
$this->delete($one["id"]);
}
}
return true;
}
hook_mail_get_details (   $detail)

Definition at line 311 of file m_mail.php.

{
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']));
}
hook_menu ( )

Definition at line 93 of file m_mail.php.

References $d, and enum_domains().

{
$obj = array(
'title' => _("Email Addresses"),
'ico' => 'images/mail.png',
'link' => 'toggle',
'pos' => 30,
'links' => array(),
) ;
foreach ($this->enum_domains() as $d) {
$obj['links'][] =
array (
'txt' => htmlentities($d["domaine"]).'&nbsp;'.htmlentities("(".$d["nb_mail"].")"),
'url' => "mail_list.php?domain_id=".urlencode($d['id']),
);
}
return $obj;
}
hook_quota_get ( )

get_quota (hook for quota class), returns the number of used service for a quota-bound service

Parameters
$namestring the named quota we want
Returns
the number of used service for the specified quota, or false if I'm not the one for the named quota

Definition at line 187 of file m_mail.php.

References $cuid, $db, $err, and $q.

{
global $db,$err,$cuid;
$err->log("mail","getquota");
$q=Array("name"=>"mail", "description"=>_("Email addresses"), "used"=>0);
$db->query("SELECT COUNT(*) AS cnt FROM address a, domaines d WHERE a.domain_id=d.id AND d.compte=$cuid AND a.type='';");
if ($db->next_record()) {
$q['used']=$db->f("cnt");
}
return $q;
}
hook_upnp_list ( )

hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests

Returns
array a key => value list of port protocol name mandatory values private

Definition at line 904 of file m_mail.php.

{
return array(
"imap" => array("port" => 143, "protocol" => "tcp", "mandatory" => 1),
"imaps" => array("port" => 993, "protocol" => "tcp", "mandatory" => 1),
"pop" => array("port" => 110, "protocol" => "tcp", "mandatory" => 1),
"pops" => array("port" => 995, "protocol" => "tcp", "mandatory" => 1),
"smtp" => array("port" => 25, "protocol" => "tcp", "mandatory" => 1),
"sieve" => array("port" => 2000, "protocol" => "tcp", "mandatory" => 1),
"submission" => array("port" => 587, "protocol" => "tcp", "mandatory" => 0),
);
}
is_it_my_mail (   $mail_id)

Check if an email is mine ...

Parameters
$mail_idinteger the number of the email to check
Returns
string the complete email address if that's mine, false if not ($err is filled accordingly)

Definition at line 409 of file m_mail.php.

References $cuid, $db, $err, $mail_id, and isset.

Referenced by delete(), disable(), enable(), get_details(), set_passwd(), and undelete().

{
global $err,$db,$cuid;
$mail_id=intval($mail_id);
// cache it (may be called more than one time in the same page).
if (isset($this->isitmy_cache[$mail_id])) return $this->isitmy_cache[$mail_id];
$db->query("SELECT concat(a.address,'@',d.domaine) AS email FROM address a, domaines d WHERE d.id=a.domain_id AND a.id=$mail_id AND d.compte=$cuid;");
if ($db->next_record()) {
return $this->isitmy_cache[$mail_id]=$db->f("email");
} else {
$err->raise("mail",_("This email is not yours, you can't change anything on it"));
return $this->isitmy_cache[$mail_id]=false;
}
}
m_mail ( )

Constructeur.

Definition at line 83 of file m_mail.php.

References variable_get().

{
$this->srv_submission = variable_get('mail_human_submission', '%%FQDN%%','Human name for mail server (submission protocol)', array(array('desc'=>'Name','type'=>'string')));
$this->srv_smtp = variable_get('mail_human_smtp', '%%FQDN%%','Human name for mail server (SMTP protocol)', array(array('desc'=>'Name','type'=>'string')));
$this->srv_smtps = variable_get('mail_human_smtps', '%%FQDN%%','Human name for mail server (SMTPS protocol)', array(array('desc'=>'Name','type'=>'string')));
$this->srv_imap = variable_get('mail_human_imap', '%%FQDN%%','Human name for IMAP mail server', array(array('desc'=>'Name','type'=>'string')));
$this->srv_imaps = variable_get('mail_human_imaps', '%%FQDN%%','Human name for IMAPS mail server', array(array('desc'=>'Name','type'=>'string')));
$this->srv_pop3 = variable_get('mail_human_pop3', '%%FQDN%%','Human name for POP3 mail server', array(array('desc'=>'Name','type'=>'string')));
$this->srv_pop3s = variable_get('mail_human_pop3s', '%%FQDN%%','Human name for POP3s mail server', array(array('desc'=>'Name','type'=>'string')));
}
set_details (   $mail_id,
  $islocal,
  $quotamb,
  $recipients,
  $delivery = "dovecot",
  $dontcheck = false 
)

Function used to update an email settings should be used by the web interface, not by third-party programs.

Parameters
$mail_idinteger the number of the email to delete
$islocalboolean is it a POP/IMAP mailbox ?
$quotambinteger if islocal=1, quota in MB
$recipientsstring recipients, one mail per line.
Returns
true if the email has been properly edited or false if an error occured ($err is filled accordingly)

Definition at line 615 of file m_mail.php.

References $cuid, $db, $dom, $err, $hooks, $mail_id, $r, ALTERNC_MAIL, and get_details().

Referenced by add_wrapper(), and create_alias().

{
global $err,$db,$cuid,$quota,$dom,$hooks;
$delivery=mysql_real_escape_string($delivery);
$err->log("mail","set_details");
if (!($me=$this->get_details($mail_id))) {
return false;
}
if ($me["islocal"] && !$islocal) {
// delete pop
$db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id=".$mail_id.";");
}
if (!$me["islocal"] && $islocal) {
// create pop
$path="";
if($delivery=="dovecot"){
$path=ALTERNC_MAIL."/".substr($me["address"]."_",0,1)."/".$me["address"]."_".$me["domain"];
}
foreach($this->forbiddenchars as $str) {
if (strpos($me["address"],$str)!==false) {
$err->raise("mail",_("There is forbidden characters in your email address. You can't make it a POP/IMAP account, you can only use it as redirection to other emails"));
return false;
break;
}
}
foreach($this->specialchars as $str) {
if (strpos($me["address"],$str)!==false) {
$path=ALTERNC_MAIL."/_/".$me["id"]."_".$me["domain"];
break;
}
}
$db->query("INSERT INTO mailbox SET address_id=$mail_id, delivery='$delivery', path='".addslashes($path)."';");
}
if ($me["islocal"] && $islocal && $me["mailbox_action"]=="DELETE") {
$db->query("UPDATE mailbox SET mail_action='OK' WHERE mail_action='DELETE' AND address_id=".$mail_id.";");
}
if ($islocal) {
if ($quotamb!=0 && $quotamb<(intval($me["used"]/1024/1024)+1)) {
$quotamb=intval($me["used"]/1024/1024)+1;
$err->raise("mail",_("You set a quota smaller than the current mailbox size. Since it's not allowed, we set the quota to the current mailbox size"));
}
$db->query("UPDATE mailbox SET quota=".intval($quotamb)." WHERE address_id=".$mail_id.";");
}
$r=explode("\n",$recipients);
$red="";
foreach($r as $m) {
$m=trim($m);
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 ;) )
$red.=$m."\n";
}
}
$db->query("DELETE FROM recipient WHERE address_id=".$mail_id.";");
if ($m) {
$db->query("INSERT INTO recipient SET address_id=".$mail_id.", recipients='".addslashes($red)."';");
}
return true;
}
set_passwd (   $mail_id,
  $pass 
)

set the password of an email address.

Parameters
$mail_idinteger email ID
$passstring the new password.
Returns
boolean true if the password has been set, false else, raise an error.

Definition at line 565 of file m_mail.php.

References $db, $err, $mail_id, and is_it_my_mail().

{
global $db,$err,$admin;
$err->log("mail","setpasswd");
if (!($email=$this->is_it_my_mail($mail_id))) return false;
if (!$admin->checkPolicy("pop",$email,$pass)) return false;
if (!$db->query("UPDATE address SET password='"._md5cr($pass)."' where id=$mail_id;")) return false;
return true;
}
undelete (   $mail_id)

Function used to undelete a pending deletion mail from the db should be used by the web interface, not by third-party programs.

Parameters
$mail_idinteger the email id
Returns
true if the email has been properly undeleted or false if an error occured ($err is filled accordingly)

Definition at line 515 of file m_mail.php.

References $cuid, $db, $dom, $err, $hooks, $mail_id, and is_it_my_mail().

{
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","undelete");
$mail_id=intval($mail_id);
if (!$mail_id) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Validate that this email is owned by me...
if (!($mail=$this->is_it_my_mail($mail_id))) {
return false;
}
// Search for that address:
$db->query("SELECT a.id, a.type, a.mail_action, m.mail_action AS mailbox_action, NOT ISNULL(m.id) AS islocal FROM address a LEFT JOIN mailbox m ON m.address_id=a.id WHERE a.id='$mail_id';");
if (!$db->next_record()) {
$err->raise("mail",_("The email %s does not exist, it can't be undeleted"),$mail);
return false;
}
if ($db->f("type")!="") { // Technically special : mailman, sympa ...
$err->raise("mail",_("The email %s is special, it can't be undeleted"),$mail);
return false;
}
if ($db->f("mailbox_action")!="DELETE" || $db->f("mail_action")!="DELETE") { // will be deleted soon ...
$err->raise("mail",_("Sorry, deletion of email %s is already in progress, or not marked for deletion, it can't be undeleted"),$mail);
return false;
}
$mail_id=$db->f("id");
if ($db->f("islocal")) {
// If it's a pop/imap mailbox, mark it for deletion
$db->query("UPDATE address SET mail_action='OK', `enabled`=1 WHERE id='$mail_id';");
$db->query("UPDATE mailbox SET mail_action='OK' WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been undeleted"),$mail);
return true;
} else {
$err->raise("mail",_("-- Program Error -- The email %s can't be undeleted"),$mail);
return false;
}
}

Field Documentation

$cache_domain_mail_size = array()

Definition at line 78 of file m_mail.php.

$domains

domain list for this account private

Definition at line 43 of file m_mail.php.

$forbiddenchars = array('"',"'",'\\','/','?','!','*','$','|','#','+')

If an email has those chars, we will ONLY allow RECIPIENTS, NOT POP/IMAP for DOVECOT ! Since Dovecot doesn't allow those characters private.

Definition at line 59 of file m_mail.php.

$isitmy_cache = array()
private

Definition at line 400 of file m_mail.php.

$specialchars = array('"',"'",'\\','/')

If an email has those chars, 'not nice in shell env' ;) we don't store the email in $mail/u/{user}_domain, but in $mail/_/{address_id}_domain private.

Definition at line 51 of file m_mail.php.

$srv_imap

Definition at line 73 of file m_mail.php.

$srv_imaps

Definition at line 74 of file m_mail.php.

$srv_pop3

Definition at line 75 of file m_mail.php.

$srv_pop3s

Definition at line 76 of file m_mail.php.

$srv_smtp

Definition at line 71 of file m_mail.php.

$srv_smtps

Definition at line 72 of file m_mail.php.

$srv_submission

Definition at line 70 of file m_mail.php.

$total

Number of results for a pager display public.

Definition at line 66 of file m_mail.php.


The documentation for this class was generated from the following file: