diff options
Diffstat (limited to 'plugins/virtuser_file')
| -rw-r--r-- | plugins/virtuser_file/package.xml | 47 | ||||
| -rw-r--r-- | plugins/virtuser_file/virtuser_file.php | 107 |
2 files changed, 0 insertions, 154 deletions
diff --git a/plugins/virtuser_file/package.xml b/plugins/virtuser_file/package.xml deleted file mode 100644 index 9b55ce427..000000000 --- a/plugins/virtuser_file/package.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.0" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 - http://pear.php.net/dtd/tasks-1.0.xsd - http://pear.php.net/dtd/package-2.0 - http://pear.php.net/dtd/package-2.0.xsd"> - <name>virtuser_file</name> - <channel>pear.roundcube.net</channel> - <summary>File based User-to-Email and Email-to-User lookup</summary> - <description>Plugin adds possibility to resolve user email/login according to lookup tables in files.</description> - <lead> - <name>Aleksander Machniak</name> - <user>alec</user> - <email>alec@alec.pl</email> - <active>yes</active> - </lead> - <date>2011-11-21</date> - <version> - <release>1.0</release> - <api>1.0</api> - </version> - <stability> - <release>stable</release> - <api>stable</api> - </stability> - <license uri="http://www.gnu.org/licenses/gpl.html">GNU GPLv3+</license> - <notes>-</notes> - <contents> - <dir baseinstalldir="/" name="/"> - <file name="virtuser_file.php" role="php"> - <tasks:replace from="@name@" to="name" type="package-info"/> - <tasks:replace from="@package_version@" to="version" type="package-info"/> - </file> - </dir> - <!-- / --> - </contents> - <dependencies> - <required> - <php> - <min>5.2.1</min> - </php> - <pearinstaller> - <min>1.7.0</min> - </pearinstaller> - </required> - </dependencies> - <phprelease/> -</package> diff --git a/plugins/virtuser_file/virtuser_file.php b/plugins/virtuser_file/virtuser_file.php deleted file mode 100644 index 01032616c..000000000 --- a/plugins/virtuser_file/virtuser_file.php +++ /dev/null @@ -1,107 +0,0 @@ -<?php - -/** - * File based User-to-Email and Email-to-User lookup - * - * Add it to the plugins list in config/main.inc.php and set - * path to a virtuser table file to resolve user names and e-mail - * addresses - * $rcmail_config['virtuser_file'] = ''; - * - * @version @package_version@ - * @license GNU GPLv3+ - * @author Aleksander Machniak - */ -class virtuser_file extends rcube_plugin -{ - private $file; - private $app; - - function init() - { - $this->app = rcmail::get_instance(); - $this->file = $this->app->config->get('virtuser_file'); - - if ($this->file) { - $this->add_hook('user2email', array($this, 'user2email')); - $this->add_hook('email2user', array($this, 'email2user')); - } - } - - /** - * User > Email - */ - function user2email($p) - { - $r = $this->findinvirtual('/\s' . preg_quote($p['user'], '/') . '\s*$/'); - $result = array(); - - for ($i=0; $i<count($r); $i++) - { - $arr = preg_split('/\s+/', $r[$i]); - - if (count($arr) > 0 && strpos($arr[0], '@')) { - $result[] = rcube_idn_to_ascii(trim(str_replace('\\@', '@', $arr[0]))); - - if ($p['first']) { - $p['email'] = $result[0]; - break; - } - } - } - - $p['email'] = empty($result) ? NULL : $result; - - return $p; - } - - /** - * Email > User - */ - function email2user($p) - { - $r = $this->findinvirtual('/^' . preg_quote($p['email'], '/') . '\s/'); - - for ($i=0; $i<count($r); $i++) { - $arr = preg_split('/\s+/', trim($r[$i])); - - if (count($arr) > 0) { - $p['user'] = trim($arr[count($arr)-1]); - break; - } - } - - return $p; - } - - /** - * Find matches of the given pattern in virtuser file - * - * @param string Regular expression to search for - * @return array Matching entries - */ - private function findinvirtual($pattern) - { - $result = array(); - $virtual = null; - - if ($this->file) - $virtual = file($this->file); - - if (empty($virtual)) - return $result; - - // check each line for matches - foreach ($virtual as $line) { - $line = trim($line); - if (empty($line) || $line[0]=='#') - continue; - - if (preg_match($pattern, $line)) - $result[] = $line; - } - - return $result; - } - -} |
