X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fabook_local_file.php;h=1c1901f7a2e8fe92439ada1241416e7516d744b6;hp=fb215e27c3f525b0f8551fb1119d24188ef28f37;hb=eceb3fe56e7ef548f83797639e9d6d993254695b;hpb=7311c377a04c1d713fcf090e120a6ac4fa93940a diff --git a/functions/abook_local_file.php b/functions/abook_local_file.php index fb215e27..1c1901f7 100644 --- a/functions/abook_local_file.php +++ b/functions/abook_local_file.php @@ -3,7 +3,7 @@ /** * abook_local_file.php * - * @copyright © 1999-2006 The SquirrelMail Project Team + * @copyright © 1999-2009 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -97,7 +97,7 @@ class abook_local_file extends addressbook_backend { * @return bool */ function abook_local_file($param) { - $this->sname = _("Personal address book"); + $this->sname = _("Personal Address Book"); $this->umask = Umask(); if(is_array($param)) { @@ -151,7 +151,7 @@ class abook_local_file extends addressbook_backend { $this->error = ''; $file = $this->filename; $create = $this->create; - $fopenmode = (($this->writeable && is_writable($file)) ? 'a+' : 'r'); + $fopenmode = (($this->writeable && sq_is_writable($file)) ? 'a+' : 'r'); /* Return true is file is open and $new is unset */ if($this->filehandle && !$new) { @@ -252,6 +252,7 @@ class abook_local_file extends addressbook_backend { return $this->set_error($this->filename . ':' . _("Unable to update")); } @unlink($this->filename . '.tmp'); + @chmod($this->filename, 0600); $this->unlock(); $this->open(true); return true; @@ -317,16 +318,29 @@ class abook_local_file extends addressbook_backend { } /** - * Lookup alias - * @param string $alias alias - * @return array search results + * Lookup an address by the indicated field. + * + * @param string $value The value to look up + * @param integer $field The field to look in, should be one + * of the SM_ABOOK_FIELD_* constants + * defined in include/constants.php + * (OPTIONAL; defaults to nickname field) + * NOTE: uniqueness is only guaranteed + * when the nickname field is used here; + * otherwise, the first matching address + * is returned. + * + * @return array Array with lookup results when the value + * was found, an empty array if the value was + * not found. + * */ - function lookup($alias) { - if(empty($alias)) { + function lookup($value, $field=SM_ABOOK_FIELD_NICKNAME) { + if(empty($value)) { return array(); } - $alias = strtolower($alias); + $value = strtolower($value); $this->open(); @rewind($this->filehandle); @@ -341,7 +355,7 @@ class abook_local_file extends addressbook_backend { $oTemplate->display('footer.tpl'); die(); } else { - if(strtolower($row[0]) == $alias) { + if(strtolower($row[$field]) == $value) { return array('nickname' => $row[0], 'name' => $this->fullname($row[1], $row[2]), 'firstname' => $row[1], @@ -512,7 +526,15 @@ class abook_local_file extends addressbook_backend { // i18n: don't use html formating in translation return $this->set_error(sprintf(_("User \"%s\" does not exist"),$alias)); } - + + /* If the alias changed, see if the new alias exists */ + if (strtolower($alias) != strtolower($userdata['nickname'])) { + $ret = $this->lookup($userdata['nickname']); + if (!empty($ret)) { + return $this->set_error(sprintf(_("User \"%s\" already exists"), $userdata['nickname'])); + } + } + /* Lock the file to make sure we're the only process working * on it. */ if(!$this->lock()) { @@ -571,6 +593,4 @@ class abook_local_file extends addressbook_backend { } return $value; } - -} /* End of class abook_local_file */ -?> +}