Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mschering committed May 21, 2024
2 parents fa5b266 + db9eb4e commit 60b1513
Show file tree
Hide file tree
Showing 19 changed files with 630 additions and 330 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Released under the GNU Affero General Public License (AGPL), version 3
<!-- If you haven't released code to this project under github before please consider doing so now, the below is alternative wording that you can choose to use -->
<!-- Released under the GNU Affero General Public License (AGPL), version 3 and Trademark Additional Terms. -->

Expand Down
5 changes: 5 additions & 0 deletions src/backend/kopano/exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public function Config($state, $flags = 0) {
*/
public function ConfigContentParameters($contentparameters){
$filtertype = $contentparameters->GetFilterType();

if ($filtertype == SYNC_FILTERTYPE_DISABLE) {
$filtertype = false;
}

switch($contentparameters->GetContentClass()) {
case "Email":
$this->restriction = ($filtertype || !Utils::CheckMapiExtVersion('7')) ? MAPIUtils::GetEmailRestriction(Utils::GetCutOffDate($filtertype)) : false;
Expand Down
5 changes: 5 additions & 0 deletions src/backend/kopano/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public function Config($state, $flags = 0) {
*/
public function ConfigContentParameters($contentparameters) {
$filtertype = $contentparameters->GetFilterType();

if ($filtertype == SYNC_FILTERTYPE_DISABLE) {
$filtertype = false;
}

switch($contentparameters->GetContentClass()) {
case "Email":
$this->cutoffdate = ($filtertype) ? Utils::GetCutOffDate($filtertype) : false;
Expand Down
79 changes: 67 additions & 12 deletions src/backend/kopano/kopano.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function GetSearchProvider() {
* @return string AS version constant
*/
public function GetSupportedASVersion() {
return ZPush::ASV_141;
return ZPush::ASV_161;
}

/**
Expand Down Expand Up @@ -1414,11 +1414,37 @@ public function GetGALSearchResults($searchquery, $searchrange, $searchpicture)
* @return array
*/
public function GetMailboxSearchResults($cpo) {
$items = array();
$flags = 0;
$searchFolder = $this->getSearchFolder();
$searchRestriction = $this->getSearchRestriction($cpo);
$searchRange = explode('-', $cpo->GetSearchRange());
$searchFolderId = $cpo->GetSearchFolderid();
$searchFolders = array();

if ($cpo->GetFindSearchId()) {
Zlog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->GetMailboxSearchResults(): Do FIND"));
$searchRange = explode('-', $cpo->GetFindRange());

$searchRestriction = $this->getFindRestriction($cpo);
$searchFolderId = $cpo->GetFindFolderId();
$range = $cpo->GetFindRange();

// if subfolders are required, do a recursive search
if ($cpo->GetFindDeepTraversal()) {
$flags |= SEARCH_RECURSIVE;
}
}
else {
Zlog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->GetMailboxSearchResults(): Do SEARCH"));
$searchRestriction = $this->getSearchRestriction($cpo);
$searchRange = explode('-', $cpo->GetSearchRange());
$searchFolderId = $cpo->GetSearchFolderid();
$range = $cpo->GetSearchRange();

// if subfolders are required, do a recursive search
if ($cpo->GetSearchDeepTraversal()) {
$flags |= SEARCH_RECURSIVE;
}
}

// search only in required folders
if (!empty($searchFolderId)) {
$searchFolderEntryId = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($searchFolderId));
Expand All @@ -1429,13 +1455,6 @@ public function GetMailboxSearchResults($cpo) {
$tmp = mapi_getprops($this->store, array(PR_ENTRYID,PR_DISPLAY_NAME,PR_IPM_SUBTREE_ENTRYID));
$searchFolders[] = $tmp[PR_IPM_SUBTREE_ENTRYID];
}
$items = array();
$flags = 0;
// if subfolders are required, do a recursive search
if ($cpo->GetSearchDeepTraversal()) {
$flags |= SEARCH_RECURSIVE;
}

mapi_folder_setsearchcriteria($searchFolder, $searchRestriction, $searchFolders, $flags);

$table = mapi_folder_getcontentstable($searchFolder);
Expand All @@ -1455,11 +1474,12 @@ public function GetMailboxSearchResults($cpo) {

$cnt = count($rows);
$items['searchtotal'] = $cnt;
$items["range"] = $cpo->GetSearchRange();
$items["range"] = $range;
for ($i = 0; $i < $cnt; $i++) {
$items[$i]['class'] = 'Email';
$items[$i]['longid'] = ZPush::GetDeviceManager()->GetFolderIdForBackendId(bin2hex($rows[$i][PR_PARENT_SOURCE_KEY])) . ":" . bin2hex($rows[$i][PR_SOURCE_KEY]);
$items[$i]['folderid'] = bin2hex($rows[$i][PR_PARENT_SOURCE_KEY]);
$items[$i]['serverid'] = bin2hex($rows[$i][PR_SOURCE_KEY]);
}
return $items;
}
Expand Down Expand Up @@ -2294,6 +2314,41 @@ private function getSearchRestriction($cpo) {
return $mapiquery;
}

/**
* Creates a FIND restriction.
*
* @param ContentParameter $cpo
*
* @return array
*/
private function getFindRestriction($cpo) {
$findText = $cpo->GetFindFreeText();

$findFor = "";
if (!(stripos($findText, ":") && (stripos($findText, "OR") || stripos($findText, "AND")))) {
$findFor = $findText;
}
else {
// just extract a list of words we search for ignoring the fields to be searched in
// this list of words is then passed to getSearchRestriction()
$words = [];
foreach (explode(" OR ", $findText) as $search) {
if (stripos($search, ':')) {
$value = explode(":", $search)[1];
}
else {
$value = $search;
}
$words[str_replace('"', '', $value)] = true;
}
$findFor = implode(" ", array_keys($words));
}
Zlog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->getFindRestriction(): extracted words: %s", $findFor));
$cpo->SetSearchFreeText($findFor);

return $this->getSearchRestriction($cpo);
}

/**
* Resolve recipient based on his email address.
*
Expand Down
4 changes: 4 additions & 0 deletions src/backend/kopano/mapimapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public static function GetEmailMapping() {
"lastverbexecuted" => PR_LAST_VERB_EXECUTED,
"lastverbexectime" => PR_LAST_VERB_EXECUTION_TIME,
"categories" => "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords",
"Displaycc" => PR_DISPLAY_CC,
"Displaybcc" => PR_DISPLAY_BCC,
"ParentSourceKey" => PR_PARENT_SOURCE_KEY,
);
}

Expand All @@ -195,6 +198,7 @@ public static function GetEmailProperties() {
"html" => PR_HTML,
"rtfinsync" => PR_RTF_IN_SYNC,
"processed" => PR_PROCESSED,
"messageflags" => PR_MESSAGE_FLAGS,
);
}

Expand Down
26 changes: 26 additions & 0 deletions src/backend/kopano/mapiprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ private function getEmail($mapimessage, $contentparameters) {
$message->lastverbexecuted = Utils::GetLastVerbExecuted($message->lastverbexecuted);
}

if ($messageprops[$emailproperties["messageflags"]] & MSGFLAG_UNSENT) {
$message->isdraft = true;
}

return $message;
}

Expand Down Expand Up @@ -1187,13 +1191,35 @@ private function setEmail($mapimessage, $message) {
// update categories
if (!isset($message->categories)) $message->categories = array();
$emailmap = MAPIMapping::GetEmailMapping();
$emailprops = MAPIMapping::GetEmailProperties();
$this->setPropsInMAPI($mapimessage, $message, array("categories" => $emailmap["categories"]));

$flagmapping = MAPIMapping::GetMailFlagsMapping();
$flagprops = MAPIMapping::GetMailFlagsProperties();
$flagprops = array_merge($this->getPropIdsFromStrings($flagmapping), $this->getPropIdsFromStrings($flagprops));
// flag specific properties to be set
$props = $delprops = array();

// save DRAFTs
if (isset($message->asbody) && $message->asbody instanceof SyncBaseBody) {
// iOS+Nine send a RFC822 message
if (isset($message->asbody->type) && $message->asbody->type == SYNC_BODYPREFERENCE_MIME) {
Zlog::Write(LOGLEVEL_DEBUG, "MAPIProvider->setEmail(): Use the mapi_inetmapi_imtomapi function to save draft email");
$mime = stream_get_contents($message->asbody->data);
$ab = mapi_openaddressbook($this->session);
mapi_inetmapi_imtomapi($this->session, $this->store, $ab, $mapimessage, $mime, []);
}
else {
$props[$emailmap["messageclass"]] = "IPM.Note";
$this->setPropsInMAPI($mapimessage, $message, $emailmap);
}
$props[$emailprops["messageflags"]] = MSGFLAG_UNSENT | MSGFLAG_READ;

if (isset($message->asbody->type) && $message->asbody->type == SYNC_BODYPREFERENCE_HTML && isset($message->asbody->data)) {
$props[$emailprops["html"]] = stream_get_contents($message->asbody->data);
}
}

// unset message flags if:
// flag is not set
if (empty($message->flag) ||
Expand Down
10 changes: 9 additions & 1 deletion src/lib/core/pingtracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ public function DoForcePingTimeout() {
// check if there is another (and newer) active ping connection
if (is_array($pings) && isset($pings[self::$devid][self::$user]) && count($pings[self::$devid][self::$user]) > 1) {
foreach ($pings[self::$devid][self::$user] as $pid=>$starttime)
if ($starttime > self::$start)
if ($starttime > self::$start) {
return true;
}
elseif ($starttime == self::$start) {
// Arbitrary decision to differentiate multiple processes that started at the same second for the same user. Compare PIDs
// If the other process has a bigger PID then kill this process
if ($pid > self::$pid) {
return true;
}
}
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/core/streamimporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public function ImportMessageChange($id, $message) {
$this->encoder->startTag(SYNC_ADD);
else {
// on update of an SyncEmail we only export the flags and categories
if($message instanceof SyncMail && ((isset($message->flag) && $message->flag instanceof SyncMailFlags) || isset($message->categories))) {
// draft emails are fully exported
if($message instanceof SyncMail && (!isset($message->isdraft) || $message->isdraft === false) && ((isset($message->flag) && $message->flag instanceof SyncMailFlags) || isset($message->categories))) {
$newmessage = new SyncMail();
$newmessage->read = $message->read;
if (isset($message->flag)) $newmessage->flag = $message->flag;
Expand Down
14 changes: 10 additions & 4 deletions src/lib/core/zpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ZPush {
const ASV_121 = "12.1";
const ASV_14 = "14.0";
const ASV_141 = "14.1";
const ASV_16 = "16.0";
const ASV_161 = "16.1";

const ASV_161 = "16.1";

Expand All @@ -70,6 +72,7 @@ class ZPush {
const COMMAND_PROVISION = 20;
const COMMAND_RESOLVERECIPIENTS = 21;
const COMMAND_VALIDATECERT = 22;
const COMMAND_FIND = 23;

const COMMAND_FIND = 23;

Expand Down Expand Up @@ -101,7 +104,9 @@ class ZPush {
self::ASV_12,
self::ASV_121,
self::ASV_14,
self::ASV_141
self::ASV_141,
self::ASV_16,
self::ASV_161
);

static private $supportedCommands = array(
Expand Down Expand Up @@ -131,6 +136,7 @@ class ZPush {
self::COMMAND_NOTIFY => array(self::ASV_1, self::REQUESTHANDLER => "Notify"), // deprecated & not implemented
self::COMMAND_ITEMOPERATIONS => array(self::ASV_12, self::REQUESTHANDLER => "ItemOperations"),
self::COMMAND_SETTINGS => array(self::ASV_12, self::REQUESTHANDLER => "Settings"),
self::COMMAND_FIND => array(self::ASV_161, self::REQUESTHANDLER => "Find"),

self::COMMAND_WEBSERVICE_DEVICE => array(self::REQUESTHANDLER => "Webservice", self::PLAININPUT, self::NOACTIVESYNCCOMMAND, self::WEBSERVICECOMMAND),
self::COMMAND_WEBSERVICE_USERS => array(self::REQUESTHANDLER => "Webservice", self::PLAININPUT, self::NOACTIVESYNCCOMMAND, self::WEBSERVICECOMMAND),
Expand Down Expand Up @@ -831,9 +837,9 @@ static public function PrintZPushLegal($message = "", $additionalMessage = "") {
<br><br>
More information about Z-Push can be found at:<br>
<a href="http://z-push.org/">Z-Push homepage</a><br>
<a href="http://z-push.org/download">Z-Push download page</a><br>
<a href="https://jira.z-hub.io/browse/ZP">Z-Push Bugtracker</a><br>
<a href="https://wiki.z-hub.io/display/ZP">Z-Push Wiki</a> and <a href="https://wiki.z-hub.io/display/ZP/Roadmap">Roadmap</a><br>
<a href="https://z-push.org/download/">Z-Push download page</a><br>
<a href="https://github.com/Z-Hub/Z-Push/issues">Z-Push Bugtracker</a><br>
<a href="https://github.com/Z-Hub/Z-Push/wiki">Z-Push Wiki</a> and <a href="https://github.com/Z-Hub/Z-Push/wiki/Roadmap">Roadmap</a><br>
<br>
All modifications to this sourcecode must be published and returned to the community.<br>
Please see <a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPLv3 License</a> for details.<br>
Expand Down
Loading

0 comments on commit 60b1513

Please sign in to comment.