Alternc  latest
Alternc logiel libre pour l'hébergement
 All Classes 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. More...
 
 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 More...
 
 alternc_password_policy ()
 Password policy kind used in this class (hook for admin class) More...
 
 enum_domains ($uid=-1)
 Returns the list of mail-hosting domains for a user. More...
 
 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. More...
 
 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. More...
 
 get_details ($mail_id)
 function used to get every information we can on a mail More...
 
 is_it_my_mail ($mail_id)
 Check if an email is mine ... More...
 
 hook_dom_del_mx_domain ($dom_id)
 Hook called when the DOMAIN class will delete a domain. More...
 
 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. More...
 
 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. More...
 
 set_passwd ($mail_id, $pass)
 set the password of an email address. More...
 
 enable ($mail_id)
 Enables an email address. More...
 
 disable ($mail_id)
 Disables an email address. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 alternc_export_conf ()
 Export the mail information of an account. More...
 
 enum_slave_account ()
 Return the list of allowed slave accounts (secondary-mx) More...
 
 check_slave_account ($login, $pass)
 Check for a slave account (secondary mx) More...
 
 echo_domain_list ($format=null)
 Out (echo) the complete hosted domain list : More...
 
 add_slave_account ($login, $pass)
 Add a slave account that will be allowed to access the mxdomain list. More...
 
 del_slave_account ($login)
 Remove a slave account. More...
 
 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 More...
 
 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 More...
 
 hook_variable_set ($name, $old, $new)
 hook function called by variables when a variable is changed private More...
 
 set_dns_spf ($domain, $spf, $previous=-1, $uid=-1, $login=-1)
 Set or UPDATE the DNS record for the domain $dom(str) to be $spf account's login is current and if not it's $login. More...
 
 set_dns_dmarc ($domain, $dmarc, $previous=-1, $uid=-1, $login=-1)
 Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc account's login is current and if not it's $login. More...
 
 hook_upnp_list ()
 hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests More...
 

Public Attributes

 $domains
 domain list for this account private More...
 
 $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. More...
 
 $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. More...
 
 $total
 Number of results for a pager display public. More...
 
 $srv_submission
 
 $srv_smtp
 
 $srv_smtps
 
 $srv_imap
 
 $srv_imaps
 
 $srv_pop3
 
 $srv_pop3s
 
 $cache_domain_mail_size = array()
 
 $enum_domains = 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 37 of file m_mail.php.

Member Function Documentation

m_mail::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 897 of file m_mail.php.

References $db, and $err.

