Skip to content

Commit

Permalink
Fix issues with embedding items without filenames, fixes PHPMailer#478
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Aug 25, 2015
1 parent 8a71910 commit c93759d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
45 changes: 31 additions & 14 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2330,12 +2330,21 @@ protected function attachAll($disposition_type, $boundary)
$cidUniq[$cid] = true;

$mime[] = sprintf('--%s%s', $boundary, $this->LE);
$mime[] = sprintf(
'Content-Type: %s; name="%s"%s',
$type,
$this->encodeHeader($this->secureHeader($name)),
$this->LE
);
//Only include a filename property if we have one
if (!empty($name)) {
$mime[] = sprintf(
'Content-Type: %s; name="%s"%s',
$type,
$this->encodeHeader($this->secureHeader($name)),
$this->LE
);
} else {
$mime[] = sprintf(
'Content-Type: %s%s',
$type,
$this->LE
);
}
// RFC1341 part 5 says 7bit is assumed if not specified
if ($encoding != '7bit') {
$mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
Expand All @@ -2359,12 +2368,20 @@ protected function attachAll($disposition_type, $boundary)
$this->LE . $this->LE
);
} else {
$mime[] = sprintf(
'Content-Disposition: %s; filename=%s%s',
$disposition,
$encoded_name,
$this->LE . $this->LE
);
if (!empty($encoded_name)) {
$mime[] = sprintf(
'Content-Disposition: %s; filename=%s%s',
$disposition,
$encoded_name,
$this->LE . $this->LE
);
} else {
$mime[] = sprintf(
'Content-Disposition: %s%s',
$disposition,
$this->LE . $this->LE
);
}
}
} else {
$mime[] = $this->LE;
Expand Down Expand Up @@ -2801,7 +2818,7 @@ public function addStringEmbeddedImage(
$disposition = 'inline'
) {
// If a MIME type is not specified, try to work it out from the name
if ($type == '') {
if ($type == '' and !empty($name)) {
$type = self::filenameToType($name);
}

Expand Down Expand Up @@ -3103,7 +3120,7 @@ public function msgHTML($message, $basedir = '', $advanced = false)
$data = rawurldecode($data);
}
$cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
if ($this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1])) {
if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
$message = str_replace(
$images[0][$imgindex],
$images[1][$imgindex] . '="cid:' . $cid . '"',
Expand Down
25 changes: 25 additions & 0 deletions test/phpmailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,31 @@ public function testHTMLAttachment()
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

/**
* Test embedded image without a name
*/
public function testHTMLStringEmbedNoName()
{
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->Subject .= ': HTML + unnamed embedded image';
$this->Mail->isHTML(true);

if (!$this->Mail->addStringEmbeddedImage(
file_get_contents('../examples/images/phpmailer_mini.png'),
md5('phpmailer_mini.png').'@phpmailer.0',
'', //intentionally empty name
'base64',
'image/png',
'inline')
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}

$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

/**
* Simple HTML and multiple attachment test
*/
Expand Down

0 comments on commit c93759d

Please sign in to comment.