|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Mail Module |
|
4
|
|
|
*/ |
|
5
|
|
|
class MailListModule extends ListModule |
|
6
|
|
|
{ |
|
7
|
|
|
// Temporary var to store the inbox entryid of the processed store |
|
8
|
|
|
private $_inboxEntryId; |
|
9
|
|
|
|
|
10
|
|
|
private $_inbox = NULL; |
|
11
|
|
|
|
|
12
|
|
|
private $_inboxTotal = NULL; |
|
13
|
|
|
|
|
14
|
|
|
private $_inboxTotalUnread = NULL; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Constructor |
|
18
|
|
|
* @param int $id unique id. |
|
19
|
|
|
* @param array $data list of all actions. |
|
20
|
|
|
*/ |
|
21
|
|
|
function __construct($id, $data) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct($id, $data); |
|
24
|
|
|
$this->properties = $GLOBALS["properties"]->getMailListProperties(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Creates the notifiers for this module, |
|
29
|
|
|
* and register them to the Bus. |
|
30
|
|
|
*/ |
|
31
|
|
|
function createNotifiers() |
|
32
|
|
|
{ |
|
33
|
|
|
$entryid = $this->getEntryID(); |
|
34
|
|
|
$GLOBALS["bus"]->registerNotifier('maillistnotifier', $entryid); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Executes all the actions in the $data variable. |
|
39
|
|
|
* @return boolean true on success of false on fialure. |
|
40
|
|
|
*/ |
|
41
|
|
|
function execute() |
|
42
|
|
|
{ |
|
43
|
|
|
$GLOBALS['PluginManager']->triggerHook("server.module.maillistmodule.execute.before", array('moduleObject' =>& $this)); |
|
44
|
|
|
|
|
45
|
|
|
foreach($this->data as $actionType => $action) |
|
46
|
|
|
{ |
|
47
|
|
|
if(isset($actionType)) { |
|
48
|
|
|
try { |
|
49
|
|
|
$this->store = $this->getActionStore($action); |
|
|
|
|
|
|
50
|
|
|
$entryid = $this->getActionEntryID($action); |
|
51
|
|
|
|
|
52
|
|
|
// Reset variables |
|
53
|
|
|
$this->_inbox = NULL; |
|
54
|
|
|
$this->_inboxEntryId = NULL; |
|
55
|
|
|
$this->_inboxTotal = NULL; |
|
56
|
|
|
$this->_inboxTotalUnread = NULL; |
|
57
|
|
|
|
|
58
|
|
|
$this->currentActionData = array( |
|
|
|
|
|
|
59
|
|
|
'store' => $this->store, |
|
60
|
|
|
'entryid' => $entryid, |
|
61
|
|
|
'actionType' => $actionType, |
|
62
|
|
|
'action' => $action, |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
switch($actionType) |
|
66
|
|
|
{ |
|
67
|
|
|
case "list": |
|
68
|
|
|
case "updatelist": |
|
69
|
|
|
$this->getDelegateFolderInfo($this->store); |
|
70
|
|
|
$this->messageList($this->store, $entryid, $action, $actionType); |
|
|
|
|
|
|
71
|
|
|
break; |
|
72
|
|
|
case "search": |
|
73
|
|
|
// @FIXME add handling for private items |
|
74
|
|
|
$this->search($this->store, $entryid, $action, $actionType); |
|
75
|
|
|
break; |
|
76
|
|
|
case "updatesearch": |
|
77
|
|
|
$this->updatesearch($this->store, $entryid, $action); |
|
78
|
|
|
break; |
|
79
|
|
|
case "stopsearch": |
|
80
|
|
|
$this->stopSearch($this->store, $entryid, $action); |
|
81
|
|
|
break; |
|
82
|
|
|
default: |
|
83
|
|
|
$this->handleUnknownActionType($actionType); |
|
84
|
|
|
} |
|
85
|
|
|
} catch (MAPIException $e) { |
|
86
|
|
|
$this->processException($e, $actionType); |
|
87
|
|
|
} catch (SearchException $e) { |
|
88
|
|
|
$this->processException($e, $actionType); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
$GLOBALS['PluginManager']->triggerHook("server.module.maillistmodule.execute.after", array('moduleObject' =>& $this)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns the Inbox folder of the currently used store if found, NULL otherwise |
|
97
|
|
|
* |
|
98
|
|
|
* @return Resource The inbox folder of the currently used store |
|
99
|
|
|
*/ |
|
100
|
|
|
function getInbox() { |
|
101
|
|
|
if ($this->_inbox === NULL) { |
|
102
|
|
|
try { |
|
103
|
|
|
$this->_inbox = mapi_msgstore_getreceivefolder($this->store); |
|
104
|
|
|
} catch (MAPIException $e) { |
|
105
|
|
|
// don't propagate this error to parent handlers, if store doesn't support it |
|
106
|
|
|
if($e->getCode() === MAPI_E_NO_SUPPORT) { |
|
107
|
|
|
$e->setHandled(); |
|
108
|
|
|
return NULL; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this->_inbox; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Returns the entryid of the Inbox folder of the currently used store if found, false otherwise |
|
118
|
|
|
* |
|
119
|
|
|
* @return String hexamdecimal representation of the entryid of the Inbox |
|
120
|
|
|
*/ |
|
121
|
|
|
function getInboxEntryId() { |
|
122
|
|
|
if ($this->_inboxEntryId === NULL) { |
|
123
|
|
|
$inbox = $this->getInbox(); |
|
124
|
|
|
try { |
|
125
|
|
|
$inboxProps = mapi_getprops($inbox, array(PR_ENTRYID)); |
|
126
|
|
|
$this->_inboxEntryId = bin2hex($inboxProps[PR_ENTRYID]); |
|
127
|
|
|
} catch (MAPIException $e) { |
|
128
|
|
|
// don't propagate this error to parent handlers, if store doesn't support it |
|
129
|
|
|
if($e->getCode() === MAPI_E_NO_SUPPORT) { |
|
130
|
|
|
$e->setHandled(); |
|
131
|
|
|
return false; |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return $this->_inboxEntryId; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Returns the total number of items in the Inbox of the currently used store |
|
141
|
|
|
* |
|
142
|
|
|
* @return Integer the number if items in the Inbox folder |
|
143
|
|
|
*/ |
|
144
|
|
|
function getInboxTotal($force = false) { |
|
145
|
|
|
if ($this->_inboxTotal === NULL || $force) { |
|
146
|
|
|
$inbox = $this->getInbox(); |
|
147
|
|
|
$contentcount = mapi_getprops($inbox, array(PR_CONTENT_COUNT, PR_CONTENT_UNREAD)); |
|
148
|
|
|
$this->_inboxTotal = $contentcount[PR_CONTENT_COUNT]; |
|
149
|
|
|
$this->_inboxTotalUnread = $contentcount[PR_CONTENT_UNREAD]; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return $this->_inboxTotal; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Returns the number of unread items in the Inbox of the currently used store. |
|
157
|
|
|
* |
|
158
|
|
|
* @return Integer the numer of unread items in the Inbox folder |
|
159
|
|
|
*/ |
|
160
|
|
|
function getInboxTotalUnread($force = false) { |
|
161
|
|
|
if ($this->_inboxTotalUnread === NULL || $force) { |
|
162
|
|
|
$this->getIboxTotal($force); |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return $this->_inboxTotalUnread; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Function does customization of exception based on module data. |
|
170
|
|
|
* like, here it will generate display message based on actionType |
|
171
|
|
|
* for particular exception. |
|
172
|
|
|
* |
|
173
|
|
|
* @param object $e Exception object |
|
174
|
|
|
* @param string $actionType the action type, sent by the client |
|
175
|
|
|
* @param MAPIobject $store Store object of the current user. |
|
|
|
|
|
|
176
|
|
|
* @param string $parententryid parent entryid of the message. |
|
177
|
|
|
* @param string $entryid entryid of the message. |
|
178
|
|
|
* @param array $action the action data, sent by the client |
|
179
|
|
|
*/ |
|
180
|
|
|
function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) |
|
181
|
|
|
{ |
|
182
|
|
|
if(is_null($e->displayMessage)) { |
|
183
|
|
|
switch($actionType) |
|
184
|
|
|
{ |
|
185
|
|
|
case "list": |
|
186
|
|
|
if($e->getCode() == MAPI_E_NO_ACCESS) |
|
187
|
|
|
$e->setDisplayMessage(_("You have insufficient privileges to see the contents of this folder.")); |
|
188
|
|
|
else |
|
189
|
|
|
$e->setDisplayMessage(_("Could not load the contents of this folder.")); |
|
190
|
|
|
break; |
|
191
|
|
|
|
|
192
|
|
|
case "search": |
|
193
|
|
|
if($e->getCode() == MAPI_E_NO_ACCESS) |
|
194
|
|
|
$e->setDisplayMessage(_("You have insufficient privileges to perform search operation in this folder.")); |
|
195
|
|
|
else |
|
196
|
|
|
$e->setDisplayMessage(_("Error in search, please try again")); |
|
197
|
|
|
break; |
|
198
|
|
|
|
|
199
|
|
|
case "updatesearch": |
|
200
|
|
|
$e->setDisplayMessage(_("Could not update search results.")); |
|
201
|
|
|
break; |
|
202
|
|
|
|
|
203
|
|
|
case "stopsearch": |
|
204
|
|
|
$e->setDisplayMessage(_("Could not stop search operation.")); |
|
205
|
|
|
break; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
parent::handleException($e, $actionType, $store, $parententryid, $entryid, $action); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Parses the incoming sort request and builds a MAPI sort order. |
|
214
|
|
|
* Overridden to rewrite the sorting for flags. (because the flags that are shown in grommunio Web |
|
215
|
|
|
* are a combination of several properties) |
|
216
|
|
|
* |
|
217
|
|
|
* @param array $action the action data, sent by the client |
|
218
|
|
|
* @param array|bool $map Normally properties are mapped from the XML to MAPI by the standard |
|
219
|
|
|
* $this->properties mapping. However, if you want other mappings, you can specify them in this parameter. |
|
220
|
|
|
* @param bool $allow_multi_instance Sort as multi-value instance (every value a different row) |
|
221
|
|
|
* @param array|bool a custom set of properties to use instead of the properties stored in module |
|
222
|
|
|
*/ |
|
223
|
|
|
function parseSortOrder($action, $map = false, $allow_multi_instance = false, $properties = false) |
|
224
|
|
|
{ |
|
225
|
|
|
if(isset($action['sort'])) { |
|
226
|
|
|
// Check if the user wants to sort the maillist on flags. |
|
227
|
|
|
// If so, we will rewrite the sorting a little |
|
228
|
|
|
if ( is_array($action['sort']) && count($action['sort'])>0 && $action['sort'][0]['field'] === 'flag_due_by' ) { |
|
229
|
|
|
$dir = $action['sort'][0]['direction']; |
|
230
|
|
|
$action['sort'] = array( |
|
231
|
|
|
array( |
|
232
|
|
|
'field' => 'flag_status', |
|
233
|
|
|
'direction' => $dir, |
|
234
|
|
|
), |
|
235
|
|
|
array( |
|
236
|
|
|
'field' => 'duedate', |
|
237
|
|
|
'direction' => $dir === 'ASC' ? 'DESC' : 'ASC', |
|
238
|
|
|
), |
|
239
|
|
|
array( |
|
240
|
|
|
'field' => 'flag_due_by', |
|
241
|
|
|
'direction' => $dir, |
|
242
|
|
|
), |
|
243
|
|
|
); |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
parent::parseSortOrder($action, $map, $allow_multi_instance, $properties); |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
?> |
|
|
|
|
|
|
251
|
|
|
|