/**
* abook_local_file.php
*
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright 1999-2011 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
* @return bool
*/
function abook_local_file($param) {
- $this->sname = _("Personal address book");
+ $this->sname = _("Personal Address Book");
$this->umask = Umask();
if(is_array($param)) {
$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) {
return $this->set_error($this->filename . ':' . _("Unable to update"));
}
@unlink($this->filename . '.tmp');
+ @chmod($this->filename, 0600);
$this->unlock();
$this->open(true);
return true;
* TODO: regexp search is supported only in local_file backend.
* Do we check format of regexp or ignore errors?
*/
- // errors on eregi call are suppressed in order to prevent display of regexp compilation errors
- if(@eregi($expr, $line)) {
+ // errors on preg_match call are suppressed in order to prevent display of regexp compilation errors
+ if(@preg_match('/' . $expr . '/i', $line)) {
array_push($res, array('nickname' => $row[0],
'name' => $this->fullname($row[1], $row[2]),
'firstname' => $row[1],
}
/**
- * 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);
$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],
$this->quotevalue((!empty($userdata['label'])?$userdata['label']:''));
/* Strip linefeeds */
- $data = ereg_replace("[\r\n]", ' ', $data);
+ $nl_str = array("\r","\n");
+ $data = str_replace($nl_str, ' ', $data);
/**
* Make sure that entry fits into allocated record space.
// 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()) {
function quotevalue($value) {
/* Quote the field if it contains | or ". Double quotes need to
* be replaced with "" */
- if(ereg("[|\"]", $value)) {
+ if(stristr($value, '"') || stristr($value, '|')) {
$value = '"' . str_replace('"', '""', $value) . '"';
}
return $value;
}
-
-} /* End of class abook_local_file */
-?>
+}