Skip to content

Commit 5be71b4

Browse files
committed
Replace embedded image with URL #151
1 parent 401fdcd commit 5be71b4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/IMAP/Attachment.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ protected function fetch() {
176176
}
177177
}
178178
}
179-
180-
if ($this->type == 'image') {
181-
$this->img_src = 'data:'.$this->content_type.';base64,'.base64_encode($this->content);
182-
}
183179
}
184180

185181
/**
@@ -256,6 +252,9 @@ public function getDisposition() {
256252
* @return null|string
257253
*/
258254
public function getImgSrc() {
255+
if ($this->type == 'image' && $this->img_src == null) {
256+
$this->img_src = 'data:'.$this->content_type.';base64,'.base64_encode($this->content);
257+
}
259258
return $this->img_src;
260259
}
261260

src/IMAP/Message.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ public function getHTMLBody($replaceImages = false) {
280280
$body = $this->bodies['html']->content;
281281
if ($replaceImages) {
282282
$this->attachments->each(function($oAttachment) use(&$body) {
283-
if ($oAttachment->id && isset($oAttachment->img_src)) {
284-
$body = str_replace('cid:'.$oAttachment->id, $oAttachment->img_src, $body);
283+
/** @var Attachment $oAttachment */
284+
if ($oAttachment->id && $oAttachment->getImgSrc() != null) {
285+
$body = str_replace('cid:'.$oAttachment->id, $oAttachment->getImgSrc(), $body);
285286
}
286287
});
287288
}
@@ -801,6 +802,7 @@ public function getEncoding($structure) {
801802
*
802803
* @return null|Folder
803804
* @throws Exceptions\ConnectionFailedException
805+
* @throws InvalidMessageDateException
804806
*/
805807
public function getContainingFolder(Folder $folder = null) {
806808
$folder = $folder ?: $this->client->getFolders()->first();

0 commit comments

Comments
 (0)