Skip to content

Commit 29bb67e

Browse files
committed
ImapDriver: bugfix; overrding variable
1 parent 0c239ee commit 29bb67e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

MailLibrary/Drivers/ImapDriver.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,22 +301,29 @@ public function getStructure($mailId, Mailbox $mailbox)
301301
* Gets part of body
302302
*
303303
* @param int $mailId
304-
* @param array $data
304+
* @param array $data requires id and encoding keys
305305
* @return string
306+
* @throws \greeny\MailLibrary\DriverException
306307
*/
307308
public function getBody($mailId, array $data)
308309
{
309310
$body = array();
310311
foreach($data as $part) {
311-
$data = ($part['id'] == 0) ? imap_body($this->resource, $mailId, FT_UID | FT_PEEK) : imap_fetchbody($this->resource, $mailId, $part['id'], FT_UID | FT_PEEK);
312+
assert(is_array($part));
313+
$dataMessage = ($part['id'] === 0) ? @imap_body($this->resource, $mailId, FT_UID | FT_PEEK) : @imap_fetchbody($this->resource, $mailId, $part['id'], FT_UID | FT_PEEK);
314+
if($dataMessage === FALSE) {
315+
throw new DriverException("Cannot read given message part - " . error_get_last()["message"]);
316+
}
312317
$encoding = $part['encoding'];
313318
if($encoding === ImapStructure::ENCODING_BASE64) {
314-
$data = base64_decode($data);
319+
$dataMessage = base64_decode($dataMessage);
315320
} else if($encoding === ImapStructure::ENCODING_QUOTED_PRINTABLE) {
316-
$data = quoted_printable_decode($data);
321+
$dataMessage = quoted_printable_decode($dataMessage);
317322
}
318323

319-
$body[] = $data;
324+
// todo: other encodings?
325+
326+
$body[] = $dataMessage;
320327
}
321328
return implode('\n\n', $body);
322329
}

0 commit comments

Comments
 (0)