diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-03-10 20:21:55 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-03-10 20:21:55 +0000 |
| commit | de1d318f54fa75a24f1a7317862b69b90d330239 (patch) | |
| tree | d11c4dcf0dde19a4e9b33e16c1ef425cfebfbf6d /plugins | |
| parent | 0b178f16f1a1139a45cc5478bd2ed3e992a61bc8 (diff) | |
Manage attachments in groups
git-svn-id: https://svn.roundcube.net/trunk@4605 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/database_attachments/database_attachments.php | 16 | ||||
| -rw-r--r-- | plugins/filesystem_attachments/filesystem_attachments.php | 22 |
2 files changed, 23 insertions, 15 deletions
diff --git a/plugins/database_attachments/database_attachments.php b/plugins/database_attachments/database_attachments.php index 919beacbf..970a36754 100644 --- a/plugins/database_attachments/database_attachments.php +++ b/plugins/database_attachments/database_attachments.php @@ -22,9 +22,10 @@ class database_attachments extends filesystem_attachments /** * Helper method to generate a unique key for the given attachment file */ - private function _key($filepath) + private function _key($args) { - return $this->cache_prefix.md5(mktime().$filepath.$_SESSION['user_id']); + $uname = $args['path'] ? $args['path'] : $args['name']; + return $this->cache_prefix . $args['group'] . md5(mktime() . $uname . $_SESSION['user_id']); } /** @@ -34,7 +35,7 @@ class database_attachments extends filesystem_attachments { $args['status'] = false; $rcmail = rcmail::get_instance(); - $key = $this->_key($args['path']); + $key = $this->_key($args); $data = base64_encode(file_get_contents($args['path'])); $status = $rcmail->db->query( @@ -62,10 +63,10 @@ class database_attachments extends filesystem_attachments $args['status'] = false; $rcmail = rcmail::get_instance(); - $key = $this->_key($args['name']); + $key = $this->_key($args); - if ($args['path']) - $args['data'] = file_get_contents($args['path']); + if ($args['path']) + $args['data'] = file_get_contents($args['path']); $data = base64_encode($args['data']); @@ -146,11 +147,12 @@ class database_attachments extends filesystem_attachments */ function cleanup($args) { + $prefix = $this->cache_prefix . $args['group']; $rcmail = rcmail::get_instance(); $rcmail->db->query( "DELETE FROM ".get_table_name('cache')." WHERE user_id=? - AND cache_key like '{$this->cache_prefix}%'", + AND cache_key like '{$prefix}%'", $_SESSION['user_id']); } } diff --git a/plugins/filesystem_attachments/filesystem_attachments.php b/plugins/filesystem_attachments/filesystem_attachments.php index a2ac3a8c9..c91c7d7ee 100644 --- a/plugins/filesystem_attachments/filesystem_attachments.php +++ b/plugins/filesystem_attachments/filesystem_attachments.php @@ -19,7 +19,7 @@ */ class filesystem_attachments extends rcube_plugin { - public $task = 'mail|addressbook'; + public $task = 'mail|addressbook|logout'; function init() { @@ -49,6 +49,7 @@ class filesystem_attachments extends rcube_plugin function upload($args) { $args['status'] = false; + $group = $args['group']; $rcmail = rcmail::get_instance(); // use common temp dir for file uploads @@ -61,7 +62,7 @@ class filesystem_attachments extends rcube_plugin $args['status'] = true; // Note the file for later cleanup - $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $tmpfname; + $_SESSION['plugins']['filesystem_attachments'][$group][] = $tmpfname; } return $args; @@ -72,6 +73,7 @@ class filesystem_attachments extends rcube_plugin */ function save($args) { + $group = $args['group']; $args['status'] = false; if (!$args['path']) { @@ -91,7 +93,7 @@ class filesystem_attachments extends rcube_plugin $args['status'] = true; // Note the file for later cleanup - $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $args['path']; + $_SESSION['plugins']['filesystem_attachments'][$group][] = $args['path']; return $args; } @@ -135,13 +137,17 @@ class filesystem_attachments extends rcube_plugin // $_SESSION['compose']['attachments'] is not a complete record of // temporary files because loading a draft or starting a forward copies // the file to disk, but does not make an entry in that array - if (is_array($_SESSION['plugins']['filesystem_attachments']['tmp_files'])){ - foreach ($_SESSION['plugins']['filesystem_attachments']['tmp_files'] as $filename){ - if(file_exists($filename)){ - unlink($filename); + if (is_array($_SESSION['plugins']['filesystem_attachments'])){ + foreach ($_SESSION['plugins']['filesystem_attachments'] as $group => $files) { + if ($args['group'] && $args['group'] != $group) + continue; + foreach ((array)$files as $filename){ + if(file_exists($filename)){ + unlink($filename); + } } + unset($_SESSION['plugins']['filesystem_attachments'][$group]); } - unset($_SESSION['plugins']['filesystem_attachments']['tmp_files']); } return $args; } |
