1 | <?php |
||
2 | |||
3 | namespace Kodus\Mail; |
||
4 | |||
5 | class InlineAttachment |
||
6 | { |
||
7 | /** |
||
8 | * @var Attachment |
||
9 | */ |
||
10 | private $attachment; |
||
11 | |||
12 | /** |
||
13 | * @var string inline Content ID (in mailbox format, per RFC 2392) |
||
14 | */ |
||
15 | private $content_id; |
||
16 | |||
17 | /** |
||
18 | * @var string random seed for Content ID creation |
||
19 | */ |
||
20 | private static $seed; |
||
21 | |||
22 | /** |
||
23 | * @param Attachment $attachment |
||
24 | */ |
||
25 | 5 | public function __construct(Attachment $attachment) |
|
26 | { |
||
27 | 5 | if (self::$seed === null) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
28 | 1 | self::$seed = sha1(mt_rand() . microtime()); |
|
29 | 1 | } else { |
|
30 | 5 | self::$seed = sha1("d73TfecaRMDmRPqBgy4Lv5wZavBeHagmqnLBgd5w" . self::$seed); |
|
31 | } |
||
32 | |||
33 | 5 | $this->attachment = $attachment; |
|
34 | 5 | $this->content_id = sha1(self::$seed) . "@kodus.mail"; |
|
35 | 5 | } |
|
36 | |||
37 | /** |
||
38 | * @return Attachment |
||
39 | */ |
||
40 | 5 | public function getAttachment(): Attachment |
|
41 | { |
||
42 | 5 | return $this->attachment; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | 5 | public function getContentID(): string |
|
49 | { |
||
50 | 5 | return $this->content_id; |
|
51 | } |
||
52 | } |
||
53 |