Skip to content

Commit

Permalink
Merge branch 'master' into horde_5_2
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 1, 2013
2 parents 2ed01e1 + 07cda3e commit a4d2110
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 20 deletions.
Expand Up @@ -166,7 +166,8 @@ public function sendNextChange()
$change['id'],
$folder->parentid,
$folder->displayname,
$folder->_serverid);
$folder->_serverid,
$folder->type);
$this->folderChange($folder);
} else {
$this->_logger->err(sprintf(
Expand Down
88 changes: 76 additions & 12 deletions framework/ActiveSync/lib/Horde/ActiveSync/Driver/Base.php
Expand Up @@ -85,6 +85,14 @@ abstract class Horde_ActiveSync_Driver_Base
*/
protected $_tempMap = array();

protected $_typeMap = array(
'F' => Horde_ActiveSync::CLASS_EMAIL,
'C' => Horde_ActiveSync::CLASS_CONTACTS,
'A' => Horde_ActiveSync::CLASS_CALENDAR,
'T' => Horde_ActiveSync::CLASS_TASKS,
'N' => Horde_ActiveSync::CLASS_NOTES
);

/**
* Const'r
*
Expand Down Expand Up @@ -350,29 +358,85 @@ static public function buildFbString($fb, Horde_Date $start, Horde_Date $end)
* serverid before, return the previously created uid, otherwise return
* a new one.
*
* @param string $imap The imap server's folder name E.g., INBOX
*
* @return string A UUID to be used by activesync to represent the folder.
* @param string $id The server's folder name E.g., INBOX
* @param string $type The folder type, a Horde_ActiveSync::FOLDER_TYPE_*
* constant. If empty, assumes FOLDER_TYPE_USER_MAIL
*
* @return string A unique identifier for the specified backend folder id.
* The first character indicates the foldertype as such:
* 'F' - Email
* 'C' - Contact
* 'A' - Appointment
* 'T' - Task
* 'N' - Note
* @since 2.4.0
*/
protected function _getFolderUidForBackendId($imap)
protected function _getFolderUidForBackendId($id, $type = null)
{
$map = $this->_state->getFolderUidToBackendIdMap();
if (!empty($map[$imap])) {
return $map[$imap];
} elseif (!empty($this->_tempMap[$imap])) {
return $this->_tempMap[$imap];
if (!empty($map[$id])) {
return $map[$id];
} elseif (!empty($this->_tempMap[$id])) {
return $this->_tempMap[$id];
}

// Convert TYPE to CLASS
$type = $this->_getClassFromType($type);
$rMap = array_flip($this->_typeMap);
$prefix = $rMap[$type];

// None found, generate a new UID.
$this->_tempMap[$imap] = sprintf('F%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff));
$this->_tempMap[$id] = sprintf('%s%04x%04x', $prefix, mt_rand(0, 0xffff), mt_rand(0, 0xffff));
$this->_logger->info(sprintf(
'[%s] Creating new folder uuid for %s: %s',
getmypid(),
$imap,
$this->_tempMap[$imap]));
$id,
$this->_tempMap[$id]));

return $this->_tempMap[$id];
}

/**
* Convert a TYPE constant into it's associated CLASS constant.
*
* @param integer $type The TYPE.
*
* @return string The CLASS
*/
protected function _getClassFromType($type)
{
// @todo This is for BC. Assume we are asking for an email collection
// if we didn't pass a type. Remove in H6.
if (empty($type)) {
return Horde_ActiveSync::CLASS_EMAIL;
}

switch ($type) {
case Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT:
case Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT:
return Horde_ActiveSync::CLASS_CALENDAR;

case Horde_ActiveSync::FOLDER_TYPE_CONTACT:
case Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT:
return Horde_ActiveSync::CLASS_CONTACTS;

return $this->_tempMap[$imap];
case Horde_ActiveSync::FOLDER_TYPE_TASK:
case Horde_ActiveSync::FOLDER_TYPE_USER_TASK:
return Horde_ActiveSync::CLASS_TASKS;

case Horde_ActiveSync::FOLDER_TYPE_NOTE:
case Horde_ActiveSync::FOLDER_TYPE_USER_NOTE:
return Horde_ActiveSync::CLASS_NOTES;

case Horde_ActiveSync::FOLDER_TYPE_INBOX:
case Horde_ActiveSync::FOLDER_TYPE_DRAFTS:
case Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET:
case Horde_ActiveSync::FOLDER_TYPE_SENTMAIL:
case Horde_ActiveSync::FOLDER_TYPE_OUTBOX:
case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL:
return Horde_ActiveSync::CLASS_EMAIL;

}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Folder/Imap.php
Expand Up @@ -377,7 +377,7 @@ public function serialize()
* @throws Horde_ActiveSync_Exception_StaleState
*/
public function unserialize($data)
{ $data = json_decode($data, true, 512, JSON_BIGINT_AS_STRING);
{ $data = json_decode($data, true);
if (!is_array($data) || empty($data['v']) || $data['v'] != self::VERSION) {
throw new Horde_ActiveSync_Exception_StaleState('Cache version change');
}
Expand Down
5 changes: 3 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/State/Mongo.php
Expand Up @@ -486,7 +486,8 @@ public function updateState(
$value['id'],
(empty($value['parent']) ? '0' : $value['parent']),
$folder->displayname,
$folder->_serverid);
$folder->_serverid,
$folder->type);
$this->_folder[] = $stat;
$this->_folder = array_values($this->_folder);
}
Expand Down Expand Up @@ -1341,7 +1342,7 @@ protected function _getMailMapChanges(array $changes)
continue 2;
} elseif ($change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) {
$results[$row['message_uid']][$change['type']] =
!is_null($row['sync_deleted']) && $row['sync_deleted'] == $change['flags']['deleted'];
!is_null($row['sync_deleted']) && $row['sync_deleted'] == true;
continue 2;
}
}
Expand Down
7 changes: 4 additions & 3 deletions framework/ActiveSync/lib/Horde/ActiveSync/State/Sql.php
Expand Up @@ -494,7 +494,8 @@ public function updateState(
$value['id'],
(empty($value['parent']) ? '0' : $value['parent']),
$folder->displayname,
$folder->_serverid);
$folder->_serverid,
$folder->type);
$this->_folder[] = $stat;
$this->_folder = array_values($this->_folder);
}
Expand Down Expand Up @@ -1193,7 +1194,7 @@ protected function _havePIMChanges()
/**
* Return all available mailMap changes for the current folder.
*
* @param array $changes The chagnes array
* @param array $changes The changes array
*
* @return array An array of hashes, each in the form of
* {uid} => array(
Expand Down Expand Up @@ -1236,7 +1237,7 @@ protected function _getMailMapChanges(array $changes)
continue 2;
} elseif ($change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) {
$results[$row['message_uid']][$change['type']] =
!is_null($row['sync_deleted']) && $row['sync_deleted'] == $change['flags']['deleted'];
!is_null($row['sync_deleted']) && $row['sync_deleted'] == true;
continue 2;
}
}
Expand Down
2 changes: 2 additions & 0 deletions framework/ActiveSync/package.xml
Expand Up @@ -21,6 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mjr] Changes to support multiple non-email collections of the same type.
* [mjr] Improvements to memory and database usage.
* [mjr] Add MongoDB state driver.
</notes>
Expand Down Expand Up @@ -1804,6 +1805,7 @@
<date>2013-10-22</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mjr] Changes to support multiple non-email collections of the same type.
* [mjr] Improvements to memory and database usage.
* [mjr] Add MongoDB state driver.
</notes>
Expand Down
2 changes: 1 addition & 1 deletion framework/Core/lib/Horde/ErrorHandler.php
Expand Up @@ -60,7 +60,7 @@ static public function fatal($error)
* issues on the login page since we would otherwise need
* to do session token checking (which might not be
* available, so logout won't happen, etc...) */
if (array_key_exists($params, 'app')) {
if (array_key_exists('app', $params)) {
$registry->clearAuth();
}

Expand Down
17 changes: 17 additions & 0 deletions imp/lib/Application.php
Expand Up @@ -120,6 +120,10 @@ protected function _bootstrap()
if (empty($injector->getInstance('IMP_Imap')->config->admin)) {
$this->auth = array_diff($this->auth, array('add', 'list', 'remove'));
}

/* Set exception handler to handle uncaught
* Horde_Imap_Client_Exceptions. */
set_exception_handler(array($this, 'exceptionHandler'));
}

/**
Expand Down Expand Up @@ -569,4 +573,17 @@ public function download(Horde_Variables $vars)
return array();
}

/* Exception handler. */

/**
*/
public function exceptionHandler(Exception $e)
{
if ($e instanceof Horde_Imap_Client_Exception) {
$e = new Horde_Exception_AuthenticationFailure($e->getMessage(), Horde_Auth::REASON_MESSAGE);
}

Horde_ErrorHandler::fatal($e);
}

}

0 comments on commit a4d2110

Please sign in to comment.