Skip to content

Commit 9aa611d

Browse files
committed
Merge branch 'abrefactor' into 'master'
Refactor getting addressbook entries See merge request grommunio/grommunio-sync!96
2 parents d5ffbe0 + 0c7c5a7 commit 9aa611d

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

lib/grommunio/grommunio.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ public function SendMail($sm) {
453453
// only save the outgoing in sent items folder if the mobile requests it
454454
$mapiprops[$sendMailProps["sentmailentryid"]] = $storeprops[$sendMailProps["ipmsentmailentryid"]];
455455

456-
$ab = mapi_openaddressbook($this->session);
456+
$ab = $this->getAddressbook();
457+
if (!$ab) {
458+
throw new StatusException(sprintf("Grommunio->SendMail(): unable to open addressbook: 0x%X", mapi_last_hresult()), SYNC_COMMONSTATUS_SERVERERROR);
459+
}
457460
mapi_inetmapi_imtomapi($this->session, $this->defaultstore, $ab, $mapimessage, $sm->mime, []);
458461

459462
// Set the appSeqNr so that tracking tab can be updated for meeting request updates
@@ -1208,28 +1211,22 @@ public function SupportsType($searchtype) {
12081211
public function GetGALSearchResults($searchquery, $searchrange, $searchpicture) {
12091212
// only return users whose displayName or the username starts with $name
12101213
// TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT
1211-
$addrbook = $this->getAddressbook();
1212-
// FIXME: create a function to get the adressbook contentstable
1213-
if ($addrbook) {
1214-
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
1215-
}
1216-
if ($ab_entryid) {
1217-
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
1218-
}
1214+
$table = null;
1215+
$ab_dir = $this->getAddressbookDir();
12191216
if ($ab_dir) {
12201217
$table = mapi_folder_getcontentstable($ab_dir);
12211218
}
12221219

12231220
if (!$table) {
1224-
throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED);
1221+
throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not open addressbook: 0x%08X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED);
12251222
}
12261223

12271224
$restriction = MAPIUtils::GetSearchRestriction($searchquery);
12281225
mapi_table_restrict($table, $restriction);
12291226
mapi_table_sort($table, [PR_DISPLAY_NAME => TABLE_SORT_ASCEND]);
12301227

12311228
if (mapi_last_hresult()) {
1232-
throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX);
1229+
throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not apply restriction: 0x%08X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX);
12331230
}
12341231

12351232
// range for the search results, default symbian range end is 50, wm 99,
@@ -2697,16 +2694,12 @@ private function resolveRecipient($to, $maxAmbiguousRecipients, $expandDistlist
26972694
*/
26982695
private function resolveRecipientGAL($to, $maxAmbiguousRecipients, $expandDistlist = true) {
26992696
SLog::Write(LOGLEVEL_WBXML, sprintf("Grommunio->resolveRecipientGAL(): Resolving recipient '%s' in GAL", $to));
2697+
$table = null;
27002698
$addrbook = $this->getAddressbook();
2701-
// FIXME: create a function to get the adressbook contentstable
2702-
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
2703-
if ($ab_entryid) {
2704-
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
2705-
}
2699+
$ab_dir = $this->getAddressbookDir();
27062700
if ($ab_dir) {
27072701
$table = mapi_folder_getcontentstable($ab_dir);
27082702
}
2709-
27102703
if (!$table) {
27112704
SLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->resolveRecipientGAL(): Unable to open addressbook:0x%X", mapi_last_hresult()));
27122705

@@ -3024,6 +3017,28 @@ private function getAddressbook() {
30243017
return $this->addressbook;
30253018
}
30263019

3020+
/**
3021+
* Returns the adressbook dir entry
3022+
*
3023+
* @access private
3024+
*
3025+
* @return mixed addressbook dir entry or false on error
3026+
*/
3027+
private function getAddressbookDir() {
3028+
try {
3029+
$addrbook = $this->getAddressbook();
3030+
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
3031+
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
3032+
3033+
return $ab_dir;
3034+
}
3035+
catch (MAPIException $e) {
3036+
SLog::Write(LOGLEVEL_ERROR, sprintf("Grommunio->getAddressbookDir(): Unable to open addressbook: %s", $e));
3037+
}
3038+
3039+
return false;
3040+
}
3041+
30273042
/**
30283043
* Checks if the user is not disabled for grommunio-sync.
30293044
*

0 commit comments

Comments
 (0)