-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmap.php
executable file
·120 lines (103 loc) · 4.02 KB
/
jmap.php
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
<?php
use OpenXPort\Jmap\Contact\ContactsAccountCapability;
use OpenXPort\Jmap\Core\CoreAccountCapability;
use OpenXPort\Jmap\Mail\SubmissionAccountCapability;
use OpenXPort\Util\RoundcubeSessionUtil;
// Define version
$oxpVersion = '1.4.0';
/**
* Fix for a refactoring bug (due to usage of bridge.php)
*
* The problem is that $_SERVER['SCRIPT_FILENAME'] is used for setting the include_path for Roundcube,
* but it references the currently executed script, which is jmap.php in our case.
* Since jmap.php is not positioned as a file on the same level as index.php,
* which is normally the running script, the include_path of Roundcube gets messed up.
* That's why we have to explicitly hack $_SERVER['SCRIPT_FILENAME'] so roundcube gets the correct
* include_path.
* For more info, see: https://github.com/roundcube/roundcubemail/blob/master/program/include/iniset.php
* (lines 27, 47 and 48)
*/
$_SERVER['SCRIPT_FILENAME'] = realpath(__DIR__ . '/../../index.php');
/* START OF OPENXPORT Code only */
// Use our composer autoload
require_once __DIR__ . '/vendor/autoload.php';
// Build config
$configDefault = include(__DIR__ . '/config/config.default.php');
$configFile = __DIR__ . '/config/config.php';
$oxpConfig = $configDefault;
if (file_exists($configFile)) {
$configUser = include($configFile);
if (is_array($configUser)) {
$oxpConfig = array_merge($configDefault, $configUser);
}
};
// Handle errors and exceptions as JSON responses
$handler = new \OpenXPort\Jmap\Core\ErrorHandler($oxpConfig["verboseErrorOutput"]);
$handler->setHandlers();
// Decode JSON post body here in case the debug capability is included
$jmapRequest = OpenXPort\Util\HttpUtil::getRequestBody();
// Initialize logging
OpenXPort\Util\Logger::init($oxpConfig, $jmapRequest);
$logger = \OpenXPort\Util\Logger::getInstance();
// Reuse auth from webmailer
require_once __DIR__ . '/bridge.php';
$logger->notice("Running PHP v" . phpversion() . ", RC v" . RCMAIL_VERSION . ", Plugin v" . $oxpVersion);
// TODO Probably from here on only
$accessors = array(
"Contacts" => null,
"Calendars" => null,
"CalendarEvents" => null,
"Tasks" => null,
"Notes" => null,
"Identities" => new \OpenXPort\DataAccess\RoundcubeIdentityDataAccess(),
"Filters" => null,
"StorageNodes" => null,
"ContactGroups" => null,
"Cards" => new \OpenXPort\DataAccess\RoundcubeContactDataAccess(),
"CardGroups" => new \OpenXPort\DataAccess\RoundcubeContactGroupDataAccess(),
);
/**
* Array to hold adapter classes for different types of data
* "null" means that no adapter class is present/available for the given data type
*/
$adapters = array(
"Contacts" => null,
"Calendars" => null,
"CalendarEvents" => null,
"Tasks" => null,
"Notes" => null,
"Identities" => new \OpenXPort\Adapter\RoundcubeIdentityAdapter(),
"Filters" => null,
"StorageNodes" => null,
"ContactGroups" => null,
"Cards" => new \OpenXPort\Adapter\RoundcubeJSContactVCardAdapter(
$oxpConfig['vCardParsing'],
$oxpConfig['dumpInvalidVCards']
),
"CardGroups" => new \OpenXPort\Adapter\RoundcubeCardGroupAdapter()
);
/**
* Array to hold mapper classes for different types of data
* "null" means that no mapper class is present/available for the given data type
*/
$mappers = array(
"Contacts" => null,
"Calendars" => null,
"CalendarEvents" => null,
"Tasks" => null,
"Notes" => null,
"Identities" => new \OpenXPort\Mapper\RoundcubeIdentityMapper(),
"Filters" => null,
"StorageNodes" => null,
"ContactGroups" => null,
"Cards" => new \OpenXPort\Mapper\RoundcubeJSContactVCardMapper(),
"CardGroups" => new \OpenXPort\Mapper\RoundcubeCardGroupMapper()
);
$accountData = [
'accountId' => $RCMAIL->user->ID,
'username' => isset($users[1]) ? $users[1] : $_POST['_user'],
'accountCapabilities' => []
];
$session = RoundcubeSessionUtil::createSession($accountData);
$server = new \OpenXPort\Jmap\Core\Server($accessors, $adapters, $mappers, $oxpConfig, $session);
$server->handleJmapRequest($jmapRequest);