Skip to content

Commit

Permalink
Fixed the keep unseen method
Browse files Browse the repository at this point in the history
  • Loading branch information
aeyoll committed Oct 5, 2015
1 parent db73923 commit d279c88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function getSize()
*
* @return string
*/
public function getContent()
public function getContent($keepUnseen = false)
{
// Null headers, so subsequent calls to getHeaders() will return
// updated seen flag
$this->headers = null;

return $this->doGetContent($this->keepUnseen);
return $this->doGetContent($this->keepUnseen ? $this->keepUnseen : $keepUnseen);
}

/**
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getBodyHtml()
$iterator = new \RecursiveIteratorIterator($this, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $part) {
if ($part->getSubtype() == 'HTML') {
return $part->getDecodedContent();
return $part->getDecodedContent($this->keepUnseen);
}
}
}
Expand All @@ -213,12 +213,12 @@ public function getBodyText()
$iterator = new \RecursiveIteratorIterator($this, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $part) {
if ($part->getSubtype() == 'PLAIN') {
return $part->getDecodedContent();
return $part->getDecodedContent($this->keepUnseen);
}
}

// If message has no parts, return content of message itself.
return $this->getDecodedContent();
return $this->getDecodedContent($this->keepUnseen);
}

/**
Expand Down Expand Up @@ -317,15 +317,15 @@ function ($nr, $error) {
);
}
);

$structure = imap_fetchstructure(
$this->stream,
$this->messageNumber,
\FT_UID
);

restore_error_handler();

$this->parseStructure($structure);
}
}
24 changes: 12 additions & 12 deletions src/Message/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Part implements \RecursiveIterator
* @var Parameters
*/
protected $parameters;

protected $stream;

protected $messageNumber;
Expand Down Expand Up @@ -144,10 +144,10 @@ public function getParameters()
*
* @return string
*/
public function getContent()
public function getContent($keepUnseen = false)
{
if (null === $this->content) {
$this->content = $this->doGetContent();
$this->content = $this->doGetContent($keepUnseen);
}

return $this->content;
Expand All @@ -158,20 +158,20 @@ public function getContent()
*
* @return string
*/
public function getDecodedContent()
public function getDecodedContent($keepUnseen = false)
{
if (null === $this->decodedContent) {
switch ($this->getEncoding()) {
case self::ENCODING_BASE64:
$this->decodedContent = base64_decode($this->getContent());
$this->decodedContent = base64_decode($this->getContent($keepUnseen));
break;
case self::ENCODING_QUOTED_PRINTABLE:
$this->decodedContent = quoted_printable_decode($this->getContent());
$this->decodedContent = quoted_printable_decode($this->getContent($keepUnseen));
break;
case self::ENCODING_7BIT:
case self::ENCODING_8BIT:
case self::ENCODING_BINARY:
$this->decodedContent = $this->getContent();
$this->decodedContent = $this->getContent($keepUnseen);
break;
default:
throw new \UnexpectedValueException('Cannot decode ' . $this->getEncoding());
Expand Down Expand Up @@ -217,7 +217,7 @@ protected function parseStructure(\stdClass $structure)
} else {
$this->type = self::TYPE_UNKNOWN;
}

$this->encoding = $this->encodingsMap[$structure->encoding];
$this->subtype = $structure->subtype;

Expand All @@ -230,12 +230,12 @@ protected function parseStructure(\stdClass $structure)
$this->$optional = $structure->$optional;
}
}

$this->parameters = new Parameters();
if (is_array($structure->parameters)) {
$this->parameters->add($structure->parameters);
}

if (isset($structure->dparameters)) {
$this->parameters->add($structure->dparameters);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ protected function doGetContent($keepUnseen = false)
\FT_UID | ($keepUnseen ? \FT_PEEK : null)
);
}

private function isAttachment($part)
{
// Attachment with correct Content-Disposition header
Expand All @@ -348,7 +348,7 @@ private function isAttachment($part)
}
}
}

return false;
}
}

0 comments on commit d279c88

Please sign in to comment.