/usr/share/z-push/backend/kopano/kopano.php is in z-push-backend-kopano 2.3.8-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 | <?php
/***********************************************
* File : kopano.php
* Project : Z-Push
* Descr : This is backend for the Kopano Core (KC).
* It is an implementation of IBackend
* and also implements the ISearchProvider
* to search in the Kopano system.
*
* Created : 01.10.2011
*
* Copyright 2007 - 2016 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
*************************************************/
// config file
$config_path = stream_resolve_include_path(__DIR__."/config.php");
if ($config_path !== false) {
require_once($config_path);
}
else {
ZLog::Write(LOGLEVEL_WARN, "Kopano backend config file can not be found");
}
// include PHP-MAPI classes
include_once('backend/kopano/mapi/mapi.util.php');
include_once('backend/kopano/mapi/mapidefs.php');
include_once('backend/kopano/mapi/mapitags.php');
include_once('backend/kopano/mapi/mapicode.php');
include_once('backend/kopano/mapi/mapiguid.php');
//setlocale to UTF-8 in order to support properties containing Unicode characters
setlocale(LC_CTYPE, "en_US.UTF-8");
class BackendKopano implements IBackend, ISearchProvider {
private $mainUser;
private $session;
private $defaultstore;
private $store;
private $storeName;
private $storeCache;
private $importedFolders;
private $notifications;
private $changesSink;
private $changesSinkFolders;
private $changesSinkStores;
private $wastebasket;
private $addressbook;
private $folderStatCache;
// KC config parameter for PR_EC_ENABLED_FEATURES / PR_EC_DISABLED_FEATURES
const MOBILE_ENABLED = 'mobile';
const OUTLOOK_ENABLED = 'outlook';
const MAXAMBIGUOUSRECIPIENTS = 9999;
const FREEBUSYENUMBLOCKS = 50;
const MAXFREEBUSYSLOTS = 32767; // max length of 32k for the MergedFreeBusy element is allowed
const HALFHOURSECONDS = 1800;
/**
* Constructor of the Kopano Backend
*
* @access public
*/
public function __construct() {
$this->session = false;
$this->store = false;
$this->storeName = false;
$this->storeCache = array();
$this->importedFolders = array();
$this->notifications = false;
$this->changesSink = false;
$this->changesSinkFolders = array();
$this->changesSinkStores = array();
$this->changesSinkHierarchyHash = false;
$this->wastebasket = false;
$this->session = false;
$this->folderStatCache = array();
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano using PHP-MAPI version: %s - PHP version: %s", phpversion("mapi"), phpversion()));
KopanoChangesWrapper::SetBackend($this);
}
/**
* Indicates which StateMachine should be used
*
* @access public
* @return boolean KopanoBackend uses the default FileStateMachine
*/
public function GetStateMachine() {
return false;
}
/**
* Returns the KopanoBackend as it implements the ISearchProvider interface
* This could be overwritten by the global configuration
*
* @access public
* @return object Implementation of ISearchProvider
*/
public function GetSearchProvider() {
return $this;
}
/**
* Indicates which AS version is supported by the backend.
*
* @access public
* @return string AS version constant
*/
public function GetSupportedASVersion() {
return ZPush::ASV_14;
}
/**
* Authenticates the user with the configured Kopano server
*
* @param string $username
* @param string $domain
* @param string $password
*
* @access public
* @return boolean
* @throws AuthenticationRequiredException
*/
public function Logon($user, $domain, $pass) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Logon(): Trying to authenticate user '%s'..", $user));
$this->mainUser = strtolower($user);
try {
// check if notifications are available in php-mapi
if(function_exists('mapi_feature') && mapi_feature('LOGONFLAGS')) {
// send Z-Push version and user agent to ZCP - ZP-589
if (Utils::CheckMapiExtVersion('7.2.0')) {
$zpush_version = 'Z-Push_' . @constant('ZPUSH_VERSION');
$user_agent = (Request::GetDeviceID()) ? ZPush::GetDeviceManager()->GetUserAgent() : "unknown";
$this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER, null, null, 0, $zpush_version, $user_agent);
}
else {
$this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER, null, null, 0);
}
$this->notifications = true;
}
// old fashioned session
else {
$this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER);
$this->notifications = false;
}
if (mapi_last_hresult()) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("KopanoBackend->Logon(): login failed with error code: 0x%X", mapi_last_hresult()));
if (mapi_last_hresult() == MAPI_E_NETWORK_ERROR)
throw new ServiceUnavailableException("Error connecting to KC (login)");
}
}
catch (MAPIException $ex) {
throw new AuthenticationRequiredException($ex->getDisplayMessage());
}
if(!$this->session) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Logon(): logon failed for user '%s'", $user));
$this->defaultstore = false;
return false;
}
// Get/open default store
$this->defaultstore = $this->openMessageStore($this->mainUser);
if (mapi_last_hresult() == MAPI_E_FAILONEPROVIDER)
throw new ServiceUnavailableException("Error connecting to KC (open store)");
if($this->defaultstore === false)
throw new AuthenticationRequiredException(sprintf("KopanoBackend->Logon(): User '%s' has no default store", $user));
$this->store = $this->defaultstore;
$this->storeName = $this->mainUser;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Logon(): User '%s' is authenticated",$user));
$this->isZPushEnabled();
// check if this is a Zarafa 7 store with unicode support
MAPIUtils::IsUnicodeStore($this->store);
return true;
}
/**
* Setup the backend to work on a specific store or checks ACLs there.
* If only the $store is submitted, all Import/Export/Fetch/Etc operations should be
* performed on this store (switch operations store).
* If the ACL check is enabled, this operation should just indicate the ACL status on
* the submitted store, without changing the store for operations.
* For the ACL status, the currently logged on user MUST have access rights on
* - the entire store - admin access if no folderid is sent, or
* - on a specific folderid in the store (secretary/full access rights)
*
* The ACLcheck MUST fail if a folder of the authenticated user is checked!
*
* @param string $store target store, could contain a "domain\user" value
* @param boolean $checkACLonly if set to true, Setup() should just check ACLs
* @param string $folderid if set, only ACLs on this folderid are relevant
* @param boolean $readonly if set, the folder needs at least read permissions
*
* @access public
* @return boolean
*/
public function Setup($store, $checkACLonly = false, $folderid = false, $readonly = false) {
list($user, $domain) = Utils::SplitDomainUser($store);
if (!isset($this->mainUser))
return false;
if ($user === false)
$user = $this->mainUser;
// This is a special case. A user will get his entire folder structure by the foldersync by default.
// The ACL check is executed when an additional folder is going to be sent to the mobile.
// Configured that way the user could receive the same folderid twice, with two different names.
if ($this->mainUser == $user && $checkACLonly && $folderid) {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->Setup(): Checking ACLs for folder of the users defaultstore. Fail is forced to avoid folder duplications on mobile.");
return false;
}
// get the users store
$userstore = $this->openMessageStore($user);
// only proceed if a store was found, else return false
if ($userstore) {
// only check permissions
if ($checkACLonly == true) {
// check for admin rights
if (!$folderid) {
if ($user != $this->mainUser) {
$zarafauserinfo = @mapi_zarafa_getuser_by_name($this->defaultstore, $this->mainUser);
$admin = (isset($zarafauserinfo['admin']) && $zarafauserinfo['admin'])?true:false;
}
// the user has always full access to his own store
else
$admin = true;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Setup(): Checking for admin ACLs on store '%s': '%s'", $user, Utils::PrintAsString($admin)));
return $admin;
}
// check permissions on this folder
else {
if (! $readonly) {
$rights = $this->HasSecretaryACLs($userstore, $folderid);
}
else {
$rights = $this->HasReadACLs($userstore, $folderid);
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Setup(): Checking for '%s' ACLs on '%s' of store '%s': '%s'", ($readonly?'read':'secretary'), $folderid, $user, Utils::PrintAsString($rights)));
return $rights;
}
}
// switch operations store
// this should also be done if called with user = mainuser or user = false
// which means to switch back to the default store
else {
// switch active store
$this->store = $userstore;
$this->storeName = $user;
return true;
}
}
return false;
}
/**
* Logs off
* Free/Busy information is updated for modified calendars
* This is done after the synchronization process is completed
*
* @access public
* @return boolean
*/
public function Logoff() {
// update if the calendar which received incoming changes
foreach($this->importedFolders as $folderid => $store) {
// open the root of the store
$storeprops = mapi_getprops($store, array(PR_USER_ENTRYID));
$root = mapi_msgstore_openentry($store);
if (!$root)
continue;
// get the entryid of the main calendar of the store and the calendar to be published
$rootprops = mapi_getprops($root, array(PR_IPM_APPOINTMENT_ENTRYID));
$entryid = mapi_msgstore_entryidfromsourcekey($store, hex2bin($folderid));
// only publish free busy for the main calendar
if(isset($rootprops[PR_IPM_APPOINTMENT_ENTRYID]) && $rootprops[PR_IPM_APPOINTMENT_ENTRYID] == $entryid) {
ZLog::Write(LOGLEVEL_INFO, sprintf("KopanoBackend->Logoff(): Updating freebusy information on folder id '%s'", $folderid));
$calendar = mapi_msgstore_openentry($store, $entryid);
$pub = new FreeBusyPublish($this->session, $store, $calendar, $storeprops[PR_USER_ENTRYID]);
$pub->publishFB(time() - (7 * 24 * 60 * 60), 6 * 30 * 24 * 60 * 60); // publish from one week ago, 6 months ahead
}
}
return true;
}
/**
* Returns an array of SyncFolder types with the entire folder hierarchy
* on the server (the array itself is flat, but refers to parents via the 'parent' property
*
* provides AS 1.0 compatibility
*
* @access public
* @return array SYNC_FOLDER
*/
public function GetHierarchy() {
$folders = array();
$mapiprovider = new MAPIProvider($this->session, $this->store);
$storeProps = $mapiprovider->GetStoreProps();
// for SYSTEM user open the public folders
if (strtoupper($this->storeName) == "SYSTEM") {
$rootfolder = mapi_msgstore_openentry($this->store, $storeProps[PR_IPM_PUBLIC_FOLDERS_ENTRYID]);
}
else {
$rootfolder = mapi_msgstore_openentry($this->store);
}
$rootfolderprops = mapi_getprops($rootfolder, array(PR_SOURCE_KEY));
$hierarchy = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
$rows = mapi_table_queryallrows($hierarchy, array(PR_DISPLAY_NAME, PR_PARENT_ENTRYID, PR_ENTRYID, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_CONTAINER_CLASS, PR_ATTR_HIDDEN, PR_EXTENDED_FOLDER_FLAGS, PR_FOLDER_TYPE));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->GetHierarchy(): fetched %d folders from MAPI", count($rows)));
foreach ($rows as $row) {
// do not display hidden and search folders
if ((isset($row[PR_ATTR_HIDDEN]) && $row[PR_ATTR_HIDDEN]) ||
(isset($row[PR_FOLDER_TYPE]) && $row[PR_FOLDER_TYPE] == FOLDER_SEARCH) ||
// for SYSTEM user $row[PR_PARENT_SOURCE_KEY] == $rootfolderprops[PR_SOURCE_KEY] is true, but we need those folders
(isset($row[PR_PARENT_SOURCE_KEY]) && $row[PR_PARENT_SOURCE_KEY] == $rootfolderprops[PR_SOURCE_KEY] && strtoupper($this->storeName) != "SYSTEM")) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->GetHierarchy(): ignoring folder '%s' as it's a hidden/search/root folder", (isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "unknown")));
continue;
}
$folder = $mapiprovider->GetFolder($row);
if ($folder) {
$folders[] = $folder;
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->GetHierarchy(): ignoring folder '%s' as MAPIProvider->GetFolder() did not return a SyncFolder object", (isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "unknown")));
}
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->GetHierarchy(): processed %d folders, starting parent remap", count($folders)));
// reloop the folders to make sure all parentids are mapped correctly
$dm = ZPush::GetDeviceManager();
foreach ($folders as $folder) {
if ($folder->parentid !== "0") {
// SYSTEM user's parentid points to $rootfolderprops[PR_SOURCE_KEY], but they need to be on the top level
$folder->parentid = (strtoupper($this->storeName) == "SYSTEM" && $folder->parentid == bin2hex($rootfolderprops[PR_SOURCE_KEY])) ? '0' : $dm->GetFolderIdForBackendId($folder->parentid);
}
}
return $folders;
}
/**
* Returns the importer to process changes from the mobile
* If no $folderid is given, hierarchy importer is expected
*
* @param string $folderid (opt)
*
* @access public
* @return object(ImportChanges)
*/
public function GetImporter($folderid = false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->GetImporter() folderid: '%s'", Utils::PrintAsString($folderid)));
if($folderid !== false) {
$this->importedFolders[$folderid] = $this->store;
$wrapper = KopanoChangesWrapper::GetWrapper($this->storeName, $this->session, $this->store, $folderid, $this->storeName == $this->mainUser);
$wrapper->Prepare(KopanoChangesWrapper::IMPORTER);
return $wrapper;
}
else
return new ImportChangesICS($this->session, $this->store);
}
/**
* Returns the exporter to send changes to the mobile
* If no $folderid is given, hierarchy exporter is expected
*
* @param string $folderid (opt)
*
* @access public
* @return object(ExportChanges)
* @throws StatusException
*/
public function GetExporter($folderid = false) {
if($folderid !== false) {
$wrapper = KopanoChangesWrapper::GetWrapper($this->storeName, $this->session, $this->store, $folderid, $this->storeName == $this->mainUser);
$wrapper->Prepare(KopanoChangesWrapper::EXPORTER);
return $wrapper;
}
else
return new ExportChangesICS($this->session, $this->store);
}
/**
* Sends an e-mail
* This messages needs to be saved into the 'sent items' folder
*
* @param SyncSendMail $sm SyncSendMail object
*
* @access public
* @return boolean
* @throws StatusException
*/
public function SendMail($sm) {
// Check if imtomapi function is available and use it to send the mime message.
// It is available since ZCP 7.0.6
// @see http://jira.zarafa.com/browse/ZCP-9508
if (!(function_exists('mapi_feature') && mapi_feature('INETMAPI_IMTOMAPI'))) {
throw new StatusException("KopanoBackend->SendMail(): ZCP/KC version is too old, INETMAPI_IMTOMAPI is not available. Install at least ZCP version 7.0.6 or later.", SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED, null, LOGLEVEL_FATAL);
return false;
}
$mimeLength = strlen($sm->mime);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): RFC822: %d bytes forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'",
$mimeLength, Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag),
Utils::PrintAsString((isset($sm->source->folderid) ? $sm->source->folderid : false)),
Utils::PrintAsString(($sm->saveinsent)), Utils::PrintAsString(isset($sm->replacemime)) ));
if ($mimeLength == 0) {
throw new StatusException("KopanoBackend->SendMail(): empty mail data", SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED);
}
// Send-As functionality - https://jira.z-hub.io/browse/ZP-908
$sendingAsSomeone = false;
if (defined('KOE_CAPABILITY_SENDAS') && KOE_CAPABILITY_SENDAS) {
$senderEmail = array();
// KOE: grep for the Sender header indicating we should send-as
// the 'X-Push-Sender-Name' header is not used
if (preg_match("/^X-Push-Sender:\s(.*?)$/im", substr($sm->mime, 0, strpos($sm->mime, "\r\n\r\n")), $senderEmail)) {
$sendAsEmail = trim($senderEmail[1]);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): Send-As '%s' requested by KOE", $sendAsEmail));
$originalFrom = array();
if (preg_match("/^(From:\s.*?)$/im", $sm->mime, $originalFrom)) {
// find the occurence of the From header and replace it
// preg_replace() uses additional 3x the length of $sm->mime to perform,
// mb_ereg_replace() requires only 1x addtional memory, but replaces ALL occurences.
// The below is different than concatenating in one line and also only uses 1x additional memory
$fromPosition = strpos($sm->mime, $originalFrom[1]);
$start = substr($sm->mime, 0, $fromPosition);
$end = substr($sm->mime, $fromPosition + strlen($originalFrom[1]));
$sm->mime = $start;
$sm->mime .= "From: ". $sendAsEmail;
$sm->mime .= $end;
unset($start, $end);
$sendingAsSomeone = true;
}
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->SendMail(): Could not find FROM header to replace for send-as");
}
}
// serverside Send-As - shared folder with DeviceManager::FLD_FLAGS_SENDASOWNER flag
elseif (isset($sm->source->folderid)) {
// get the owner of this folder - System is not allowed
$sharedUser = ZPush::GetAdditionalSyncFolderStore($sm->source->folderid);
if ($sharedUser != false && $sharedUser != 'SYSTEM') {
$folders = ZPush::GetAdditionalSyncFolders();
if (isset($folders[$sm->source->folderid]) && ($folders[$sm->source->folderid]->Flags & DeviceManager::FLD_FLAGS_SENDASOWNER)) {
$sendAs = false;
// for multi-company this is (mostly always) already an email address and we can just use it - ZP-1255
if (Utils::CheckEmail($sharedUser)) {
$sendAs = $sharedUser;
}
else {
$gabResult = $this->resolveRecipientGAL($sharedUser, 1);
if (isset($gabResult[0])) {
$sendAs = $gabResult[0]->emailaddress;
}
}
if ($sendAs) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): Server side Send-As activated for shared folder. Sending as '%s'.", $sendAs));
$sm->mime = preg_replace("/^From: .*?$/im", "From: ". $sendAs, $sm->mime, 1);
$sendingAsSomeone = true;
}
}
}
}
}
$sendMailProps = MAPIMapping::GetSendMailProperties();
$sendMailProps = getPropIdsFromStrings($this->defaultstore, $sendMailProps);
// Open the outbox and create the message there
$storeprops = mapi_getprops($this->defaultstore, array($sendMailProps["outboxentryid"], $sendMailProps["ipmsentmailentryid"]));
if(isset($storeprops[$sendMailProps["outboxentryid"]]))
$outbox = mapi_msgstore_openentry($this->defaultstore, $storeprops[$sendMailProps["outboxentryid"]]);
if(!$outbox)
throw new StatusException(sprintf("KopanoBackend->SendMail(): No Outbox found or unable to create message: 0x%X", mapi_last_hresult()), SYNC_COMMONSTATUS_SERVERERROR);
$mapimessage = mapi_folder_createmessage($outbox);
//message properties to be set
$mapiprops = array();
// only save the outgoing in sent items folder if the mobile requests it
$mapiprops[$sendMailProps["sentmailentryid"]] = $storeprops[$sendMailProps["ipmsentmailentryid"]];
ZLog::Write(LOGLEVEL_DEBUG, "Use the mapi_inetmapi_imtomapi function");
$ab = mapi_openaddressbook($this->session);
mapi_inetmapi_imtomapi($this->session, $this->defaultstore, $ab, $mapimessage, $sm->mime, array());
// Set the appSeqNr so that tracking tab can be updated for meeting request updates
// @see http://jira.zarafa.com/browse/ZP-68
$meetingRequestProps = MAPIMapping::GetMeetingRequestProperties();
$meetingRequestProps = getPropIdsFromStrings($this->defaultstore, $meetingRequestProps);
$props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS, $meetingRequestProps["goidtag"], $sendMailProps["internetcpid"], $sendMailProps["body"], $sendMailProps["html"], $sendMailProps["rtf"], $sendMailProps["rtfinsync"]));
// Convert sent message's body to UTF-8 if it was a HTML message.
// @see http://jira.zarafa.com/browse/ZP-505 and http://jira.zarafa.com/browse/ZP-555
if (isset($props[$sendMailProps["internetcpid"]]) && $props[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8 && MAPIUtils::GetNativeBodyType($props) == SYNC_BODYPREFERENCE_HTML) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Sent email cpid is not unicode (%d). Set it to unicode and convert email html body.", $props[$sendMailProps["internetcpid"]]));
$mapiprops[$sendMailProps["internetcpid"]] = INTERNET_CPID_UTF8;
$bodyHtml = MAPIUtils::readPropStream($mapimessage, PR_HTML);
$bodyHtml = Utils::ConvertCodepageStringToUtf8($props[$sendMailProps["internetcpid"]], $bodyHtml);
$mapiprops[$sendMailProps["html"]] = $bodyHtml;
mapi_setprops($mapimessage, $mapiprops);
}
if (stripos($props[PR_MESSAGE_CLASS], "IPM.Schedule.Meeting.Resp.") === 0) {
// search for calendar items using goid
$mr = new Meetingrequest($this->defaultstore, $mapimessage);
$appointments = $mr->findCalendarItems($props[$meetingRequestProps["goidtag"]]);
if (is_array($appointments) && !empty($appointments)) {
$app = mapi_msgstore_openentry($this->defaultstore, $appointments[0]);
$appprops = mapi_getprops($app, array($meetingRequestProps["appSeqNr"]));
if (isset($appprops[$meetingRequestProps["appSeqNr"]]) && $appprops[$meetingRequestProps["appSeqNr"]]) {
$mapiprops[$meetingRequestProps["appSeqNr"]] = $appprops[$meetingRequestProps["appSeqNr"]];
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Set sequence number to:%d", $appprops[$meetingRequestProps["appSeqNr"]]));
}
}
}
// Delete the PR_SENT_REPRESENTING_* properties because some android devices
// do not send neither From nor Sender header causing empty PR_SENT_REPRESENTING_NAME and
// PR_SENT_REPRESENTING_EMAIL_ADDRESS properties and "broken" PR_SENT_REPRESENTING_ENTRYID
// which results in spooler not being able to send the message.
// @see http://jira.zarafa.com/browse/ZP-85
// If using KOE send-as feature, we keep this properties because they actually are the send-as
if (!$sendingAsSomeone) {
mapi_deleteprops($mapimessage,
array( $sendMailProps["sentrepresentingname"], $sendMailProps["sentrepresentingemail"], $sendMailProps["representingentryid"],
$sendMailProps["sentrepresentingaddt"], $sendMailProps["sentrepresentinsrchk"]));
}
// Processing of KOE X-Push-Receipts header - delivery notification: ZP-1204
if (defined('KOE_CAPABILITY_RECEIPTS') && KOE_CAPABILITY_RECEIPTS) {
// KOE: grep for the Sender header indicating that there are TODOs
if (preg_match("/^X-Push-Receipts:\s(.*?)$/im", $sm->mime, $receiptsvalue)) {
$receipts = trim($receiptsvalue[1]);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): Receipts '%s' requested by KOE", $receipts));
// delivery notification requested
if (stripos($receipts, 'delivery') !== false) {
$mapiprops[PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED] = true;
}
}
}
if(isset($sm->source->itemid) && $sm->source->itemid) {
// answering an email in a public/shared folder
// TODO as the store is setup, we should actually user $this->store instead of $this->defaultstore - nevertheless we need to make sure this store is able to send mail (has an outbox)
if (!$this->Setup(ZPush::GetAdditionalSyncFolderStore($sm->source->folderid)))
throw new StatusException(sprintf("KopanoBackend->SendMail() could not Setup() the backend for folder id '%s'", $sm->source->folderid), SYNC_COMMONSTATUS_SERVERERROR);
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($sm->source->folderid), hex2bin($sm->source->itemid));
if ($entryid)
$fwmessage = mapi_msgstore_openentry($this->store, $entryid);
if (isset($fwmessage) && $fwmessage) {
// update icon and last_verb when forwarding or replying message
// reply-all (verb 103) is not supported, as we cannot really detect this case
if ($sm->forwardflag) {
$updateProps = array(
PR_ICON_INDEX => 262,
PR_LAST_VERB_EXECUTED => 104,
);
}
elseif ($sm->replyflag) {
$updateProps = array(
PR_ICON_INDEX => 261,
PR_LAST_VERB_EXECUTED => 102,
);
}
if (isset($updateProps)) {
$updateProps[PR_LAST_VERB_EXECUTION_TIME] = time();
mapi_setprops($fwmessage, $updateProps);
mapi_savechanges($fwmessage);
}
// only attach the original message if the mobile does not send it itself
if (!isset($sm->replacemime)) {
// get message's body in order to append forward or reply text
if (!isset($body)) {
$body = MAPIUtils::readPropStream($mapimessage, PR_BODY);
}
if (!isset($bodyHtml)) {
$bodyHtml = MAPIUtils::readPropStream($mapimessage, PR_HTML);
}
$cpid = mapi_getprops($fwmessage, array($sendMailProps["internetcpid"]));
if($sm->forwardflag) {
// attach the original attachments to the outgoing message
$this->copyAttachments($mapimessage, $fwmessage);
}
// regarding the conversion @see ZP-470
if (strlen($body) > 0) {
$fwbody = MAPIUtils::readPropStream($fwmessage, PR_BODY);
// if only the old message's cpid is set, convert from old charset to utf-8
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): convert plain forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbody = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbody);
}
// otherwise to the general conversion
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->SendMail(): no charset conversion done for plain forwarded message");
$fwbody = w2u($fwbody);
}
$mapiprops[$sendMailProps["body"]] = $body."\r\n\r\n".$fwbody;
}
if (strlen($bodyHtml) > 0) {
$fwbodyHtml = MAPIUtils::readPropStream($fwmessage, PR_HTML);
// if only new message's cpid is set, convert to UTF-8
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->SendMail(): convert html forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbodyHtml = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbodyHtml);
}
// otherwise to the general conversion
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->SendMail(): no charset conversion done for html forwarded message");
$fwbodyHtml = w2u($fwbodyHtml);
}
$mapiprops[$sendMailProps["html"]] = $bodyHtml."<br><br>".$fwbodyHtml;
}
}
}
else {
// no fwmessage could be opened and we need it because we do not replace mime
if (!isset($sm->replacemime) || $sm->replacemime == false) {
throw new StatusException(sprintf("KopanoBackend->SendMail(): Could not open message id '%s' in folder id '%s' to be replied/forwarded: 0x%X", $sm->source->itemid, $sm->source->folderid, mapi_last_hresult()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
}
}
}
mapi_setprops($mapimessage, $mapiprops);
mapi_message_savechanges($mapimessage);
mapi_message_submitmessage($mapimessage);
$hr = mapi_last_hresult();
if ($hr)
throw new StatusException(sprintf("KopanoBackend->SendMail(): Error saving/submitting the message to the Outbox: 0x%X", mapi_last_hresult()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED);
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->SendMail(): email submitted");
return true;
}
/**
* Returns all available data of a single message
*
* @param string $folderid
* @param string $id
* @param ContentParameters $contentparameters flag
*
* @access public
* @return object(SyncObject)
* @throws StatusException
*/
public function Fetch($folderid, $id, $contentparameters) {
// id might be in the new longid format, so we have to split it here
list($fsk, $sk) = Utils::SplitMessageId($id);
// get the entry id of the message
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($sk));
if(!$entryid)
throw new StatusException(sprintf("BackendKopano->Fetch('%s','%s'): Error getting entryid: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
// open the message
$message = mapi_msgstore_openentry($this->store, $entryid);
if(!$message)
throw new StatusException(sprintf("BackendKopano->Fetch('%s','%s'): Error, unable to open message: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
// convert the mapi message into a SyncObject and return it
$mapiprovider = new MAPIProvider($this->session, $this->store);
// override truncation
$contentparameters->SetTruncation(SYNC_TRUNCATION_ALL);
// TODO check for body preferences
return $mapiprovider->GetMessage($message, $contentparameters);
}
/**
* Returns the waste basket
*
* @access public
* @return string
*/
public function GetWasteBasket() {
if ($this->wastebasket) {
return $this->wastebasket;
}
$storeprops = mapi_getprops($this->defaultstore, array(PR_IPM_WASTEBASKET_ENTRYID));
if (isset($storeprops[PR_IPM_WASTEBASKET_ENTRYID])) {
$wastebasket = mapi_msgstore_openentry($this->defaultstore, $storeprops[PR_IPM_WASTEBASKET_ENTRYID]);
$wastebasketprops = mapi_getprops($wastebasket, array(PR_SOURCE_KEY));
if (isset($wastebasketprops[PR_SOURCE_KEY])) {
$this->wastebasket = bin2hex($wastebasketprops[PR_SOURCE_KEY]);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Got waste basket with id '%s'", $this->wastebasket));
return $this->wastebasket;
}
}
return false;
}
/**
* Returns the content of the named attachment as stream
*
* @param string $attname
* @access public
* @return SyncItemOperationsAttachment
* @throws StatusException
*/
public function GetAttachmentData($attname) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetAttachmentData('%s')", $attname));
if(!strpos($attname, ":"))
throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, attachment requested for non-existing item", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
list($id, $attachnum, $parentEntryid) = explode(":", $attname);
if (isset($parentEntryid)) {
$this->Setup(ZPush::GetAdditionalSyncFolderStore($parentEntryid));
}
$entryid = hex2bin($id);
$message = mapi_msgstore_openentry($this->store, $entryid);
if(!$message)
throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open item for attachment data for id '%s' with: 0x%X", $attname, $id, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
MAPIUtils::ParseSmime($this->session, $this->defaultstore, $this->getAddressbook(), $message);
$attach = mapi_message_openattach($message, $attachnum);
if(!$attach)
throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open attachment number '%s' with: 0x%X", $attname, $attachnum, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
// get necessary attachment props
$attprops = mapi_getprops($attach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_MIME_TAG_W, PR_ATTACH_METHOD));
$attachment = new SyncItemOperationsAttachment();
// check if it's an embedded message and open it in such a case
if (isset($attprops[PR_ATTACH_METHOD]) && $attprops[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
$embMessage = mapi_attach_openobj($attach);
$addrbook = $this->getAddressbook();
$stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $embMessage, array('use_tnef' => -1));
// set the default contenttype for this kind of messages
$attachment->contenttype = "message/rfc822";
}
else
$stream = mapi_openproperty($attach, PR_ATTACH_DATA_BIN, IID_IStream, 0, 0);
if(!$stream)
throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open attachment data stream: 0x%X", $attname, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
// put the mapi stream into a wrapper to get a standard stream
$attachment->data = MAPIStreamWrapper::Open($stream);
if (isset($attprops[PR_ATTACH_MIME_TAG]))
$attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG];
elseif (isset($attprops[PR_ATTACH_MIME_TAG_W]))
$attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG_W];
//TODO default contenttype
return $attachment;
}
/**
* Deletes all contents of the specified folder.
* This is generally used to empty the trash (wastebasked), but could also be used on any
* other folder.
*
* @param string $folderid
* @param boolean $includeSubfolders (opt) also delete sub folders, default true
*
* @access public
* @return boolean
* @throws StatusException
*/
public function EmptyFolder($folderid, $includeSubfolders = true) {
$folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid));
if (!$folderentryid)
throw new StatusException(sprintf("BackendKopano->EmptyFolder('%s','%s'): Error, unable to open folder (no entry id)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR);
$folder = mapi_msgstore_openentry($this->store, $folderentryid);
if (!$folder)
throw new StatusException(sprintf("BackendKopano->EmptyFolder('%s','%s'): Error, unable to open parent folder (open entry)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR);
$flags = 0;
if ($includeSubfolders)
$flags = DEL_ASSOCIATED;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->EmptyFolder('%s','%s'): emptying folder",$folderid, Utils::PrintAsString($includeSubfolders)));
// empty folder!
mapi_folder_emptyfolder($folder, $flags);
if (mapi_last_hresult())
throw new StatusException(sprintf("BackendKopano->EmptyFolder('%s','%s'): Error, mapi_folder_emptyfolder() failed: 0x%X", $folderid, Utils::PrintAsString($includeSubfolders), mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR);
return true;
}
/**
* Processes a response to a meeting request.
* CalendarID is a reference and has to be set if a new calendar item is created
*
* @param string $requestid id of the object containing the request
* @param string $folderid id of the parent folder of $requestid
* @param string $response
*
* @access public
* @return string id of the created/updated calendar obj
* @throws StatusException
*/
public function MeetingResponse($requestid, $folderid, $response) {
// Use standard meeting response code to process meeting request
list($fid, $requestid) = Utils::SplitMessageId($requestid);
$reqentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($requestid));
if (!$reqentryid)
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s', '%s', '%s'): Error, unable to entryid of the message 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ);
$mapimessage = mapi_msgstore_openentry($this->store, $reqentryid);
if(!$mapimessage)
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, unable to open request message for response 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ);
$meetingrequest = new Meetingrequest($this->store, $mapimessage, $this->session);
if(!$meetingrequest->isMeetingRequest())
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, attempt to respond to non-meeting request", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ);
if($meetingrequest->isLocalOrganiser())
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, attempt to response to meeting request that we organized", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ);
// Process the meeting response. We don't have to send the actual meeting response
// e-mail, because the device will send it itself.
switch($response) {
case 1: // accept
default:
$entryid = $meetingrequest->doAccept(false, false, false, false, false, false, true); // last true is the $userAction
break;
case 2: // tentative
$entryid = $meetingrequest->doAccept(true, false, false, false, false, false, true); // last true is the $userAction
break;
case 3: // decline
$meetingrequest->doDecline(false);
break;
}
// F/B will be updated on logoff
// We have to return the ID of the new calendar item, so do that here
$calendarid = "";
$calFolderId = "";
if (isset($entryid)) {
$newitem = mapi_msgstore_openentry($this->store, $entryid);
// new item might be in a delegator's store. ActiveSync does not support accepting them.
if (!$newitem) {
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Object with entryid '%s' was not found in user's store (0x%X). It might be in a delegator's store.", $requestid, $folderid, $response, bin2hex($entryid), mapi_last_hresult()), SYNC_MEETRESPSTATUS_SERVERERROR, null, LOGLEVEL_WARN);
}
$newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY));
$calendarid = bin2hex($newprops[PR_SOURCE_KEY]);
$calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]);
}
// on recurring items, the MeetingRequest class responds with a wrong entryid
if ($requestid == $calendarid) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): returned calender id is the same as the requestid - re-searching", $requestid, $folderid, $response));
$props = MAPIMapping::GetMeetingRequestProperties();
$props = getPropIdsFromStrings($this->store, $props);
$messageprops = mapi_getprops($mapimessage, Array($props["goidtag"]));
$goid = $messageprops[$props["goidtag"]];
$items = $meetingrequest->findCalendarItems($goid);
if (is_array($items)) {
$newitem = mapi_msgstore_openentry($this->store, $items[0]);
$newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY));
$calendarid = bin2hex($newprops[PR_SOURCE_KEY]);
$calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response));
}
if ($requestid == $calendarid)
throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error finding the accepted meeting response in the calendar", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ);
}
// delete meeting request from Inbox
$folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid));
$folder = mapi_msgstore_openentry($this->store, $folderentryid);
mapi_folder_deletemessages($folder, array($reqentryid), 0);
$prefix = '';
// prepend the short folderid of the target calendar: if available and short ids are used
if ($calFolderId) {
$shortFolderId = ZPush::GetDeviceManager()->GetFolderIdForBackendId($calFolderId);
if ($calFolderId != $shortFolderId) {
$prefix = $shortFolderId . ':';
}
}
return $prefix . $calendarid;
}
/**
* Indicates if the backend has a ChangesSink.
* A sink is an active notification mechanism which does not need polling.
* Since Zarafa 7.0.5 such a sink is available.
* The Kopano backend uses this method to initialize the sink with mapi.
*
* @access public
* @return boolean
*/
public function HasChangesSink() {
if (!$this->notifications) {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->HasChangesSink(): sink is not available");
return false;
}
$this->changesSink = @mapi_sink_create();
if (! $this->changesSink || mapi_last_hresult()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->HasChangesSink(): sink could not be created with 0x%X", mapi_last_hresult()));
return false;
}
$this->changesSinkHierarchyHash = $this->getHierarchyHash();
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->HasChangesSink(): created - HierarchyHash: %s", $this->changesSinkHierarchyHash));
// advise the main store and also to check if the connection supports it
return $this->adviseStoreToSink($this->defaultstore);
}
/**
* The folder should be considered by the sink.
* Folders which were not initialized should not result in a notification
* of IBackend->ChangesSink().
*
* @param string $folderid
*
* @access public
* @return boolean false if entryid can not be found for that folder
*/
public function ChangesSinkInitialize($folderid) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->ChangesSinkInitialize(): folderid '%s'", $folderid));
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid));
if (!$entryid)
return false;
// add entryid to the monitored folders
$this->changesSinkFolders[$entryid] = $folderid;
// advise the current store to the sink
return $this->adviseStoreToSink($this->store);
}
/**
* The actual ChangesSink.
* For max. the $timeout value this method should block and if no changes
* are available return an empty array.
* If changes are available a list of folderids is expected.
*
* @param int $timeout max. amount of seconds to block
*
* @access public
* @return array
*/
public function ChangesSink($timeout = 30) {
// clear the folder stats cache
unset($this->folderStatCache);
$notifications = array();
$hierarchyNotifications = array();
$sinkresult = @mapi_sink_timedwait($this->changesSink, $timeout * 1000);
// reverse array so that the changes on folders are before changes on messages and
// it's possible to filter such notifications
$sinkresult = array_reverse($sinkresult, true);
foreach ($sinkresult as $sinknotif) {
// add a notification on a folder
if ($sinknotif['objtype'] == MAPI_FOLDER) {
$hierarchyNotifications[$sinknotif['entryid']] = IBackend::HIERARCHYNOTIFICATION;
}
// change on a message, remove hierarchy notification
if (isset($sinknotif['parentid']) && $sinknotif['objtype'] == MAPI_MESSAGE && isset($notifications[$sinknotif['parentid']])) {
unset($hierarchyNotifications[$sinknotif['parentid']]);
}
// TODO check if adding $sinknotif['objtype'] = MAPI_MESSAGE wouldn't break anything
// check if something in the monitored folders changed
if (isset($sinknotif['parentid']) && array_key_exists($sinknotif['parentid'], $this->changesSinkFolders)) {
$notifications[] = $this->changesSinkFolders[$sinknotif['parentid']];
}
// deletes and moves
if (isset($sinknotif['oldparentid']) && array_key_exists($sinknotif['oldparentid'], $this->changesSinkFolders)) {
$notifications[] = $this->changesSinkFolders[$sinknotif['oldparentid']];
}
}
// validate hierarchy notifications by comparing the hierarchy hashes (too many false positives otherwise)
if (!empty($hierarchyNotifications)) {
$hash = $this->getHierarchyHash();
if ($hash !== $this->changesSinkHierarchyHash) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->ChangesSink() Hierarchy notification, pending validation. New hierarchyHash: %s", $hash));
$notifications[] = IBackend::HIERARCHYNOTIFICATION;
$this->changesSinkHierarchyHash = $hash;
}
}
return $notifications;
}
/**
* Applies settings to and gets informations from the device
*
* @param SyncObject $settings (SyncOOF or SyncUserInformation possible)
*
* @access public
* @return SyncObject $settings
*/
public function Settings($settings) {
if ($settings instanceof SyncOOF) {
$this->settingsOOF($settings);
}
if ($settings instanceof SyncUserInformation) {
$this->settingsUserInformation($settings);
}
return $settings;
}
/**
* Resolves recipients
*
* @param SyncObject $resolveRecipients
*
* @access public
* @return SyncObject $resolveRecipients
*/
public function ResolveRecipients($resolveRecipients) {
if ($resolveRecipients instanceof SyncResolveRecipients) {
$resolveRecipients->status = SYNC_RESOLVERECIPSSTATUS_SUCCESS;
$resolveRecipients->response = array();
$resolveRecipientsOptions = new SyncResolveRecipientsOptions();
$maxAmbiguousRecipients = self::MAXAMBIGUOUSRECIPIENTS;
if (isset($resolveRecipients->options)) {
$resolveRecipientsOptions = $resolveRecipients->options;
// only limit ambiguous recipients if the client requests it.
if (isset($resolveRecipientsOptions->maxambiguousrecipients) &&
$resolveRecipientsOptions->maxambiguousrecipients >= 0 &&
$resolveRecipientsOptions->maxambiguousrecipients <= self::MAXAMBIGUOUSRECIPIENTS) {
$maxAmbiguousRecipients = $resolveRecipientsOptions->maxambiguousrecipients;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("The client requested %d max ambigous recipients to resolve.", $maxAmbiguousRecipients));
}
}
foreach ($resolveRecipients->to as $i => $to) {
$response = new SyncResolveRecipientsResponse();
$response->to = $to;
$response->status = SYNC_RESOLVERECIPSSTATUS_SUCCESS;
$recipient = $this->resolveRecipient($to, $maxAmbiguousRecipients);
if (is_array($recipient) && !empty($recipient)) {
$response->recipientcount = 0;
foreach ($recipient as $entry) {
if ($entry instanceof SyncResolveRecipient) {
// certificates are already set. Unset them if they weren't required.
if (!isset($resolveRecipientsOptions->certificateretrieval)) {
unset($entry->certificates);
}
if (isset($resolveRecipientsOptions->availability)) {
if (!isset($resolveRecipientsOptions->starttime)) {
// TODO error, the request must include a valid StartTime element value
}
$entry->availability = $this->getAvailability($to, $entry, $resolveRecipientsOptions);
}
if (isset($resolveRecipientsOptions->picture)) {
// TODO implement picture retrieval of the recipient
}
$response->recipientcount++;
$response->recipient[] = $entry;
}
elseif (is_int($recipient)) {
$response->status = $recipient;
}
}
}
$resolveRecipients->response[$i] = $response;
}
return $resolveRecipients;
}
ZLog::Write(LOGLEVEL_WARN, "Not a valid SyncResolveRecipients object.");
// return a SyncResolveRecipients object so that sync doesn't fail
$r = new SyncResolveRecipients();
$r->status = SYNC_RESOLVERECIPSSTATUS_PROTOCOLERROR;
return $r;
}
/**
* Returns the policy name for the user.
* If the backend returns false, the 'default' policy is used.
* If the backend returns any other name than 'default' the policygroup with
* that name (defined in the policies.ini file) will be applied for this user.
*
* @access public
* @return string|boolean
*/
public function GetUserPolicyName() {
// TODO: get the user's policy from the users' directory
return false;
}
/**
* Returns the backend ID of the folder of the KOE GAB.
*
* @param string $foldername
*
* @access public
* @return string|boolean
*/
public function GetKoeGabBackendFolderId($foldername) {
$rootfolder = mapi_msgstore_openentry($this->store);
$table = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
$restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_DISPLAY_NAME, VALUE => $foldername));
mapi_table_restrict($table, $restriction);
$querycnt = mapi_table_getrowcount($table);
if ($querycnt == 1) {
$entry = mapi_table_queryallrows($table, array(PR_SOURCE_KEY));
if (isset($entry[0]) && isset($entry[0][PR_SOURCE_KEY])) {
return bin2hex($entry[0][PR_SOURCE_KEY]);
}
}
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->GetKoeGabBackendFolderId() Found %d entries in the store '%s' matching the name '%s'.", $querycnt, $this->storeName, $foldername));
return false;
}
/**----------------------------------------------------------------------------------------------------------
* Implementation of the ISearchProvider interface
*/
/**
* Indicates if a search type is supported by this SearchProvider
* Currently only the type ISearchProvider::SEARCH_GAL (Global Address List) is implemented
*
* @param string $searchtype
*
* @access public
* @return boolean
*/
public function SupportsType($searchtype) {
return ($searchtype == ISearchProvider::SEARCH_GAL) || ($searchtype == ISearchProvider::SEARCH_MAILBOX);
}
/**
* Searches the GAB of Kopano
* Can be overwitten globally by configuring a SearchBackend
*
* @param string $searchquery
* @param string $searchrange
*
* @access public
* @return array
* @throws StatusException
*/
public function GetGALSearchResults($searchquery, $searchrange){
// only return users whose displayName or the username starts with $name
//TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT
$addrbook = $this->getAddressbook();
// FIXME: create a function to get the adressbook contentstable
if ($addrbook)
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
if ($ab_entryid)
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
if ($ab_dir)
$table = mapi_folder_getcontentstable($ab_dir);
if (!$table)
throw new StatusException(sprintf("KopanoBackend->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED);
$restriction = MAPIUtils::GetSearchRestriction(u2w($searchquery));
mapi_table_restrict($table, $restriction);
mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
if (mapi_last_hresult())
throw new StatusException(sprintf("KopanoBackend->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX);
//range for the search results, default symbian range end is 50, wm 99,
//so we'll use that of nokia
$rangestart = 0;
$rangeend = 50;
if ($searchrange != '0') {
$pos = strpos($searchrange, '-');
$rangestart = substr($searchrange, 0, $pos);
$rangeend = substr($searchrange, ($pos + 1));
}
$items = array();
$querycnt = mapi_table_getrowcount($table);
//do not return more results as requested in range
$querylimit = (($rangeend + 1) < $querycnt) ? ($rangeend + 1) : $querycnt;
if ($querycnt > 0)
$abentries = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION), $rangestart, $querylimit);
for ($i = 0; $i < $querylimit; $i++) {
if (!isset($abentries[$i][PR_SMTP_ADDRESS])) {
ZLog::Write(LOGLEVEL_WARN, sprintf("The GAL entry '%s' does not have an email address and will be ignored.", w2u($abentries[$i][PR_DISPLAY_NAME])));
continue;
}
$items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_DISPLAY_NAME]);
if (strlen(trim($items[$i][SYNC_GAL_DISPLAYNAME])) == 0)
$items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_ACCOUNT]);
$items[$i][SYNC_GAL_ALIAS] = w2u($abentries[$i][PR_ACCOUNT]);
//it's not possible not get first and last name of an user
//from the gab and user functions, so we just set lastname
//to displayname and leave firstname unset
//this was changed in Zarafa 6.40, so we try to get first and
//last name and fall back to the old behaviour if these values are not set
if (isset($abentries[$i][PR_GIVEN_NAME]))
$items[$i][SYNC_GAL_FIRSTNAME] = w2u($abentries[$i][PR_GIVEN_NAME]);
if (isset($abentries[$i][PR_SURNAME]))
$items[$i][SYNC_GAL_LASTNAME] = w2u($abentries[$i][PR_SURNAME]);
if (!isset($items[$i][SYNC_GAL_LASTNAME])) $items[$i][SYNC_GAL_LASTNAME] = $items[$i][SYNC_GAL_DISPLAYNAME];
$items[$i][SYNC_GAL_EMAILADDRESS] = w2u($abentries[$i][PR_SMTP_ADDRESS]);
//check if an user has an office number or it might produce warnings in the log
if (isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]))
$items[$i][SYNC_GAL_PHONE] = w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]);
//check if an user has a mobile number or it might produce warnings in the log
if (isset($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]))
$items[$i][SYNC_GAL_MOBILEPHONE] = w2u($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]);
//check if an user has a home number or it might produce warnings in the log
if (isset($abentries[$i][PR_HOME_TELEPHONE_NUMBER]))
$items[$i][SYNC_GAL_HOMEPHONE] = w2u($abentries[$i][PR_HOME_TELEPHONE_NUMBER]);
if (isset($abentries[$i][PR_COMPANY_NAME]))
$items[$i][SYNC_GAL_COMPANY] = w2u($abentries[$i][PR_COMPANY_NAME]);
if (isset($abentries[$i][PR_TITLE]))
$items[$i][SYNC_GAL_TITLE] = w2u($abentries[$i][PR_TITLE]);
if (isset($abentries[$i][PR_OFFICE_LOCATION]))
$items[$i][SYNC_GAL_OFFICE] = w2u($abentries[$i][PR_OFFICE_LOCATION]);
}
$nrResults = count($items);
$items['range'] = ($nrResults > 0) ? $rangestart.'-'.($nrResults - 1) : '0-0';
$items['searchtotal'] = $nrResults;
return $items;
}
/**
* Searches for the emails on the server
*
* @param ContentParameter $cpo
*
* @return array
*/
public function GetMailboxSearchResults($cpo) {
$searchFolder = $this->getSearchFolder();
$searchRestriction = $this->getSearchRestriction($cpo);
$searchRange = explode('-', $cpo->GetSearchRange());
$searchFolderId = $cpo->GetSearchFolderid();
$searchFolders = array();
// search only in required folders
if (!empty($searchFolderId)) {
$searchFolderEntryId = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($searchFolderId));
$searchFolders[] = $searchFolderEntryId;
}
// if no folder was required then search in the entire store
else {
$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);
$searchStart = time();
// do the search and wait for all the results available
while (time() - $searchStart < SEARCH_WAIT) {
$searchcriteria = mapi_folder_getsearchcriteria($searchFolder);
if(($searchcriteria["searchstate"] & SEARCH_REBUILD) == 0)
break; // Search is done
sleep(1);
}
// if the search range is set limit the result to it, otherwise return all found messages
$rows = (is_array($searchRange) && isset($searchRange[0]) && isset($searchRange[1])) ?
mapi_table_queryrows($table, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY), $searchRange[0], $searchRange[1] - $searchRange[0] + 1) :
mapi_table_queryrows($table, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY), 0, SEARCH_MAXRESULTS);
$cnt = count($rows);
$items['searchtotal'] = $cnt;
$items["range"] = $cpo->GetSearchRange();
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]);
}
return $items;
}
/**
* Terminates a search for a given PID
*
* @param int $pid
*
* @return boolean
*/
public function TerminateSearch($pid) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->TerminateSearch(): terminating search for pid %d", $pid));
if (!isset($this->store) || $this->store === false) {
ZLog::Write(LOGLEVEL_WARN, sprintf("The store is not available. It is not possible to remove search folder with pid %d", $pid));
return false;
}
$storeProps = mapi_getprops($this->store, array(PR_STORE_SUPPORT_MASK, PR_FINDER_ENTRYID));
if (($storeProps[PR_STORE_SUPPORT_MASK] & STORE_SEARCH_OK) != STORE_SEARCH_OK) {
ZLog::Write(LOGLEVEL_WARN, "Store doesn't support search folders. Public store doesn't have FINDER_ROOT folder");
return false;
}
$finderfolder = mapi_msgstore_openentry($this->store, $storeProps[PR_FINDER_ENTRYID]);
if(mapi_last_hresult() != NOERROR) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open search folder (0x%X)", mapi_last_hresult()));
return false;
}
$hierarchytable = mapi_folder_gethierarchytable($finderfolder);
mapi_table_restrict($hierarchytable,
array(RES_CONTENT,
array(
FUZZYLEVEL => FL_PREFIX,
ULPROPTAG => PR_DISPLAY_NAME,
VALUE => array(PR_DISPLAY_NAME=>"Z-Push Search Folder ".$pid)
)
),
TBL_BATCH);
$folders = mapi_table_queryallrows($hierarchytable, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_LAST_MODIFICATION_TIME));
foreach($folders as $folder) {
mapi_folder_deletefolder($finderfolder, $folder[PR_ENTRYID]);
}
return true;
}
/**
* Disconnects from the current search provider
*
* @access public
* @return boolean
*/
public function Disconnect() {
return true;
}
/**
* Returns the MAPI store ressource for a folderid
* This is not part of IBackend but necessary for the ImportChangesICS->MoveMessage() operation if
* the destination folder is not in the default store
* Note: The current backend store might be changed as IBackend->Setup() is executed
*
* @param string $store target store, could contain a "domain\user" value - if emtpy default store is returned
* @param string $folderid
*
* @access public
* @return Ressource/boolean
*/
public function GetMAPIStoreForFolderId($store, $folderid) {
if ($store == false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetMAPIStoreForFolderId('%s', '%s'): no store specified, returning default store", $store, $folderid));
return $this->defaultstore;
}
// setup the correct store
if ($this->Setup($store, false, $folderid)) {
return $this->store;
}
else {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->GetMAPIStoreForFolderId('%s', '%s'): store is not available", $store, $folderid));
return false;
}
}
/**
* Returns the email address and the display name of the user. Used by autodiscover.
*
* @param string $username The username
*
* @access public
* @return Array
*/
public function GetUserDetails($username) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("KopanoBackend->GetUserDetails for '%s'.", $username));
$zarafauserinfo = @mapi_zarafa_getuser_by_name($this->store, $username);
$userDetails['emailaddress'] = (isset($zarafauserinfo['emailaddress']) && $zarafauserinfo['emailaddress']) ? $zarafauserinfo['emailaddress'] : false;
$userDetails['fullname'] = (isset($zarafauserinfo['fullname']) && $zarafauserinfo['fullname']) ? $zarafauserinfo['fullname'] : false;
return $userDetails;
}
/**
* Returns the username of the currently active user
*
* @access public
* @return String
*/
public function GetCurrentUsername() {
return $this->storeName;
}
/**
* Indicates if the Backend supports folder statistics.
*
* @access public
* @return boolean
*/
public function HasFolderStats() {
return true;
}
/**
* Returns a status indication of the folder.
* If there are changes in the folder, the returned value must change.
* The returned values are compared with '===' to determine if a folder needs synchronization or not.
*
* @param string $store the store where the folder resides
* @param string $folderid the folder id
*
* @access public
* @return string
*/
public function GetFolderStat($store, $folderid) {
list($user, $domain) = Utils::SplitDomainUser($store);
if ($user === false) {
$user = $this->mainUser;
}
// if there is a ReplyBackImExporter, the exporter needs to run!
$wrapper = KopanoChangesWrapper::GetWrapper($user, false, null, $folderid, null);
if ($wrapper && $wrapper->HasReplyBackExporter()) {
return "replyback-". time();
}
if (!isset($this->folderStatCache[$user])) {
$this->folderStatCache[$user] = array();
}
// if there is nothing in the cache for a store, load the data for all folders of it
if (empty($this->folderStatCache[$user])) {
// get the store
$userstore = $this->openMessageStore($user);
$rootfolder = mapi_msgstore_openentry($userstore);
$hierarchy = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
$rows = mapi_table_queryallrows($hierarchy, array(PR_SOURCE_KEY, PR_LOCAL_COMMIT_TIME_MAX, PR_CONTENT_COUNT, PR_CONTENT_UNREAD, PR_DELETED_MSG_COUNT));
if (count($rows) == 0) {
ZLog::Write(LOGLEVEL_INFO, sprintf("KopanoBackend->GetFolderStat(): could not access folder statistics for user '%s'. Probably missing 'read' permissions on the root folder! Folders of this store will be synchronized ONCE per hour only!", $user));
}
foreach($rows as $folder) {
$commit_time = isset($folder[PR_LOCAL_COMMIT_TIME_MAX])? $folder[PR_LOCAL_COMMIT_TIME_MAX] : "0000000000";
$content_count = isset($folder[PR_CONTENT_COUNT])? $folder[PR_CONTENT_COUNT] : -1;
$content_unread = isset($folder[PR_CONTENT_UNREAD])? $folder[PR_CONTENT_UNREAD] : -1;
$content_deleted = isset($folder[PR_DELETED_MSG_COUNT])? $folder[PR_DELETED_MSG_COUNT] : -1;
$this->folderStatCache[$user][bin2hex($folder[PR_SOURCE_KEY])] = $commit_time ."/". $content_count ."/". $content_unread ."/". $content_deleted;
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetFolderStat() fetched status information of %d folders for store '%s'", count($this->folderStatCache[$user]), $user));
}
if (isset($this->folderStatCache[$user][$folderid])) {
return $this->folderStatCache[$user][$folderid];
}
else {
// a timestamp that changes once per hour is returned in case there is no data found for this folder. It will be synchronized only once per hour.
return gmdate("Y-m-d-H");
}
}
/**
* Returns a KoeSignatures object.
*
* @access public
* @return KoeSignatures
*/
public function GetKoeSignatures() {
$sigs = new KoeSignatures();
$storeProps = mapi_getprops($this->store, array(PR_EC_WEBACCESS_SETTINGS_JSON));
// Check if property exists, if it doesn't exist then we can continue with an empty signature object
if (isset($storeProps[PR_EC_WEBACCESS_SETTINGS_JSON]) || MAPIUtils::GetError(PR_EC_WEBACCESS_SETTINGS_JSON, $storeProps) == MAPI_E_NOT_ENOUGH_MEMORY) {
$settings_string = MAPIUtils::readPropStream($this->store, PR_EC_WEBACCESS_SETTINGS_JSON);
if(!empty($settings_string)) {
$settings = json_decode($settings_string, true);
if (json_last_error()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->GetKoeSignatures(): Error decoding JSON WebApp settings: %s", json_last_error()));
}
if (isset($settings['settings']['zarafa']['v1']['contexts']['mail']['signatures'])) {
// convert WebApp signatures into KoeSignatures object
$sigs->LoadSignaturesFromData($settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetKoeSignatures(): Found %d signatures - new '%s' - reply/fw: '%s' - hash: %s", count($sigs->GetSignatures()), $sigs->GetNewMessageSignatureId(), $sigs->GetReplyForwardSignatureId(), $sigs->GetHash()));
}
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->GetKoeSignatures(): No signature data in WebApp settings");
}
}
}
return $sigs;
}
/**----------------------------------------------------------------------------------------------------------
* Private methods
*/
/**
* Returns a hash representing changes in the hierarchy of the main user.
* It changes if a folder is added, renamed or deleted.
*
* @access private
* @return string
*/
private function getHierarchyHash() {
$rootfolder = mapi_msgstore_openentry($this->defaultstore);
$hierarchy = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
return md5(serialize(mapi_table_queryallrows($hierarchy, array(PR_DISPLAY_NAME, PR_PARENT_ENTRYID))));
}
/**
* Advises a store to the changes sink
*
* @param mapistore $store store to be advised
*
* @access private
* @return boolean
*/
private function adviseStoreToSink($store) {
// check if we already advised the store
if (!in_array($store, $this->changesSinkStores)) {
mapi_msgstore_advise($store, null, fnevObjectModified | fnevObjectCreated | fnevObjectMoved | fnevObjectDeleted, $this->changesSink);
if (mapi_last_hresult()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->adviseStoreToSink(): failed to advised store '%s' with code 0x%X. Polling will be performed.", $store, mapi_last_hresult()));
return false;
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->adviseStoreToSink(): advised store '%s'", $store));
$this->changesSinkStores[] = $store;
}
}
return true;
}
/**
* Open the store marked with PR_DEFAULT_STORE = TRUE
* if $return_public is set, the public store is opened
*
* @param string $user User which store should be opened
*
* @access public
* @return boolean
*/
private function openMessageStore($user) {
// During PING requests the operations store has to be switched constantly
// the cache prevents the same store opened several times
if (isset($this->storeCache[$user]))
return $this->storeCache[$user];
$entryid = false;
$return_public = false;
if (strtoupper($user) == 'SYSTEM')
$return_public = true;
// loop through the storestable if authenticated user of public folder
if ($user == $this->mainUser || $return_public === true) {
// Find the default store
$storestables = mapi_getmsgstorestable($this->session);
$result = mapi_last_hresult();
if ($result == NOERROR){
$rows = mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_DEFAULT_STORE, PR_MDB_PROVIDER));
foreach($rows as $row) {
if(!$return_public && isset($row[PR_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE] == true) {
$entryid = $row[PR_ENTRYID];
break;
}
if ($return_public && isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
$entryid = $row[PR_ENTRYID];
break;
}
}
}
}
else
$entryid = @mapi_msgstore_createentryid($this->defaultstore, $user);
if($entryid) {
$store = @mapi_openmsgstore($this->session, $entryid);
if (!$store) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->openMessageStore('%s'): Could not open store", $user));
return false;
}
// add this store to the cache
if (!isset($this->storeCache[$user]))
$this->storeCache[$user] = $store;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->openMessageStore('%s'): Found '%s' store: '%s'", $user, (($return_public)?'PUBLIC':'DEFAULT'),$store));
return $store;
}
else {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->openMessageStore('%s'): No store found for this user", $user));
return false;
}
}
/**
* Checks if the logged in user has secretary permissions on a folder.
*
* @param ressource $store
* @param string $folderid
*
* @access public
* @return boolean
*/
public function HasSecretaryACLs($store, $folderid) {
$entryid = mapi_msgstore_entryidfromsourcekey($store, hex2bin($folderid));
if (!$entryid) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->HasSecretaryACLs(): error, no entryid resolved for %s on store %s", $folderid, $store));
return false;
}
$folder = mapi_msgstore_openentry($store, $entryid);
if (!$folder) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->HasSecretaryACLs(): error, could not open folder with entryid %s on store %s", bin2hex($entryid), $store));
return false;
}
$props = mapi_getprops($folder, array(PR_RIGHTS));
if (isset($props[PR_RIGHTS]) &&
($props[PR_RIGHTS] & ecRightsReadAny) &&
($props[PR_RIGHTS] & ecRightsCreate) &&
($props[PR_RIGHTS] & ecRightsEditOwned) &&
($props[PR_RIGHTS] & ecRightsDeleteOwned) &&
($props[PR_RIGHTS] & ecRightsEditAny) &&
($props[PR_RIGHTS] & ecRightsDeleteAny) &&
($props[PR_RIGHTS] & ecRightsFolderVisible) ) {
return true;
}
return false;
}
/**
* Checks if the logged in user has read permissions on a folder.
*
* @param ressource $store
* @param string $folderid
*
* @access public
* @return boolean
*/
public function HasReadACLs($store, $folderid) {
$entryid = mapi_msgstore_entryidfromsourcekey($store, hex2bin($folderid));
if (!$entryid) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->HasReadACLs(): error, no entryid resolved for %s on store %s", $folderid, $store));
return false;
}
$folder = mapi_msgstore_openentry($store, $entryid);
if (!$folder) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->HasReadACLs(): error, could not open folder with entryid %s on store %s", bin2hex($entryid), $store));
return false;
}
$props = mapi_getprops($folder, array(PR_RIGHTS));
if (isset($props[PR_RIGHTS]) &&
($props[PR_RIGHTS] & ecRightsReadAny) ) {
return true;
}
return false;
}
/**
* The meta function for out of office settings.
*
* @param SyncObject $oof
*
* @access private
* @return void
*/
private function settingsOOF(&$oof) {
//if oof state is set it must be set of oof and get otherwise
if (isset($oof->oofstate)) {
$this->settingsOofSet($oof);
}
else {
$this->settingsOofGet($oof);
}
}
/**
* Gets the out of office settings
*
* @param SyncObject $oof
*
* @access private
* @return void
*/
private function settingsOofGet(&$oof) {
$oofprops = mapi_getprops($this->defaultstore, array(PR_EC_OUTOFOFFICE, PR_EC_OUTOFOFFICE_MSG, PR_EC_OUTOFOFFICE_SUBJECT, PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL));
$oof->oofstate = SYNC_SETTINGSOOF_DISABLED;
$oof->Status = SYNC_SETTINGSSTATUS_SUCCESS;
if ($oofprops != false) {
$oof->oofstate = isset($oofprops[PR_EC_OUTOFOFFICE]) ? ($oofprops[PR_EC_OUTOFOFFICE] ? SYNC_SETTINGSOOF_GLOBAL : SYNC_SETTINGSOOF_DISABLED) : SYNC_SETTINGSOOF_DISABLED;
//TODO external and external unknown
$oofmessage = new SyncOOFMessage();
$oofmessage->appliesToInternal = "";
$oofmessage->enabled = $oof->oofstate;
$oofmessage->replymessage = (isset($oofprops[PR_EC_OUTOFOFFICE_MSG])) ? w2u($oofprops[PR_EC_OUTOFOFFICE_MSG]) : "";
$oofmessage->bodytype = $oof->bodytype;
unset($oofmessage->appliesToExternal, $oofmessage->appliesToExternalUnknown);
$oof->oofmessage[] = $oofmessage;
// check whether time based out of office is set
if ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && isset($oofprops[PR_EC_OUTOFOFFICE_FROM], $oofprops[PR_EC_OUTOFOFFICE_UNTIL])) {
$now = time();
if ($now > $oofprops[PR_EC_OUTOFOFFICE_FROM] && $now > $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) {
// Out of office is set but the date is in the past. Set the state to disabled.
// @see https://jira.z-hub.io/browse/ZP-1188 for details
$oof->oofstate = SYNC_SETTINGSOOF_DISABLED;
@mapi_setprops($this->defaultstore, array(PR_EC_OUTOFOFFICE => false));
@mapi_deleteprops($this->defaultstore, array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL));
ZLog::Write(LOGLEVEL_INFO, "BackendKopano->settingsOofGet(): Out of office is set but the from and until are in the past. Disabling out of office.");
}
elseif ($oofprops[PR_EC_OUTOFOFFICE_FROM] < $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) {
$oof->oofstate = SYNC_SETTINGSOOF_TIMEBASED;
$oof->starttime = $oofprops[PR_EC_OUTOFOFFICE_FROM];
$oof->endtime = $oofprops[PR_EC_OUTOFOFFICE_UNTIL];
}
else {
ZLog::Write(LOGLEVEL_WARN, sprintf("BackendKopano->settingsOofGet(): Time based out of office set but end time ('%s') is before startime ('%s').",
date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]), date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL])));
$oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR;
}
}
elseif ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && (isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) || isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]))) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Kopano->settingsOofGet(): Time based out of office set but either start time ('%s') or end time ('%s') is missing.",
(isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]) : 'empty'),
(isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) : 'empty')));
$oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR;
}
}
else {
ZLog::Write(LOGLEVEL_WARN, "Unable to get out of office information");
}
//unset body type for oof in order not to stream it
unset($oof->bodytype);
}
/**
* Sets the out of office settings.
*
* @param SyncObject $oof
*
* @access private
* @return void
*/
private function settingsOofSet(&$oof) {
$oof->Status = SYNC_SETTINGSSTATUS_SUCCESS;
$props = array();
if ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL || $oof->oofstate == SYNC_SETTINGSOOF_TIMEBASED) {
$props[PR_EC_OUTOFOFFICE] = true;
foreach ($oof->oofmessage as $oofmessage) {
if (isset($oofmessage->appliesToInternal)) {
$props[PR_EC_OUTOFOFFICE_MSG] = isset($oofmessage->replymessage) ? u2w($oofmessage->replymessage) : "";
$props[PR_EC_OUTOFOFFICE_SUBJECT] = "Out of office";
}
}
if ($oof->oofstate == SYNC_SETTINGSOOF_TIMEBASED) {
if(isset($oof->starttime) && isset($oof->endtime)) {
$props[PR_EC_OUTOFOFFICE_FROM] = $oof->starttime;
$props[PR_EC_OUTOFOFFICE_UNTIL] = $oof->endtime;
}
elseif (isset($oof->starttime) || isset($oof->endtime)) {
$oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR;
}
}
else {
$deleteProps = array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL);
}
}
elseif($oof->oofstate == SYNC_SETTINGSOOF_DISABLED) {
$props[PR_EC_OUTOFOFFICE] = false;
$deleteProps = array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL);
}
if (!empty($props)) {
@mapi_setprops($this->defaultstore, $props);
$result = mapi_last_hresult();
if ($result != NOERROR) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("Setting oof information failed (%X)", $result));
return false;
}
}
if (!empty($deleteProps)) {
@mapi_deleteprops($this->defaultstore, $deleteProps);
}
return true;
}
/**
* Gets the user's email address from server
*
* @param SyncObject $userinformation
*
* @access private
* @return void
*/
private function settingsUserInformation(&$userinformation) {
if (!isset($this->defaultstore) || !isset($this->mainUser)) {
ZLog::Write(LOGLEVEL_ERROR, "The store or user are not available for getting user information");
return false;
}
$user = mapi_zarafa_getuser($this->defaultstore, $this->mainUser);
if ($user != false) {
$userinformation->Status = SYNC_SETTINGSSTATUS_USERINFO_SUCCESS;
$userinformation->emailaddresses[] = $user["emailaddress"];
return true;
}
ZLog::Write(LOGLEVEL_ERROR, sprintf("Getting user information failed: mapi_zarafa_getuser(%X)", mapi_last_hresult()));
return false;
}
/**
* Sets the importance and priority of a message from a RFC822 message headers.
*
* @param int $xPriority
* @param array $mapiprops
*
* @return void
*/
private function getImportanceAndPriority($xPriority, &$mapiprops, $sendMailProps) {
switch($xPriority) {
case 1:
case 2:
$priority = PRIO_URGENT;
$importance = IMPORTANCE_HIGH;
break;
case 4:
case 5:
$priority = PRIO_NONURGENT;
$importance = IMPORTANCE_LOW;
break;
case 3:
default:
$priority = PRIO_NORMAL;
$importance = IMPORTANCE_NORMAL;
break;
}
$mapiprops[$sendMailProps["importance"]] = $importance;
$mapiprops[$sendMailProps["priority"]] = $priority;
}
/**
* Copies attachments from one message to another.
*
* @param MAPIMessage $toMessage
* @param MAPIMessage $fromMessage
*
* @return void
*/
private function copyAttachments(&$toMessage, $fromMessage) {
$attachtable = mapi_message_getattachmenttable($fromMessage);
$rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
foreach($rows as $row) {
if(isset($row[PR_ATTACH_NUM])) {
$attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
$newattach = mapi_message_createattach($toMessage);
mapi_copyto($attach, array(), array(), $newattach, 0);
mapi_savechanges($newattach);
}
}
}
/**
* Function will create a search folder in FINDER_ROOT folder
* if folder exists then it will open it
*
* @see createSearchFolder($store, $openIfExists = true) function in the webaccess
*
* @return mapiFolderObject $folder created search folder
*/
private function getSearchFolder() {
// create new or open existing search folder
$searchFolderRoot = $this->getSearchFoldersRoot($this->store);
if($searchFolderRoot === false) {
// error in finding search root folder
// or store doesn't support search folders
return false;
}
$searchFolder = $this->createSearchFolder($searchFolderRoot);
if($searchFolder !== false && mapi_last_hresult() == NOERROR) {
return $searchFolder;
}
return false;
}
/**
* Function will open FINDER_ROOT folder in root container
* public folder's don't have FINDER_ROOT folder
*
* @see getSearchFoldersRoot($store) function in the webaccess
*
* @return mapiFolderObject root folder for search folders
*/
private function getSearchFoldersRoot() {
// check if we can create search folders
$storeProps = mapi_getprops($this->store, array(PR_STORE_SUPPORT_MASK, PR_FINDER_ENTRYID));
if(($storeProps[PR_STORE_SUPPORT_MASK] & STORE_SEARCH_OK) != STORE_SEARCH_OK) {
ZLog::Write(LOGLEVEL_WARN, "Store doesn't support search folders. Public store doesn't have FINDER_ROOT folder");
return false;
}
// open search folders root
$searchRootFolder = mapi_msgstore_openentry($this->store, $storeProps[PR_FINDER_ENTRYID]);
if(mapi_last_hresult() != NOERROR) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open search folder (0x%X)", mapi_last_hresult()));
return false;
}
return $searchRootFolder;
}
/**
* Creates a search folder if it not exists or opens an existing one
* and returns it.
*
* @param mapiFolderObject $searchFolderRoot
*
* @return mapiFolderObject
*/
private function createSearchFolder($searchFolderRoot) {
$folderName = "Z-Push Search Folder ".@getmypid();
$searchFolders = mapi_folder_gethierarchytable($searchFolderRoot);
$restriction = array(
RES_CONTENT,
array(
FUZZYLEVEL => FL_PREFIX,
ULPROPTAG => PR_DISPLAY_NAME,
VALUE => array(PR_DISPLAY_NAME=>$folderName)
)
);
//restrict the hierarchy to the z-push search folder only
mapi_table_restrict($searchFolders, $restriction);
if (mapi_table_getrowcount($searchFolders)) {
$searchFolder = mapi_table_queryrows($searchFolders, array(PR_ENTRYID), 0, 1);
return mapi_msgstore_openentry($this->store, $searchFolder[0][PR_ENTRYID]);
}
return mapi_folder_createfolder($searchFolderRoot, $folderName, null, 0, FOLDER_SEARCH);
}
/**
* Creates a search restriction
*
* @param ContentParameter $cpo
* @return array
*/
private function getSearchRestriction($cpo) {
$searchText = $cpo->GetSearchFreeText();
$searchGreater = strtotime($cpo->GetSearchValueGreater());
$searchLess = strtotime($cpo->GetSearchValueLess());
if (version_compare(phpversion(),'5.3.4') < 0) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Your system's PHP version (%s) might not correctly process unicode strings. Search containing such characters might not return correct results. It is recommended to update to at least PHP 5.3.4. See ZP-541 for more information.", phpversion()));
}
// split the search on whitespache and look for every word
$searchText = preg_split("/\W+/u", $searchText);
$searchProps = array(PR_BODY, PR_SUBJECT, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SENDER_NAME, PR_SENDER_EMAIL_ADDRESS, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS);
$resAnd = array();
foreach($searchText as $term) {
$resOr = array();
foreach($searchProps as $property) {
array_push($resOr,
array(RES_CONTENT,
array(
FUZZYLEVEL => FL_SUBSTRING|FL_IGNORECASE,
ULPROPTAG => $property,
VALUE => u2w($term)
)
)
);
}
array_push($resAnd, array(RES_OR, $resOr));
}
// add time range restrictions
if ($searchGreater) {
array_push($resAnd, array(RES_PROPERTY, array(RELOP => RELOP_GE, ULPROPTAG => PR_MESSAGE_DELIVERY_TIME, VALUE => array(PR_MESSAGE_DELIVERY_TIME => $searchGreater)))); // RES_AND;
}
if ($searchLess) {
array_push($resAnd, array(RES_PROPERTY, array(RELOP => RELOP_LE, ULPROPTAG => PR_MESSAGE_DELIVERY_TIME, VALUE => array(PR_MESSAGE_DELIVERY_TIME => $searchLess))));
}
$mapiquery = array(RES_AND, $resAnd);
return $mapiquery;
}
/**
* Resolve recipient based on his email address.
*
* @param string $to
* @param int $maxAmbiguousRecipients
*
* @return SyncResolveRecipient|boolean
*/
private function resolveRecipient($to, $maxAmbiguousRecipients) {
$recipient = $this->resolveRecipientGAL($to, $maxAmbiguousRecipients);
if ($recipient !== false) {
return $recipient;
}
$recipient = $this->resolveRecipientContact($to, $maxAmbiguousRecipients);
if ($recipient !== false) {
return $recipient;
}
return false;
}
/**
* Resolves recipient from the GAL and gets his certificates.
*
* @param string $to
* @param int $maxAmbiguousRecipients
* @return array|boolean
*/
private function resolveRecipientGAL($to, $maxAmbiguousRecipients) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("Resolving recipient '%s' in GAL", $to));
$addrbook = $this->getAddressbook();
// FIXME: create a function to get the adressbook contentstable
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
if ($ab_entryid)
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
if ($ab_dir)
$table = mapi_folder_getcontentstable($ab_dir);
if (!$table) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open addressbook:0x%X", mapi_last_hresult()));
return false;
}
$restriction = MAPIUtils::GetSearchRestriction(u2w($to));
mapi_table_restrict($table, $restriction);
$querycnt = mapi_table_getrowcount($table);
if ($querycnt > 0) {
$recipientGal = array();
$rowsToQuery = $maxAmbiguousRecipients;
// some devices request 0 ambiguous recipients
if ($querycnt == 1 && $maxAmbiguousRecipients == 0) {
$rowsToQuery = 1;
}
elseif ($querycnt > 1 && $maxAmbiguousRecipients == 0) {
ZLog::Write(LOGLEVEL_INFO, sprintf("GAL search found %d recipients but the device hasn't requested ambiguous recipients", $querycnt));
return $recipientGal;
}
// get the certificate every time because caching the certificate is less expensive than opening addressbook entry again
$abentries = mapi_table_queryrows($table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_EMS_AB_TAGGED_X509_CERT, PR_OBJECT_TYPE), 0, $rowsToQuery);
for ($i = 0, $nrEntries = count($abentries); $i < $nrEntries; $i++) {
if ($abentries[$i][PR_OBJECT_TYPE] == MAPI_DISTLIST) {
// dist lists must be expanded into their members
ZLog::Write(LOGLEVEL_DEBUG, sprintf("'%s' is a dist list. Expand it to members.", $to));
$distList = mapi_ab_openentry($addrbook, $abentries[$i][PR_ENTRYID]);
$distListContent = mapi_folder_getcontentstable($distList);
$distListMembers = mapi_table_queryallrows($distListContent, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_EMS_AB_TAGGED_X509_CERT));
for ($j = 0, $nrDistListMembers = mapi_table_getrowcount($distListContent); $j < $nrDistListMembers; $j++) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("distlist's '%s' member", $to, $distListMembers[$j][PR_DISPLAY_NAME]));
$recipientGal[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, $to, $distListMembers[$j], $nrDistListMembers);
}
}
elseif ($abentries[$i][PR_OBJECT_TYPE] == MAPI_MAILUSER) {
$recipientGal[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, $to, $abentries[$i]);
}
}
ZLog::Write(LOGLEVEL_WBXML, "Found a recipient in GAL");
return $recipientGal;
}
else {
ZLog::Write(LOGLEVEL_WARN, sprintf("No recipient found for: '%s' in GAL", $to));
return SYNC_RESOLVERECIPSSTATUS_RESPONSE_UNRESOLVEDRECIP;
}
return false;
}
/**
* Resolves recipient from the contact list and gets his certificates.
*
* @param string $to
* @param int $maxAmbiguousRecipients
*
* @return array|boolean
*/
private function resolveRecipientContact($to, $maxAmbiguousRecipients) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("Resolving recipient '%s' in user's contacts", $to));
// go through all contact folders of the user and
// check if there's a contact with the given email address
$root = mapi_msgstore_openentry($this->defaultstore);
if (!$root) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("Unable to open default store: 0x%X", mapi_last_hresult));
}
$rootprops = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
$contacts = $this->getContactsFromFolder($this->defaultstore, $rootprops[PR_IPM_CONTACT_ENTRYID], $to);
$recipients = array();
if ($contacts !== false) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("Found %d contacts in main contacts folder.", count($contacts)));
// create resolve recipient object
foreach ($contacts as $contact) {
$recipients[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, $to, $contact);
}
}
$contactfolder = mapi_msgstore_openentry($this->defaultstore, $rootprops[PR_IPM_CONTACT_ENTRYID]);
$subfolders = MAPIUtils::GetSubfoldersForType($contactfolder, "IPF.Contact");
if ($subfolders !== false) {
foreach($subfolders as $folder) {
$contacts = $this->getContactsFromFolder($this->defaultstore, $folder[PR_ENTRYID], $to);
if ($contacts !== false) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("Found %d contacts in contacts' subfolder.", count($contacts)));
foreach ($contacts as $contact) {
$recipients[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, $to, $contact);
}
}
}
}
// search contacts in public folders
$storestables = mapi_getmsgstorestable($this->session);
$result = mapi_last_hresult();
if ($result == NOERROR){
$rows = mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_DEFAULT_STORE, PR_MDB_PROVIDER));
foreach($rows as $row) {
if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
// TODO refactor public store
$publicstore = mapi_openmsgstore($this->session, $row[PR_ENTRYID]);
$publicfolder = mapi_msgstore_openentry($publicstore);
$subfolders = MAPIUtils::GetSubfoldersForType($publicfolder, "IPF.Contact");
if ($subfolders !== false) {
foreach($subfolders as $folder) {
$contacts = $this->getContactsFromFolder($publicstore, $folder[PR_ENTRYID], $to);
if ($contacts !== false) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("Found %d contacts in public contacts folder.", count($contacts)));
foreach ($contacts as $contact) {
$recipients[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, $to, $contact);
}
}
}
}
break;
}
}
}
else {
ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open public store: 0x%X", $result));
}
if (empty($recipients)) {
$contactProperties = array();
$contactProperties[PR_DISPLAY_NAME] = $to;
$contactProperties[PR_USER_X509_CERTIFICATE] = false;
$recipients[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, $to, $contactProperties);
}
return $recipients;
}
/**
* Creates SyncResolveRecipientsCertificates object for ResolveRecipients
*
* @param binary $certificates
* @param int $recipientCount
*
* @return SyncResolveRecipientsCertificates
*/
private function getCertificates($certificates, $recipientCount = 0) {
$cert = new SyncResolveRecipientsCertificates();
if ($certificates === false) {
$cert->status = SYNC_RESOLVERECIPSSTATUS_CERTIFICATES_NOVALIDCERT;
return $cert;
}
$cert->status = SYNC_RESOLVERECIPSSTATUS_SUCCESS;
$cert->certificatecount = count ($certificates);
$cert->recipientcount = $recipientCount;
$cert->certificate = array();
foreach ($certificates as $certificate) {
$cert->certificate[] = base64_encode($certificate);
}
return $cert;
}
/**
* Creates SyncResolveRecipient object for ResolveRecipientsResponse.
* @param int $type
* @param string $email
* @param array $recipientProperties
* @param int $recipientCount
*
* @return SyncResolveRecipient
*/
private function createResolveRecipient($type, $email, $recipientProperties, $recipientCount = 0) {
$recipient = new SyncResolveRecipient();
$recipient->type = $type;
$recipient->displayname = u2w($recipientProperties[PR_DISPLAY_NAME]);
$recipient->emailaddress = $email;
if ($type == SYNC_RESOLVERECIPIENTS_TYPE_GAL) {
$certificateProp = PR_EMS_AB_TAGGED_X509_CERT;
}
elseif ($type == SYNC_RESOLVERECIPIENTS_TYPE_CONTACT) {
$certificateProp = PR_USER_X509_CERTIFICATE;
}
else {
$certificateProp = null;
}
if (isset($recipientProperties[$certificateProp]) && is_array($recipientProperties[$certificateProp]) && !empty($recipientProperties[$certificateProp])) {
$certificates = $this->getCertificates($recipientProperties[$certificateProp], $recipientCount);
}
else {
$certificates = $this->getCertificates(false);
ZLog::Write(LOGLEVEL_INFO, sprintf("No certificate found for '%s' (requested email address: '%s')", $recipientProperties[PR_DISPLAY_NAME], $email));
}
$recipient->certificates = $certificates;
if (isset($recipientProperties[PR_ENTRYID])) {
$recipient->id = $recipientProperties[PR_ENTRYID];
}
return $recipient;
}
/**
* Gets the availability of a user for the given time window.
*
* @param string $to
* @param SyncResolveRecipient $resolveRecipient
* @param SyncResolveRecipientsOptions $resolveRecipientsOptions
*
* @access private
* @return SyncResolveRecipientsAvailability
*/
private function getAvailability($to, $resolveRecipient, $resolveRecipientsOptions) {
$availability = new SyncResolveRecipientsAvailability();
$availability->status = SYNC_RESOLVERECIPSSTATUS_AVAILABILITY_SUCCESS;
if (!isset($resolveRecipient->id)) {
// TODO this shouldn't happen but try to get the recipient in such a case
}
$fbsupport = mapi_freebusysupport_open($this->session);
if (mapi_last_hresult()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open free busy support (0x%08X)", mapi_last_hresult()));
$availability->status = SYNC_RESOLVERECIPSSTATUS_AVAILABILITY_FAILED;
return $availability;
}
$fbDataArray = mapi_freebusysupport_loaddata($fbsupport, array($resolveRecipient->id));
$start = strtotime($resolveRecipientsOptions->availability->starttime);
$end = strtotime($resolveRecipientsOptions->availability->endtime);
// Each digit in the MergedFreeBusy indicates the free/busy status for the user for every 30 minute interval.
$timeslots = intval(ceil(($end - $start) / self::HALFHOURSECONDS));
if ($timeslots > self::MAXFREEBUSYSLOTS) {
throw new StatusException("KopanoBackend->getAvailability(): the requested free busy range is too large.", SYNC_RESOLVERECIPSSTATUS_PROTOCOLERROR);
}
$mergedFreeBusy = str_pad(fbNoData, $timeslots, fbNoData);
if(is_array($fbDataArray) && !empty($fbDataArray)) {
foreach($fbDataArray as $fbDataUser) {
if ($fbDataUser == null) {
ZLog::Write(LOGLEVEL_INFO, sprintf("KopanoBackend->getAvailability(): freebusy user is null for '%s'. Unable to retrieve his availability.", $resolveRecipient->displayname));
continue;
}
$rangeuser = mapi_freebusydata_getpublishrange($fbDataUser);
if($rangeuser == null) {
ZLog::Write(LOGLEVEL_INFO, sprintf("KopanoBackend->getAvailability(): Unable to retrieve mapi_freebusydata_getpublishrange (0x%X) for '%s'", mapi_last_hresult(), $resolveRecipient->displayname));
$availability->status = SYNC_RESOLVERECIPSSTATUS_AVAILABILITY_FAILED;
return $availability;
}
// if free busy information is available for the whole requested period,
// assume that the user is free for the requested range.
if ($rangeuser['start'] <= $start && $rangeuser['end'] >= $end) {
$mergedFreeBusy = str_pad(fbFree, $timeslots, fbFree);
}
// available free busy information is outside of the requested data
elseif ($rangeuser['end'] <= $start || $rangeuser['start'] >= $end) {
$mergedFreeBusy = str_pad(fbNoData, $timeslots, fbNoData);
}
// free busy information is not available at the begin of the requested period
elseif ($rangeuser['start'] > $start && $rangeuser['end'] >= $end) {
$missingSlots = intval(ceil(($rangeuser['start'] - $start) / self::HALFHOURSECONDS));
$mergedFreeBusy = str_pad(fbNoData, $missingSlots, fbNoData) . str_pad(fbFree, ($timeslots - $missingSlots), fbFree);
}
// free busy information is not available at the end of the requested period
elseif ($rangeuser['start'] <= $start && $rangeuser['end'] < $end) {
$missingSlots = intval(ceil(($rangeuser['end'] - $end) / self::HALFHOURSECONDS));
$mergedFreeBusy = str_pad(fbFree, ($timeslots - $missingSlots), fbFree) . str_pad(fbNoData, $missingSlots, fbNoData) ;
}
// free busy information is not available at the begin and at the end of the requested period
else {
$missingBeginSlots = intval(ceil(($rangeuser['start'] - $start) / self::HALFHOURSECONDS));
$missingEndSlots = intval(ceil(($rangeuser['end'] - $end) / self::HALFHOURSECONDS));
$mergedFreeBusy = str_pad(fbNoData, $missingBeginSlots, fbNoData) .
str_pad(fbFree, ($timeslots - $missingBeginSlots - $missingEndSlots), fbFree) .
str_pad(fbNoData, $missingEndSlots, fbNoData) ;
}
$enumblock = mapi_freebusydata_enumblocks($fbDataUser, $start, $end);
mapi_freebusyenumblock_reset($enumblock);
while(true) {
$blocks = mapi_freebusyenumblock_next($enumblock, self::FREEBUSYENUMBLOCKS);
if(!$blocks) {
break;
}
foreach($blocks as $blockItem) {
// calculate which timeslot of mergedFreeBusy should be replaced.
$blockDuration = ($blockItem['end'] - $blockItem['start']) / self::HALFHOURSECONDS;
$startSlot = intval(floor(($blockItem['start'] - $start) / self::HALFHOURSECONDS));
$endSlot = intval(floor(($blockItem['end'] - $start) / self::HALFHOURSECONDS));
// check if the end slot is the exact begin of the next slot from request; in such case it's necessary to reduce the endslot.
if ($start + $endSlot * self::HALFHOURSECONDS == $blockItem['end'] && $endSlot > $startSlot) {
$endSlot--;
}
for ($i = $startSlot; $i <= $endSlot; $i++) {
// only set the new slot's free busy status if it's higher than the current one
if ($blockItem['status'] > $mergedFreeBusy[$i]) {
$mergedFreeBusy[$i] = $blockItem['status'];
}
}
}
}
}
}
mapi_freebusysupport_close($fbsupport);
$availability->mergedfreebusy = $mergedFreeBusy;
return $availability;
}
/**
* Returns contacts matching given email address from a folder.
*
* @param MAPIStore $store
* @param binary $folderEntryid
* @param string $email
*
* @return array|boolean
*/
private function getContactsFromFolder($store, $folderEntryid, $email) {
$folder = mapi_msgstore_openentry($store, $folderEntryid);
$folderContent = mapi_folder_getcontentstable($folder);
mapi_table_restrict($folderContent, MAPIUtils::GetEmailAddressRestriction($store, $email));
// TODO max limit
if (mapi_table_getrowcount($folderContent) > 0) {
return mapi_table_queryallrows($folderContent, array(PR_DISPLAY_NAME, PR_USER_X509_CERTIFICATE, PR_ENTRYID));
}
return false;
}
/**
* Get MAPI addressbook object
*
* @access private
* @return MAPIAddressbook object to be used with mapi_ab_* or false on failure
*/
private function getAddressbook() {
if (isset($this->addressbook) && $this->addressbook) {
return $this->addressbook;
}
$this->addressbook = mapi_openaddressbook($this->session);
$result = mapi_last_hresult();
if ($result && $this->addressbook === false) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("MAPIProvider->getAddressbook error opening addressbook 0x%X", $result));
return false;
}
return $this->addressbook;
}
/**
* Checks if the user is not disabled for Z-Push.
*
* @access private
* @throws FatalException if user is disabled for Z-Push
*
* @return boolean
*/
private function isZPushEnabled() {
$addressbook = $this->getAddressbook();
$userEntryid = mapi_getprops($this->store, array(PR_MAILBOX_OWNER_ENTRYID));
$mailuser = mapi_ab_openentry($addressbook, $userEntryid[PR_MAILBOX_OWNER_ENTRYID]);
$enabledFeatures = mapi_getprops($mailuser, array(PR_EC_DISABLED_FEATURES));
if (isset($enabledFeatures[PR_EC_DISABLED_FEATURES]) && is_array($enabledFeatures[PR_EC_DISABLED_FEATURES])) {
$mobileDisabled = in_array(self::MOBILE_ENABLED, $enabledFeatures[PR_EC_DISABLED_FEATURES]);
$outlookDisabled = in_array(self::OUTLOOK_ENABLED, $enabledFeatures[PR_EC_DISABLED_FEATURES]);
if ($mobileDisabled && $outlookDisabled) {
throw new FatalException("User is disabled for Z-Push.");
}
elseif (Request::IsOutlook() && $outlookDisabled) {
throw new FatalException("User is disabled for Outlook usage with Z-Push.");
}
elseif (!Request::IsOutlook() && $mobileDisabled) {
throw new FatalException("User is disabled for mobile device usage with Z-Push.");
}
}
return true;
}
}
/**
* DEPRECATED legacy classes
*/
class BackendICS extends BackendKopano {}
class BackendZarafa extends BackendKopano {}
|