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 ()
 Hook called by menu class to add the email menu to the left pane. More...
 
 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)
 function used to list every mail address hosted on a domain. More...
 
 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)
 return the alternc account's ID of the mail_id More...
 
 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, $canbeempty=false)
 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...
 

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.

This class is directly using the following alternc MySQL tables: address = any used email address will be defined here, mailbox = pop/imap mailboxes, recipient = redirection from an email to another and indirectly the domain class, to know domain names from their id in the DB. This class is also defining a few hooks, search ->invoke in the code.

Definition at line 32 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 901 of file m_mail.php.

References $db, $login, and $msg.

901  {
902  global $db, $msg;
903  $db->query("SELECT * FROM mxaccount WHERE login= ? ;", array($login));
904  if ($db->next_record()) {
905  $msg->raise("ERROR", "mail", _("The slave MX account was not found"));
906  return false;
907  }
908  $db->query("INSERT INTO mxaccount (login,pass) VALUES (?, ?);", array($login, $pass));
909  return true;
910  }
$login
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
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 747 of file m_mail.php.

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

747  {
748  global $msg, $mail;
749  $msg->log("mail", "add_wrapper", "creating $delivery $m address");
750 
751  $mail_id = $mail->create($dom_id, $m, $delivery);
752  $this->set_details($mail_id, 1, 0, '', $delivery);
753  // FIXME return error code
754  }
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:678
$msg
Definition: config.php:155
$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 797 of file m_mail.php.

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

797  {
798  global $msg;
799  $msg->log("mail", "export");
800  $domain = $this->enum_domains();
801  $str = "<mail>\n";
802  foreach ($domain as $d) {
803  $str.=" <domain>\n <name>" . xml_entities($d["domain"]) . "</name>\n";
804  $s = $this->enum_domain_mails($d["id"]);
805  if (count($s)) {
806  while (list($key, $val) = each($s)) {
807  $str.=" <address>\n";
808  $str.=" <name>" . xml_entities($val["address"]) . "</name>\n";
809  $str.=" <enabled>" . xml_entities($val["enabled"]) . "</enabled>\n";
810  if (is_array($val["islocal"])) {
811  $str.=" <islocal>1</islocal>\n";
812  $str.=" <quota>" . $val["quota"] . "</quota>\n";
813  $str.=" <path>" . $val["path"] . "</path>\n";
814  } else {
815  $str.=" <islocal>0</islocal>\n";
816  }
817  if (!empty($val["recipients"])) {
818  $r = explode("\n", $val["recipients"]);
819  foreach ($r as $recip) {
820  $str.=" <recipients>" . $recip . "<recipients>\n";
821  }
822  }
823  $str.=" </address>\n";
824  }
825  }
826  $str.=" </domain>\n";
827  }
828  $str.="</mail>\n";
829  return $str;
830  }
$val
Definition: tempovars.php:15
enum_domain_mails($dom_id=null, $search="", $offset=0, $count=30, $show_systemmails=false)
function used to list every mail address hosted on a domain.
Definition: m_mail.php:296
$r
Definition: aws_add.php:75
$msg
Definition: config.php:155
xml_entities($string)
Echappe les caract�res pouvant perturber un flux XML standard :
Definition: functions.php:561
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:229
$domain
Definition: dom_import.php:36
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 220 of file m_mail.php.

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

References $db, $dom, $domain, $login, and $msg.

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

Definition at line 132 of file m_mail.php.

References $db, $dom, $rr, and elseif.

Referenced by catchall_del().

132  {
133  global $dom, $db;
134  $rr = array(
135  'mail_id' => '',
136  'domain' => $dom->get_domain_byid($domain_id),
137  'target' => '',
138  'type' => '',
139  );
140 
141  $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));
142  if ($db->next_record()) {
143  $rr['target'] = $db->f('dst');
144  $rr['mail_id'] = $db->f('mail_id');
145  }
146 
147  // Does it redirect to a specific mail or to a domain
148  if (empty($rr['target'])) {
149  $rr['type'] = 'none';
150  } elseif (substr($rr['target'], 0, 1) == '@') {
151  $rr['type'] = 'domain';
152  } else {
153  $rr['type'] = 'mail';
154  }
155 
156  return $rr;
157  }
global $db
Definition: bootstrap.php:22
if(empty($site_name)) elseif($piwik->site_add($site_name, $site_urls))
$dom
Definition: whois_test.php:10
$rr
Definition: ftp_edit.php:52
m_mail::catchall_set (   $domain_id,
  $target 
)
Parameters
string$domain_id
string$target

