|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
|
5
|
|
|
* SPDX-FileCopyrightText: Copyright 2016 - 2018 Kopano b.v. |
|
6
|
|
|
* SPDX-FileCopyrightText: Copyright 2020 - 2025 grommunio GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* PHP wrapper class for ICS. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace grommunio\DAV; |
|
12
|
|
|
|
|
13
|
|
|
class PHPWrapper { |
|
14
|
|
|
private $store; |
|
15
|
|
|
private $logger; |
|
16
|
|
|
private $props; |
|
17
|
|
|
private $fileext; |
|
18
|
|
|
private $added; |
|
19
|
|
|
private $modified; |
|
20
|
|
|
private $deleted; |
|
21
|
|
|
private $syncstate; |
|
22
|
|
|
private $folderid; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param mixed $store |
|
28
|
|
|
* @param GLogger $logger |
|
29
|
|
|
* @param mixed $props |
|
30
|
|
|
* @param string $fileext |
|
31
|
|
|
* @param GrommunioSyncState $syncstate |
|
32
|
|
|
* @param string $folderid |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct($store, $logger, $props, $fileext, $syncstate, $folderid) { |
|
35
|
|
|
$this->store = $store; |
|
36
|
|
|
$this->logger = $logger; |
|
37
|
|
|
$this->props = $props; |
|
38
|
|
|
$this->fileext = $fileext; |
|
39
|
|
|
$this->syncstate = $syncstate; |
|
40
|
|
|
$this->folderid = $folderid; |
|
41
|
|
|
|
|
42
|
|
|
$this->added = []; |
|
43
|
|
|
$this->modified = []; |
|
44
|
|
|
$this->deleted = []; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Accessor for $this->added. |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public function GetAdded() { |
|
53
|
|
|
return $this->added; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Accessor for $this->modified. |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
public function GetModified() { |
|
62
|
|
|
return $this->modified; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Accessor for $this->deleted. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function GetDeleted() { |
|
71
|
|
|
return $this->deleted; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns total changes. |
|
76
|
|
|
* |
|
77
|
|
|
* @return int |
|
78
|
|
|
*/ |
|
79
|
|
|
public function Total() { |
|
80
|
|
|
return count($this->added) + count($this->modified) + count($this->deleted); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Imports a single message. |
|
85
|
|
|
* |
|
86
|
|
|
* @param array $props |
|
87
|
|
|
* @param int $flags |
|
88
|
|
|
* @param object $retmapimessage |
|
89
|
|
|
* |
|
90
|
|
|
* @return int |
|
91
|
|
|
*/ |
|
92
|
|
|
public function ImportMessageChange($props, $flags, $retmapimessage) { |
|
93
|
|
|
$entryid = $props[PR_ENTRYID] ?? null; |
|
|
|
|
|
|
94
|
|
|
// if the entryid is not available, do the fallback to the sourcekey |
|
95
|
|
|
if (!$entryid && isset($props[PR_SOURCE_KEY], $props[PR_PARENT_SOURCE_KEY])) { |
|
|
|
|
|
|
96
|
|
|
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, $props[PR_PARENT_SOURCE_KEY], $props[PR_SOURCE_KEY]); |
|
97
|
|
|
} |
|
98
|
|
|
$mapimessage = mapi_msgstore_openentry($this->store, $entryid); |
|
99
|
|
|
$messageProps = mapi_getprops($mapimessage, [PR_SOURCE_KEY, $this->props["goid"]]); |
|
100
|
|
|
|
|
101
|
|
|
$url = null; |
|
102
|
|
|
if (isset($messageProps[$this->props["goid"]])) { |
|
103
|
|
|
// get uid from goid and check if it's a valid one |
|
104
|
|
|
$url = getUidFromGoid($messageProps[$this->props["goid"]]); |
|
|
|
|
|
|
105
|
|
|
if ($url != null) { |
|
106
|
|
|
$this->logger->trace("got %s (goid: %s uid: %s), flags: %d", bin2hex($messageProps[PR_SOURCE_KEY]), bin2hex($messageProps[$this->props["goid"]]), $url, $flags); |
|
107
|
|
|
$this->syncstate->rememberAppttsref($this->folderid, bin2hex($messageProps[PR_SOURCE_KEY]), $url); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
if (!$url) { |
|
111
|
|
|
$this->logger->trace("got %s (PR_SOURCE_KEY), flags: %d", bin2hex($messageProps[PR_SOURCE_KEY]), $flags); |
|
112
|
|
|
$url = bin2hex($messageProps[PR_SOURCE_KEY]); |
|
113
|
|
|
} |
|
114
|
|
|
$url = rawurlencode($url); |
|
115
|
|
|
|
|
116
|
|
|
if ($flags == SYNC_NEW_MESSAGE) { |
|
|
|
|
|
|
117
|
|
|
$this->added[] = $url . $this->fileext; |
|
118
|
|
|
} |
|
119
|
|
|
else { |
|
120
|
|
|
$this->modified[] = $url . $this->fileext; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return SYNC_E_IGNORE; |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Imports a list of messages to be deleted. |
|
128
|
|
|
* |
|
129
|
|
|
* @param int $flags |
|
130
|
|
|
* @param array $sourcekeys array with sourcekeys |
|
131
|
|
|
*/ |
|
132
|
|
|
public function ImportMessageDeletion($flags, $sourcekeys) { |
|
133
|
|
|
foreach ($sourcekeys as $sourcekey) { |
|
134
|
|
|
$this->logger->trace("got %s", bin2hex($sourcekey)); |
|
135
|
|
|
$appttsref = $this->syncstate->getAppttsref($this->folderid, bin2hex($sourcekey)); |
|
136
|
|
|
if ($appttsref !== null) { |
|
137
|
|
|
$this->deleted[] = $appttsref . $this->fileext; |
|
138
|
|
|
} |
|
139
|
|
|
else { |
|
140
|
|
|
$this->deleted[] = bin2hex($sourcekey) . $this->fileext; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** Implement MAPI interface */ |
|
146
|
|
|
public function Config($stream, $flags = 0) {} |
|
147
|
|
|
|
|
148
|
|
|
public function GetLastError($hresult, $ulflags, &$lpmapierror) {} |
|
149
|
|
|
|
|
150
|
|
|
public function UpdateState($stream) {} |
|
151
|
|
|
|
|
152
|
|
|
public function ImportMessageMove($sourcekeysrcfolder, $sourcekeysrcmessage, $message, $sourcekeydestmessage, $changenumdestmessage) {} |
|
153
|
|
|
|
|
154
|
|
|
public function ImportPerUserReadStateChange($readstates) {} |
|
155
|
|
|
|
|
156
|
|
|
public function ImportFolderChange($props) { |
|
157
|
|
|
return 0; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function ImportFolderDeletion($flags, $sourcekeys) { |
|
161
|
|
|
return 0; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|