From ed7019ff5c78bee7324b39ec1d58edd8a4738dbd Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Mon, 10 Oct 2011 22:15:16 +0000 Subject: [PATCH] MailboxHandler: - whitespace changes git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1200 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/MailboxHandler.php | 86 ++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 51 deletions(-) diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index 5631886b..d4f81de2 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -7,7 +7,7 @@ class MailboxHandler { protected $username = null; - + public $errormsg = array(); public function __construct($username) { @@ -20,7 +20,7 @@ class MailboxHandler { } /** - * @return boolean true on success; false on failure + * @return boolean true on success; false on failure * @param string $old_password * @param string $new_passwords * @param bool $match = true @@ -33,19 +33,19 @@ class MailboxHandler { $E_username = escape_string($this->username); $table_mailbox = table_by_key('mailbox'); - + if ($match == true) { $active = db_get_boolean(True); $result = db_query("SELECT password FROM $table_mailbox WHERE username='$E_username' AND active='$active'"); $result = db_assoc($result['result']); - + if (pacrypt($old_password, $result['password']) != $result['password']) { db_log ($domain, 'edit_password', "MATCH FAILURE: " . $this->username); $this->errormsg[] = 'Passwords do not match'; # TODO: make translatable return false; } } - + $set = array( 'password' => pacrypt($new_password) , ); @@ -57,7 +57,7 @@ class MailboxHandler { $this->errormsg[] = Lang::read('pEdit_mailbox_result_error'); return false; } - + db_log ($domain, 'edit_password', $this->username); return true; } @@ -76,8 +76,7 @@ class MailboxHandler { $query = "SELECT password FROM $table_mailbox WHERE username='$username' AND active='$active'"; $result = db_query ($query); - if ($result['rows'] == 1) - { + if ($result['rows'] == 1) { $row = db_array ($result['result']); $crypt_password = pacrypt ($password, $row['password']); @@ -89,7 +88,7 @@ class MailboxHandler { } /** * Add mailbox - * @param password string password of account + * @param password string password of account * @param gen boolean * @param name string * @@ -98,7 +97,7 @@ class MailboxHandler { # FIXME: default value of $quota (-999) is intentionally invalid. Add fallback to default quota. # Solution: Invent an sub config class with additional informations about domain based configs like default qouta. # FIXME: Should the parameters be optional at all? -# TODO: check if parameters are valid/allowed (quota?). +# TODO: check if parameters are valid/allowed (quota?). # TODO: most code should live in a separate function that can be used by add and edit. # TODO: On the longer term, the web interface should also use this class. @@ -116,11 +115,11 @@ class MailboxHandler { # check if an alias with this name already exists $result = db_query ("SELECT * FROM " . table_by_key('alias') . " WHERE address='" . escape_string($username) . "'"); - if ($result['rows'] == 1){ + if ($result['rows'] == 1) { $this->errormsg[] = Lang::read('pCreate_mailbox_username_text_error2'); return false; } - + $plain = $password; $password = pacrypt ($password); @@ -131,25 +130,18 @@ class MailboxHandler { # $password = '{' . $method . '}' . $password; # } -#TODO: 2nd clause should be the first for self explaining code. +#TODO: 2nd clause should be the first for self explaining code. #TODO: When calling config::Read with parameter we sould be right that read return false if the parameter isn't in our config file. if(Config::read('maildir_name_hook') != 'NO' && function_exists(Config::read('maildir_name_hook')) ) { $hook_func = $CONF['maildir_name_hook']; $maildir = $hook_func ($fDomain, $fUsername); - } - elseif (Config::read('domain_path') == "YES") - { - if (Config::read('domain_in_mailbox') == "YES") - { + } elseif (Config::read('domain_path') == "YES") { + if (Config::read('domain_in_mailbox') == "YES") { $maildir = $domain . "/" . $username . "/"; - } - else - { + } else { $maildir = $domain . "/" . $local_part . "/"; } - } - else - { + } else { $maildir = $username . "/"; } @@ -157,18 +149,17 @@ class MailboxHandler { $active = db_get_boolean($active); $quota = multiply_quota ($quota); - + $alias_data = array( 'address' => $username, 'goto' => $username, 'domain' => $domain, 'active' => $active, - ); - + ); + $result = db_insert('alias', $alias_data); #MARK: db_insert returns true/false?? - if ($result != 1) - { + if ($result != 1) { $this->errormsg[] = Lang::read('pAlias_result_error') . "\n($username -> $username)\n"; return false; } @@ -194,8 +185,7 @@ class MailboxHandler { db_log ($domain, 'create_mailbox', $username); - if ($mail == true) - { + if ($mail == true) { # TODO: move "send the mail" to a function $fTo = $username; $fFrom = smtp_get_admin_email(); @@ -203,27 +193,25 @@ class MailboxHandler { $fSubject = Lang::read('pSendmail_subject_text'); $fBody = Config::read('welcome_text'); - if (!smtp_mail ($fTo, $fFrom, $fSubject, $fBody)) - { + if (!smtp_mail ($fTo, $fFrom, $fSubject, $fBody)) { $this->errormsg[] = Lang::read('pSendmail_result_error'); return false; } } create_mailbox_subfolders($username,$plain); - } return true; } - - - - + + + + public function view() { $username = $this->username; $table_mailbox = table_by_key('mailbox'); - + # TODO: check if DATE_FORMAT works in MySQL and PostgreSQL # TODO: maybe a more fine-grained date format would be better for non-CLI usage $result = db_query("SELECT username, name, maildir, quota, local_part, domain, DATE_FORMAT(created, '%d.%m.%y') AS created, DATE_FORMAT(modified, '%d.%m.%y') AS modified, active FROM $table_mailbox WHERE username='$username'"); @@ -234,14 +222,14 @@ class MailboxHandler { $this->errormsg = $result['error']; return false; } - + public function delete() { $username = $this->username; list(/*$local_part*/,$domain) = explode ('@', $username); $E_username = escape_string($username); $E_domain = escape_string($domain); - + #TODO: At this level of table by key calls we should think about a solution in our query function and drupal like {mailbox} {alias}. # Pseudocode for db_query etc. # if {} in query then @@ -254,8 +242,8 @@ class MailboxHandler { $table_vacation_notification = table_by_key('vacation_notification'); db_begin(); - -#TODO: ture/false replacement! + +#TODO: true/false replacement! $error = 0; $result = db_query("SELECT * FROM $table_alias WHERE address = '$E_username' AND domain = '$domain'"); @@ -269,23 +257,19 @@ class MailboxHandler { /* is there a mailbox? if do delete it from orbit; it's the only way to be sure */ $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$E_username' AND domain='$domain'"); - if ($result['rows'] == 1) - { + if ($result['rows'] == 1) { $result = db_delete('mailbox', 'username', $username); $postdel_res=mailbox_postdeletion($username,$domain); - if ($result != 1 || !$postdel_res) - { + if ($result != 1 || !$postdel_res) { $tMessage = Lang::read('pDelete_delete_error') . "$username ("; - if ($result['rows']!=1) # TODO: invalid test, $result is from db_delete and only contains the number of deleted rows - { + if ($result['rows']!=1) { # TODO: invalid test, $result is from db_delete and only contains the number of deleted rows $tMessage.='mailbox'; if (!$postdel_res) $tMessage.=', '; $this->errormsg[] = "no mailbox $username"; # todo: better message, make translatable $error = 1; } - if (!$postdel_res) - { + if (!$postdel_res) { $tMessage.='post-deletion'; $this->errormsg[] = "post-deletion script failed"; # todo: better message, make translatable $error = 1;