Skip to content

Commit 4b16945

Browse files
committed
Replace images in html with something like an url example added
1 parent e8f4de8 commit 4b16945

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* File: replace_images_with_url.php
4+
* Category: Example
5+
* Author: M.Goldenbaum
6+
* Created: 14.03.19 18:47
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
/** @var \Webklex\IMAP\Client $oClient */
14+
$oClient = \Webklex\IMAP\Facades\Client::account('default');
15+
$oClient->connect();
16+
17+
/** @var \Webklex\IMAP\Folder $folder */
18+
$folder = $oClient->getFolder('INBOX');
19+
20+
/** @var \Webklex\IMAP\Message $message */
21+
$message = $folder->query()->limit(1)->get()->first();
22+
23+
$html = $message->getHTMLBody(function($body, $oAttachment){
24+
/** @var \Webklex\IMAP\Attachment $oAttachment */
25+
if ($oAttachment->id && $oAttachment->getImgSrc() != null) {
26+
$oMessage = $oAttachment->getMessage();
27+
28+
$image_url = route('my.custom.imap.attachment.route', [
29+
'muid' => urlencode($oMessage->uid),
30+
'mid' => urlencode($oMessage->message_id),
31+
'mti' => urlencode($oMessage->date->timestamp),
32+
'aid' => urlencode($oAttachment->id)
33+
]);
34+
35+
$body = str_replace('cid:'.$oAttachment->id, $image_url, $body);
36+
}
37+
38+
return $body;
39+
});
40+
41+
//Alternative way:
42+
$message_mask = $message->mask();
43+
$html = $message_mask->getHTMLBodyWithEmbeddedUrlImages('my.custom.imap.attachment.route');

0 commit comments

Comments
 (0)