]> git.donarmstrong.com Git - roundcube.git/blobdiff - plugins/filesystem_attachments/filesystem_attachments.php
Merge commit 'debian/0.5.3+dfsg-1' into debian
[roundcube.git] / plugins / filesystem_attachments / filesystem_attachments.php
index fcdcea7a5d73fc47a8153548555e64db025be2b0..a2ac3a8c9d62580dce8ffa8a868ba925224b618e 100644 (file)
  */
 class filesystem_attachments extends rcube_plugin
 {
-    public $task = 'mail';
-    
+    public $task = 'mail|addressbook';
+
     function init()
     {
         // Save a newly uploaded attachment
-        $this->add_hook('upload_attachment', array($this, 'upload'));
+        $this->add_hook('attachment_upload', array($this, 'upload'));
 
         // Save an attachment from a non-upload source (draft or forward)
-        $this->add_hook('save_attachment', array($this, 'save'));
+        $this->add_hook('attachment_save', array($this, 'save'));
 
         // Remove an attachment from storage
-        $this->add_hook('remove_attachment', array($this, 'remove'));
+        $this->add_hook('attachment_delete', array($this, 'remove'));
 
         // When composing an html message, image attachments may be shown
-        $this->add_hook('display_attachment', array($this, 'display'));
+        $this->add_hook('attachment_display', array($this, 'display'));
 
         // Get the attachment from storage and place it on disk to be sent
-        $this->add_hook('get_attachment', array($this, 'get_attachment'));
+        $this->add_hook('attachment_get', array($this, 'get'));
 
         // Delete all temp files associated with this user
-        $this->add_hook('cleanup_attachments', array($this, 'cleanup'));
-        $this->add_hook('kill_session', array($this, 'cleanup'));
+        $this->add_hook('attachments_cleanup', array($this, 'cleanup'));
+        $this->add_hook('session_destroy', array($this, 'cleanup'));
     }
 
     /**
@@ -52,12 +52,11 @@ class filesystem_attachments extends rcube_plugin
         $rcmail = rcmail::get_instance();
 
         // use common temp dir for file uploads
-        // #1484529: we need absolute path on Windows for move_uploaded_file()
-        $temp_dir = realpath($rcmail->config->get('temp_dir'));
+        $temp_dir = $rcmail->config->get('temp_dir');
         $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
 
         if (move_uploaded_file($args['path'], $tmpfname) && file_exists($tmpfname)) {
-            $args['id'] = count($_SESSION['plugins']['filesystem_attachments']['tmp_files'])+1;
+            $args['id'] = $this->file_id();
             $args['path'] = $tmpfname;
             $args['status'] = true;
 
@@ -77,7 +76,7 @@ class filesystem_attachments extends rcube_plugin
 
         if (!$args['path']) {
             $rcmail = rcmail::get_instance();
-            $temp_dir = unslashify($rcmail->config->get('temp_dir'));
+            $temp_dir = $rcmail->config->get('temp_dir');
             $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
 
             if ($fp = fopen($tmp_path, 'w')) {
@@ -87,10 +86,10 @@ class filesystem_attachments extends rcube_plugin
             } else
                 return $args;
         }
-        
-        $args['id'] = count($_SESSION['plugins']['filesystem_attachments']['tmp_files'])+1;
+
+        $args['id'] = $this->file_id();
         $args['status'] = true;
-            
+
         // Note the file for later cleanup
         $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $args['path'];
 
@@ -123,11 +122,11 @@ class filesystem_attachments extends rcube_plugin
      * on disk for use.  This stub function is kept here to make this 
      * class handy as a parent class for other plugins which may need it.
      */
-    function get_attachment($args)
+    function get($args)
     {
         return $args;
     }
-    
+
     /**
      * Delete all temp files associated with this user
      */
@@ -146,4 +145,11 @@ class filesystem_attachments extends rcube_plugin
         }
         return $args;
     }
+
+    function file_id()
+    {
+        $userid = rcmail::get_instance()->user->ID;
+           list($usec, $sec) = explode(' ', microtime()); 
+        return preg_replace('/[^0-9]/', '', $userid . $sec . $usec);
+    }
 }