Definition at line 176 of file m_mail.php.

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

Referenced by hook_dom_add_slave_domain().

176  {
177  global $msg;
178  $target = rtrim($target);
179  if (strlen($target) > 0 && substr_count($target, '@') == 0) { // Pas de @
180  $target = '@' . $target;
181  }
182 
183  if (substr($target, 0, 1) == '@') { // the first character is @
184  // FIXME validate domain
185  } else { // it MUST be an email
186  if (!filter_var($target, FILTER_VALIDATE_EMAIL)) {
187  $msg->raise("ERROR", "mail", _("The email you entered is syntaxically incorrect"));
188  return false;
189  }
190  }
191  $this->catchall_del($domain_id);
192  return $this->create_alias($domain_id, '', $target, "catchall", true);
193  }
$msg
Definition: config.php:155
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:767
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 857 of file m_mail.php.

References $db, and $login.

857  {
858  global $db;
859  $db->query("SELECT * FROM mxaccount WHERE login= ? AND pass= ?;", array($login, $pass));
860  if ($db->next_record()) {
861  return true;
862  }
863  return false;
864  }
$login
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 ($msg is filled accordingly)

Definition at line 361 of file m_mail.php.

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

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

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

Referenced by catchall_set(), and hook_dom_add_mx_domain().

767  {
768  global $msg, $mail;
769  $msg->log("mail", "create_alias", "creating $m alias for $alias type $type");
770 
771  $mail_id = $mail->create($dom_id, $m, $type, $dontcheck);
772  if (!$mail_id) {
773  return false;
774  }
775  $this->set_details($mail_id, 0, 0, $alias, "dovecot", $dontcheck);
776  return true;
777  }
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:678
$msg
Definition: config.php:155
$mail_id
m_mail::del_slave_account (   $login)

Remove a slave account.

Parameters
string$loginthe login to delete

Definition at line 917 of file m_mail.php.

References $db, and $login.

917  {
918  global $db;
919  $db->query("DELETE FROM mxaccount WHERE login= ? ;", array($login));
920  return true;
921  }
$login
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 785 of file m_mail.php.

References $mail_id, and $msg.

785  {
786  global $msg;
787  $msg->log("mail", "del_wrapper");
788  $this->delete($mail_id);
789  }
$msg
Definition: config.php:155
$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 ($msg is filled accordingly)

Definition at line 511 of file m_mail.php.

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

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

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

654  {
655  global $db, $msg;
656  $msg->log("mail", "disable");
657  if (!($email = $this->is_it_my_mail($mail_id))) {
658  return false;
659  }
660  if (!$db->query("UPDATE address SET `enabled`=0 where id= ? ;", array($mail_id))) {
661  return false;
662  }
663  return true;
664  }
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:447
$msg
Definition: config.php:155
$mail_id
m_mail::echo_domain_list (   $format = null)

Out (echo) the complete hosted domain list :

Definition at line 870 of file m_mail.php.

References $db.

870  {
871  global $db;
872  $db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
873  $lst = array();
874  $tt = "";
875  while ($db->next_record()) {
876  $lst[] = $db->f("domaine");
877  $tt.=$db->f("domaine");
878  }
879 
880  // Generate an integrity check
881  $obj = array('integrity' => md5($tt), 'items' => $lst);
882 
883  switch ($format) {
884  case "json":
885  return json_encode($obj);
886  default:
887  foreach ($lst as $l) {
888  echo $l . "\n";
889  }
890  return true;
891  } // switch
892  }
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 636 of file m_mail.php.

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

636  {
637  global $db, $msg;
638  $msg->log("mail", "enable");
639  if (!($email = $this->is_it_my_mail($mail_id))) {
640  return false;
641  }
642  if (!$db->query("UPDATE address SET `enabled`=1 where id= ? ;", array($mail_id))) {
643  return false;
644  }
645  return true;
646  }
global $db
Definition: bootstrap.php:22
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:447
$msg
Definition: config.php:155
$mail_id
m_mail::enum_domain_mails (   $dom_id = null,
  $search = "",
  $offset = 0,
  $count = 30,
  $show_systemmails = false 
)

function used to list every mail address hosted on a domain.

Parameters
$dom_idinteger the domain id.
$searchstring search that string in recipients or address.
$offsetinteger skip THAT much emails in the result.
$countinteger return no more than THAT much emails. -1 for ALL. Offset is ignored then.
Returns
an array of each mail hosted under the domain.

Definition at line 296 of file m_mail.php.

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

Referenced by alternc_export_conf(), and hook_dom_del_mx_domain().

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

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

