removed local directory name used for testing.
[squirrelmail.git] / functions / abook_local_file.php
index e8d43c1c587d6982b53f0e07f36291cbec0a23f5..e0ad818992e4c101b71f7712f0228af32801cd2c 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * abook_local_file.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * @version $Id$
  * ? create    => if true: file is created if it does not exist.
  * ? umask     => umask set before opening file.
  * ? name      => name of address book.
- * ? detect_writeable => detect address book access permissions by 
+ * ? detect_writeable => detect address book access permissions by
  *                checking file permissions.
  * ? writeable => allow writing into address book. Used only when
  *                detect_writeable is set to false.
+ * ? listing   => enable/disable listing
  *</pre>
  * NOTE. This class should not be used directly. Use the
  *       "AddressBook" class instead.
@@ -34,7 +35,7 @@
 class abook_local_file extends addressbook_backend {
     /**
      * Backend type
-     * @var string 
+     * @var string
      */
     var $btype = 'local';
     /**
@@ -70,6 +71,11 @@ class abook_local_file extends addressbook_backend {
      * @var bool
      */
     var $writeable = false;
+    /**
+     * controls listing of address book
+     * @var bool
+     */
+    var $listing = true;
     /**
      * Umask of the file
      * @var string
@@ -113,6 +119,9 @@ class abook_local_file extends addressbook_backend {
             if(!empty($param['writeable'])) {
                 $this->writeable = $param['writeable'];
             }
+            if(isset($param['listing'])) {
+                $this->listing = $param['listing'];
+            }
 
             $this->open(true);
         } else {
@@ -132,7 +141,7 @@ class abook_local_file extends addressbook_backend {
         $this->error = '';
         $file   = $this->filename;
         $create = $this->create;
-        $fopenmode = ($this->writeable ? 'a+' : 'r');
+        $fopenmode = (($this->writeable && is_writable($file)) ? 'a+' : 'r');
 
         /* Return true is file is open and $new is unset */
         if($this->filehandle && !$new) {
@@ -250,6 +259,10 @@ class abook_local_file extends addressbook_backend {
         /* To be replaced by advanded search expression parsing */
         if(is_array($expr)) { return; }
 
+        // don't allow wide search when listing is disabled.
+        if ($expr=='*' && ! $this->listing)
+            return array();
+
         /* Make regexp from glob'ed expression
          * May want to quote other special characters like (, ), -, [, ], etc. */
         $expr = str_replace('?', '.', $expr);
@@ -315,6 +328,11 @@ class abook_local_file extends addressbook_backend {
      */
     function list_addr() {
         $res = array();
+
+        if(isset($this->listing) && !$this->listing) {
+            return array();
+        }
+
         $this->open();
         @rewind($this->filehandle);
 
@@ -343,8 +361,8 @@ class abook_local_file extends addressbook_backend {
         /* See if user exists already */
         $ret = $this->lookup($userdata['nickname']);
         if(!empty($ret)) {
-            return $this->set_error(sprintf(_("User '%s' already exist"),
-                   $ret['nickname']));
+            // i18n: don't use html formating in translation
+            return $this->set_error(sprintf(_("User \"%s\" already exists"),$ret['nickname']));
         }
 
         /* Here is the data to write */
@@ -436,8 +454,8 @@ class abook_local_file extends addressbook_backend {
         /* See if user exists */
         $ret = $this->lookup($alias);
         if(empty($ret)) {
-            return $this->set_error(sprintf(_("User '%s' does not exist"),
-                $alias));
+            // i18n: don't use html formating in translation
+            return $this->set_error(sprintf(_("User \"%s\" does not exist"),$alias));
         }
 
         /* Lock the file to make sure we're the only process working