Subversion Repositories Applications.papyrus

Rev

Rev 1713 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1173 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
4
/**
5
 * Storage driver for use against a POP3 server
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   Authentication
16
 * @package    Auth
1713 jp_milcent 17
 * @author     Stefan Ekman <stekman@sedata.org>
1173 jp_milcent 18
 * @author     Martin Jansen <mj@php.net>
1713 jp_milcent 19
 * @author     Mika Tuupola <tuupola@appelsiini.net>
1173 jp_milcent 20
 * @author     Adam Ashley <aashley@php.net>
21
 * @copyright  2001-2006 The PHP Group
22
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
2150 mathias 23
 * @version    CVS: $Id: POP3.php,v 1.12 2007/06/12 03:11:26 aashley Exp $
1173 jp_milcent 24
 * @link       http://pear.php.net/package/Auth
25
 * @since      File available since Release 1.2.0
26
 */
27
 
28
/**
29
 * Include Auth_Container base class
30
 */
31
require_once 'Auth/Container.php';
32
/**
33
 * Include PEAR package for error handling
34
 */
35
require_once 'PEAR.php';
36
/**
37
 * Include PEAR Net_POP3 package
38
 */
39
require_once 'Net/POP3.php';
40
 
41
/**
42
 * Storage driver for Authentication on a POP3 server.
43
 *
44
 * @category   Authentication
45
 * @package    Auth
46
 * @author     Martin Jansen <mj@php.net>
1713 jp_milcent 47
 * @author     Mika Tuupola <tuupola@appelsiini.net>
1173 jp_milcent 48
 * @author     Adam Ashley <aashley@php.net>
49
 * @copyright  2001-2006 The PHP Group
50
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
2150 mathias 51
 * @version    Release: 1.5.4  File: $Revision: 1.12 $
1173 jp_milcent 52
 * @link       http://pear.php.net/package/Auth
53
 * @since      Class available since Release 1.2.0
54
 */
55
class Auth_Container_POP3 extends Auth_Container
56
{
57
 
58
    // {{{ properties
59
 
60
    /**
61
     * POP3 Server
62
     * @var string
63
     */
64
    var $server='localhost';
65
 
66
    /**
67
     * POP3 Server port
68
     * @var string
69
     */
70
    var $port='110';
71
 
72
    /**
73
     * POP3 Authentication method
74
     *
75
     * Prefered POP3 authentication method. Acceptable values:
76
     *      Boolean TRUE    - Use Net_POP3's autodetection
77
     *      String 'DIGEST-MD5','CRAM-MD5','LOGIN','PLAIN','APOP','USER'
78
     *                      - Attempt this authentication style first
79
     *                        then fallback to autodetection.
1713 jp_milcent 80
     * @var mixed
1173 jp_milcent 81
     */
82
    var $method=true;
83
 
84
    // }}}
85
    // {{{ Auth_Container_POP3() [constructor]
86
 
87
    /**
88
     * Constructor of the container class
89
     *
90
     * @param  $server string server or server:port combination
91
     * @return object Returns an error object if something went wrong
92
     */
93
    function Auth_Container_POP3($server=null)
94
    {
95
        if (isset($server) && !is_null($server)) {
96
            if (is_array($server)) {
97
                if (isset($server['host'])) {
98
                    $this->server = $server['host'];
99
                }
100
                if (isset($server['port'])) {
101
                    $this->port = $server['port'];
102
                }
103
                if (isset($server['method'])) {
104
                    $this->method = $server['method'];
105
                }
106
            } else {
107
                if (strstr($server, ':')) {
108
                    $serverparts = explode(':', trim($server));
109
                    $this->server = $serverparts[0];
110
                    $this->port = $serverparts[1];
111
                } else {
112
                    $this->server = $server;
113
                }
114
            }
115
        }
116
    }
117
 
118
    // }}}
119
    // {{{ fetchData()
120
 
121
    /**
122
     * Try to login to the POP3 server
123
     *
124
     * @param   string Username
125
     * @param   string Password
126
     * @return  boolean
127
     */
128
    function fetchData($username, $password)
129
    {
1713 jp_milcent 130
        $this->log('Auth_Container_POP3::fetchData() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 131
        $pop3 =& new Net_POP3();
132
        $res = $pop3->connect($this->server, $this->port, $this->method);
133
        if (!$res) {
1713 jp_milcent 134
            $this->log('Connection to POP3 server failed.', AUTH_LOG_DEBUG);
1173 jp_milcent 135
            return $res;
136
        }
137
        $result = $pop3->login($username, $password);
138
        $pop3->disconnect();
139
        return $result;
140
    }
141
 
142
    // }}}
143
 
144
}
145
?>