1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mail outlook message file. |
4
|
|
|
* |
5
|
|
|
* @package App |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce S.A. |
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Mail\ScannerEngine; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Mail outlook message class. |
16
|
|
|
*/ |
17
|
|
|
abstract class Base extends \App\Base |
18
|
|
|
{ |
19
|
|
|
const MAIL_TYPE_SENT = 0; |
20
|
|
|
const MAIL_TYPE_RECEIVED = 1; |
21
|
|
|
const MAIL_TYPE_INTERNAL = 2; |
22
|
|
|
/** |
23
|
|
|
* Mail types map. |
24
|
|
|
*/ |
25
|
|
|
const MAIL_TYPES = [ |
26
|
|
|
0 => 'Sent', |
27
|
|
|
1 => 'Received', |
28
|
|
|
2 => 'Internal', |
29
|
|
|
]; |
30
|
|
|
/** |
31
|
|
|
* Process data. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
public $processData = []; |
36
|
|
|
/** |
37
|
|
|
* Emails fields cache. |
38
|
|
|
* |
39
|
|
|
* @var string[] |
40
|
|
|
*/ |
41
|
|
|
protected $emailsFieldsCache = []; |
42
|
|
|
/** |
43
|
|
|
* Number fields cache. |
44
|
|
|
* |
45
|
|
|
* @var string[] |
46
|
|
|
*/ |
47
|
|
|
protected $numberFieldsCache = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Main function to execute scanner engine actions. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function process(): void |
55
|
|
|
{ |
56
|
|
|
foreach ($this->getActions() as $action) { |
57
|
|
|
$class = "App\\Mail\\ScannerAction\\{$action}"; |
58
|
|
|
(new $class($this))->process(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get scanner actions. |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
abstract public function getActions(): array; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get mail crm id. |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
abstract public function getMailCrmId(); |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get user id. |
78
|
|
|
* |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
|
|
abstract public function getUserId(): int; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get emails fields to search. |
85
|
|
|
* |
86
|
|
|
* @param string|null $searchModuleName |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
abstract public function getEmailsFields(?string $searchModuleName = null): array; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Find related records. |
94
|
|
|
* |
95
|
|
|
* @param bool $onlyId |
96
|
|
|
* |
97
|
|
|
* @return int[] |
98
|
|
|
*/ |
99
|
|
|
abstract public function findRelatedRecords(bool $onlyId = false): array; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Find related records by emails. |
103
|
|
|
* |
104
|
|
|
* @return int[] |
105
|
|
|
*/ |
106
|
|
|
abstract public function findRelatedRecordsByEmail(): array; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Find related records by subject. |
110
|
|
|
* |
111
|
|
|
* @return int[] |
112
|
|
|
*/ |
113
|
|
|
abstract public function findRelatedRecordsBySubject(): array; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get exceptions. |
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
abstract public function getExceptions(): array; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Initialize with request data. |
124
|
|
|
* |
125
|
|
|
* @param \App\Request $request |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
abstract public function initFromRequest(\App\Request $request); |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get mail type. |
133
|
|
|
* 0 = Sent |
134
|
|
|
* 1 = Received |
135
|
|
|
* 2 = Internal. |
136
|
|
|
* |
137
|
|
|
* @return int |
138
|
|
|
*/ |
139
|
|
|
abstract public function getMailType(): int; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get related records. |
143
|
|
|
* |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function getRelatedRecords(): array |
147
|
|
|
{ |
148
|
|
|
$relations = []; |
149
|
|
|
$query = (new \App\Db\Query())->select(['vtiger_crmentity.crmid', 'vtiger_crmentity.setype']) |
150
|
|
|
->from('vtiger_ossmailview_relation') |
151
|
|
|
->innerJoin('vtiger_crmentity', 'vtiger_ossmailview_relation.crmid = vtiger_crmentity.crmid') |
152
|
|
|
->where(['vtiger_ossmailview_relation.ossmailviewid' => $this->getMailCrmId(), 'vtiger_crmentity.deleted' => 0]); |
153
|
|
|
$dataReader = $query->createCommand()->query(); |
154
|
|
|
while ($row = $dataReader->read()) { |
155
|
|
|
$relations[] = [ |
156
|
|
|
'id' => $row['crmid'], |
157
|
|
|
'module' => $row['setype'], |
158
|
|
|
'label' => \App\Record::getLabel($row['crmid']), |
159
|
|
|
]; |
160
|
|
|
} |
161
|
|
|
$dataReader->close(); |
162
|
|
|
return $relations; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Generation crm unique id. |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getCid(): string |
171
|
|
|
{ |
172
|
|
|
if ($this->has('cid')) { |
173
|
|
|
return $this->get('cid'); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
$cid = hash('sha256', $this->get('from_email') . '|' . $this->get('date') . '|' . $this->get('subject') . '|' . $this->get('message_id')); |
176
|
|
|
$this->set('cid', $cid); |
177
|
|
|
return $cid; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|