| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | $Id: m_mail_localbox.php author: squidly |
|---|
| 5 | ---------------------------------------------------------------------- |
|---|
| 6 | LICENSE |
|---|
| 7 | |
|---|
| 8 | This program is free software; you can redistribute it and/or |
|---|
| 9 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 10 | as published by the Free Software Foundation; either version 2 |
|---|
| 11 | of the License, or (at your option) any later version. |
|---|
| 12 | |
|---|
| 13 | This program is distributed in the hope that it will be useful, |
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | GNU General Public License for more details. |
|---|
| 17 | |
|---|
| 18 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 19 | ---------------------------------------------------------------------- |
|---|
| 20 | Original Author of file: Benjamin Sonntag, Franck Missoum |
|---|
| 21 | Purpose of file: Manage Email accounts and aliases. |
|---|
| 22 | ---------------------------------------------------------------------- |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * This class handle emails local mailboxes |
|---|
| 27 | * |
|---|
| 28 | * Copyleft {@link http://alternc.net/ AlternC Team} |
|---|
| 29 | * |
|---|
| 30 | * @copyright AlternC-Team 2002-11-01 http://alternc.net/ |
|---|
| 31 | * |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | Class m_mail_localbox{ |
|---|
| 35 | var $enabled; |
|---|
| 36 | var $advanced; |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Function used to set the "visibility" of the property: meaning wheter the option is enabled (hence visible) and if it is part of the advanced options. |
|---|
| 42 | */ |
|---|
| 43 | function m_mail_localbox(){ |
|---|
| 44 | $this->enabled=variable_get('mail_localbox_enabled',null); |
|---|
| 45 | if (is_null($this->enabled)) { // if not configuration var, setup one (with a default value) |
|---|
| 46 | variable_set('mail_localbox_enabled',true,'To enable or disable the alias module in the mail edit page'); |
|---|
| 47 | $this->enabled=true; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | $this->advanced=variable_get('mail_localbox_advanced',null); |
|---|
| 51 | if (is_null($this->advanced)) { // if not configuration var, setup one (with a default value) |
|---|
| 52 | variable_set('mail_localbox_advanced',false,'To place the alias option in the advanced area'); |
|---|
| 53 | $this->advanced=false; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /* |
|---|
| 58 | * Set a localbox |
|---|
| 59 | * @param integer $mail_id |
|---|
| 60 | */ |
|---|
| 61 | function set_localbox($mail_id){ |
|---|
| 62 | global $db, $err; |
|---|
| 63 | $err->log("localbox","set_localbox"); |
|---|
| 64 | $path="mail/"; |
|---|
| 65 | if(!$db->query("select distinct left(ad.address,1) as letter,ad.address ,d.domaine from address ad, domaines d where ad.domain_id = d.id and ad.id = $mail_id order by letter;")); |
|---|
| 66 | |
|---|
| 67 | if(! $db->next_record()){ |
|---|
| 68 | return null; |
|---|
| 69 | } |
|---|
| 70 | $path="/var/alternc/mail/".$db->f('letter')."/".$db->f('address')."_".$db->f('domaine'); |
|---|
| 71 | //FIXME faire un touch de la maildir si dovecot ne sait pas le faire. |
|---|
| 72 | if(!$db->query("INSERT into mailbox (address_id,path,quota) values ($mail_id,'$path',50);")); |
|---|
| 73 | |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /* |
|---|
| 77 | * Set a localbox |
|---|
| 78 | * @param integer $mail_id |
|---|
| 79 | */ |
|---|
| 80 | function unset_localbox($mail_id){ |
|---|
| 81 | global $db, $err; |
|---|
| 82 | $err->log("localbox","set_localbox"); |
|---|
| 83 | if(!$db->query("DELETE from mailbox where address_id=$mail_id;")); |
|---|
| 84 | |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | /* |
|---|
| 89 | hooks called by the mail class, it is used to verify that a given mail is not already in the adress table |
|---|
| 90 | in wich case we can create it so the |
|---|
| 91 | @param: dom_id=domain in use, mail_arg= mail address waiting to be created |
|---|
| 92 | @result: an hashtable contening the state ( success /failure, un case of success) the id of the created mail, and an error message if something went wrong. |
|---|
| 93 | */ |
|---|
| 94 | function hooks_mail_cancreate($dom_id, $mail_arg){ |
|---|
| 95 | global $db, $err, $cuid; |
|---|
| 96 | $err->log("m_mail_localbox","hooks_mail_cancreate"); |
|---|
| 97 | $return = array ( |
|---|
| 98 | "state" => true, |
|---|
| 99 | "mail_id" => null, |
|---|
| 100 | "error" => ""); |
|---|
| 101 | |
|---|
| 102 | return $return; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | function form($mail_id) { |
|---|
| 107 | global $mail, $err; |
|---|
| 108 | include('mail_localbox_edit.inc.php'); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /* hooks called to list a given mail properties |
|---|
| 112 | * @param: the id of the mail being processed |
|---|
| 113 | * @return: an hashtable of every information usefull to edit the mail if it is part of the class |
|---|
| 114 | * including a url to the edition page of the propertie in question ( here local hosting of a mail) |
|---|
| 115 | * if the mail cannot be a localbox because of some of it's properties the return is NULL, thus not displayed in the properties listing page. |
|---|
| 116 | */ |
|---|
| 117 | function hooks_mail_properties_list($mail_id){ |
|---|
| 118 | global $db, $err; |
|---|
| 119 | $err->log("mail_localbox","mail_properties_list"); |
|---|
| 120 | $return = array ( |
|---|
| 121 | "label" => "localbox", |
|---|
| 122 | "short_desc" => _("Local mailbox"), |
|---|
| 123 | "human_desc" => _("Actually disabled.<br/>To have your mail stored on the server.<br/><i>You can access them remotely with the webmail, IMAP or POP</i>"), |
|---|
| 124 | "url" => "mail_localbox_edit.php", |
|---|
| 125 | "form_param" => Array($mail_id), |
|---|
| 126 | "class" => 'mail_localbox', |
|---|
| 127 | "pass_required" => true, |
|---|
| 128 | "advanced" => $this->advanced |
|---|
| 129 | ); |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | // on recherche si la boite est deja presente en tant que boite locale |
|---|
| 133 | $db->query("select address_id from mailbox where address_id=$mail_id;"); |
|---|
| 134 | |
|---|
| 135 | // Si pas d'entrée dans mailbox, on retourne directement le Array |
|---|
| 136 | if(! $db->next_record()){ |
|---|
| 137 | $return['url'] .= "?mail_id=$mail_id"; |
|---|
| 138 | return $return; |
|---|
| 139 | } |
|---|
| 140 | // Sinon, on le met à jour avant |
|---|
| 141 | $return["is_local"]= true; |
|---|
| 142 | $return["object_id"]= $db->f('address_id'); |
|---|
| 143 | $return["human_desc"] = _("Actually enabled.<br/>Your mails are stored on the server.<br/><i>You can access them remotely with the webmail, IMAP or POP</i>"); |
|---|
| 144 | |
|---|
| 145 | // On met à jour l'URL |
|---|
| 146 | $return['url'] .= "?mail_id=$mail_id"; |
|---|
| 147 | |
|---|
| 148 | return $return; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | /* Function testing if a given mail id is hosted as a localbox on the domain or not |
|---|
| 153 | * @param: mail_id |
|---|
| 154 | * @return: an indexed array of localbox usefull informations |
|---|
| 155 | */ |
|---|
| 156 | function details($mail_id){ |
|---|
| 157 | global $db,$err; |
|---|
| 158 | $err->log("mail_localbox","details"); |
|---|
| 159 | $mail_local = array ( |
|---|
| 160 | "path" => "", |
|---|
| 161 | "quota" => null, |
|---|
| 162 | "delivery" => ""); |
|---|
| 163 | |
|---|
| 164 | $db->query("select path, quota, delivery from mailbox where address_id=$mail_id;"); |
|---|
| 165 | if (! $db->next_record()) return false; |
|---|
| 166 | |
|---|
| 167 | $mail_local["path"]=$db->f("path"); |
|---|
| 168 | $mail_local["quota"]=$db->f("quota"); |
|---|
| 169 | $mail_local["delivery"]=$db->f("delivery"); |
|---|
| 170 | return $mail_local; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | ?> |
|---|