Blame view

sources/apps/user_external/lib/imap.php 1.4 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
2
3
4
5
6
7
  <?php
  /**
   * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
6d9380f96   Cédric Dupont   Update sources OC...
8
9
10
11
12
13
14
15
16
17
  /**
   * User authentication against an IMAP mail server
   *
   * @category Apps
   * @package  UserExternal
   * @author   Robin Appelman <icewind@owncloud.com>
   * @license  http://www.gnu.org/licenses/agpl AGPL
   * @link     http://github.com/owncloud/apps
   */
  class OC_User_IMAP extends \OCA\user_external\Base {
d1bafeea1   Kload   [fix] Upgrade to ...
18
  	private $mailbox;
6d9380f96   Cédric Dupont   Update sources OC...
19
20
21
22
23
24
  	/**
  	 * Create new IMAP authentication provider
  	 *
  	 * @param string $mailbox PHP imap_open mailbox definition, e.g.
  	 *                        {127.0.0.1:143/imap/readonly}
  	 */
d1bafeea1   Kload   [fix] Upgrade to ...
25
  	public function __construct($mailbox) {
6d9380f96   Cédric Dupont   Update sources OC...
26
  		parent::__construct($mailbox);
d1bafeea1   Kload   [fix] Upgrade to ...
27
28
29
30
  		$this->mailbox=$mailbox;
  	}
  
  	/**
d1bafeea1   Kload   [fix] Upgrade to ...
31
  	 * Check if the password is correct without logging in the user
6d9380f96   Cédric Dupont   Update sources OC...
32
33
34
35
36
  	 *
  	 * @param string $uid      The username
  	 * @param string $password The password
  	 *
  	 * @return true/false
d1bafeea1   Kload   [fix] Upgrade to ...
37
38
  	 */
  	public function checkPassword($uid, $password) {
6d9380f96   Cédric Dupont   Update sources OC...
39
40
41
42
43
  		if (!function_exists('imap_open')) {
  			OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR);
  			return false;
  		}
  		$mbox = @imap_open($this->mailbox, $uid, $password, OP_HALFOPEN);
d1bafeea1   Kload   [fix] Upgrade to ...
44
45
  		imap_errors();
  		imap_alerts();
6d9380f96   Cédric Dupont   Update sources OC...
46
  		if($mbox !== FALSE) {
d1bafeea1   Kload   [fix] Upgrade to ...
47
  			imap_close($mbox);
6d9380f96   Cédric Dupont   Update sources OC...
48
  			$this->storeUser($uid);
d1bafeea1   Kload   [fix] Upgrade to ...
49
50
51
52
53
  			return $uid;
  		}else{
  			return false;
  		}
  	}
d1bafeea1   Kload   [fix] Upgrade to ...
54
  }