Referenced by alternc_export_conf(), and hook_menu().

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

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

Returns
array

Definition at line 837 of file m_mail.php.

References $db, and $res.

837  {
838  global $db;
839  $db->query("SELECT login,pass FROM mxaccount;");
840  $res = array();
841  while ($db->next_record()) {
842  $res[] = $db->Record;
843  }
844  if (!count($res)) {
845  return false;
846  }
847  return $res;
848  }
global $db
Definition: bootstrap.php:22
$res
Definition: index.php:125
m_mail::get_account_by_mail_id (   $mail_id)

return the alternc account's ID of the mail_id

Definition at line 493 of file m_mail.php.

References $db, and $mail_id.

493  {
494  global $db;
495  $db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = ? ;", array($mail_id));
496  if (!$db->next_record()) {
497  return false;
498  }
499  return $db->f('uid');
500  }
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 413 of file m_mail.php.

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

Referenced by delete(), and set_details().

413  {
414  global $db, $msg, $hooks;
415  $msg->log("mail", "get_details");
416 
417  $mail_id = intval($mail_id);
418  // Validate that this email is owned by me...
419  if (!($mail = $this->is_it_my_mail($mail_id))) {
420  return false;
421  }
422 
423  // We fetch all the informations for that email: these will fill the hastable :
424  $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, q.quota_dovecot AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.mail_action, m.mail_action AS mailbox_action FROM ((domaines d, address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN dovecot_quota q ON CONCAT(a.address,'@',d.domaine) = q.user) LEFT JOIN recipient r ON r.address_id=a.id WHERE a.id= ? AND d.id=a.domain_id;", array($mail_id));
425  if (!$db->next_record()) {
426  return false;
427  }
428  $details = $db->Record;
429  // if necessary, fill the typedata with data from hooks ...
430  if ($details["type"]) {
431  $result = $hooks->invoke("hook_mail_get_details", array($mail_id)); // Will fill typedata if necessary
432  $details["typedata"] = implode("<br />", $result);
433  }
434  return $details;
435  }
$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:447
$msg
Definition: config.php:155
$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_quota 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:36
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 948 of file m_mail.php.

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

948  {
949  global $msg, $mem, $db;
950  $msg->log("mail", "hook_dom_add_mx_domain", $domain_id);
951 
952  $db->query("SELECT value FROM variable where name='mailname_bounce';");
953  if (!$db->next_record()) {
954  $msg->raise("ERROR", "mail", _("Problem: can't create default bounce mail"));
955  return false;
956  }
957  $mailname = $db->f("value");
958  // set spf & dmarc for this domain
959  $db->query("SELECT domaine FROM domaines WHERE id= ?;", array($domain_id));
960  if ($db->next_record()) {
961  if ($spf = variable_get("default_spf_value")) {
962  $this->set_dns_spf($db->Record["domaine"], $spf);
963  }
964  if ($dmarc = variable_get("default_dmarc_value")) {
965  $this->set_dns_dmarc($db->Record["domaine"], $dmarc);
966  }
967  }
968  return $this->create_alias($domain_id, 'postmaster', $mem->user['login'] . '@' . $mailname);
969  }
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:1040
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85
$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:767
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:1010
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 932 of file m_mail.php.

References $msg, and catchall_set().

932  {
933  global $msg;
934  $msg->log("mail", "hook_dom_add_slave_domain", $domain_id);
935  $this->catchall_set($domain_id, '@' . $target_domain);
936  return true;
937  }
catchall_set($domain_id, $target)
Definition: m_mail.php:176
$msg
Definition: config.php:155
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 ($msg is filled accordingly)

Definition at line 471 of file m_mail.php.

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

471  {
472  global $db;
473  $list = $this->enum_domain_mails($dom_id, "", 0, -1);
474  if (is_array($list)) {
475  foreach ($list as $one) {
476  $this->delete($one["id"]);
477  }
478  }
479  $db->query("SELECT domaine FROM domaines WHERE id= ? ;", array($dom_id));
480  if ($db->next_record()) {
481  $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"]));
482  $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine= ? AND (type='defmx' OR type='defmx2');", array($db->Record["domaine"]));
483  $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE id= ? ;", array($dom_id));
484  }
485 
486  return true;
487  }
enum_domain_mails($dom_id=null, $search="", $offset=0, $count=30, $show_systemmails=false)
function used to list every mail address hosted on a domain.
Definition: m_mail.php:296
global $db
Definition: bootstrap.php:22
$list
Show a list of all found log files for an account and allow to see / tail / download them...
Definition: logs_list.php:30
m_mail::hook_mail_get_details (   $detail)

Definition at line 341 of file m_mail.php.

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

Hook called by menu class to add the email menu to the left pane.

Definition at line 93 of file m_mail.php.

References $d, and enum_domains().

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

203  {
204  global $db, $msg, $cuid, $quota;
205  $msg->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  $q['sizeondisk'] = $quota->get_size_mail_sum_user($cuid)/1024;
211  }
212  return $q;
213  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$cuid
Definition: bootstrap.php:43
m_mail::hook_variable_set (   $name,
  $old,
  $new 
)

hook function called by variables when a variable is changed private

Definition at line 976 of file m_mail.php.

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

976  {
977  global $msg, $db;
978  $msg->log("mail", "hook_variable_set($name,$old,$new)");
979 
980  if ($name == "default_spf_value") {
981  $new = trim($new);
982  $old = trim($old);
983  $db->query("SELECT domaine,login,compte FROM domaines, membres WHERE gesdns=1 AND gesmx=1 and membres.uid=domaines.compte;");
984  $res=array();
985  while ($db->next_record()) $res[]=$db->Record;
986  foreach ($res as $record) {
987  $this->set_dns_spf($record["domaine"], $new, $old, $record["compte"], $record["login"]);
988  }
989  }
990 
991  if ($name == "default_dmarc_value") {
992  $new = trim($new);
993  $old = trim($old);
994  $db->query("SELECT domaine,login,compte FROM domaines, membres WHERE gesdns=1 AND gesmx=1 and membres.uid=domaines.compte;");
995  $res=array();
996  while ($db->next_record()) $res[]=$db->Record;
997  foreach ($res as $record) {
998  $this->set_dns_dmarc($record["domaine"], $new, $old, $record["compte"], $record["login"]);
999  }
1000  }
1001  }
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:1040
global $db
Definition: bootstrap.php:22
$res
Definition: index.php:125
$msg
Definition: config.php:155
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:1010
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 ($msg is filled accordingly)

Definition at line 447 of file m_mail.php.

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

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

447  {
448  global $msg, $db, $cuid;
449  $mail_id = intval($mail_id);
450  // cache it (may be called more than one time in the same page).
451  if (isset($this->isitmy_cache[$mail_id])) {
452  return $this->isitmy_cache[$mail_id];
453  }
454  $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));
455  if ($db->next_record()) {
456  return $this->isitmy_cache[$mail_id] = $db->f("email");
457  } else {
458  $msg->raise("ERROR", "mail", _("This email is not yours, you can't change anything on it"));
459  return $this->isitmy_cache[$mail_id] = false;
460  }
461  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$cuid
Definition: bootstrap.php:43
$mail_id
m_mail::m_mail ( )

