Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
9f6554fa
Commit
9f6554fa
authored
9 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
pear: Upgrade to Net_SMTP v1.7.1
parent
152840ca
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/pear/BUNDLE
+6
-0
6 additions, 0 deletions
include/pear/BUNDLE
include/pear/Net/SMTP.php
+353
-444
353 additions, 444 deletions
include/pear/Net/SMTP.php
with
359 additions
and
444 deletions
include/pear/BUNDLE
+
6
−
0
View file @
9f6554fa
Log of pear packages bundled with osTicket
* osTicket v1.9.13, v1.10 *
===========================================================
Mail_Mime-1.10.0
Mail_mimeDecode-1.5.5
Net_SMTP-1.7.1
* osTicket v1.7.*
===========================================================
PEAR-1.9.4 - core class
...
...
This diff is collapsed.
Click to expand it.
include/pear/Net/SMTP.php
+
353
−
444
View file @
9f6554fa
<?php
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
/*
*
vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version
4
|
// | PHP Version
5 and 7
|
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-20
03 The PHP Group
|
// | Copyright (c) 1997-20
15 Jon Parise and Chuck Hagenbuch
|
// +----------------------------------------------------------------------+
// | This source file is subject to version
2
.0
2
of the PHP license, |
// | This source file is subject to version
3
.0
1
of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/
2
_0
2
.txt. |
// | http://www.php.net/license/
3
_0
1
.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
...
...
@@ -17,52 +17,46 @@
// | Jon Parise <jon@php.net> |
// | Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar> |
// +----------------------------------------------------------------------+
//
// $Id: SMTP.php 314875 2011-08-13 17:03:30Z jon $
require_once
'PEAR.php'
;
require_once
'Net/Socket.php'
;
/**
* Provides an implementation of the SMTP protocol using PEAR's
* Net_Socket
::
class.
* Net_Socket class.
*
* @package Net_SMTP
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jon Parise <jon@php.net>
* @author Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>
*
* @example basic.php
A basic implementation of the Net_SMTP package.
* @example basic.php A basic implementation of the Net_SMTP package.
*/
class
Net_SMTP
{
/**
* The server to connect to.
* @var string
* @access public
*/
var
$host
=
'localhost'
;
public
$host
=
'localhost'
;
/**
* The port to connect to.
* @var int
* @access public
*/
var
$port
=
25
;
public
$port
=
25
;
/**
* The value to give when sending EHLO or HELO.
* @var string
* @access public
*/
var
$localhost
=
'localhost'
;
public
$localhost
=
'localhost'
;
/**
* List of supported authentication methods, in preferential order.
* @var array
* @access public
*/
var
$auth_methods
=
array
();
public
$auth_methods
=
array
();
/**
* Use SMTP command pipelining (specified in RFC 2920) if the SMTP
...
...
@@ -73,80 +67,69 @@ class Net_SMTP
* SMTP server but return immediately.
*
* @var bool
* @access public
*/
var
$pipelining
=
false
;
public
$pipelining
=
false
;
/**
* Number of pipelined commands.
* @var int
* @access private
*/
var
$
_
pipelined_commands
=
0
;
protected
$pipelined_commands
=
0
;
/**
* Should debugging output be enabled?
* @var boolean
* @access private
*/
var
$
_
debug
=
false
;
protected
$debug
=
false
;
/**
* Debug output handler.
* @var callback
* @access private
*/
var
$
_
debug_handler
=
null
;
protected
$debug_handler
=
null
;
/**
* The socket resource being used to connect to the SMTP server.
* @var resource
* @access private
*/
var
$
_
socket
=
null
;
protected
$socket
=
null
;
/**
* Array of socket options that will be passed to Net_Socket::connect().
* @see stream_context_create()
* @var array
* @access private
*/
var
$
_
socket_options
=
null
;
protected
$socket_options
=
null
;
/**
* The socket I/O timeout value in seconds.
* @var int
* @access private
*/
var
$
_
timeout
=
0
;
protected
$timeout
=
0
;
/**
* The most recent server response code.
* @var int
* @access private
*/
var
$
_
code
=
-
1
;
protected
$code
=
-
1
;
/**
* The most recent server response arguments.
* @var array
* @access private
*/
var
$
_
arguments
=
array
();
protected
$arguments
=
array
();
/**
* Stores the SMTP server's greeting string.
* @var string
* @access private
*/
var
$
_
greeting
=
null
;
protected
$greeting
=
null
;
/**
* Stores detected features of the SMTP server.
* @var array
* @access private
*/
var
$
_
esmtp
=
array
();
protected
$esmtp
=
array
();
/**
* Instantiates a new Net_SMTP object, overriding any defaults
...
...
@@ -159,19 +142,18 @@ class Net_SMTP
* $smtp = new Net_SMTP('ssl://mail.host.com', 465);
* $smtp->connect();
*
* @param string $host The server to connect to.
* @param integer $port The port to connect to.
* @param string $localhost The value to give when sending EHLO or HELO.
* @param boolean $pipelin
g
Use SMTP command pipelining
* @param integer $timeout Socket I/O timeout in seconds.
* @param string $host
The server to connect to.
* @param integer $port
The port to connect to.
* @param string $localhost
The value to give when sending EHLO or HELO.
* @param boolean $pipelin
ing
Use SMTP command pipelining
* @param integer $timeout
Socket I/O timeout in seconds.
* @param array $socket_options Socket stream_context_create() options.
*
* @access public
* @since 1.0
* @since 1.0
*/
function
Net_SMTP
(
$host
=
null
,
$port
=
null
,
$localhost
=
null
,
$pipelining
=
false
,
$timeout
=
0
,
$socket_options
=
null
)
{
public
function
__construct
(
$host
=
null
,
$port
=
null
,
$localhost
=
null
,
$pipelining
=
false
,
$timeout
=
0
,
$socket_options
=
null
)
{
if
(
isset
(
$host
))
{
$this
->
host
=
$host
;
}
...
...
@@ -181,65 +163,65 @@ class Net_SMTP
if
(
isset
(
$localhost
))
{
$this
->
localhost
=
$localhost
;
}
$this
->
pipelining
=
$pipelining
;
$this
->
_socket
=
new
Net_Socket
();
$this
->
_socket_options
=
$socket_options
;
$this
->
_timeout
=
$timeout
;
$this
->
pipelining
=
$pipelining
;
$this
->
socket
=
new
Net_Socket
();
$this
->
socket_options
=
$socket_options
;
$this
->
timeout
=
$timeout
;
/* Include the Auth_SASL package. If the package is available, we
* enable the authentication methods that depend upon it. */
if
(
@
include_once
'Auth/SASL.php'
)
{
$this
->
setAuthMethod
(
'CRAM-MD5'
,
array
(
$this
,
'
_
authCram
_
MD5'
));
$this
->
setAuthMethod
(
'DIGEST-MD5'
,
array
(
$this
,
'
_
authDigest
_
MD5'
));
$this
->
setAuthMethod
(
'CRAM-MD5'
,
array
(
$this
,
'authCramMD5'
));
$this
->
setAuthMethod
(
'DIGEST-MD5'
,
array
(
$this
,
'authDigestMD5'
));
}
/* These standard authentication methods are always available. */
$this
->
setAuthMethod
(
'LOGIN'
,
array
(
$this
,
'
_
authLogin'
),
false
);
$this
->
setAuthMethod
(
'PLAIN'
,
array
(
$this
,
'
_
authPlain'
),
false
);
$this
->
setAuthMethod
(
'LOGIN'
,
array
(
$this
,
'authLogin'
),
false
);
$this
->
setAuthMethod
(
'PLAIN'
,
array
(
$this
,
'authPlain'
),
false
);
}
/**
* Set the socket I/O timeout value in seconds plus microseconds.
*
* @param
integer $seconds
Timeout value in seconds.
* @param
integer $microseconds
Additional value in microseconds.
* @param integer $seconds Timeout value in seconds.
* @param integer $microseconds Additional value in microseconds.
*
* @access public
* @since 1.5.0
* @since 1.5.0
*/
function
setTimeout
(
$seconds
,
$microseconds
=
0
)
{
return
$this
->
_socket
->
setTimeout
(
$seconds
,
$microseconds
);
public
function
setTimeout
(
$seconds
,
$microseconds
=
0
)
{
return
$this
->
socket
->
setTimeout
(
$seconds
,
$microseconds
);
}
/**
* Set the value of the debugging flag.
*
* @param boolean $debug New value for the debugging flag.
* @param boolean $debug New value for the debugging flag.
* @param callback $handler Debug handler callback
*
* @access public
* @since 1.1.0
* @since 1.1.0
*/
function
setDebug
(
$debug
,
$handler
=
null
)
public
function
setDebug
(
$debug
,
$handler
=
null
)
{
$this
->
_
debug
=
$debug
;
$this
->
_
debug_handler
=
$handler
;
$this
->
debug
=
$debug
;
$this
->
debug_handler
=
$handler
;
}
/**
* Write the given debug text to the current debug output handler.
*
* @param
string
$message
Debug mesage text.
* @param string $message Debug mesage text.
*
* @access private
* @since 1.3.3
* @since 1.3.3
*/
function
_
debug
(
$message
)
protected
function
debug
(
$message
)
{
if
(
$this
->
_debug
)
{
if
(
$this
->
_debug_handler
)
{
call_user_func_array
(
$this
->
_debug_handler
,
array
(
&
$this
,
$message
));
if
(
$this
->
debug
)
{
if
(
$this
->
debug_handler
)
{
call_user_func_array
(
$this
->
debug_handler
,
array
(
&
$this
,
$message
)
);
}
else
{
echo
"DEBUG:
$message
\n
"
;
}
...
...
@@ -249,23 +231,21 @@ class Net_SMTP
/**
* Send the given string of data to the server.
*
* @param
string
$data
The string of data to send.
* @param string $data The string of data to send.
*
* @return
mixed
The number of bytes that were actually written,
*
or a PEAR_Error object on failure.
* @return mixed The number of bytes that were actually written,
* or a PEAR_Error object on failure.
*
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
send
(
$data
)
protected
function
send
(
$data
)
{
$this
->
_
debug
(
"Send:
$data
"
);
$this
->
debug
(
"Send:
$data
"
);
$result
=
$this
->
_
socket
->
write
(
$data
);
$result
=
$this
->
socket
->
write
(
$data
);
if
(
!
$result
||
PEAR
::
isError
(
$result
))
{
$msg
=
(
$result
)
?
$result
->
getMessage
()
:
"unknown error"
;
return
PEAR
::
raiseError
(
"Failed to write to socket:
$msg
"
,
null
,
PEAR_ERROR_RETURN
);
$msg
=
$result
?
$result
->
getMessage
()
:
"unknown error"
;
return
PEAR
::
raiseError
(
"Failed to write to socket:
$msg
"
);
}
return
$result
;
...
...
@@ -276,81 +256,77 @@ class Net_SMTP
* arguments. A carriage return / linefeed (CRLF) sequence will
* be appended to each command string before it is sent to the
* SMTP server - an error will be thrown if the command string
* already contains any newline characters. Use
_
send() for
* already contains any newline characters. Use send() for
* commands that must contain newlines.
*
* @param
string
$command
The SMTP command to send to the server.
* @param
string
$args
A string of optional arguments to append
*
to the command.
* @param string $command The SMTP command to send to the server.
* @param string $args A string of optional arguments to append
* to the command.
*
* @return
mixed
The result of the
_
send() call.
* @return mixed The result of the send() call.
*
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
put
(
$command
,
$args
=
''
)
protected
function
put
(
$command
,
$args
=
''
)
{
if
(
!
empty
(
$args
))
{
$command
.
=
' '
.
$args
;
}
if
(
strcspn
(
$command
,
"
\r\n
"
)
!==
strlen
(
$command
))
{
return
PEAR
::
raiseError
(
'Commands cannot contain newlines'
,
null
,
PEAR_ERROR_RETURN
);
return
PEAR
::
raiseError
(
'Commands cannot contain newlines'
);
}
return
$this
->
_
send
(
$command
.
"
\r\n
"
);
return
$this
->
send
(
$command
.
"
\r\n
"
);
}
/**
* Read a reply from the SMTP server. The reply consists of a response
* code and a response message.
*
* @param
mixed
$valid
The set of valid response codes. These
*
may be specified as an array of integer
*
values or as a single integer value.
* @param
bool
$later
Do not parse the response now, but wait
*
until the last command in the pipelined
*
command group
* @param mixed $valid The set of valid response codes. These
* may be specified as an array of integer
* values or as a single integer value.
* @param bool $later Do not parse the response now, but wait
* until the last command in the pipelined
* command group
*
* @return
mixed
True if the server returned a valid response code or
*
a PEAR_Error object is an error condition is reached.
* @return mixed True if the server returned a valid response code or
* a PEAR_Error object is an error condition is reached.
*
* @access private
* @since 1.1.0
* @since 1.1.0
*
* @see
getResponse
* @see getResponse
*/
function
_
parseResponse
(
$valid
,
$later
=
false
)
protected
function
parseResponse
(
$valid
,
$later
=
false
)
{
$this
->
_
code
=
-
1
;
$this
->
_
arguments
=
array
();
$this
->
code
=
-
1
;
$this
->
arguments
=
array
();
if
(
$later
)
{
$this
->
_
pipelined_commands
++
;
$this
->
pipelined_commands
++
;
return
true
;
}
for
(
$i
=
0
;
$i
<=
$this
->
_
pipelined_commands
;
$i
++
)
{
while
(
$line
=
$this
->
_
socket
->
readLine
())
{
$this
->
_
debug
(
"Recv:
$line
"
);
for
(
$i
=
0
;
$i
<=
$this
->
pipelined_commands
;
$i
++
)
{
while
(
$line
=
$this
->
socket
->
readLine
())
{
$this
->
debug
(
"Recv:
$line
"
);
/* If we receive an empty line, the connection was closed. */
if
(
empty
(
$line
))
{
$this
->
disconnect
();
return
PEAR
::
raiseError
(
'Connection was closed'
,
null
,
PEAR_ERROR_RETURN
);
return
PEAR
::
raiseError
(
'Connection was closed'
);
}
/* Read the code and store the rest in the arguments array. */
$code
=
substr
(
$line
,
0
,
3
);
$this
->
_
arguments
[]
=
trim
(
substr
(
$line
,
4
));
$this
->
arguments
[]
=
trim
(
substr
(
$line
,
4
));
/* Check the syntax of the response code. */
if
(
is_numeric
(
$code
))
{
$this
->
_
code
=
(
int
)
$code
;
$this
->
code
=
(
int
)
$code
;
}
else
{
$this
->
_
code
=
-
1
;
$this
->
code
=
-
1
;
break
;
}
...
...
@@ -361,38 +337,36 @@ class Net_SMTP
}
}
$this
->
_
pipelined_commands
=
0
;
$this
->
pipelined_commands
=
0
;
/* Compare the server's response code with the valid code/codes. */
if
(
is_int
(
$valid
)
&&
(
$this
->
_
code
===
$valid
))
{
if
(
is_int
(
$valid
)
&&
(
$this
->
code
===
$valid
))
{
return
true
;
}
elseif
(
is_array
(
$valid
)
&&
in_array
(
$this
->
_
code
,
$valid
,
true
))
{
}
elseif
(
is_array
(
$valid
)
&&
in_array
(
$this
->
code
,
$valid
,
true
))
{
return
true
;
}
return
PEAR
::
raiseError
(
'Invalid response code received from server'
,
$this
->
_code
,
PEAR_ERROR_RETURN
);
return
PEAR
::
raiseError
(
'Invalid response code received from server'
,
$this
->
code
);
}
/**
* Issue an SMTP command and verify its response.
*
* @param
string
$command
The SMTP command string or data.
* @param
mixed
$valid
The set of valid response codes.
These
*
may be specified as an array of integer
*
values or as a single integer value.
* @param string $command The SMTP command string or data.
* @param mixed $valid The set of valid response codes. These
* may be specified as an array of integer
* values or as a single integer value.
*
* @return
mixed
True on success or a PEAR_Error object on failure.
* @return mixed True on success or a PEAR_Error object on failure.
*
* @access public
* @since 1.6.0
* @since 1.6.0
*/
function
command
(
$command
,
$valid
)
public
function
command
(
$command
,
$valid
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
$command
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
$command
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
$valid
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
$valid
)))
{
return
$error
;
}
...
...
@@ -402,76 +376,76 @@ class Net_SMTP
/**
* Return a 2-tuple containing the last response from the SMTP server.
*
* @return
array
A two-element array: the first element contains the
*
response code as an integer and the second element
*
contains the response's arguments as a string.
* @return array A two-element array: the first element contains the
* response code as an integer and the second element
* contains the response's arguments as a string.
*
* @access public
* @since 1.1.0
* @since 1.1.0
*/
function
getResponse
()
public
function
getResponse
()
{
return
array
(
$this
->
_
code
,
join
(
"
\n
"
,
$this
->
_
arguments
));
return
array
(
$this
->
code
,
join
(
"
\n
"
,
$this
->
arguments
));
}
/**
* Return the SMTP server's greeting string.
*
* @return
string
A string containing the greeting string, or null if
a
*
greeting has not been received.
* @return string A string containing the greeting string, or null if
*
a
greeting has not been received.
*
* @access public
* @since 1.3.3
* @since 1.3.3
*/
function
getGreeting
()
public
function
getGreeting
()
{
return
$this
->
_
greeting
;
return
$this
->
greeting
;
}
/**
* Attempt to connect to the SMTP server.
*
* @param
int
$timeout The timeout value (in seconds) for the
*
socket connection attempt.
* @param
bool
$persistent Should a persistent socket connection
*
be used?
* @param int $timeout The timeout value (in seconds) for the
* socket connection attempt.
* @param bool $persistent Should a persistent socket connection
* be used?
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
connect
(
$timeout
=
null
,
$persistent
=
false
)
public
function
connect
(
$timeout
=
null
,
$persistent
=
false
)
{
$this
->
_greeting
=
null
;
$result
=
$this
->
_socket
->
connect
(
$this
->
host
,
$this
->
port
,
$persistent
,
$timeout
,
$this
->
_socket_options
);
$this
->
greeting
=
null
;
$result
=
$this
->
socket
->
connect
(
$this
->
host
,
$this
->
port
,
$persistent
,
$timeout
,
$this
->
socket_options
);
if
(
PEAR
::
isError
(
$result
))
{
return
PEAR
::
raiseError
(
'Failed to connect socket: '
.
$result
->
getMessage
());
return
PEAR
::
raiseError
(
'Failed to connect socket: '
.
$result
->
getMessage
()
);
}
/*
* Now that we're connected, reset the socket's timeout value for
* future I/O operations. This allows us to have different socket
* timeout values for the initial connection (our $timeout parameter)
* Now that we're connected, reset the socket's timeout value for
* future I/O operations. This allows us to have different socket
* timeout values for the initial connection (our $timeout parameter)
* and all other socket operations.
*/
if
(
$this
->
_
timeout
>
0
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
setTimeout
(
$this
->
_
timeout
)))
{
if
(
$this
->
timeout
>
0
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
setTimeout
(
$this
->
timeout
)))
{
return
$error
;
}
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
220
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
220
)))
{
return
$error
;
}
/* Extract and store a copy of the server's greeting string. */
list
(,
$this
->
_
greeting
)
=
$this
->
getResponse
();
list
(,
$this
->
greeting
)
=
$this
->
getResponse
();
if
(
PEAR
::
isError
(
$error
=
$this
->
_
negotiate
()))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
negotiate
()))
{
return
$error
;
}
...
...
@@ -483,20 +457,20 @@ class Net_SMTP
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
disconnect
()
public
function
disconnect
()
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'QUIT'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'QUIT'
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
221
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
221
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_socket
->
disconnect
()))
{
return
PEAR
::
raiseError
(
'Failed to disconnect socket: '
.
$error
->
getMessage
());
if
(
PEAR
::
isError
(
$error
=
$this
->
socket
->
disconnect
()))
{
return
PEAR
::
raiseError
(
'Failed to disconnect socket: '
.
$error
->
getMessage
()
);
}
return
true
;
...
...
@@ -509,41 +483,34 @@ class Net_SMTP
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
*
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
negotiate
()
protected
function
negotiate
()
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'EHLO'
,
$this
->
localhost
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'EHLO'
,
$this
->
localhost
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$this
->
_parseResponse
(
250
)))
{
/* If we receive a 503 response, we're already authenticated. */
if
(
$this
->
_code
===
503
)
{
return
true
;
}
if
(
PEAR
::
isError
(
$this
->
parseResponse
(
250
)))
{
/* If the EHLO failed, try the simpler HELO command. */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'HELO'
,
$this
->
localhost
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'HELO'
,
$this
->
localhost
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$this
->
_parseResponse
(
250
)))
{
return
PEAR
::
raiseError
(
'HELO was not accepted: '
,
$this
->
_code
,
PEAR_ERROR_RETURN
);
if
(
PEAR
::
isError
(
$this
->
parseResponse
(
250
)))
{
return
PEAR
::
raiseError
(
'HELO was not accepted'
,
$this
->
code
);
}
return
true
;
}
foreach
(
$this
->
_
arguments
as
$argument
)
{
$verb
=
strtok
(
$argument
,
' '
);
$
arguments
=
substr
(
$argument
,
strlen
(
$verb
)
+
1
,
strlen
(
$argument
)
-
strlen
(
$verb
)
-
1
);
$this
->
_
esmtp
[
$verb
]
=
$arguments
;
foreach
(
$this
->
arguments
as
$argument
)
{
$verb
=
strtok
(
$argument
,
' '
);
$
len
=
strlen
(
$verb
)
;
$arguments
=
substr
(
$argument
,
$len
+
1
,
strlen
(
$argument
)
-
$len
-
1
);
$this
->
esmtp
[
$verb
]
=
$arguments
;
}
if
(
!
isset
(
$this
->
_
esmtp
[
'PIPELINING'
]))
{
if
(
!
isset
(
$this
->
esmtp
[
'PIPELINING'
]))
{
$this
->
pipelining
=
false
;
}
...
...
@@ -554,15 +521,14 @@ class Net_SMTP
* Returns the name of the best authentication method that the server
* has advertised.
*
* @return mixed Returns a string containing the name of the best
* supported authentication method or a PEAR_Error object
* if a failure condition is encountered.
* @access private
* @since 1.1.0
* @return mixed Returns a string containing the name of the best
* supported authentication method or a PEAR_Error object
* if a failure condition is encountered.
* @since 1.1.0
*/
function
_
getBestAuthMethod
()
protected
function
getBestAuthMethod
()
{
$available_methods
=
explode
(
' '
,
$this
->
_
esmtp
[
'AUTH'
]);
$available_methods
=
explode
(
' '
,
$this
->
esmtp
[
'AUTH'
]);
foreach
(
$this
->
auth_methods
as
$method
=>
$callback
)
{
if
(
in_array
(
$method
,
$available_methods
))
{
...
...
@@ -570,44 +536,53 @@ class Net_SMTP
}
}
return
PEAR
::
raiseError
(
'No supported authentication methods'
,
null
,
PEAR_ERROR_RETURN
);
return
PEAR
::
raiseError
(
'No supported authentication methods'
);
}
/**
* Attempt to do SMTP authentication.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The requested authentication method. If none is
* specified, the best supported method will be used.
* @param bool Flag indicating whether or not TLS should be attempted.
* @param string An optional authorization identifier. If specified, this
* identifier will be used as the authorization proxy.
* @param string
$uid
The userid to authenticate as.
* @param string
$pwd
The password to authenticate with.
* @param string
$method
The requested authentication method. If none is
*
specified, the best supported method will be used.
* @param bool
$tls
Flag indicating whether or not TLS should be attempted.
* @param string
$authz
An optional authorization identifier. If specified, this
*
identifier will be used as the authorization proxy.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
auth
(
$uid
,
$pwd
,
$method
=
''
,
$tls
=
true
,
$authz
=
''
)
public
function
auth
(
$uid
,
$pwd
,
$method
=
''
,
$tls
=
true
,
$authz
=
''
)
{
/* We can only attempt a TLS connection if one has been requested,
* we're running PHP 5.1.0 or later, have access to the OpenSSL
* extension, are connected to an SMTP server which supports the
* STARTTLS extension, and aren't already connected over a secure
* we're running PHP 5.1.0 or later, have access to the OpenSSL
* extension, are connected to an SMTP server which supports the
* STARTTLS extension, and aren't already connected over a secure
* (SSL) socket connection. */
if
(
$tls
&&
version_compare
(
PHP_VERSION
,
'5.1.0'
,
'>='
)
&&
extension_loaded
(
'openssl'
)
&&
isset
(
$this
->
_esmtp
[
'STARTTLS'
])
&&
strncasecmp
(
$this
->
host
,
'ssl://'
,
6
)
!==
0
)
{
if
(
$tls
&&
version_compare
(
PHP_VERSION
,
'5.1.0'
,
'>='
)
&&
extension_loaded
(
'openssl'
)
&&
isset
(
$this
->
esmtp
[
'STARTTLS'
])
&&
strncasecmp
(
$this
->
host
,
'ssl://'
,
6
)
!==
0
)
{
/* Start the TLS connection attempt. */
if
(
PEAR
::
isError
(
$result
=
$this
->
_
put
(
'STARTTLS'
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
put
(
'STARTTLS'
)))
{
return
$result
;
}
if
(
PEAR
::
isError
(
$result
=
$this
->
_
parseResponse
(
220
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
parseResponse
(
220
)))
{
return
$result
;
}
if
(
PEAR
::
isError
(
$result
=
$this
->
_socket
->
enableCrypto
(
true
,
STREAM_CRYPTO_METHOD_TLS_CLIENT
)))
{
if
(
isset
(
$this
->
socket_options
[
'ssl'
][
'crypto_method'
]))
{
$crypto_method
=
$this
->
socket_options
[
'ssl'
][
'crypto_method'
];
}
else
{
/* STREAM_CRYPTO_METHOD_TLS_ANY_CLIENT constant does not exist
* and STREAM_CRYPTO_METHOD_SSLv23_CLIENT constant is
* inconsistent across PHP versions. */
$crypto_method
=
STREAM_CRYPTO_METHOD_TLS_CLIENT
|
@
STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT
|
@
STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
;
}
if
(
PEAR
::
isError
(
$result
=
$this
->
socket
->
enableCrypto
(
true
,
$crypto_method
)))
{
return
$result
;
}
elseif
(
$result
!==
true
)
{
return
PEAR
::
raiseError
(
'STARTTLS failed'
);
...
...
@@ -615,17 +590,17 @@ class Net_SMTP
/* Send EHLO again to recieve the AUTH string from the
* SMTP server. */
$this
->
_
negotiate
();
$this
->
negotiate
();
}
if
(
empty
(
$this
->
_
esmtp
[
'AUTH'
]))
{
if
(
empty
(
$this
->
esmtp
[
'AUTH'
]))
{
return
PEAR
::
raiseError
(
'SMTP server does not support authentication'
);
}
/* If no method has been specified, get the name of the best
* supported method advertised by the SMTP server. */
if
(
empty
(
$method
))
{
if
(
PEAR
::
isError
(
$method
=
$this
->
_
getBestAuthMethod
()))
{
if
(
PEAR
::
isError
(
$method
=
$this
->
getBestAuthMethod
()))
{
/* Return the PEAR_Error object from _getBestAuthMethod(). */
return
$method
;
}
...
...
@@ -648,9 +623,9 @@ class Net_SMTP
list
(
$object
,
$method
)
=
$this
->
auth_methods
[
$method
];
$result
=
$object
->
{
$method
}(
$uid
,
$pwd
,
$authz
,
$this
);
}
else
{
$func
=
$this
->
auth_methods
[
$method
];
$func
=
$this
->
auth_methods
[
$method
];
$result
=
$func
(
$uid
,
$pwd
,
$authz
,
$this
);
}
}
/* If an error was encountered, return the PEAR_Error object. */
if
(
PEAR
::
isError
(
$result
))
{
...
...
@@ -663,19 +638,18 @@ class Net_SMTP
/**
* Add a new authentication method.
*
* @param string The authentication method name (e.g. 'PLAIN')
* @param mixed
The authentication callback (given as the name of a
* function or as an (object, method name) array).
* @param bool
Should the new method be prepended to the list of
* available methods? This is the default behavior,
* giving the new method the highest priority.
* @param string
$name
The authentication method name (e.g. 'PLAIN')
* @param mixed
$callback
The authentication callback (given as the name of a
*
function or as an (object, method name) array).
* @param bool
$prepend
Should the new method be prepended to the list of
*
available methods? This is the default behavior,
*
giving the new method the highest priority.
*
* @return
mixed
True on success or a PEAR_Error object on failure.
* @return mixed True on success or a PEAR_Error object on failure.
*
* @access public
* @since 1.6.0
* @since 1.6.0
*/
function
setAuthMethod
(
$name
,
$callback
,
$prepend
=
true
)
public
function
setAuthMethod
(
$name
,
$callback
,
$prepend
=
true
)
{
if
(
!
is_string
(
$name
))
{
return
PEAR
::
raiseError
(
'Method name is not a string'
);
...
...
@@ -686,13 +660,15 @@ class Net_SMTP
}
if
(
is_array
(
$callback
))
{
if
(
!
is_object
(
$callback
[
0
])
||
!
is_string
(
$callback
[
1
]))
if
(
!
is_object
(
$callback
[
0
])
||
!
is_string
(
$callback
[
1
]))
{
return
PEAR
::
raiseError
(
'Bad mMethod callback array'
);
}
}
if
(
$prepend
)
{
$this
->
auth_methods
=
array_merge
(
array
(
$name
=>
$callback
),
$this
->
auth_methods
);
$this
->
auth_methods
=
array_merge
(
array
(
$name
=>
$callback
),
$this
->
auth_methods
);
}
else
{
$this
->
auth_methods
[
$name
]
=
$callback
;
}
...
...
@@ -703,51 +679,50 @@ class Net_SMTP
/**
* Authenticates the user using the DIGEST-MD5 method.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The optional authorization proxy identifier.
* @param string
$uid
The userid to authenticate as.
* @param string
$pwd
The password to authenticate with.
* @param string
$authz
The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
authDigest
_
MD5
(
$uid
,
$pwd
,
$authz
=
''
)
protected
function
authDigestMD5
(
$uid
,
$pwd
,
$authz
=
''
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'AUTH'
,
'DIGEST-MD5'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'AUTH'
,
'DIGEST-MD5'
)))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
/* 503: Error: already authenticated */
if
(
$this
->
_
code
===
503
)
{
if
(
$this
->
code
===
503
)
{
return
true
;
}
return
$error
;
}
$
challenge
=
base64_decode
(
$this
->
_arguments
[
0
]
);
$
digest
=
&
Auth_SASL
::
factory
(
'digestmd5'
);
$auth_str
=
base64_encode
(
$digest
->
getResponse
(
$uid
,
$pwd
,
$challenge
,
$this
->
host
,
"smtp"
,
$authz
)
);
$
digest
=
Auth_SASL
::
factory
(
'digest-md5'
);
$
challenge
=
base64_decode
(
$this
->
arguments
[
0
]
);
$auth_str
=
base64_encode
(
$digest
->
getResponse
(
$uid
,
$pwd
,
$challenge
,
$this
->
host
,
"smtp"
,
$authz
)
);
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
$auth_str
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
$auth_str
)))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
return
$error
;
}
/* We don't use the protocol's third step because SMTP doesn't
* allow subsequent authentication, so we just silently ignore
* it. */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
''
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
''
)))
{
return
$error
;
}
/* 235: Authentication successful */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
235
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
235
)))
{
return
$error
;
}
}
...
...
@@ -755,39 +730,38 @@ class Net_SMTP
/**
* Authenticates the user using the CRAM-MD5 method.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The optional authorization proxy identifier.
* @param string
$uid
The userid to authenticate as.
* @param string
$pwd
The password to authenticate with.
* @param string
$authz
The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
authCRAM
_
MD5
(
$uid
,
$pwd
,
$authz
=
''
)
protected
function
authCRAMMD5
(
$uid
,
$pwd
,
$authz
=
''
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'AUTH'
,
'CRAM-MD5'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'AUTH'
,
'CRAM-MD5'
)))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
/* 503: Error: already authenticated */
if
(
$this
->
_
code
===
503
)
{
if
(
$this
->
code
===
503
)
{
return
true
;
}
return
$error
;
}
$challenge
=
base64_decode
(
$this
->
_
arguments
[
0
]);
$cram
=
&
Auth_SASL
::
factory
(
'crammd5'
);
$auth_str
=
base64_encode
(
$cram
->
getResponse
(
$uid
,
$pwd
,
$challenge
));
$challenge
=
base64_decode
(
$this
->
arguments
[
0
]);
$cram
=
Auth_SASL
::
factory
(
'cram
-
md5'
);
$auth_str
=
base64_encode
(
$cram
->
getResponse
(
$uid
,
$pwd
,
$challenge
));
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
$auth_str
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
$auth_str
)))
{
return
$error
;
}
/* 235: Authentication successful */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
235
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
235
)))
{
return
$error
;
}
}
...
...
@@ -795,43 +769,42 @@ class Net_SMTP
/**
* Authenticates the user using the LOGIN method.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The optional authorization proxy identifier.
* @param string
$uid
The userid to authenticate as.
* @param string
$pwd
The password to authenticate with.
* @param string
$authz
The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
authLogin
(
$uid
,
$pwd
,
$authz
=
''
)
protected
function
authLogin
(
$uid
,
$pwd
,
$authz
=
''
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'AUTH'
,
'LOGIN'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'AUTH'
,
'LOGIN'
)))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
/* 503: Error: already authenticated */
if
(
$this
->
_
code
===
503
)
{
if
(
$this
->
code
===
503
)
{
return
true
;
}
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
base64_encode
(
$uid
))))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
base64_encode
(
$uid
))))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
base64_encode
(
$pwd
))))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
base64_encode
(
$pwd
))))
{
return
$error
;
}
/* 235: Authentication successful */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
235
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
235
)))
{
return
$error
;
}
...
...
@@ -841,24 +814,23 @@ class Net_SMTP
/**
* Authenticates the user using the PLAIN method.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The optional authorization proxy identifier.
* @param string
$uid
The userid to authenticate as.
* @param string
$pwd
The password to authenticate with.
* @param string
$authz
The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
* @since 1.1.0
*/
function
_
authPlain
(
$uid
,
$pwd
,
$authz
=
''
)
protected
function
authPlain
(
$uid
,
$pwd
,
$authz
=
''
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'AUTH'
,
'PLAIN'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'AUTH'
,
'PLAIN'
)))
{
return
$error
;
}
/* 334: Continue authentication request */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
334
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
334
)))
{
/* 503: Error: already authenticated */
if
(
$this
->
_
code
===
503
)
{
if
(
$this
->
code
===
503
)
{
return
true
;
}
return
$error
;
...
...
@@ -866,12 +838,12 @@ class Net_SMTP
$auth_str
=
base64_encode
(
$authz
.
chr
(
0
)
.
$uid
.
chr
(
0
)
.
$pwd
);
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
$auth_str
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
$auth_str
)))
{
return
$error
;
}
/* 235: Authentication successful */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
235
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
235
)))
{
return
$error
;
}
...
...
@@ -881,19 +853,18 @@ class Net_SMTP
/**
* Send the HELO command.
*
* @param string The domain name to say we are.
* @param string
$domain
The domain name to say we are.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
helo
(
$domain
)
public
function
helo
(
$domain
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'HELO'
,
$domain
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'HELO'
,
$domain
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
)))
{
return
$error
;
}
...
...
@@ -904,44 +875,39 @@ class Net_SMTP
* Return the list of SMTP service extensions advertised by the server.
*
* @return array The list of SMTP service extensions.
* @access public
* @since 1.3
*/
function
getServiceExtensions
()
public
function
getServiceExtensions
()
{
return
$this
->
_
esmtp
;
return
$this
->
esmtp
;
}
/**
* Send the MAIL FROM: command.
*
* @param string $sender
The sender (reverse path) to set.
* @param string $params
String containing additional MAIL parameters,
*
such as the NOTIFY flags defined by RFC 1891
*
or the VERP protocol.
* @param string $sender The sender (reverse path) to set.
* @param string $params String containing additional MAIL parameters,
* such as the NOTIFY flags defined by RFC 1891
* or the VERP protocol.
*
*
If $params is an array, only the 'verp' option
*
is supported. If 'verp' is true, the XVERP
*
parameter is appended to the MAIL command.
If
*
the 'verp' value is a string, the full
*
XVERP=value parameter is appended.
* If $params is an array, only the 'verp' option
* is supported. If 'verp' is true, the XVERP
* parameter is appended to the MAIL command.
*
If
the 'verp' value is a string, the full
* XVERP=value parameter is appended.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
mailFrom
(
$sender
,
$params
=
null
)
public
function
mailFrom
(
$sender
,
$params
=
null
)
{
$args
=
"FROM:<
$sender
>"
;
/* Support the deprecated array form of $params. */
if
(
is_array
(
$params
)
&&
isset
(
$params
[
'verp'
]))
{
/* XVERP */
if
(
$params
[
'verp'
]
===
true
)
{
$args
.
=
' XVERP'
;
/* XVERP=something */
}
elseif
(
trim
(
$params
[
'verp'
]))
{
$args
.
=
' XVERP='
.
$params
[
'verp'
];
}
...
...
@@ -949,10 +915,10 @@ class Net_SMTP
$args
.
=
' '
.
$params
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'MAIL'
,
$args
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'MAIL'
,
$args
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
...
...
@@ -969,20 +935,19 @@ class Net_SMTP
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
*
* @access public
* @since 1.0
* @since 1.0
*/
function
rcptTo
(
$recipient
,
$params
=
null
)
public
function
rcptTo
(
$recipient
,
$params
=
null
)
{
$args
=
"TO:<
$recipient
>"
;
if
(
is_string
(
$params
))
{
$args
.
=
' '
.
$params
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'RCPT'
,
$args
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'RCPT'
,
$args
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
array
(
250
,
251
),
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
array
(
250
,
251
),
$this
->
pipelining
)))
{
return
$error
;
}
...
...
@@ -996,38 +961,34 @@ class Net_SMTP
* easier overloading for the cases where it is desirable to
* customize the quoting behavior.
*
* @param string $data
The message text to quote. The string must be passed
* @param string
&
$data The message text to quote. The string must be passed
* by reference, and the text will be modified in place.
*
* @access public
* @since 1.2
* @since 1.2
*/
function
quotedata
(
&
$data
)
public
function
quotedata
(
&
$data
)
{
/* Change Unix (\n) and Mac (\r) linefeeds into
* Internet-standard CRLF (\r\n) linefeeds. */
$data
=
preg_replace
(
array
(
'/(?<!\r)\n/'
,
'/\r(?!\n)/'
),
"
\r\n
"
,
$data
);
/* Because a single leading period (.) signifies an end to the
* data, legitimate leading periods need to be "doubled"
* (e.g. '..'). */
$data
=
str_replace
(
"
\n
."
,
"
\n
.."
,
$data
);
* data, legitimate leading periods need to be "doubled" ('..'). */
$data
=
preg_replace
(
'/^\./m'
,
'..'
,
$data
);
/* Change Unix (\n) and Mac (\r) linefeeds into CRLF's (\r\n). */
$data
=
preg_replace
(
'/(?:\r\n|\n|\r(?!\n))/'
,
"
\r\n
"
,
$data
);
}
/**
* Send the DATA command.
*
* @param mixed $data
The message data, either as a string or an open
* @param mixed
$data The message data, either as a string or an open
* file resource.
* @param string $headers The message headers. If $headers is provided,
* $data is assumed to contain only body data.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
data
(
$data
,
$headers
=
null
)
public
function
data
(
$data
,
$headers
=
null
)
{
/* Verify that $data is a supported type. */
if
(
!
is_string
(
$data
)
&&
!
is_resource
(
$data
))
{
...
...
@@ -1053,24 +1014,24 @@ class Net_SMTP
* that no fixed maximum message size is in force". Furthermore, it
* says that if "the parameter is omitted no information is conveyed
* about the server's fixed maximum message size". */
$limit
=
(
isset
(
$this
->
_
esmtp
[
'SIZE'
]))
?
$this
->
_
esmtp
[
'SIZE'
]
:
0
;
$limit
=
(
isset
(
$this
->
esmtp
[
'SIZE'
]))
?
$this
->
esmtp
[
'SIZE'
]
:
0
;
if
(
$limit
>
0
&&
$size
>=
$limit
)
{
$this
->
disconnect
();
return
PEAR
::
raiseError
(
'Message size exceeds server limit'
);
}
/* Initiate the DATA command. */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'DATA'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'DATA'
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
354
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
354
)))
{
return
$error
;
}
/* If we have a separate headers string, send it first. */
if
(
!
is_null
(
$headers
))
{
$this
->
quotedata
(
$headers
);
if
(
PEAR
::
isError
(
$result
=
$this
->
_
send
(
$headers
.
"
\r\n\r\n
"
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
send
(
$headers
.
"
\r\n\r\n
"
)))
{
return
$result
;
}
}
...
...
@@ -1091,10 +1052,12 @@ class Net_SMTP
}
}
$this
->
quotedata
(
$line
);
if
(
PEAR
::
isError
(
$result
=
$this
->
_
send
(
$line
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
send
(
$line
)))
{
return
$result
;
}
}
$last
=
$line
;
}
else
{
/*
* Break up the data by sending one chunk (up to 512k) at a time.
...
...
@@ -1123,22 +1086,27 @@ class Net_SMTP
$this
->
quotedata
(
$chunk
);
/* If we run into a problem along the way, abort. */
if
(
PEAR
::
isError
(
$result
=
$this
->
_
send
(
$chunk
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
send
(
$chunk
)))
{
return
$result
;
}
/* Advance the offset to the end of this chunk. */
$offset
=
$end
;
}
$last
=
$chunk
;
}
/* Don't add another CRLF sequence if it's already in the data */
$terminator
=
(
substr
(
$last
,
-
2
)
==
"
\r\n
"
?
''
:
"
\r\n
"
)
.
".
\r\n
"
;
/* Finally, send the DATA terminator sequence. */
if
(
PEAR
::
isError
(
$result
=
$this
->
_
send
(
"
\r\n
.
\r\n
"
)))
{
if
(
PEAR
::
isError
(
$result
=
$this
->
send
(
$terminator
)))
{
return
$result
;
}
/* Verify that the data was successfully received by the server. */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
...
...
@@ -1148,134 +1116,79 @@ class Net_SMTP
/**
* Send the SEND FROM: command.
*
* @param string The reverse path to send.
* @param string
$path
The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.2.6
* @since 1.2.6
*/
function
sendFrom
(
$path
)
public
function
sendFrom
(
$path
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'SEND'
,
"FROM:<
$path
>"
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'SEND'
,
"FROM:<
$path
>"
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
return
true
;
}
/**
* Backwards-compatibility wrapper for sendFrom().
*
* @param string The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
*
* @access public
* @since 1.0
* @deprecated 1.2.6
*/
function
send_from
(
$path
)
{
return
sendFrom
(
$path
);
}
/**
* Send the SOML FROM: command.
*
* @param string The reverse path to send.
* @param string
$path
The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.2.6
* @since 1.2.6
*/
function
somlFrom
(
$path
)
public
function
somlFrom
(
$path
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'SOML'
,
"FROM:<
$path
>"
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'SOML'
,
"FROM:<
$path
>"
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
return
true
;
}
/**
* Backwards-compatibility wrapper for somlFrom().
*
* @param string The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
*
* @access public
* @since 1.0
* @deprecated 1.2.6
*/
function
soml_from
(
$path
)
{
return
somlFrom
(
$path
);
}
/**
* Send the SAML FROM: command.
*
* @param string The reverse path to send.
* @param string
$path
The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.2.6
* @since 1.2.6
*/
function
samlFrom
(
$path
)
public
function
samlFrom
(
$path
)
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'SAML'
,
"FROM:<
$path
>"
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'SAML'
,
"FROM:<
$path
>"
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
return
true
;
}
/**
* Backwards-compatibility wrapper for samlFrom().
*
* @param string The reverse path to send.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
*
* @access public
* @since 1.0
* @deprecated 1.2.6
*/
function
saml_from
(
$path
)
{
return
samlFrom
(
$path
);
}
/**
* Send the RSET command.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
*/
function
rset
()
public
function
rset
()
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'RSET'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'RSET'
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
,
$this
->
pipelining
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
,
$this
->
pipelining
)))
{
return
$error
;
}
...
...
@@ -1285,20 +1198,19 @@ class Net_SMTP
/**
* Send the VRFY command.
*
* @param string The string to verify
* @param string
$string
The string to verify
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
vrfy
(
$string
)
public
function
vrfy
(
$string
)
{
/* Note: 251 is also a valid response code */
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'VRFY'
,
$string
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'VRFY'
,
$string
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
array
(
250
,
252
))))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
array
(
250
,
252
))))
{
return
$error
;
}
...
...
@@ -1310,15 +1222,14 @@ class Net_SMTP
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
* @since 1.0
*/
function
noop
()
public
function
noop
()
{
if
(
PEAR
::
isError
(
$error
=
$this
->
_
put
(
'NOOP'
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
put
(
'NOOP'
)))
{
return
$error
;
}
if
(
PEAR
::
isError
(
$error
=
$this
->
_
parseResponse
(
250
)))
{
if
(
PEAR
::
isError
(
$error
=
$this
->
parseResponse
(
250
)))
{
return
$error
;
}
...
...
@@ -1329,14 +1240,12 @@ class Net_SMTP
* Backwards-compatibility method. identifySender()'s functionality is
* now handled internally.
*
* @return
boolean
This method always return true.
* @return boolean This method always return true.
*
* @access public
* @since 1.0
* @since 1.0
*/
function
identifySender
()
public
function
identifySender
()
{
return
true
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment