Skip to content

Commit

Permalink
Fix inappropriate checks in set(), make more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Jan 28, 2015
1 parent 7b66825 commit c00fdf7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -12,6 +12,7 @@
* Improve pointers to docs and support in README
* Add example file upload script
* Refactor and major cleanup of EasyPeasyICS, now a lot more usable
* Make set() method simpler and more reliable

## Version 5.2.9 (Sept 25th 2014)
* **Important: The autoloader is no longer autoloaded by the PHPMailer class**
Expand Down
38 changes: 16 additions & 22 deletions class.phpmailer.php
Expand Up @@ -424,8 +424,8 @@ class PHPMailer
public $action_function = '';

/**
* What to use in the X-Mailer header.
* Options: null for default, whitespace for none, or a string to use
* What to put in the X-Mailer header.
* Options: An empty string for PHPMailer default, whitespace for none, or a string to use
* @type string
*/
public $XMailer = '';
Expand Down Expand Up @@ -3160,33 +3160,27 @@ public static function mb_pathinfo($path, $options = null)

/**
* Set or reset instance properties.
*
* You should avoid this function - it's more verbose, less efficient, more error-prone and
* harder to debug than setting properties directly.
* Usage Example:
* $page->set('X-Priority', '3');
*
* `$mail->set('SMTPSecure', 'tls');`
* is the same as:
* `$mail->SMTPSecure = 'tls';`
* @access public
* @param string $name
* @param mixed $value
* NOTE: will not work with arrays, there are no arrays to set/reset
* @throws phpmailerException
* @param string $name The property name to set
* @param mixed $value The value to set the property to
* @return boolean
* @TODO Should this not be using __set() magic function?
* @TODO Should this not be using the __set() magic function?
*/
public function set($name, $value = '')
{
try {
if (isset($this->$name)) {
$this->$name = $value;
} else {
throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
}
} catch (Exception $exc) {
$this->setError($exc->getMessage());
if ($exc->getCode() == self::STOP_CRITICAL) {
return false;
}
if (property_exists($this, $name)) {
$this->$name = $value;
return true;
} else {
$this->setError($this->lang('variable_set') . $name);
return false;
}
return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/phpmailerTest.php
Expand Up @@ -1355,6 +1355,8 @@ public function testMiscellaneous()
$this->Mail->createHeader();
$this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
$this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
$this->assertTrue($this->Mail->set('AllowEmpty', null), 'Null property set failed');
$this->assertTrue($this->Mail->set('AllowEmpty', false), 'Valid property set of null property failed');
//Test pathinfo
$a = '/mnt/files/飛兒樂 團光茫.mp3';
$q = PHPMailer::mb_pathinfo($a);
Expand Down

0 comments on commit c00fdf7

Please sign in to comment.