summaryrefslogtreecommitdiff
path: root/plugins/password/drivers/poppassd.php
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2012-03-31 12:25:48 +0000
committerthomascube <thomas@roundcube.net>2012-03-31 12:25:48 +0000
commit48e9c14ebded89d858c8be0333f77f77a81b0877 (patch)
treee97fd2ea338eea2dbe5f3fb7431e73f44cb8bf18 /plugins/password/drivers/poppassd.php
parent13db9ee199b0a452a6efaf09e6f7c5a76f739ef5 (diff)
Move plugins repository into roundcubemail root folder; svn:externals are not defined anymore
Diffstat (limited to 'plugins/password/drivers/poppassd.php')
-rw-r--r--plugins/password/drivers/poppassd.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/password/drivers/poppassd.php b/plugins/password/drivers/poppassd.php
new file mode 100644
index 000000000..e18ec2660
--- /dev/null
+++ b/plugins/password/drivers/poppassd.php
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * Poppassd Password Driver
+ *
+ * Driver to change passwords via Poppassd/Courierpassd
+ *
+ * @version 2.0
+ * @author Philip Weir
+ *
+ */
+
+class rcube_poppassd_password
+{
+ function format_error_result($code, $line)
+ {
+ if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) {
+ return array('code' => $code, 'message' => $matches[1]);
+ } else {
+ return $code;
+ }
+ }
+
+ function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
+// include('Net/Socket.php');
+ $poppassd = new Net_Socket();
+
+ $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null);
+ if (PEAR::isError($result)) {
+ return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage());
+ }
+ else {
+ $result = $poppassd->readLine();
+ if(!preg_match('/^2\d\d/', $result)) {
+ $poppassd->disconnect();
+ return $this->format_error_result(PASSWORD_ERROR, $result);
+ }
+ else {
+ $poppassd->writeLine("user ". $_SESSION['username']);
+ $result = $poppassd->readLine();
+ if(!preg_match('/^[23]\d\d/', $result) ) {
+ $poppassd->disconnect();
+ return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result);
+ }
+ else {
+ $poppassd->writeLine("pass ". $curpass);
+ $result = $poppassd->readLine();
+ if(!preg_match('/^[23]\d\d/', $result) ) {
+ $poppassd->disconnect();
+ return $this->format_error_result(PASSWORD_ERROR, $result);
+ }
+ else {
+ $poppassd->writeLine("newpass ". $passwd);
+ $result = $poppassd->readLine();
+ $poppassd->disconnect();
+ if (!preg_match('/^2\d\d/', $result))
+ return $this->format_error_result(PASSWORD_ERROR, $result);
+ else
+ return PASSWORD_SUCCESS;
+ }
+ }
+ }
+ }
+ }
+}