PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Imap2 / HeaderInfo.php

HeaderInfo.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Libraries/Imap2/HeaderInfo.php

128 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the PHP IMAP2 package.
5 *
6 * (c) Francesco Bianco <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace AcyMailing\Libraries\Imap2;
13
14 class HeaderInfo
15 {
16
17 public static function fromMessage($message, $defaultHost)
18 {
19 #file_put_contents('t3.json', json_encode($message, JSON_PRETTY_PRINT));
20
21 $to = Functions::writeAddressFromEnvelope($message->envelope[5]);
22 $cc = Functions::writeAddressFromEnvelope($message->envelope[6]);
23 $from = Functions::writeAddressFromEnvelope($message->envelope[2]);
24 $sender = Functions::writeAddressFromEnvelope($message->envelope[3]);
25
26 if (empty($message->replyto)) {
27 $replyTo = $from;
28 } else {
29 $replyTo = Functions::writeAddressFromEnvelope($message->envelope[4]);
30 }
31
32 $headerInfo = [
33 'date' => $message->envelope[0],
34 'Date' => $message->envelope[0],
35 'subject' => $message->envelope[1],
36 'Subject' => $message->envelope[1],
37 'in_reply_to' => $message->envelope[8],
38 'message_id' => $message->envelope[9],
39 'references' => $message->references,
40 'toaddress' => $to,
41 'to' => self::parseAddressList($to, $defaultHost),
42 'fromaddress' => $from,
43 'from' => self::parseAddressList($from, $defaultHost),
44 'ccaddress' => $cc,
45 'cc' => self::parseAddressList($cc, $defaultHost),
46 'reply_toaddress' => $replyTo,
47 'reply_to' => self::parseAddressList($replyTo, $defaultHost),
48 'senderaddress' => $sender,
49 'sender' => self::parseAddressList($sender, $defaultHost),
50 'Recent' => ' ',
51 'Unseen' => isset($message->flags['SEEN']) && $message->flags['SEEN'] ? ' ' : 'U',
52 'Flagged' => empty($message->flags['FLAGGED']) ? ' ' : 'F',
53 'Answered' => empty($message->flags['ANSWERED']) ? ' ' : 'A',
54 'Deleted' => empty($message->flags['DELETED']) ? ' ' : 'X',
55 'Draft' => empty($message->flags['DRAFT']) ? ' ' : 'D',
56 'Msgno' => str_pad($message->id, 4, ' ', STR_PAD_LEFT),
57 'MailDate' => self::sanitizeMailDate($message->internaldate),
58 'Size' => strval($message->size),
59 'udate' => strtotime($message->internaldate),
60 ];
61
62 if (empty($headerInfo['subject'])) {
63 unset($headerInfo['subject']);
64 unset($headerInfo['Subject']);
65 }
66
67 if (empty($headerInfo['in_reply_to'])) {
68 unset($headerInfo['in_reply_to']);
69 }
70
71 if (empty($headerInfo['references'])) {
72 unset($headerInfo['references']);
73 }
74
75 if (empty($headerInfo['to'])) {
76 unset($headerInfo['toaddress']);
77 unset($headerInfo['to']);
78 }
79
80 if (empty($headerInfo['cc'])) {
81 unset($headerInfo['ccaddress']);
82 unset($headerInfo['cc']);
83 }
84
85 return (object)$headerInfo;
86 }
87
88 protected static function parseAddressList($address, $defaultHost)
89 {
90 $addressList = imap_rfc822_parse_adrlist($address, $defaultHost);
91 $customAddressList = [];
92
93 foreach ($addressList as $objectEntry) {
94 $addressEntry = (object)[
95 'personal' => $objectEntry->personal ?? null,
96 'mailbox' => @$objectEntry->mailbox,
97 'host' => @$objectEntry->host,
98 ];
99
100 if (empty($addressEntry->personal)) {
101 unset($addressEntry->personal);
102 }
103
104 if (empty($addressEntry->host)) {
105 unset($addressEntry->host);
106 }
107
108 if (empty($addressEntry->mailbox)) {
109 continue;
110 }
111
112 $customAddressList[] = $addressEntry;
113 }
114
115 return $customAddressList;
116 }
117
118 public static function sanitizeMailDate($mailDate)
119 {
120 if ($mailDate[0] == '0') {
121 $mailDate = ' '.substr($mailDate, 1);
122 }
123
124 return $mailDate;
125 }
126 }
127
128