Skip to content

Commit

Permalink
Prevent text bodies from being fetched as attachment #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Oct 15, 2020
1 parent 6b82256 commit 8354f23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [UNRELEASED]
### Fixed
- NaN
- Prevent text bodies from being fetched as attachment #27

### Added
- NaN

### Affected Classes
- NaN
- [Message::class](src/Message.php)

### Breaking changes
- Text bodies might no longer get fetched as attachment

## [2.1.13] - 2020-10-13
### Fixed
Expand Down
18 changes: 3 additions & 15 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private function fetchPart(Part $part) {

if ($part->type == IMAP::MESSAGE_TYPE_TEXT && ($part->ifdisposition == 0 || (empty($part->disposition) || !in_array(strtolower($part->disposition), ['attachment', 'inline'])) ) ) {

if (strtolower($part->subtype) == "plain" || strtolower($part->subtype) == "csv") {
if ( in_array(($subtype = strtolower($part->subtype)), ["plain", "csv", "html"]) && $part->filename == null && $part->name == null) {
$encoding = $this->getEncoding($part);

$content = $this->decodeString($part->content, $part->encoding);
Expand All @@ -456,20 +456,8 @@ private function fetchPart(Part $part) {
$content = $this->convertEncoding($content, $encoding);
}

$this->bodies['text'] = $content;

$this->fetchAttachment($part);

} elseif (strtolower($part->subtype) == "html") {
$encoding = $this->getEncoding($part);

$content = $this->decodeString($part->content, $part->encoding);
if ($encoding != 'us-ascii') {
$content = $this->convertEncoding($content, $encoding);
}

$this->bodies['html'] = $content;
} elseif ($part->ifdisposition == 1 && strtolower($part->disposition) == 'attachment') {
$this->bodies[$subtype == "plain" ? "text" : $subtype] = $content;
} else {
$this->fetchAttachment($part);
}
} else {
Expand Down

0 comments on commit 8354f23

Please sign in to comment.