Skip to content

Commit

Permalink
[mms] Added Horde_Smtp property indicating whether error is permanent…
Browse files Browse the repository at this point in the history
… or transient.
  • Loading branch information
slusarz committed Nov 19, 2014
1 parent 3040b97 commit 6694f97
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
4 changes: 4 additions & 0 deletions framework/Smtp/doc/Horde/Smtp/UPGRADING
Expand Up @@ -27,6 +27,10 @@ Upgrading to 1.7.0
Deprecated the '8bit' option. The correct encoding mode to use is now
automatically determined.

- Horde_Smtp_Exception

Added the $permanent property.


Upgrading to 1.6.0
==================
Expand Down
73 changes: 47 additions & 26 deletions framework/Smtp/lib/Horde/Smtp/Exception.php
Expand Up @@ -19,6 +19,11 @@
* @copyright 2013-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Smtp
*
* @property-read boolean $permanent Is this a permanent (non-tranisent)
* error? (@since 1.7.0)
* @property-read string $raw_msg Raw error message from server (in English).
* (@since 1.4.0)
*/
class Horde_Smtp_Exception extends Horde_Exception
{
Expand Down Expand Up @@ -69,20 +74,18 @@ class Horde_Smtp_Exception extends Horde_Exception


/**
* Raw error message (in English).
*
* @since 1.4.0
* SMTP Enhanced Mail System Status Code (see RFC 3463).
*
* @var string
*/
public $raw_msg = '';
protected $_enhancedcode = null;

/**
* SMTP Enhanced Mail System Status Code (see RFC 3463).
* Raw error message (in English).
*
* @var string
*/
protected $_enhancedcode = null;
protected $_rawmsg = '';

/**
* SMTP reply code.
Expand All @@ -104,7 +107,27 @@ public function __construct($message = null, $code = null)
$code
);

$this->raw_msg = $message;
$this->_rawmsg = $message;
}

/**
*/
public function __get($name)
{
switch ($name) {
case 'permanent':
$str_code = is_null($this->_enhancedcode)
? strval($this->_smtpcode)
: explode('.', $this->_enhancedcode);
/* Enhanced codes: Permanent errors are 5.y.z codes. (4.y.z are
* tranisent errors)
* Status code: permanent errors are 5yz codes. (4yz are tranisent
* errors) */
return ($str_code[0] === '5');

case 'raw_msg':
return $this->_rawmsg;
}
}

/**
Expand All @@ -114,40 +137,39 @@ public function __construct($message = null, $code = null)
*/
public function setSmtpCode($code)
{
$this->_enhancedcode = null;
$this->_smtpcode = $code;

// Any code not listed here will get the details of the error message
// as returned from the server.

/* Any code not listed here will get the details of the error message
* as returned from the server.
* Need to store $code/$message here because getCode()/getMessage() is
* declared final in the parent class and we can not alter on-demand
* at that location (darn). */
switch ($code) {
case 450:
$this->raw_msg = Horde_Smtp_Translation::r("Mailbox unavailable.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::MAILBOX_UNAVAILABLE;
$this->message = Horde_Smtp_Translation::t("Mailbox unavailable.");

break;

case 452:
$this->raw_msg = Horde_Smtp_Translation::r("Insufficient system storage.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::INSUFFICIENT_STORAGE;
$this->message = Horde_Smtp_Translation::t("Insufficient system storage.");
break;

case 454:
$this->raw_msg = Horde_Smtp_Translation::r("Could not open secure TLS connection to the server.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::LOGIN_TLSFAILURE;
$this->message = Horde_Smtp_Translation::t("Could not open secure TLS connection to the server.");
break;

case 530:
$this->raw_msg = Horde_Smtp_Translation::r("Server requires authentication.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::LOGIN_REQUIREAUTHENTICATION;
$this->message = Horde_Smtp_Translation::t("Server requires authentication.");
break;

case 550:
$this->raw_msg = Horde_Smtp_Translation::r("Message could not be delivered - the address was not found, is unknown, or is not receiving messages.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::MAILBOX_UNAVAILABLE;
$this->message = Horde_Smtp_Translation::t("Message could not be delivered - the address was not found, is unknown, or is not receiving messages.");
break;

case 551:
Expand All @@ -159,9 +181,8 @@ public function setSmtpCode($code)
break;

case 554:
$this->raw_msg = Horde_Smtp_Translation::r("Server is not accepting SMTP connections.");
$this->message = Horde_Smtp_Translation::t($this->raw_msg);
$this->code = self::DISCONNECT;
$this->message = Horde_Smtp_Translation::t("Server is not accepting SMTP connections.");
break;
}
}
Expand All @@ -177,19 +198,19 @@ public function getSmtpCode()
}

/**
* Set SMTP Enhanced Mail System Status Code.
* Set SMTP Enhanced Mail System Status Code (RFC 3463).
*
* @param string $code Status code.
* @param string $code Enhanced status code.
*/
public function setEnhancedSmtpCode($code)
{
$this->_enhancedcode = $code;
}

/**
* Get SMTP Enhanced Mail System Status Code.
* Get SMTP Enhanced Mail System Status Code (RFC 3463).
*
* @return string Status code.
* @return string Enhanced status code.
*/
public function getEnhancedSmtpCode()
{
Expand Down
2 changes: 2 additions & 0 deletions framework/Smtp/package.xml
Expand Up @@ -21,6 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Added Horde_Smtp_Exception property indicating whether error is permanent or transient.
* [mms] Determine EAI and Body transport information by analyzing the message data, instead of requiring a parameter.
* [mms] Add support for ETRN extension (RFC 1985).
* [mms] Add support for BINARYMIME extension (RFC 3030).
Expand Down Expand Up @@ -451,6 +452,7 @@
<date>2014-10-28</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Added Horde_Smtp_Exception property indicating whether error is permanent or transient.
* [mms] Determine EAI and Body transport information by analyzing the message data, instead of requiring a parameter.
* [mms] Add support for ETRN extension (RFC 1985).
* [mms] Add support for BINARYMIME extension (RFC 3030).
Expand Down

0 comments on commit 6694f97

Please sign in to comment.