Constructeur.

Definition at line 78 of file m_mail.php.

References variable_get().

78  {
79  global $L_FQDN;
80  $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'));
81  $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'));
82  $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'));
83  $this->srv_imap = variable_get('mail_human_imap', $L_FQDN, 'Human name for IMAP mail server', array('desc' => 'Name', 'type' => 'string'));
84  $this->srv_imaps = variable_get('mail_human_imaps', $L_FQDN, 'Human name for IMAPS mail server', array('desc' => 'Name', 'type' => 'string'));
85  $this->srv_pop3 = variable_get('mail_human_pop3', $L_FQDN, 'Human name for POP3 mail server', array('desc' => 'Name', 'type' => 'string'));
86  $this->srv_pop3s = variable_get('mail_human_pop3s', $L_FQDN, 'Human name for POP3s mail server', array('desc' => 'Name', 'type' => 'string'));
87  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85
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 ($msg is filled accordingly)

Definition at line 678 of file m_mail.php.

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

Referenced by add_wrapper(), and create_alias().

678  {
679  global $msg, $db;
680  $msg->log("mail", "set_details");
681  if (!($me = $this->get_details($mail_id))) {
682  return false;
683  }
684  if ($me["islocal"] && !$islocal) {
685  // delete pop
686  $db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id= ? ;", array($mail_id));
687  }
688  if (!$me["islocal"] && $islocal) {
689  // create pop
690  $path = "";
691  if ($delivery == "dovecot") {
692  $path = ALTERNC_MAIL . "/" . substr($me["address"] . "_", 0, 1) . "/" . $me["address"] . "_" . $me["domain"];
693  }
694  foreach ($this->forbiddenchars as $str) {
695  if (strpos($me["address"], $str) !== false) {
696  $msg->raise("ERROR", "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"));
697  return false;
698  }
699  }
700  foreach ($this->specialchars as $str) {
701  if (strpos($me["address"], $str) !== false) {
702  $path = ALTERNC_MAIL . "/_/" . $me["id"] . "_" . $me["domain"];
703  break;
704  }
705  }
706  $db->query("INSERT INTO mailbox SET address_id= ? , delivery= ?, path= ? ;", array($mail_id, $delivery, $path));
707  }
708  if ($me["islocal"] && $islocal && $me["mailbox_action"] == "DELETE") {
709  $db->query("UPDATE mailbox SET mail_action='OK' WHERE mail_action='DELETE' AND address_id= ? ;", array($mail_id));
710  }
711 
712  if ($islocal) {
713  if ($quotamb != 0 && $quotamb < (intval($me["used"] / 1024 / 1024) + 1)) {
714  $quotamb = intval($me["used"] / 1024 / 1024) + 1;
715  $msg->raise("ALERT", "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"));
716  }
717  $db->query("UPDATE mailbox SET quota= ? WHERE address_id= ? ;", array($quotamb, $mail_id));
718  }
719 
720  $recipients = preg_replace('/[\r\t\s]/', "\n", $recipients); // Handle space AND new line
721  $r = explode("\n", $recipients);
722  $red = "";
723  foreach ($r as $m) {
724  $m = trim($m);
725  if ($m && ( filter_var($m, FILTER_VALIDATE_EMAIL) || $dontcheck) // Recipient Email is valid
726  && $m != ($me["address"] . "@" . $me["domain"])) { // And not myself (no loop allowed easily ;) )
727  $red.=$m . "\n";
728  }
729  }
730  $db->query("DELETE FROM recipient WHERE address_id= ? ;", array($mail_id));
731  if (isset($red) && $red) {
732  $db->query("INSERT INTO recipient SET address_id= ?, recipients= ? ;", array($mail_id, $red));
733  }
734  if (!$islocal && !$red) {
735  $msg->raise("ALERT", "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."));
736  }
737  return true;
738  }
$quotamb
Definition: mail_edit.php:46
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:75
$recipients
Definition: mail_add.php:50
$msg
Definition: config.php:155
get_details($mail_id)
function used to get every information we can on a mail
Definition: m_mail.php:413
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 1040 of file m_mail.php.

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

