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\PHPIMAP\Support\Masks; |
14
|
|
|
|
15
|
|
|
use Webklex\PHPIMAP\Attachment; |
16
|
|
|
use Webklex\PHPIMAP\Message; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class MessageMask |
20
|
|
|
* |
21
|
|
|
* @package Webklex\PHPIMAP\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
|
|
|
* |
31
|
|
|
* @return null |
32
|
|
|
*/ |
33
|
|
|
public function getHtmlBody(){ |
34
|
|
|
$bodies = $this->parent->getBodies(); |
35
|
|
|
if (!isset($bodies['html'])) { |
36
|
|
|
return null; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if(is_object($bodies['html']) && property_exists($bodies['html'], 'content')) { |
40
|
|
|
return $bodies['html']->content; |
41
|
|
|
} |
42
|
|
|
return $bodies['html']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the Message html body filtered by an optional callback |
47
|
|
|
* @param callable|bool $callback |
48
|
|
|
* |
49
|
|
|
* @return string|null |
50
|
|
|
*/ |
51
|
|
|
public function getCustomHTMLBody($callback = false) { |
52
|
|
|
$body = $this->getHtmlBody(); |
|
|
|
|
53
|
|
|
if($body === null) return null; |
|
|
|
|
54
|
|
|
|
55
|
|
|
if ($callback !== false) { |
56
|
|
|
$aAttachment = $this->parent->getAttachments(); |
57
|
|
|
$aAttachment->each(function($oAttachment) use(&$body, $callback) { |
58
|
|
|
/** @var Attachment $oAttachment */ |
59
|
|
|
if(is_callable($callback)) { |
60
|
|
|
$body = $callback($body, $oAttachment); |
61
|
|
|
}elseif(is_string($callback)) { |
62
|
|
|
call_user_func($callback, [$body, $oAttachment]); |
63
|
|
|
} |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $body; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the Message html body with embedded base64 images |
72
|
|
|
* the resulting $body. |
73
|
|
|
* |
74
|
|
|
* @return string|null |
75
|
|
|
*/ |
76
|
|
|
public function getHTMLBodyWithEmbeddedBase64Images() { |
77
|
|
|
return $this->getCustomHTMLBody(function($body, $oAttachment){ |
|
|
|
|
78
|
|
|
/** @var Attachment $oAttachment */ |
79
|
|
|
if ($oAttachment->id) { |
80
|
|
|
$body = str_replace('cid:'.$oAttachment->id, 'data:'.$oAttachment->getContentType().';base64, '.base64_encode($oAttachment->getContent()), $body); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $body; |
84
|
|
|
}); |
85
|
|
|
} |
86
|
|
|
} |
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.