1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* File: MessageMask.php |
4
|
|
|
* Category: Mask |
5
|
|
|
* Author: M.Goldenbaum |
6
|
|
|
* Created: 14.03.19 20:49 |
7
|
|
|
* Updated: - |
8
|
|
|
* |
9
|
|
|
* Description: |
10
|
|
|
* - |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Webklex\IMAP\Support\Masks; |
14
|
|
|
|
15
|
|
|
use Webklex\IMAP\Attachment; |
16
|
|
|
use Webklex\IMAP\Message; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class MessageMask |
20
|
|
|
* |
21
|
|
|
* @package Webklex\IMAP\Support\Masks |
22
|
|
|
*/ |
23
|
|
|
class MessageMask extends Mask { |
24
|
|
|
|
25
|
|
|
/** @var Message $parent */ |
26
|
|
|
protected $parent; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get the message html body |
30
|
|
|
* @return null |
31
|
|
|
*/ |
32
|
|
|
public function getHtmlBody(){ |
33
|
|
|
$bodies = $this->parent->getBodies(); |
34
|
|
|
if (!isset($bodies['html'])) { |
35
|
|
|
return null; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $bodies['html']->content; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the Message html body filtered by an optional callback |
43
|
|
|
* |
44
|
|
|
* @return string|null |
45
|
|
|
*/ |
46
|
|
|
public function getCustomHTMLBody($callback = false) { |
47
|
|
|
$body = $this->getHtmlBody(); |
|
|
|
|
48
|
|
|
if($body === null) return null; |
|
|
|
|
49
|
|
|
|
50
|
|
|
if ($callback !== false) { |
51
|
|
|
$aAttachment = $this->parent->getAttachments(); |
52
|
|
|
$aAttachment->each(function($oAttachment) use(&$body, $callback) { |
53
|
|
|
/** @var Attachment $oAttachment */ |
54
|
|
|
if(is_callable($callback)) { |
55
|
|
|
$body = $callback($body, $oAttachment); |
56
|
|
|
}elseif(is_string($callback)) { |
57
|
|
|
call_user_func($callback, [$body, $oAttachment]); |
58
|
|
|
} |
59
|
|
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $body; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the Message html body with embedded base64 images |
67
|
|
|
* the resulting $body. |
68
|
|
|
* |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
|
|
public function getHTMLBodyWithEmbeddedBase64Images() { |
72
|
|
|
return $this->getCustomHTMLBody(function($body, $oAttachment){ |
|
|
|
|
73
|
|
|
/** @var \Webklex\IMAP\Attachment $oAttachment */ |
74
|
|
|
if ($oAttachment->id && $oAttachment->getImgSrc() != null) { |
|
|
|
|
75
|
|
|
$body = str_replace('cid:'.$oAttachment->id, $oAttachment->getImgSrc(), $body); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $body; |
79
|
|
|
}); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the Message html body with embedded image urls |
84
|
|
|
* the resulting $body. |
85
|
|
|
* |
86
|
|
|
* @param string $route_name |
87
|
|
|
* @param array $params |
88
|
|
|
* |
89
|
|
|
* @return null|string |
90
|
|
|
*/ |
91
|
|
|
public function getHTMLBodyWithEmbeddedUrlImages($route_name, $params = []) { |
92
|
|
|
return $this->getCustomHTMLBody(function($body, $oAttachment) use($route_name, $params){ |
|
|
|
|
93
|
|
|
/** @var \Webklex\IMAP\Attachment $oAttachment */ |
94
|
|
|
if ($oAttachment->id && $oAttachment->getImgSrc() != null) { |
|
|
|
|
95
|
|
|
$oMessage = $oAttachment->getMessage(); |
96
|
|
|
|
97
|
|
|
$image_url = route($route_name, array_merge([ |
98
|
|
|
'muid' => urlencode($oMessage->uid), |
99
|
|
|
'mid' => urlencode($oMessage->message_id), |
100
|
|
|
'mti' => urlencode($oMessage->date->timestamp), |
101
|
|
|
'aid' => urlencode($oAttachment->id) |
102
|
|
|
], $params)); |
103
|
|
|
|
104
|
|
|
$body = str_replace('cid:'.$oAttachment->id, $image_url, $body); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $body; |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Alias method for better code reading |
113
|
|
|
* |
114
|
|
|
* @return Message |
115
|
|
|
*/ |
116
|
|
|
public function getMessage(){ |
117
|
|
|
return $this->parent; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.