Referenced by hook_dom_add_mx_domain(), and hook_variable_set().

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

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

Referenced by hook_dom_add_mx_domain(), and hook_variable_set().

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

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

References $db, $mail_id, $msg, _md5cr(), is_it_my_mail(), and null.

612  {
613  global $db, $msg, $admin;
614  $msg->log("mail", "setpasswd");
615 
616  if (!($email = $this->is_it_my_mail($mail_id))) {
617  return false;
618  }
619  if (!$admin->checkPolicy("pop", $email, $pass, $canbeempty)) {
620  return false;
621  }
622  if ($canbeempty && empty($pass)) {
623  return $db->query("UPDATE address SET password= ? where id = ? ;", array(null, $mail_id ));
624  } else if (!$db->query("UPDATE address SET password= ? where id = ? ;", array(_md5cr($pass), $mail_id ))) {
625  return false;
626  }
627  return true;
628  }
global $db
Definition: bootstrap.php:22
_md5cr($pass, $salt="")
Hashe a password using proper crypto function.
Definition: functions.php:533
is_it_my_mail($mail_id)
Check if an email is mine ...
Definition: m_mail.php:447
PR null
Definition: lang-css.js:1
$msg
Definition: config.php:155
$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 ($msg is filled accordingly)

Definition at line 563 of file m_mail.php.

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

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

Member Data Documentation

m_mail::$cache_domain_mail_size = array()

Definition at line 71 of file m_mail.php.

m_mail::$domains

domain list for this account private

Definition at line 38 of file m_mail.php.

m_mail::$enum_domains = array()

Definition at line 72 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 54 of file m_mail.php.

m_mail::$isitmy_cache = array()
private

Definition at line 437 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 46 of file m_mail.php.

m_mail::$srv_imap

Definition at line 67 of file m_mail.php.

m_mail::$srv_imaps

Definition at line 68 of file m_mail.php.

m_mail::$srv_pop3

Definition at line 69 of file m_mail.php.

m_mail::$srv_pop3s

Definition at line 70 of file m_mail.php.

m_mail::$srv_smtp

Definition at line 65 of file m_mail.php.

m_mail::$srv_smtps

Definition at line 66 of file m_mail.php.

m_mail::$srv_submission

Definition at line 64 of file m_mail.php.

m_mail::$total

Number of results for a pager display public.

Definition at line 61 of file m_mail.php.


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