Fix issues with embedding items without filenames, fixes #478

This commit is contained in:
Synchro 2015-08-25 12:01:39 +02:00
parent 8a719102d2
commit c93759dcd1
2 changed files with 56 additions and 14 deletions

View File

@ -2330,12 +2330,21 @@ class PHPMailer
$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);
@ -2359,12 +2368,20 @@ class PHPMailer
$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;
@ -2801,7 +2818,7 @@ class PHPMailer
$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);
}
@ -3103,7 +3120,7 @@ class PHPMailer
$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 . '"',

View File

@ -975,6 +975,31 @@ EOT;
$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
*/