2010-12-02 09:46:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware: ActiveSync access: Addressbook plugin
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package addressbook
|
|
|
|
* @subpackage activesync
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @author Klaus Leithoff <kl@stylite.de>
|
|
|
|
* @author Philip Herbert <philip@knauber.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2010-12-02 09:59:05 +01:00
|
|
|
* @version $Id$
|
2010-12-02 09:46:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Addressbook activesync plugin
|
|
|
|
*/
|
2010-12-06 11:04:29 +01:00
|
|
|
class addressbook_activesync implements activesync_plugin_write, activesync_plugin_search_gal
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
/**
|
2010-12-02 14:03:52 +01:00
|
|
|
* @var BackendEGW
|
2010-12-02 09:46:20 +01:00
|
|
|
*/
|
|
|
|
private $backend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instance of addressbook_bo
|
|
|
|
*
|
2010-12-02 14:03:52 +01:00
|
|
|
* @var addressbook_bo
|
2010-12-02 09:46:20 +01:00
|
|
|
*/
|
|
|
|
private $addressbook;
|
|
|
|
|
2010-12-06 11:04:29 +01:00
|
|
|
/**
|
|
|
|
* Mapping of ActiveSync SyncContact attributes to EGroupware contact array-keys
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-12-02 14:03:52 +01:00
|
|
|
static public $mapping = array(
|
2010-12-06 11:04:29 +01:00
|
|
|
//'anniversary' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'assistantname' => 'assistent',
|
|
|
|
'assistnamephonenumber' => 'tel_assistent',
|
|
|
|
'birthday' => 'bday',
|
|
|
|
'body' => 'note',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'bodysize' => '',
|
|
|
|
//'bodytruncated' => '',
|
|
|
|
//'business2phonenumber' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'businesscity' => 'adr_one_locality',
|
|
|
|
'businesscountry' => 'adr_one_countryname',
|
|
|
|
'businesspostalcode' => 'adr_one_postalcode',
|
2010-12-02 15:14:14 +01:00
|
|
|
'businessstate' => 'adr_one_region',
|
2010-12-02 14:03:52 +01:00
|
|
|
'businessstreet' => 'adr_one_street',
|
|
|
|
'businessfaxnumber' => 'tel_fax',
|
|
|
|
'businessphonenumber' => 'tel_work',
|
|
|
|
'carphonenumber' => 'tel_car',
|
2010-12-02 20:42:03 +01:00
|
|
|
'categories' => 'cat_id',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'children' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'companyname' => 'org_name',
|
|
|
|
'department' => 'org_unit',
|
|
|
|
'email1address' => 'email',
|
|
|
|
'email2address' => 'email_home',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'email3address' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'fileas' => 'n_fileas',
|
|
|
|
'firstname' => 'n_given',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'home2phonenumber' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'homecity' => 'adr_two_locality',
|
|
|
|
'homecountry' => 'adr_two_countryname',
|
|
|
|
'homepostalcode' => 'adr_two_postalcode',
|
2010-12-02 15:14:14 +01:00
|
|
|
'homestate' => 'adr_two_region',
|
2010-12-02 14:03:52 +01:00
|
|
|
'homestreet' => 'adr_two_street',
|
|
|
|
'homefaxnumber' => 'tel_fax_home',
|
|
|
|
'homephonenumber' => 'tel_home',
|
|
|
|
'jobtitle' => 'role',
|
|
|
|
'lastname' => 'n_family',
|
|
|
|
'middlename' => 'n_middle',
|
|
|
|
'mobilephonenumber' => 'tel_cell',
|
|
|
|
'officelocation' => 'room',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'othercity' => '',
|
|
|
|
//'othercountry' => '',
|
|
|
|
//'otherpostalcode' => '',
|
|
|
|
//'otherstate' => '',
|
|
|
|
//'otherstreet' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'pagernumber' => 'tel_pager',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'radiophonenumber' => '',
|
|
|
|
//'spouse' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'suffix' => 'n_suffix',
|
|
|
|
'title' => 'title', // @TODO: check if n_prefix
|
|
|
|
'webpage' => 'url',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'yomicompanyname' => '',
|
|
|
|
//'yomifirstname' => '',
|
|
|
|
//'yomilastname' => '',
|
|
|
|
//'rtf' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
'picture' => 'jpegphoto',
|
2010-12-06 11:04:29 +01:00
|
|
|
//'nickname' => '',
|
|
|
|
//'airsyncbasebody' => '',
|
2010-12-02 14:03:52 +01:00
|
|
|
);
|
|
|
|
|
2010-12-02 09:46:20 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param BackendEGW $backend
|
|
|
|
*/
|
|
|
|
public function __construct(BackendEGW $backend)
|
|
|
|
{
|
|
|
|
$this->backend = $backend;
|
|
|
|
}
|
|
|
|
|
2010-12-02 14:03:52 +01:00
|
|
|
/**
|
|
|
|
* Get addressbooks (no extra private one and do some caching)
|
|
|
|
*
|
|
|
|
* @param int $account=null account_id of addressbook or null to get array of all addressbooks
|
|
|
|
* @return string|array addressbook name of array with int account_id => label pairs
|
|
|
|
*/
|
|
|
|
private function get_addressbooks($account=null)
|
|
|
|
{
|
|
|
|
static $abs;
|
|
|
|
|
|
|
|
if (!isset($abs))
|
|
|
|
{
|
|
|
|
translation::add_app('addressbook'); // we need the addressbook translations
|
|
|
|
|
|
|
|
if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['private_addressbook'])
|
|
|
|
{
|
|
|
|
unset($GLOBALS['egw_info']['user']['preferences']['addressbook']['private_addressbook']);
|
|
|
|
if (isset($this->addressbook)) $this->addressbook->private_addressbook = false;
|
|
|
|
}
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
|
|
|
$abs = $this->addressbook->get_addressbooks(EGW_ACL_READ);
|
|
|
|
}
|
|
|
|
return is_null($account) ? $abs : $abs[$account];
|
|
|
|
}
|
2010-12-02 09:46:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is analogous to GetMessageList.
|
|
|
|
*
|
|
|
|
* @ToDo implement preference, include own private calendar
|
|
|
|
*/
|
|
|
|
public function GetFolderList()
|
|
|
|
{
|
|
|
|
// error_log(print_r($this->addressbook->get_addressbooks(EGW_ACL_READ),true));
|
|
|
|
|
2010-12-02 14:03:52 +01:00
|
|
|
foreach ($this->get_addressbooks() as $account => $label)
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
2010-12-02 14:03:52 +01:00
|
|
|
$folderlist[] = array(
|
|
|
|
'id' => $this->backend->createID('addressbook',$account),
|
2010-12-02 09:46:20 +01:00
|
|
|
'mod' => $label,
|
|
|
|
'parent'=> '0',
|
|
|
|
);
|
|
|
|
};
|
2010-12-06 11:04:29 +01:00
|
|
|
debugLog(__METHOD__."() returning ".array2string($folderlist));
|
2010-12-02 20:42:03 +01:00
|
|
|
//error_log(__METHOD__."() returning ".array2string($folderlist));
|
2010-12-02 09:46:20 +01:00
|
|
|
return $folderlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Information about a folder
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return SyncFolder|boolean false on error
|
|
|
|
*/
|
|
|
|
public function GetFolder($id)
|
|
|
|
{
|
|
|
|
$this->backend->splitID($id, $type, $owner);
|
|
|
|
|
|
|
|
$folderObj = new SyncFolder();
|
|
|
|
$folderObj->serverid = $id;
|
|
|
|
$folderObj->parentid = '0';
|
2010-12-02 14:03:52 +01:00
|
|
|
$folderObj->displayname = $this->get_addressbooks($owner);
|
|
|
|
|
2010-12-02 09:46:20 +01:00
|
|
|
if ($owner == $GLOBALS['egw_info']['user']['account_id'])
|
|
|
|
{
|
|
|
|
$folderObj->type = SYNC_FOLDER_TYPE_CONTACT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$folderObj->type = SYNC_FOLDER_TYPE_USER_CONTACT;
|
|
|
|
}
|
2010-12-02 20:42:03 +01:00
|
|
|
//error_log(__METHOD__."('$id') returning ".array2string($folderObj));
|
2010-12-02 09:46:20 +01:00
|
|
|
return $folderObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return folder stats. This means you must return an associative array with the
|
|
|
|
* following properties:
|
|
|
|
*
|
|
|
|
* "id" => The server ID that will be used to identify the folder. It must be unique, and not too long
|
|
|
|
* How long exactly is not known, but try keeping it under 20 chars or so. It must be a string.
|
|
|
|
* "parent" => The server ID of the parent of the folder. Same restrictions as 'id' apply.
|
|
|
|
* "mod" => This is the modification signature. It is any arbitrary string which is constant as long as
|
|
|
|
* the folder has not changed. In practice this means that 'mod' can be equal to the folder name
|
|
|
|
* as this is the only thing that ever changes in folders. (the type is normally constant)
|
|
|
|
*
|
|
|
|
* @return array with values for keys 'id', 'mod' and 'parent'
|
|
|
|
*/
|
|
|
|
public function StatFolder($id)
|
|
|
|
{
|
|
|
|
$this->backend->splitID($id, $type, $owner);
|
|
|
|
|
|
|
|
$stat = array(
|
|
|
|
'id' => $id,
|
2010-12-02 14:03:52 +01:00
|
|
|
'mod' => $this->get_addressbooks($owner),
|
2010-12-02 09:46:20 +01:00
|
|
|
'parent' => '0',
|
|
|
|
);
|
2010-12-02 20:42:03 +01:00
|
|
|
//error_log(__METHOD__."('$id') returning ".array2string($stat));
|
2010-12-06 11:04:29 +01:00
|
|
|
debugLog(__METHOD__."('$id') returning ".array2string($stat));
|
2010-12-02 09:46:20 +01:00
|
|
|
return $stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should return a list (array) of messages, each entry being an associative array
|
|
|
|
* with the same entries as StatMessage(). This function should return stable information; ie
|
|
|
|
* if nothing has changed, the items in the array must be exactly the same. The order of
|
|
|
|
* the items within the array is not important though.
|
|
|
|
*
|
|
|
|
* The cutoffdate is a date in the past, representing the date since which items should be shown.
|
|
|
|
* This cutoffdate is determined by the user's setting of getting 'Last 3 days' of e-mail, etc. If
|
|
|
|
* you ignore the cutoffdate, the user will not be able to select their own cutoffdate, but all
|
|
|
|
* will work OK apart from that.
|
|
|
|
*
|
|
|
|
* @param string $id folder id
|
|
|
|
* @param int $cutoffdate=null
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function GetMessageList($id, $cutoffdate=NULL)
|
|
|
|
{
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
|
|
|
$this->backend->splitID($id,$type,$user);
|
2010-12-02 14:03:52 +01:00
|
|
|
$filter = array('owner' => $user);
|
2010-12-02 09:46:20 +01:00
|
|
|
|
|
|
|
$messagelist = array();
|
2010-12-06 11:04:29 +01:00
|
|
|
if (($contacts =& $this->addressbook->search($criteria,'contact_id,contact_etag',$order_by='',$extra_cols='',$wildcard='',
|
2010-12-02 15:14:14 +01:00
|
|
|
$empty=false,$op='AND',$start=false,$filter)))
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
2010-12-02 15:14:14 +01:00
|
|
|
foreach($contacts as $contact)
|
|
|
|
{
|
|
|
|
$messagelist[] = $this->StatMessage($id, $contact);
|
|
|
|
}
|
2010-12-02 09:46:20 +01:00
|
|
|
}
|
2010-12-02 20:42:03 +01:00
|
|
|
//error_log(__METHOD__."('$id') returning ".count($messagelist).' entries');
|
2010-12-02 09:46:20 +01:00
|
|
|
return $messagelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get specified item from specified folder.
|
|
|
|
*
|
|
|
|
* @param string $folderid
|
|
|
|
* @param string $id
|
|
|
|
* @param int $truncsize
|
|
|
|
* @param int $bodypreference
|
|
|
|
* @param bool $mimesupport
|
|
|
|
* @return $messageobject|boolean false on error
|
|
|
|
*/
|
|
|
|
public function GetMessage($folderid, $id, $truncsize, $bodypreference=false, $mimesupport = 0)
|
|
|
|
{
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
|
|
|
debugLog (__METHOD__."('$folderid', $id, truncsize=$truncsize, bodyprefence=$bodypreference, mimesupport=$mimesupport)");
|
|
|
|
$this->backend->splitID($folderid, $type, $account);
|
|
|
|
if ($type != 'addressbook' || !($contact = $this->addressbook->read($id)))
|
|
|
|
{
|
2010-12-02 15:14:14 +01:00
|
|
|
error_log(__METHOD__."('$folderid',$id,...) Folder wrong (type=$type, account=$account) or contact not existing (read($id)=".array2string($contact).")! returning false");
|
2010-12-02 09:46:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$message = new SyncContact();
|
2010-12-02 14:03:52 +01:00
|
|
|
foreach(self::$mapping as $key => $attr)
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
switch ($attr)
|
|
|
|
{
|
|
|
|
case 'note':
|
|
|
|
if (empty($contact[$attr])) break;
|
|
|
|
if ($bodypreference == false)
|
|
|
|
{
|
|
|
|
$message->body = $contact[$attr];
|
|
|
|
$message->bodysize = strlen($message->body);
|
|
|
|
$message->bodytruncated = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$message->airsyncbasebody = new SyncAirSyncBaseBody();
|
|
|
|
debugLog("airsyncbasebody!");
|
|
|
|
$message->airsyncbasenativebodytype=1;
|
|
|
|
$message->airsyncbasebody = new SyncAirSyncBaseBody();
|
|
|
|
if (isset($bodypreference[2]))
|
|
|
|
{
|
|
|
|
//debugLog("HTML Body");
|
|
|
|
$message->airsyncbasebody->type = 2;
|
|
|
|
$html = '<html>'.
|
|
|
|
'<head>'.
|
|
|
|
'<meta name="Generator" content="Z-Push">'.
|
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
|
|
|
|
'</head>'.
|
|
|
|
'<body>'.
|
2010-12-02 20:42:03 +01:00
|
|
|
str_replace(array("\n","\r","\r\n"),"<br />",$contact[$attr]).
|
2010-12-02 09:46:20 +01:00
|
|
|
'</body>'.
|
|
|
|
'</html>';
|
|
|
|
if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"])
|
|
|
|
{
|
|
|
|
$html = utf8_truncate($html,$bodypreference[2]["TruncationSize"]);
|
|
|
|
$message->airsyncbasebody->truncated = 1;
|
|
|
|
}
|
|
|
|
$message->airsyncbasebody->data = $html;
|
|
|
|
$message->airsyncbasebody->estimateddatasize = strlen($html);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// debugLog("Plaintext Body");
|
|
|
|
$note = str_replace("\n","\r\n",str_replace("\r","",$contact[$attr]));
|
|
|
|
$message->airsyncbasebody->type = 1;
|
|
|
|
if(isset($bodypreference[1]["TruncationSize"]) && strlen($note) > $bodypreference[1]["TruncationSize"])
|
|
|
|
{
|
|
|
|
$note = utf8_truncate($note, $bodypreference[1]["TruncationSize"]);
|
|
|
|
$message->airsyncbasebody->truncated = 1;
|
|
|
|
}
|
|
|
|
$message->airsyncbasebody->estimateddatasize = strlen($note);
|
|
|
|
$message->airsyncbasebody->data = $note;
|
|
|
|
}
|
|
|
|
if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0))
|
|
|
|
{
|
|
|
|
$message->airsyncbasebody->data = " ";
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 14:03:52 +01:00
|
|
|
break;
|
|
|
|
|
2010-12-02 09:46:20 +01:00
|
|
|
case 'jpegphoto':
|
2010-12-02 14:03:52 +01:00
|
|
|
if (!empty($contact[$attr])) $message->$key = base64_encode($contact[$attr]);
|
|
|
|
break;
|
|
|
|
|
2010-12-02 20:42:03 +01:00
|
|
|
case 'bday':
|
|
|
|
if (!empty($contact[$attr])) $message->$key = egw_time::to($contact[$attr],'ts');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cat_id':
|
|
|
|
/*$message->$key = array();
|
|
|
|
foreach($contact[$attr] ? explode(',',$contact[$attr]) : array() as $cat_id)
|
|
|
|
{
|
|
|
|
$message->categories[] = categories::id2name($cat_id);
|
|
|
|
}*/
|
|
|
|
break;
|
|
|
|
|
2010-12-02 09:46:20 +01:00
|
|
|
default:
|
|
|
|
if (!empty($contact[$attr])) $message->$key = $contact[$attr];
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 15:14:14 +01:00
|
|
|
//error_log(__METHOD__."(folder='$folderid',$id,...) returning ".array2string($message));
|
2010-12-02 09:46:20 +01:00
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* StatMessage should return message stats, analogous to the folder stats (StatFolder). Entries are:
|
|
|
|
* 'id' => Server unique identifier for the message. Again, try to keep this short (under 20 chars)
|
|
|
|
* 'flags' => simply '0' for unread, '1' for read
|
|
|
|
* 'mod' => modification signature. As soon as this signature changes, the item is assumed to be completely
|
|
|
|
* changed, and will be sent to the PDA as a whole. Normally you can use something like the modification
|
|
|
|
* time for this field, which will change as soon as the contents have changed.
|
|
|
|
*
|
|
|
|
* @param string $folderid
|
2010-12-02 14:03:52 +01:00
|
|
|
* @param int|array $contact contact id or array
|
2010-12-02 09:46:20 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2010-12-02 14:03:52 +01:00
|
|
|
public function StatMessage($folderid, $contact)
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
2010-12-02 14:03:52 +01:00
|
|
|
if (!is_array($contact)) $contact = $this->addressbook->read($contact);
|
|
|
|
|
|
|
|
if (!$contact)
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
$stat = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$stat = array(
|
2010-12-02 14:03:52 +01:00
|
|
|
'mod' => $contact['etag'],
|
|
|
|
'id' => $contact['id'],
|
2010-12-02 09:46:20 +01:00
|
|
|
'flags' => 1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
//debugLog (__METHOD__."('$folderid',".array2string($id).") returning ".array2string($stat));
|
2010-12-02 20:42:03 +01:00
|
|
|
//error_log(__METHOD__."('$folderid',$contact) returning ".array2string($stat));
|
2010-12-02 09:46:20 +01:00
|
|
|
return $stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates or modifies a folder
|
|
|
|
*
|
|
|
|
* @param $id of the parent folder
|
|
|
|
* @param $oldid => if empty -> new folder created, else folder is to be renamed
|
|
|
|
* @param $displayname => new folder name (to be created, or to be renamed to)
|
|
|
|
* @param type => folder type, ignored in IMAP
|
|
|
|
*
|
|
|
|
* @return stat | boolean false on error
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function ChangeFolder($id, $oldid, $displayname, $type)
|
|
|
|
{
|
2010-12-02 20:42:03 +01:00
|
|
|
debugLog(__METHOD__." not implemented");
|
2010-12-02 09:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes (really delete) a Folder
|
|
|
|
*
|
|
|
|
* @param $parentid of the folder to delete
|
|
|
|
* @param $id of the folder to delete
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @TODO check what is to be returned
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function DeleteFolder($parentid, $id)
|
|
|
|
{
|
|
|
|
debugLog(__METHOD__." not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes or adds a message on the server
|
|
|
|
*
|
|
|
|
* @param $folderid
|
|
|
|
* @param $id for change | empty for create new
|
|
|
|
* @param $message object to SyncObject to create
|
|
|
|
*
|
|
|
|
* @return $stat whatever would be returned from StatMessage
|
|
|
|
*
|
|
|
|
* This function is called when a message has been changed on the PDA. You should parse the new
|
|
|
|
* message here and save the changes to disk. The return value must be whatever would be returned
|
|
|
|
* from StatMessage() after the message has been saved. This means that both the 'flags' and the 'mod'
|
|
|
|
* properties of the StatMessage() item may change via ChangeMessage().
|
|
|
|
* Note that this function will never be called on E-mail items as you can't change e-mail items, you
|
|
|
|
* can only set them as 'read'.
|
|
|
|
*/
|
|
|
|
public function ChangeMessage($folderid, $id, $message)
|
|
|
|
{
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
|
|
|
$this->backend->splitID($folderid, $type, $account);
|
|
|
|
// error_log(__METHOD__. " Id " .$id. " Account ". $account . " FolderID " . $folderid);
|
|
|
|
if ($type != 'addressbook') // || !($contact = $this->addressbook->read($id)))
|
|
|
|
{
|
|
|
|
debugLog(__METHOD__." Folder wrong or contact not existing");
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-18 21:35:36 +01:00
|
|
|
if ($account == 0) return false; //no changing of accounts
|
|
|
|
$contact = array();
|
|
|
|
if ((empty($id) && ($this->addressbook->grants[$account] & EGW_ACL_EDIT)) || ( $contact = $this->addressbook->read($id) && $this->addressbook->check_perms(EGW_ACL_EDIT, $id)))
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
$contact = array();
|
2010-12-02 14:03:52 +01:00
|
|
|
foreach (self::$mapping as $key => $attr)
|
2010-12-02 09:46:20 +01:00
|
|
|
{
|
|
|
|
switch ($attr)
|
|
|
|
{
|
|
|
|
case 'note':
|
2010-12-02 14:03:52 +01:00
|
|
|
error_log ("Note !");
|
|
|
|
|
2010-12-18 21:35:36 +01:00
|
|
|
// Since in >=AS12.1 we have the airsyncbasebody object
|
|
|
|
// By doing this hack we can continue using our current functions...
|
|
|
|
if (isset($message->airsyncbasebody))
|
|
|
|
{
|
|
|
|
switch($message->airsyncbasebody->type)
|
|
|
|
{
|
|
|
|
case '3' : $message->rtf = $message->airsyncbasebody->data;
|
|
|
|
error_log("Airsyncbase RTF Body");
|
|
|
|
break;
|
|
|
|
case '1' : $message->body = $message->airsyncbasebody->data;
|
|
|
|
error_log("Airsyncbase Plain Body");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($message->rtf))
|
|
|
|
{
|
|
|
|
// Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
|
|
|
|
// The RTF is empty, the body contains the note therefore we need to unpack the rtf
|
|
|
|
// to see if it is realy empty and in case not, take the appointment body.
|
|
|
|
error_log("RTF Body");
|
|
|
|
$rtf_body = new rtf ();
|
|
|
|
$rtf_body->loadrtf(base64_decode($message->rtf));
|
|
|
|
$rtf_body->output("ascii");
|
|
|
|
$rtf_body->parse();
|
|
|
|
if (isset($message->body) && isset($rtf_body->out) && $rtf_body->out == "" && $message->body != "")
|
|
|
|
{
|
|
|
|
unset($message->rtf);
|
|
|
|
}
|
|
|
|
|
|
|
|
$rtf_body = new rtf ();
|
|
|
|
$rtf_body->loadrtf(base64_decode($message->rtf));
|
|
|
|
$rtf_body->output("ascii");
|
|
|
|
$rtf_body->parse();
|
|
|
|
//put rtf into body
|
|
|
|
if($rtf_body->out <> "") $message->body=$rtf_body->out;
|
|
|
|
}
|
|
|
|
if (!empty(self::$mapping[$key])) $contact[$attr] = $message->body;
|
|
|
|
break;
|
2010-12-02 09:46:20 +01:00
|
|
|
case 'jpegphoto':
|
2010-12-18 21:35:36 +01:00
|
|
|
if (!empty(self::$mapping[$key])) $contact[$attr] = base64_decode($message->$key);
|
2010-12-02 14:03:52 +01:00
|
|
|
break;
|
|
|
|
|
2010-12-02 09:46:20 +01:00
|
|
|
default:
|
2010-12-18 21:35:36 +01:00
|
|
|
if (!empty(self::$mapping[$key])) $contact[$attr] = $message->$key;
|
2010-12-02 14:03:52 +01:00
|
|
|
break;
|
2010-12-02 09:46:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact['owner'] = $account;
|
2010-12-18 21:35:36 +01:00
|
|
|
if (!empty($id)) $contact['id'] = $id;
|
2010-12-02 09:46:20 +01:00
|
|
|
$this->addressbook->fixup_contact($contact);
|
2010-12-18 21:35:36 +01:00
|
|
|
$newid = $this->addressbook->save($contact);
|
|
|
|
return $this->StatMessage($folderid, $newid);
|
2010-12-02 09:46:20 +01:00
|
|
|
}
|
2010-12-18 21:35:36 +01:00
|
|
|
return false;
|
2010-12-02 09:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a message from one folder to another
|
|
|
|
*
|
|
|
|
* @param $folderid of the current folder
|
|
|
|
* @param $id of the message
|
|
|
|
* @param $newfolderid
|
|
|
|
*
|
|
|
|
* @return $newid as a string | boolean false on error
|
|
|
|
*
|
|
|
|
* After this call, StatMessage() and GetMessageList() should show the items
|
|
|
|
* to have a new parent. This means that it will disappear from GetMessageList() will not return the item
|
|
|
|
* at all on the source folder, and the destination folder will show the new message
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function MoveMessage($folderid, $id, $newfolderid)
|
|
|
|
{
|
|
|
|
error_log(__METHOD__);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete (really delete) a message in a folder
|
|
|
|
*
|
|
|
|
* @param $folderid
|
|
|
|
* @param $id
|
|
|
|
*
|
|
|
|
* @TODO check what is to be returned
|
|
|
|
*
|
|
|
|
* @DESC After this call has succeeded, a call to
|
|
|
|
* GetMessageList() should no longer list the message. If it does, the message will be re-sent to the PDA
|
|
|
|
* as it will be seen as a 'new' item. This means that if you don't implement this function, you will
|
|
|
|
* be able to delete messages on the PDA, but as soon as you sync, you'll get the item back
|
|
|
|
*/
|
|
|
|
public function DeleteMessage($folderid, $id)
|
|
|
|
{
|
|
|
|
error_log (__METHOD__);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-02 20:42:03 +01:00
|
|
|
* Return a changes array
|
|
|
|
*
|
|
|
|
* if changes occurr default diff engine computes the actual changes
|
|
|
|
*
|
|
|
|
* @param string $folderid
|
|
|
|
* @param string &$syncstate on call old syncstate, on return new syncstate
|
|
|
|
* @return array|boolean false if $folderid not found, array() if no changes or array(array("type" => "fakeChange"))
|
2010-12-02 09:46:20 +01:00
|
|
|
*/
|
|
|
|
function AlterPingChanges($folderid, &$syncstate)
|
|
|
|
{
|
2010-12-02 20:42:03 +01:00
|
|
|
$this->backend->splitID($folderid, $type, $owner);
|
2010-12-02 09:46:20 +01:00
|
|
|
|
2010-12-02 20:42:03 +01:00
|
|
|
if ($type != 'addressbook') return false;
|
2010-12-02 09:46:20 +01:00
|
|
|
|
2010-12-02 20:42:03 +01:00
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
$ctag = $this->addressbook->get_ctag($owner);
|
2010-12-02 09:46:20 +01:00
|
|
|
|
2010-12-02 20:42:03 +01:00
|
|
|
$changes = array(); // no change
|
|
|
|
$syncstate_was = $syncstate;
|
2010-12-02 09:46:20 +01:00
|
|
|
|
2010-12-02 20:42:03 +01:00
|
|
|
if ($ctag !== $syncstate)
|
|
|
|
{
|
|
|
|
$syncstate = $ctag;
|
|
|
|
$changes = array(array('type' => 'fakeChange'));
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."('$folderid','$syncstate_was') syncstate='$syncstate' returning ".array2string($changes));
|
|
|
|
return $changes;
|
|
|
|
}
|
2010-12-06 11:04:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search global address list for a given pattern
|
|
|
|
*
|
|
|
|
* @param string $searchquery
|
|
|
|
* @return array with just rows (no values for keys rows, status or global_search_status!)
|
|
|
|
* @todo search range not verified, limits might be a good idea
|
|
|
|
*/
|
|
|
|
function getSearchResultsGAL($searchquery)
|
|
|
|
{
|
|
|
|
if (!isset($this->addressbook)) $this->addressbook = new addressbook_bo();
|
|
|
|
|
|
|
|
$items = array();
|
|
|
|
if (($contacts =& $this->addressbook->search($searchquery, false, false, '', '%', false, 'OR')))
|
|
|
|
{
|
|
|
|
foreach($contacts as $contact)
|
|
|
|
{
|
|
|
|
$item['username'] = $contact['n_family'];
|
|
|
|
$item['fullname'] = $contact['n_fn'];
|
|
|
|
if (!trim($item['fullname'])) $item['fullname'] = $item['username'];
|
|
|
|
$item['emailaddress'] = $contact['email'] ? $contact['email'] : (string)$contact['email_private'] ;
|
|
|
|
$item['nameid'] = $searchquery;
|
|
|
|
$item['phone'] = (string)$contact['tel_work'];
|
|
|
|
$item['homephone'] = (string)$contact['tel_home'];
|
|
|
|
$item['mobilephone'] = (string)$contact['tel_cell'];
|
|
|
|
$item['company'] = (string)$contact['org_name'];
|
|
|
|
$item['office'] = $contact['room'];
|
|
|
|
$item['title'] = $contact['title'];
|
|
|
|
|
|
|
|
//do not return users without email
|
|
|
|
if (!trim($item['emailaddress'])) continue;
|
|
|
|
|
|
|
|
$items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $items;
|
|
|
|
}
|
2010-12-02 20:42:03 +01:00
|
|
|
}
|