897  {
898  global $db, $err;
899  $db->query("SELECT * FROM mxaccount WHERE login= ? ;", array($login));
900  if ($db->next_record()) {
901  $err->raise("mail", _("The slave MX account was not found"));
902  return false;
903  }
904  $db->query("INSERT INTO mxaccount (login,pass) VALUES (?, ?);", array($login, $pass));
905  return true;
906  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
m_mail::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 740 of file m_mail.php.

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

740  {
741  global $err, $mail;
742  $err->log("mail", "add_wrapper", "creating $delivery $m address");
743 
744  $mail_id = $mail->create($dom_id, $m, $delivery);
745  $this->set_details($mail_id, 1, 0, '', $delivery);
746  // FIXME return error code
747  }
$err
Definition: bootstrap.php:72
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 pro...
Definition: m_mail.php:671
$mail_id
m_mail::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 790 of file m_mail.php.

References $d, $domain, $err, $key, $r, $val, each(), enum_domain_mails(), enum_domains(), and xml_entities().

790  {
791  global $err;
792  $err->log("mail", "export");
793  $domain = $this->enum_domains();
794  $str = "<mail>\n";
795  foreach ($domain as $d) {
796  $str.=" <domain>\n <name>" . xml_entities($d["domain"]) . "</name>\n";
797  $s = $this->enum_domain_mails($d["id"]);
798  if (count($s)) {
799  while (list($key, $val) = each($s)) {
800  $str.=" <address>\n";
801  $str.=" <name>" . xml_entities($val["address"]) . "</name>\n";
802  $str.=" <enabled>" . xml_entities($val["enabled"]) . "</enabled>\n";
803  if (is_array($val["islocal"])) {
804  $str.=" <islocal>1</islocal>\n";
805  $str.=" <quota>" . $val["quota"] . "</quota>\n";
806  $str.=" <path>" . $val["path"] . "</path>\n";
807  } else {
808  $str.=" <islocal>0</islocal>\n";
809  }
810  if (!empty($val["recipients"])) {
811  $r = explode("\n", $val["recipients"]);
812  foreach ($r as $recip) {
813  $str.=" <recipients>" . $recip . "<recipients>\n";
814  }
815  }
816  $str.=" </address>\n";
817  }
818  }
819  $str.=" </domain>\n";
820  }
821  $str.="</mail>\n";
822  return $str;
823  }
$val
Definition: tempovars.php:15
enum_domain_mails($dom_id=null, $search="", $offset=0, $count=30, $show_systemmails=false)
Definition: m_mail.php:295
$r
Definition: aws_add.php:77
$err
Definition: bootstrap.php:72
xml_entities($string)
Echappe les caract�res pouvant perturber un flux XML standard :
Definition: functions.php:541
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
enum_domains($uid=-1)
Returns the list of mail-hosting domains for a user.
Definition: m_mail.php:228
$domain
Definition: dom_import.php:40
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
$d
m_mail::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 219 of file m_mail.php.

219  {
220  return array("pop" => _("Email account password"));
221  }
m_mail::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 264 of file m_mail.php.

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

264  {
265  global $db, $err, $dom;
266  $err->log("mail", "available");
267  list($login, $domain) = explode("@", $mail, 2);
268  // Validate the domain ownership & syntax
269  if (!($dom_id = $dom->get_domain_byname($domain))) {
270  return false;
271  }
272  // Validate the email syntax:
273  if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
274  $err->raise("mail", _("The email you entered is syntaxically incorrect"));
275  return false;
276  }
277  // Check the availability
278  $db->query("SELECT a.id FROM address a WHERE a.domain_id= ? AND a.address= ?;", array($dom_id, $login));
279  if ($db->next_record()) {
280  return false;
281  } else {
282  return true;
283  }
284  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$domain
Definition: dom_import.php:40
$dom
Definition: whois_test.php:10
m_mail::catchall_del (   $domain_id)
Parameters
string$domain_id

Definition at line 163 of file m_mail.php.

References $catch, and catchall_getinfos().

Referenced by catchall_set().

163  {
164  $catch = $this->catchall_getinfos($domain_id);
165  if (empty($catch['mail_id'])) {
166  return false;
167  }
168  return $this->delete($catch['mail_id']);
169  }
if(is_null($domain_id)) if(!is_null($target_type)) $catch
catchall_getinfos($domain_id)
Definition: m_mail.php:133
m_mail::catchall_getinfos (   $domain_id)
Parameters
string$domain_id

Definition at line 133 of file m_mail.php.

References $db, $dom, and $rr.

Referenced by catchall_del().

133  {
134  global $dom, $db;
135  $rr = array(
136  'mail_id' => '',
137  'domain' => $dom->get_domain_byid($domain_id),
138  'target' => '',
139  'type' => '',
140  );
141 
142  $db->query("select r.recipients as dst, a.id mail_id from address a, recipient r where a.domain_id = ? and r.address_id = a.id and a.address='';", array($domain_id));
143  if ($db->next_record()) {
144  $rr['target'] = $db->f('dst');
145  $rr['mail_id'] = $db->f('mail_id');
146  }
147 
148  // Does it redirect to a specific mail or to a domain
149  if (empty($rr['target'])) {
150  $rr['type'] = 'none';
151  } elseif (substr($rr['target'], 0, 1) == '@') {
152  $rr['type'] = 'domain';
153  } else {
154  $rr['type'] = 'mail';
155  }
156 
157  return $rr;
158  }
global $db
Definition: bootstrap.php:22
$dom
Definition: whois_test.php:10
$rr
Definition: ftp_edit.php:55
m_mail::catchall_set (   $domain_id,
  $target 
)
Parameters
string$domain_id
string$target

Definition at line 175 of file m_mail.php.

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

Referenced by hook_dom_add_slave_domain().

175  {
176  global $err;
177  $target = rtrim($target);
178  if (substr_count($target, '@') == 0) { // Pas de @
179  $target = '@' . $target;
180  }
181 
182  if (substr($target, 0, 1) == '@') { // le premier caractere est un @
183  // FIXME validate domain
184  } else { // ca doit être un mail
185  if (!filter_var($target, FILTER_VALIDATE_EMAIL)) {
186  $err->raise("mail", _("The email you entered is syntaxically incorrect"));
187  return false;
188  }
189  }
190  $this->catchall_del($domain_id);
191  $err->error = "";
192  return $this->create_alias($domain_id, '', $target, "catchall", true);
193  }
$err
Definition: bootstrap.php:72
catchall_del($domain_id)
Definition: m_mail.php:163
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 identifi...
Definition: m_mail.php:760
m_mail::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 852 of file m_mail.php.

References $db.

852  {
853  global $db;
854  $db->query("SELECT * FROM mxaccount WHERE login= ? AND pass= ?;", array($login, $pass));
855  if ($db->next_record()) {
856  return true;
857  }
858  return false;
859  }
global $db
Definition: bootstrap.php:22
m_mail::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 360 of file m_mail.php.

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

360  {
361  global $err, $db, $quota, $dom, $hooks;
362  $err->log("mail", "create", $mail);
363 
364  // Validate the domain id
365  if (!($domain = $dom->get_domain_byid($dom_id))) {
366  return false;
367  }
368 
369  // Validate the email syntax:
370  $m = $mail . "@" . $domain;
371  if (!filter_var($m, FILTER_VALIDATE_EMAIL) && !$dontcheck) {
372  $err->raise("mail", _("The email you entered is syntaxically incorrect"));
373  return false;
374  }
375 
376  // Call other classes to check we can create it:
377  $cancreate = $hooks->invoke("hook_mail_cancreate", array($dom_id, $mail));
378  if (in_array(false, $cancreate, true)) {
379  return false;
380  }
381 
382  // Check the quota:
383  if (($type=="")&&!$quota->cancreate("mail")) {
384  $err->raise("mail", _("You cannot create email addresses: your quota is over"));
385  return false;
386  }
387  // Already exists?
388  $db->query("SELECT * FROM address WHERE domain_id= ? AND address= ? ;", array($dom_id, $mail));
389  if ($db->next_record()) {
390  $err->raise("mail", _("This email address already exists"));
391  return false;
392  }
393  // Create it now
394  $db->query("INSERT INTO address (domain_id, address,type) VALUES (?, ?, ?);", array($dom_id, $mail, $type));
395  if (!($id = $db->lastid())) {
396  $err->raise("mail", _("An unexpected error occured when creating the email"));
397  return false;
398  }
399  return $id;
400  }
$hooks
Definition: bootstrap.php:74
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$domain
Definition: dom_import.php:40
$dom
Definition: whois_test.php:10
if(!isset($is_include)) if(!$key &&!$crt) $id
m_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.

Parameters
string$m
string$alias
string$dom_id

Definition at line 760 of file m_mail.php.

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

Referenced by catchall_set(), and hook_dom_add_mx_domain().

760  {
761  global $err, $mail;
762  $err->log("mail", "create_alias", "creating $m alias for $alias type $type");
763 
764  $mail_id = $mail->create($dom_id, $m, $type, $dontcheck);
765  if (!$mail_id) {
766  return false;
767  }
768  $this->set_details($mail_id, 0, 0, $alias, "dovecot", $dontcheck);
769  return true;
770  }
$err
Definition: bootstrap.php:72
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 pro...
Definition: m_mail.php:671
$mail_id
m_mail::del_slave_account (   $login)

Remove a slave account.

Parameters
string$loginthe login to delete

Definition at line 914 of file m_mail.php.

References $db.

914  {
915  global $db;
916  $db->query("DELETE FROM mxaccount WHERE login= ? ;", array($login));
917  return true;
918  }
global $db
Definition: bootstrap.php:22
m_mail::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 778 of file m_mail.php.

References $err, and $mail_id.

778  {
779  global $err;
780  $err->log("mail", "del_wrapper");
781  $this->delete($mail_id);
782  }
$err
Definition: bootstrap.php:72
$mail_id
m_mail::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
boolean if the email has been properly deleted or false if an error occured ($err is filled accordingly)

Definition at line 503 of file m_mail.php.

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

503  {
504  global $err, $db, $hooks;
505  $err->log("mail", "delete");
506 
507  $mail_id = intval($mail_id);
508 
509  if (!$mail_id) {
510  $err->raise("mail", _("The email you entered is syntaxically incorrect"));
511  return false;
512  }
513  // Validate that this email is owned by me...
514  if (!($mail = $this->is_it_my_mail($mail_id))) {
515  return false;
516  }
517 
518  $mailinfos = $this->get_details($mail_id);
519  $hooks->invoke('hook_mail_delete', array($mail_id, $mailinfos['address'] . '@' . $mailinfos['domain']));
520 
521  // Search for that address:
522  $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= ? ;", array($mail_id));
523  if (!$db->next_record()) {
524  $err->raise("mail", _("The email %s does not exist, it can't be deleted"), $mail);
525  return false;
526  }
527  if ($db->f("mail_action") != "OK" || ($db->f("islocal") && $db->f("mailbox_action") != "OK")) { // will be deleted soon ...
528  $err->raise("mail", _("The email %s is already marked for deletion, it can't be deleted"), $mail);
529  return false;
530  }
531  $mail_id = $db->f("id");
532 
533  if ($db->f("islocal")) {
534  // If it's a pop/imap mailbox, mark it for deletion
535  $db->query("UPDATE address SET mail_action='DELETE', enabled=0 WHERE id= ?;", array($mail_id));
536  $db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id= ?;", array($mail_id));
537  $err->raise("mail", _("The email %s has been marked for deletion"), $mail);
538  } else {
539  // If it's only aliases, delete it NOW.
540  $db->query("DELETE FROM address WHERE id= ? ;", array($mail_id));
541  $db->query("DELETE FROM mailbox WHERE address_id= ? ;", array($mail_id));
542  $db->query("DELETE FROM recipient WHERE address_id= ? ;", array($mail_id));
543  $err->raise("mail", _("The email %s has been successfully deleted"), $mail);
544  }
545  return true;
546  }
$hooks
Definition: bootstrap.php:74
$mailinfos
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
get_details($mail_id)
function used to get every information we can on a mail
Definition: m_mail.php:408
$mail_id
m_mail::disable (   $mail_id)

Disables an email address.

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

Definition at line 647 of file m_mail.php.

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

647  {
648  global $db, $err;
649  $err->log("mail", "disable");
650  if (!($email = $this->is_it_my_mail($mail_id))) {
651  return false;
652  }
653  if (!$db->query("UPDATE address SET `enabled`=0 where id= ? ;", array($mail_id))) {
654  return false;
655  }
656  return true;
657  }
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
$mail_id
m_mail::echo_domain_list (   $format = null)

Out (echo) the complete hosted domain list :

Definition at line 865 of file m_mail.php.

References $db.

865  {
866  global $db;
867  $db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
868  $lst = array();
869  $tt = "";
870  while ($db->next_record()) {
871  $lst[] = $db->f("domaine");
872  $tt.=$db->f("domaine");
873  }
874 
875  # Generate an integrity check
876  $obj = array('integrity' => md5($tt), 'items' => $lst);
877 
878  switch ($format) {
879  case "json":
880  return json_encode($obj);
881  default:
882  foreach ($lst as $l) {
883  echo $l . "\n";
884  }
885  return true;
886  } // switch
887  }
global $db
Definition: bootstrap.php:22
m_mail::enable (   $mail_id)

Enables an email address.

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

Definition at line 629 of file m_mail.php.

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

629  {
630  global $db, $err;
631  $err->log("mail", "enable");
632  if (!($email = $this->is_it_my_mail($mail_id))) {
633  return false;
634  }
635  if (!$db->query("UPDATE address SET `enabled`=1 where id= ? ;", array($mail_id))) {
636  return false;
637  }
638  return true;
639  }
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
$mail_id
m_mail::enum_domain_mails (   $dom_id = null,
  $search = "",
  $offset = 0,
  $count = 30,
  $show_systemmails = false 
)

Definition at line 295 of file m_mail.php.

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

Referenced by alternc_export_conf(), and hook_dom_del_mx_domain().

295  {
296  global $db, $err, $hooks;
297  $err->log("mail", "enum_domains_mail");
298 
299  $query_args = array($dom_id);
300  $search = trim($search);
301  $where = " a.domain_id = ? ";
302 
303  if ($search) {
304  $where .= " AND (a.address LIKE ? OR r.recipients LIKE ? )";
305  array_push($query_args, "%" . $search . "%", "%" . $search . "%");
306  }
307  if (!$show_systemmails) {
308  $where .= " AND type='' ";
309  }
310  $db->query("SELECT count(a.id) AS total FROM address a LEFT JOIN recipient r ON r.address_id=a.id WHERE " . $where . ";", $query_args);
311  $db->next_record();
312  $this->total = $db->f("total");
313  if ($count != -1) {
314  $offset = intval($offset);
315  $count = intval($count);
316  $limit = " LIMIT $offset, $count ";
317  } else {
318  $limit = "";
319  }
320  $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
321  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
322  WHERE " . $where . " AND d.id=a.domain_id " . $limit . " ;", $query_args);
323  if (!$db->next_record()) {
324  $err->raise("mail", _("No email found for this query"));
325  return array();
326  }
327  $res = array();
328  do {
329  $details = $db->Record;
330  // if necessary, fill the typedata with data from hooks ...
331  if ($details["type"]) {
332  $result = $hooks->invoke("hook_mail_get_details", array($details)); // Will fill typedata if necessary
333  $details["typedata"] = implode("<br />", $result);
334  }
335  $res[] = $details;
336  } while ($db->next_record());
337  return $res;
338  }
$hooks
Definition: bootstrap.php:74
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$res
Definition: index.php:127
m_mail::enum_domains (   $uid = -1)

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

Returns
array indexed array of hosted domains

Definition at line 228 of file m_mail.php.

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

Referenced by alternc_export_conf(), and hook_menu().

228  {
229  global $db, $err, $cuid;
230  $err->log("mail", "enum_domains");
231  if ($uid == -1) {
232  $uid = $cuid;
233  }
234  $db->query("
235 SELECT
236  d.id,
237  d.domaine,
238  IFNULL( COUNT(a.id), 0) as nb_mail
239 FROM
240  domaines d LEFT JOIN address a ON (d.id=a.domain_id AND a.type='')
241 WHERE
242  d.compte = ?
243  and d.gesmx = 1
244 GROUP BY
245  d.id
246 ORDER BY
247  d.domaine
248 ;
249 ", array($uid));
250  $this->enum_domains = array();
251  while ($db->next_record()) {
252  $this->enum_domains[] = $db->Record;
253  }
254  return $this->enum_domains;
255  }
$uid
global $db
Definition: bootstrap.php:22
$enum_domains
Definition: m_mail.php:76
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
enum_domains($uid=-1)
Returns the list of mail-hosting domains for a user.
Definition: m_mail.php:228
m_mail::enum_slave_account ( )

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

Returns
array

Definition at line 831 of file m_mail.php.

References $db, and $res.

831  {
832  global $db;
833  $db->query("SELECT login,pass FROM mxaccount;");
834  $res = array();
835  while ($db->next_record()) {
836  $res[] = $db->Record;
837  }
838  if (!count($res)) {
839  return false;
840  }
841  return $res;
842  }
global $db
Definition: bootstrap.php:22
$res
Definition: index.php:127
m_mail::get_account_by_mail_id (   $mail_id)

Definition at line 485 of file m_mail.php.

References $db, and $mail_id.

485  {
486  global $db;
487  $db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = ? ;", array($mail_id));
488  if (!$db->next_record()) {
489  return false;
490  }
491  return $db->f('uid');
492  }
global $db
Definition: bootstrap.php:22
$mail_id
m_mail::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 408 of file m_mail.php.

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

Referenced by delete(), and set_details().

408  {
409  global $db, $err, $hooks;
410  $err->log("mail", "get_details");
411 
412  $mail_id = intval($mail_id);
413  // Validate that this email is owned by me...
414  if (!($mail = $this->is_it_my_mail($mail_id))) {
415  return false;
416  }
417 
418  // We fetch all the informations for that email: these will fill the hastable :
419  $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= ? AND d.id=a.domain_id;", array($mail_id));
420  if (!$db->next_record()) {
421  return false;
422  }
423  $details = $db->Record;
424  // if necessary, fill the typedata with data from hooks ...
425  if ($details["type"]) {
426  $result = $hooks->invoke("hook_mail_get_details", array($mail_id)); // Will fill typedata if necessary
427  $details["typedata"] = implode("<br />", $result);
428  }
429  return $details;
430  }
$hooks
Definition: bootstrap.php:74
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
$mail_id
m_mail::get_total_size_for_domain (   $domain)

Definition at line 113 of file m_mail.php.

References $db, and $domain.

113  {
114  global $db;
115  if (empty($this->cache_domain_mail_size)) {
116  $db->query("SELECT SUBSTRING_INDEX(user,'@', -1) as domain, SUM(quota_dovecot) AS sum FROM dovecot_view group by domain ;");
117  while ($db->next_record()) {
118  $dd = $db->f('domain');
119  $this->cache_domain_mail_size[$dd] = $db->f('sum');
120  }
121  }
122  if (isset($this->cache_domain_mail_size[$domain])) {
123  return $this->cache_domain_mail_size[$domain];
124  }
125  return 0;
126  }
global $db
Definition: bootstrap.php:22
$domain
Definition: dom_import.php:40
m_mail::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 945 of file m_mail.php.

References $db, $err, $mem, create_alias(), set_dns_dmarc(), set_dns_spf(), and variable_get().

945  {
946  global $err, $mem, $db;
947  $err->log("mail", "hook_dom_add_mx_domain", $domain_id);
948 
949  $db->query("SELECT value FROM variable where name='mailname_bounce';");
950  if (!$db->next_record()) {
951  $err->raise("mail", _("Problem: can't create default bounce mail"));
952  return false;
953  }
954  $mailname = $db->f("value");
955  // set spf & dmarc for this domain
956  $db->query("SELECT domaine FROM domaines WHERE id= ?;", array($domain_id));
957  if ($db->next_record()) {
958  if ($spf = variable_get("default_spf_value")) {
959  $this->set_dns_spf($db->Record["domaine"], $spf);
960  }
961  if ($dmarc = variable_get("default_dmarc_value")) {
962  $this->set_dns_dmarc($db->Record["domaine"], $dmarc);
963  }
964  }
965  return $this->create_alias($domain_id, 'postmaster', $mem->user['login'] . '@' . $mailname);
966  }
set_dns_dmarc($domain, $dmarc, $previous=-1, $uid=-1, $login=-1)
Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc account's login is current and if ...
Definition: m_mail.php:1037
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:90
$mem
Definition: bootstrap.php:71
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 identifi...
Definition: m_mail.php:760
set_dns_spf($domain, $spf, $previous=-1, $uid=-1, $login=-1)
Set or UPDATE the DNS record for the domain $dom(str) to be $spf account's login is current and if no...
Definition: m_mail.php:1007
m_mail::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 929 of file m_mail.php.

References $err, and catchall_set().

929  {
930  global $err;
931  $err->log("mail", "hook_dom_add_slave_domain", $domain_id);
932  $this->catchall_set($domain_id, '@' . $target_domain);
933  return true;
934  }
catchall_set($domain_id, $target)
Definition: m_mail.php:175
$err
Definition: bootstrap.php:72
m_mail::hook_dom_del_mx_domain (   $dom_id)

Hook called when the DOMAIN class will delete a domain.

OR when the DOMAIN class tells us we don't host the emails of this domain anymore.

Parameters
$domthe ID of the domain to delete
Returns
boolean if the email has been properly deleted or false if an error occured ($err is filled accordingly)

Definition at line 466 of file m_mail.php.

References $db, $list, and enum_domain_mails().

466  {
467  global $db;
468  $list = $this->enum_domain_mails($dom_id, "", 0, -1);
469  if (is_array($list)) {
470  foreach ($list as $one) {
471  $this->delete($one["id"]);
472  }
473  }
474  $db->query("SELECT domaine FROM domaines WHERE id= ? ;", array($dom_id));
475  if ($db->next_record()) {
476  $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine= ? AND type='txt' AND (sub='' AND valeur LIKE 'v=spf1 %') OR (sub='_dmarc' AND valeur LIKE 'v=dmarc1;%');", array($db->Record["domaine"]));
477  $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine= ? AND (type='defmx' OR type='defmx2');", array($db->Record["domaine"]));
478  $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE id= ? ;", array($dom_id));
479  }
480 
481  return true;
482  }
enum_domain_mails($dom_id=null, $search="", $offset=0, $count=30, $show_systemmails=false)
Definition: m_mail.php:295
global $db
Definition: bootstrap.php:22
$list
Definition: logs_list.php:33
m_mail::hook_mail_get_details (   $detail)

Definition at line 340 of file m_mail.php.

340  {
341  if ($detail['type'] == 'catchall') {
342  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']));
343  }
344  }
m_mail::hook_menu ( )

Definition at line 94 of file m_mail.php.

References $d, and enum_domains().

94  {
95  $obj = array(
96  'title' => _("Email Addresses"),
97  'ico' => 'images/mail.png',
98  'link' => 'toggle',
99  'pos' => 30,
100  'links' => array(),
101  );
102 
103  foreach ($this->enum_domains() as $d) {
104  $obj['links'][] = array(
105  'txt' => htmlentities($d["domaine"]) . '&nbsp;' . htmlentities("(" . $d["nb_mail"] . ")"),
106  'url' => "mail_list.php?domain_id=" . urlencode($d['id']),
107  );
108  }
109 
110  return $obj;
111  }
enum_domains($uid=-1)
Returns the list of mail-hosting domains for a user.
Definition: m_mail.php:228
$d
m_mail::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 203 of file m_mail.php.

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

203  {
204  global $db, $err, $cuid;
205  $err->log("mail", "getquota");
206  $q = Array("name" => "mail", "description" => _("Email addresses"), "used" => 0);
207  $db->query("SELECT COUNT(*) AS cnt FROM address a, domaines d WHERE a.domain_id=d.id AND d.compte= ? AND a.type='';", array($cuid));
208  if ($db->next_record()) {
209  $q['used'] = $db->f("cnt");
210  }
211  return $q;
212  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_mail::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 1070 of file m_mail.php.

1070  {
1071  return array(
1072  "imap" => array("port" => 143, "protocol" => "tcp", "mandatory" => 1),
1073  "imaps" => array("port" => 993, "protocol" => "tcp", "mandatory" => 1),
1074  "pop" => array("port" => 110, "protocol" => "tcp", "mandatory" => 1),
1075  "pops" => array("port" => 995, "protocol" => "tcp", "mandatory" => 1),
1076  "smtp" => array("port" => 25, "protocol" => "tcp", "mandatory" => 1),
1077  "sieve" => array("port" => 2000, "protocol" => "tcp", "mandatory" => 1),
1078  "submission" => array("port" => 587, "protocol" => "tcp", "mandatory" => 0),
1079  );
1080  }
m_mail::hook_variable_set (   $name,
  $old,
  $new 
)

hook function called by variables when a variable is changed private

Definition at line 973 of file m_mail.php.

References $db, $err, $res, foreach, set_dns_dmarc(), and set_dns_spf().

973  {
974  global $err, $db;
975  $err->log("mail", "hook_variable_set($name,$old,$new)");
976 
977  if ($name == "default_spf_value") {
978  $new = trim($new);
979  $old = trim($old);
980  $db->query("SELECT domaine,login,compte FROM domaines, membres WHERE gesdns=1 AND gesmx=1 and membres.uid=domaines.compte;");
981  $res=array();
982  while ($db->next_record()) $res[]=$db->Record;
983  foreach ($res as $record) {
984  $this->set_dns_spf($record["domaine"], $new, $old, $record["compte"], $record["login"]);
985  }
986  }
987 
988  if ($name == "default_dmarc_value") {
989  $new = trim($new);
990  $old = trim($old);
991  $db->query("SELECT domaine,login,compte FROM domaines, membres WHERE gesdns=1 AND gesmx=1 and membres.uid=domaines.compte;");
992  $res=array();
993  while ($db->next_record()) $res[]=$db->Record;
994  foreach ($res as $record) {
995  $this->set_dns_dmarc($record["domaine"], $new, $old, $record["compte"], $record["login"]);
996  }
997  }
998  }
set_dns_dmarc($domain, $dmarc, $previous=-1, $uid=-1, $login=-1)
Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc account's login is current and if ...
Definition: m_mail.php:1037
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$res
Definition: index.php:127
foreach($list_ip as $i)
set_dns_spf($domain, $spf, $previous=-1, $uid=-1, $login=-1)
Set or UPDATE the DNS record for the domain $dom(str) to be $spf account's login is current and if no...
Definition: m_mail.php:1007
m_mail::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 442 of file m_mail.php.

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

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

442  {
443  global $err, $db, $cuid;
444  $mail_id = intval($mail_id);
445  // cache it (may be called more than one time in the same page).
446  if (isset($this->isitmy_cache[$mail_id])) {
447  return $this->isitmy_cache[$mail_id];
448  }
449  $db->query("SELECT concat(a.address,'@',d.domaine) AS email FROM address a, domaines d WHERE d.id=a.domain_id AND a.id= ? AND d.compte= ?;", array($mail_id, $cuid));
450  if ($db->next_record()) {
451  return $this->isitmy_cache[$mail_id] = $db->f("email");
452  } else {
453  $err->raise("mail", _("This email is not yours, you can't change anything on it"));
454  return $this->isitmy_cache[$mail_id] = false;
455  }
456  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
$mail_id
m_mail::m_mail ( )

Constructeur.

Definition at line 83 of file m_mail.php.

References variable_get().

83  {
84  global $L_FQDN;
85  $this->srv_submission = variable_get('mail_human_submission', $L_FQDN, 'Human name for mail server (submission protocol), leave empty to disable help', array('desc' => 'Name', 'type' => 'string'));
86  $this->srv_smtp = variable_get('mail_human_smtp', $L_FQDN, 'Human name for mail server (SMTP protocol), leave empty to disable help', array('desc' => 'Name', 'type' => 'string'));
87  $this->srv_smtps = variable_get('mail_human_smtps', $L_FQDN, 'Human name for mail server (SMTPS protocol), leave empty to disable help', array('desc' => 'Name', 'type' => 'string'));
88  $this->srv_imap = variable_get('mail_human_imap', $L_FQDN, 'Human name for IMAP mail server', array('desc' => 'Name', 'type' => 'string'));
89  $this->srv_imaps = variable_get('mail_human_imaps', $L_FQDN, 'Human name for IMAPS mail server', array('desc' => 'Name', 'type' => 'string'));
90  $this->srv_pop3 = variable_get('mail_human_pop3', $L_FQDN, 'Human name for POP3 mail server', array('desc' => 'Name', 'type' => 'string'));
91  $this->srv_pop3s = variable_get('mail_human_pop3s', $L_FQDN, 'Human name for POP3s mail server', array('desc' => 'Name', 'type' => 'string'));
92  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:90
m_mail::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
integer$islocalboolean is it a POP/IMAP mailbox ?
integer$quotambinteger if islocal=1, quota in MB
string$recipientsstring recipients, one mail per line.
Returns
boolean if the email has been properly edited or false if an error occured ($err is filled accordingly)

Definition at line 671 of file m_mail.php.

References $db, $err, $mail_id, $quotamb, $r, $recipients, ALTERNC_MAIL, and get_details().

Referenced by add_wrapper(), and create_alias().

671  {
672  global $err, $db;
673  $err->log("mail", "set_details");
674  if (!($me = $this->get_details($mail_id))) {
675  return false;
676  }
677  if ($me["islocal"] && !$islocal) {
678  // delete pop
679  $db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id= ? ;", array($mail_id));
680  }
681  if (!$me["islocal"] && $islocal) {
682  // create pop
683  $path = "";
684  if ($delivery == "dovecot") {
685  $path = ALTERNC_MAIL . "/" . substr($me["address"] . "_", 0, 1) . "/" . $me["address"] . "_" . $me["domain"];
686  }
687  foreach ($this->forbiddenchars as $str) {
688  if (strpos($me["address"], $str) !== false) {
689  $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"));
690  return false;
691  }
692  }
693  foreach ($this->specialchars as $str) {
694  if (strpos($me["address"], $str) !== false) {
695  $path = ALTERNC_MAIL . "/_/" . $me["id"] . "_" . $me["domain"];
696  break;
697  }
698  }
699  $db->query("INSERT INTO mailbox SET address_id= ? , delivery= ?, path= ? ;", array($mail_id, $delivery, $path));
700  }
701  if ($me["islocal"] && $islocal && $me["mailbox_action"] == "DELETE") {
702  $db->query("UPDATE mailbox SET mail_action='OK' WHERE mail_action='DELETE' AND address_id= ? ;", array($mail_id));
703  }
704 
705  if ($islocal) {
706  if ($quotamb != 0 && $quotamb < (intval($me["used"] / 1024 / 1024) + 1)) {
707  $quotamb = intval($me["used"] / 1024 / 1024) + 1;
708  $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"));
709  }
710  $db->query("UPDATE mailbox SET quota= ? WHERE address_id= ? ;", array($quotamb, $mail_id));
711  }
712 
713  $recipients = preg_replace('/[\r\t\s]/', "\n", $recipients); // Handle space AND new line
714  $r = explode("\n", $recipients);
715  $red = "";
716  foreach ($r as $m) {
717  $m = trim($m);
718  if ($m && ( filter_var($m, FILTER_VALIDATE_EMAIL) || $dontcheck) // Recipient Email is valid
719  && $m != ($me["address"] . "@" . $me["domain"])) { // And not myself (no loop allowed easily ;) )
720  $red.=$m . "\n";
721  }
722  }
723  $db->query("DELETE FROM recipient WHERE address_id= ? ;", array($mail_id));
724  if (isset($red) && $red) {
725  $db->query("INSERT INTO recipient SET address_id= ?, recipients= ? ;", array($mail_id, $red));
726  }
727  if (!$islocal && !$red) {
728  $err->raise("mail", _("Warning: you created an email which is not an alias, and not a POP/IMAP mailbox. This is certainly NOT what you want to do. To fix this, edit the email address and check 'Yes' in POP/IMAP account, or set some recipients in the redirection field."));
729  }
730  return true;
731  }
$quotamb
Definition: mail_edit.php:46
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
$err
Definition: bootstrap.php:72
$recipients
Definition: mail_add.php:50
get_details($mail_id)
function used to get every information we can on a mail
Definition: m_mail.php:408
const ALTERNC_MAIL
Definition: bootstrap.php:9
$mail_id
m_mail::set_dns_dmarc (   $domain,
  $dmarc,
  $previous = -1,
  $uid = -1,
  $login = -1 
)

Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc account's login is current and if not it's $login.

don't change dmarc if current value is not $old private

Definition at line 1037 of file m_mail.php.

References $cuid, $db, $domain, $mem, and $uid.

Referenced by hook_dom_add_mx_domain(), and hook_variable_set().

1037  {
1038  global $db, $cuid, $mem, $L_FQDN;
1039  // defaults
1040  if ($uid === -1) {
1041  $uid = intval($cuid);
1042  } else {
1043  $uid = intval($uid);
1044  }
1045  if ($login === -1) {
1046  $login = $mem->user["login"];
1047  }
1048  $dmarc = str_replace("%%ADMINMAIL%%", "admin@" . $L_FQDN, $dmarc);
1049  $dmarc = str_replace("%%USERMAIL%%", $login . "@" . $L_FQDN, $dmarc);
1050 
1051  // Search for the record in sub_domaines table
1052  $db->query("SELECT * FROM sub_domaines WHERE compte= ? AND domaine= ? AND sub='_dmarc' AND type='txt' AND valeur LIKE 'v=dmarc1;%' AND web_action!='DELETE';", array($uid, $domain));
1053  if ($db->next_record()) {
1054  if ($previous !== -1 && $db->Record["valeur"] == "v=dmarc1;" . $dmarc) {
1055  return; // skip, no change asked.
1056  }
1057  $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE id= ?;", array($db->Record["id"]));
1058  }
1059  $db->query("INSERT INTO sub_domaines SET compte= ?, domaine= ?, sub='_dmarc', type='txt', valeur= ?, web_action='UPDATE';", array($uid, $domain, "v=dmarc1;" . $dmarc));
1060  $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine= ?;", array($domain));
1061  }
$uid
global $db
Definition: bootstrap.php:22
$cuid
Definition: bootstrap.php:43
$domain
Definition: dom_import.php:40
$mem
Definition: bootstrap.php:71
m_mail::set_dns_spf (   $domain,
  $spf,
  $previous = -1,
  $uid = -1,
  $login = -1 
)

Set or UPDATE the DNS record for the domain $dom(str) to be $spf account's login is current and if not it's $login.

don't change spf if current value is not $old private

Definition at line 1007 of file m_mail.php.

References $cuid, $db, $domain, $mem, and $uid.

Referenced by hook_dom_add_mx_domain(), and hook_variable_set().

1007  {
1008  global $db, $cuid, $mem;
1009  // defaults
1010  if ($uid === -1) {
1011  $uid = intval($cuid);
1012  } else {
1013  $uid = intval($uid);
1014  }
1015  if ($login === -1) {
1016  $login = $mem->user["login"];
1017  }
1018  // Search for the record in sub_domaines table
1019  $db->query("SELECT * FROM sub_domaines WHERE compte= ? AND domaine= ? AND sub='' AND type='txt' AND valeur LIKE 'v=spf1 %' AND web_action!='DELETE';", array($uid, $domain));
1020  if ($db->next_record()) {
1021  if ($previous !== -1 && $db->Record["valeur"] == "v=spf1 " . $spf) {
1022  return; // skip, no change asked.
1023  }
1024  $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE id= ? ;",array($db->Record["id"]));
1025  }
1026  $db->query("INSERT INTO sub_domaines SET compte= ?, domaine= ?, sub='', type='txt', valeur= ? , web_action='UPDATE';", array($uid, $domain, "v=spf1 " . $spf));
1027  $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine= ?;", array($domain));
1028  }
$uid
global $db
Definition: bootstrap.php:22
$cuid
Definition: bootstrap.php:43
$domain
Definition: dom_import.php:40
$mem
Definition: bootstrap.php:71
m_mail::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 607 of file m_mail.php.

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

607  {
608  global $db, $err, $admin;
609  $err->log("mail", "setpasswd");
610 
611  if (!($email = $this->is_it_my_mail($mail_id))) {
612  return false;
613  }
614  if (!$admin->checkPolicy("pop", $email, $pass)) {
615  return false;
616  }
617  if (!$db->query("UPDATE address SET password= ? where id = ? ;", array(_md5cr($pass), $mail_id ))) {
618  return false;
619  }
620  return true;
621  }
global $db
Definition: bootstrap.php:22
_md5cr($pass, $salt="")
Hashe un mot de passe en clair en MD5 avec un salt al�atoire.
Definition: functions.php:513
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
$mail_id
m_mail::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
boolean if the email has been properly undeleted or false if an error occured ($err is filled accordingly)

Definition at line 557 of file m_mail.php.

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

557  {
558  global $err, $db;
559  $err->log("mail", "undelete");
560 
561  $mail_id = intval($mail_id);
562 
563  if (!$mail_id) {
564  $err->raise("mail", _("The email you entered does not exist"));
565  return false;
566  }
567  // Validate that this email is owned by me...
568  if (!($mail = $this->is_it_my_mail($mail_id))) {
569  return false;
570  }
571 
572  // Search for that address:
573  $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= ? ;", array($mail_id));
574  if (!$db->next_record()) {
575  $err->raise("mail", _("The email %s does not exist, it can't be undeleted"), $mail);
576  return false;
577  }
578  if ($db->f("type") != "") { // Technically special : mailman, sympa ...
579  $err->raise("mail", _("The email %s is special, it can't be undeleted"), $mail);
580  return false;
581  }
582  if ($db->f("mailbox_action") != "DELETE" || $db->f("mail_action") != "DELETE") { // will be deleted soon ...
583  $err->raise("mail", _("Sorry, deletion of email %s is already in progress, or not marked for deletion, it can't be undeleted"), $mail);
584  return false;
585  }
586  $mail_id = $db->f("id");
587 
588  if ($db->f("islocal")) {
589  // If it's a pop/imap mailbox, mark it for deletion
590  $db->query("UPDATE address SET mail_action='OK', `enabled`=1 WHERE id= ?;", array($mail_id));
591  $db->query("UPDATE mailbox SET mail_action='OK' WHERE address_id= ? ;", array($mail_id));
592  $err->raise("mail", _("The email %s has been undeleted"), $mail);
593  return true;
594  } else {
595  $err->raise("mail", _("-- Program Error -- The email %s can't be undeleted"), $mail);
596  return false;
597  }
598  }
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:442
$err
Definition: bootstrap.php:72
$mail_id

Member Data Documentation

m_mail::$cache_domain_mail_size = array()

Definition at line 75 of file m_mail.php.

m_mail::$domains

domain list for this account private

Definition at line 43 of file m_mail.php.

m_mail::$enum_domains = array()

Definition at line 76 of file m_mail.php.

Referenced by enum_domains().

m_mail::$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.

m_mail::$isitmy_cache = array()
private

Definition at line 432 of file m_mail.php.

m_mail::$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.

m_mail::$srv_imap

Definition at line 71 of file m_mail.php.

m_mail::$srv_imaps

Definition at line 72 of file m_mail.php.

m_mail::$srv_pop3

Definition at line 73 of file m_mail.php.

m_mail::$srv_pop3s

Definition at line 74 of file m_mail.php.

m_mail::$srv_smtp

Definition at line 69 of file m_mail.php.

m_mail::$srv_smtps

Definition at line 70 of file m_mail.php.

m_mail::$srv_submission

Definition at line 68 of file m_mail.php.

m_mail::$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: