@@ -59,201 +59,201 @@ |
||
59 | 59 | |
60 | 60 | class Server { |
61 | 61 | |
62 | - /** @var IRequest */ |
|
63 | - private $request; |
|
62 | + /** @var IRequest */ |
|
63 | + private $request; |
|
64 | 64 | |
65 | - /** @var string */ |
|
66 | - private $baseUri; |
|
65 | + /** @var string */ |
|
66 | + private $baseUri; |
|
67 | 67 | |
68 | - /** @var Connector\Sabre\Server */ |
|
69 | - private $server; |
|
68 | + /** @var Connector\Sabre\Server */ |
|
69 | + private $server; |
|
70 | 70 | |
71 | - public function __construct(IRequest $request, $baseUri) { |
|
72 | - $this->request = $request; |
|
73 | - $this->baseUri = $baseUri; |
|
74 | - $logger = \OC::$server->getLogger(); |
|
75 | - $mailer = \OC::$server->getMailer(); |
|
76 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
77 | - $timezone = new TimeFactory(); |
|
71 | + public function __construct(IRequest $request, $baseUri) { |
|
72 | + $this->request = $request; |
|
73 | + $this->baseUri = $baseUri; |
|
74 | + $logger = \OC::$server->getLogger(); |
|
75 | + $mailer = \OC::$server->getMailer(); |
|
76 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
77 | + $timezone = new TimeFactory(); |
|
78 | 78 | |
79 | - $root = new RootCollection(); |
|
80 | - $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
79 | + $root = new RootCollection(); |
|
80 | + $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
81 | 81 | |
82 | - // Add maintenance plugin |
|
83 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
82 | + // Add maintenance plugin |
|
83 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
84 | 84 | |
85 | - // Backends |
|
86 | - $authBackend = new Auth( |
|
87 | - \OC::$server->getSession(), |
|
88 | - \OC::$server->getUserSession(), |
|
89 | - \OC::$server->getRequest(), |
|
90 | - \OC::$server->getTwoFactorAuthManager(), |
|
91 | - \OC::$server->getBruteForceThrottler() |
|
92 | - ); |
|
85 | + // Backends |
|
86 | + $authBackend = new Auth( |
|
87 | + \OC::$server->getSession(), |
|
88 | + \OC::$server->getUserSession(), |
|
89 | + \OC::$server->getRequest(), |
|
90 | + \OC::$server->getTwoFactorAuthManager(), |
|
91 | + \OC::$server->getBruteForceThrottler() |
|
92 | + ); |
|
93 | 93 | |
94 | - // Set URL explicitly due to reverse-proxy situations |
|
95 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
96 | - $this->server->setBaseUri($this->baseUri); |
|
94 | + // Set URL explicitly due to reverse-proxy situations |
|
95 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
96 | + $this->server->setBaseUri($this->baseUri); |
|
97 | 97 | |
98 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
99 | - $authPlugin = new Plugin(); |
|
100 | - $authPlugin->addBackend(new PublicAuth()); |
|
101 | - $this->server->addPlugin($authPlugin); |
|
98 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
99 | + $authPlugin = new Plugin(); |
|
100 | + $authPlugin->addBackend(new PublicAuth()); |
|
101 | + $this->server->addPlugin($authPlugin); |
|
102 | 102 | |
103 | - // allow setup of additional auth backends |
|
104 | - $event = new SabrePluginEvent($this->server); |
|
105 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
103 | + // allow setup of additional auth backends |
|
104 | + $event = new SabrePluginEvent($this->server); |
|
105 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
106 | 106 | |
107 | - $bearerAuthBackend = new BearerAuth( |
|
108 | - \OC::$server->getUserSession(), |
|
109 | - \OC::$server->getSession(), |
|
110 | - \OC::$server->getRequest() |
|
111 | - ); |
|
112 | - $authPlugin->addBackend($bearerAuthBackend); |
|
113 | - // because we are throwing exceptions this plugin has to be the last one |
|
114 | - $authPlugin->addBackend($authBackend); |
|
107 | + $bearerAuthBackend = new BearerAuth( |
|
108 | + \OC::$server->getUserSession(), |
|
109 | + \OC::$server->getSession(), |
|
110 | + \OC::$server->getRequest() |
|
111 | + ); |
|
112 | + $authPlugin->addBackend($bearerAuthBackend); |
|
113 | + // because we are throwing exceptions this plugin has to be the last one |
|
114 | + $authPlugin->addBackend($authBackend); |
|
115 | 115 | |
116 | - // debugging |
|
117 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
118 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
119 | - } else { |
|
120 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
121 | - } |
|
116 | + // debugging |
|
117 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
118 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
119 | + } else { |
|
120 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
121 | + } |
|
122 | 122 | |
123 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
124 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
125 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
123 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
124 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
125 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
126 | 126 | |
127 | - // acl |
|
128 | - $acl = new DavAclPlugin(); |
|
129 | - $acl->principalCollectionSet = [ |
|
130 | - 'principals/users', 'principals/groups' |
|
131 | - ]; |
|
132 | - $acl->defaultUsernamePath = 'principals/users'; |
|
133 | - $this->server->addPlugin($acl); |
|
127 | + // acl |
|
128 | + $acl = new DavAclPlugin(); |
|
129 | + $acl->principalCollectionSet = [ |
|
130 | + 'principals/users', 'principals/groups' |
|
131 | + ]; |
|
132 | + $acl->defaultUsernamePath = 'principals/users'; |
|
133 | + $this->server->addPlugin($acl); |
|
134 | 134 | |
135 | - // calendar plugins |
|
136 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
137 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
138 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
139 | - if(\OC::$server->getConfig()->getSystemValue('caldav_send_invitations', true)) { |
|
140 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone)); |
|
141 | - } |
|
142 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
143 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
144 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
145 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
146 | - \OC::$server->getConfig(), |
|
147 | - \OC::$server->getURLGenerator() |
|
148 | - )); |
|
135 | + // calendar plugins |
|
136 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
137 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
138 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
139 | + if(\OC::$server->getConfig()->getSystemValue('caldav_send_invitations', true)) { |
|
140 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone)); |
|
141 | + } |
|
142 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
143 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
144 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
145 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
146 | + \OC::$server->getConfig(), |
|
147 | + \OC::$server->getURLGenerator() |
|
148 | + )); |
|
149 | 149 | |
150 | - // addressbook plugins |
|
151 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
152 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
153 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
150 | + // addressbook plugins |
|
151 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
152 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
153 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
154 | 154 | |
155 | - // system tags plugins |
|
156 | - $this->server->addPlugin(new SystemTagPlugin( |
|
157 | - \OC::$server->getSystemTagManager(), |
|
158 | - \OC::$server->getGroupManager(), |
|
159 | - \OC::$server->getUserSession() |
|
160 | - )); |
|
155 | + // system tags plugins |
|
156 | + $this->server->addPlugin(new SystemTagPlugin( |
|
157 | + \OC::$server->getSystemTagManager(), |
|
158 | + \OC::$server->getGroupManager(), |
|
159 | + \OC::$server->getUserSession() |
|
160 | + )); |
|
161 | 161 | |
162 | - // comments plugin |
|
163 | - $this->server->addPlugin(new CommentsPlugin( |
|
164 | - \OC::$server->getCommentsManager(), |
|
165 | - \OC::$server->getUserSession() |
|
166 | - )); |
|
162 | + // comments plugin |
|
163 | + $this->server->addPlugin(new CommentsPlugin( |
|
164 | + \OC::$server->getCommentsManager(), |
|
165 | + \OC::$server->getUserSession() |
|
166 | + )); |
|
167 | 167 | |
168 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
168 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
169 | 169 | |
170 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
171 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
172 | - if($request->isUserAgent([ |
|
173 | - '/WebDAVFS/', |
|
174 | - '/Microsoft Office OneNote 2013/', |
|
175 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
176 | - ])) { |
|
177 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
178 | - } |
|
170 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
171 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
172 | + if($request->isUserAgent([ |
|
173 | + '/WebDAVFS/', |
|
174 | + '/Microsoft Office OneNote 2013/', |
|
175 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
176 | + ])) { |
|
177 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
178 | + } |
|
179 | 179 | |
180 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
181 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
182 | - } |
|
180 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
181 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
182 | + } |
|
183 | 183 | |
184 | - // wait with registering these until auth is handled and the filesystem is setup |
|
185 | - $this->server->on('beforeMethod', function () { |
|
186 | - // custom properties plugin must be the last one |
|
187 | - $userSession = \OC::$server->getUserSession(); |
|
188 | - $user = $userSession->getUser(); |
|
189 | - if ($user !== null) { |
|
190 | - $view = \OC\Files\Filesystem::getView(); |
|
191 | - $this->server->addPlugin( |
|
192 | - new FilesPlugin( |
|
193 | - $this->server->tree, |
|
194 | - \OC::$server->getConfig(), |
|
195 | - $this->request, |
|
196 | - \OC::$server->getPreviewManager(), |
|
197 | - false, |
|
198 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
199 | - ) |
|
200 | - ); |
|
184 | + // wait with registering these until auth is handled and the filesystem is setup |
|
185 | + $this->server->on('beforeMethod', function () { |
|
186 | + // custom properties plugin must be the last one |
|
187 | + $userSession = \OC::$server->getUserSession(); |
|
188 | + $user = $userSession->getUser(); |
|
189 | + if ($user !== null) { |
|
190 | + $view = \OC\Files\Filesystem::getView(); |
|
191 | + $this->server->addPlugin( |
|
192 | + new FilesPlugin( |
|
193 | + $this->server->tree, |
|
194 | + \OC::$server->getConfig(), |
|
195 | + $this->request, |
|
196 | + \OC::$server->getPreviewManager(), |
|
197 | + false, |
|
198 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
199 | + ) |
|
200 | + ); |
|
201 | 201 | |
202 | - $this->server->addPlugin( |
|
203 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
204 | - new CustomPropertiesBackend( |
|
205 | - $this->server->tree, |
|
206 | - \OC::$server->getDatabaseConnection(), |
|
207 | - \OC::$server->getUserSession()->getUser() |
|
208 | - ) |
|
209 | - ) |
|
210 | - ); |
|
211 | - if ($view !== null) { |
|
212 | - $this->server->addPlugin( |
|
213 | - new QuotaPlugin($view)); |
|
214 | - } |
|
215 | - $this->server->addPlugin( |
|
216 | - new TagsPlugin( |
|
217 | - $this->server->tree, \OC::$server->getTagManager() |
|
218 | - ) |
|
219 | - ); |
|
220 | - // TODO: switch to LazyUserFolder |
|
221 | - $userFolder = \OC::$server->getUserFolder(); |
|
222 | - $this->server->addPlugin(new SharesPlugin( |
|
223 | - $this->server->tree, |
|
224 | - $userSession, |
|
225 | - $userFolder, |
|
226 | - \OC::$server->getShareManager() |
|
227 | - )); |
|
228 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
229 | - \OC::$server->getCommentsManager(), |
|
230 | - $userSession |
|
231 | - )); |
|
232 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
233 | - if ($view !== null) { |
|
234 | - $this->server->addPlugin(new FilesReportPlugin( |
|
235 | - $this->server->tree, |
|
236 | - $view, |
|
237 | - \OC::$server->getSystemTagManager(), |
|
238 | - \OC::$server->getSystemTagObjectMapper(), |
|
239 | - \OC::$server->getTagManager(), |
|
240 | - $userSession, |
|
241 | - \OC::$server->getGroupManager(), |
|
242 | - $userFolder |
|
243 | - )); |
|
244 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
245 | - $this->server->tree, |
|
246 | - $user, |
|
247 | - \OC::$server->getRootFolder(), |
|
248 | - \OC::$server->getShareManager(), |
|
249 | - $view |
|
250 | - ))); |
|
251 | - } |
|
252 | - } |
|
253 | - }); |
|
254 | - } |
|
202 | + $this->server->addPlugin( |
|
203 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
204 | + new CustomPropertiesBackend( |
|
205 | + $this->server->tree, |
|
206 | + \OC::$server->getDatabaseConnection(), |
|
207 | + \OC::$server->getUserSession()->getUser() |
|
208 | + ) |
|
209 | + ) |
|
210 | + ); |
|
211 | + if ($view !== null) { |
|
212 | + $this->server->addPlugin( |
|
213 | + new QuotaPlugin($view)); |
|
214 | + } |
|
215 | + $this->server->addPlugin( |
|
216 | + new TagsPlugin( |
|
217 | + $this->server->tree, \OC::$server->getTagManager() |
|
218 | + ) |
|
219 | + ); |
|
220 | + // TODO: switch to LazyUserFolder |
|
221 | + $userFolder = \OC::$server->getUserFolder(); |
|
222 | + $this->server->addPlugin(new SharesPlugin( |
|
223 | + $this->server->tree, |
|
224 | + $userSession, |
|
225 | + $userFolder, |
|
226 | + \OC::$server->getShareManager() |
|
227 | + )); |
|
228 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
229 | + \OC::$server->getCommentsManager(), |
|
230 | + $userSession |
|
231 | + )); |
|
232 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
233 | + if ($view !== null) { |
|
234 | + $this->server->addPlugin(new FilesReportPlugin( |
|
235 | + $this->server->tree, |
|
236 | + $view, |
|
237 | + \OC::$server->getSystemTagManager(), |
|
238 | + \OC::$server->getSystemTagObjectMapper(), |
|
239 | + \OC::$server->getTagManager(), |
|
240 | + $userSession, |
|
241 | + \OC::$server->getGroupManager(), |
|
242 | + $userFolder |
|
243 | + )); |
|
244 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
245 | + $this->server->tree, |
|
246 | + $user, |
|
247 | + \OC::$server->getRootFolder(), |
|
248 | + \OC::$server->getShareManager(), |
|
249 | + $view |
|
250 | + ))); |
|
251 | + } |
|
252 | + } |
|
253 | + }); |
|
254 | + } |
|
255 | 255 | |
256 | - public function exec() { |
|
257 | - $this->server->exec(); |
|
258 | - } |
|
256 | + public function exec() { |
|
257 | + $this->server->exec(); |
|
258 | + } |
|
259 | 259 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $authPlugin->addBackend($authBackend); |
115 | 115 | |
116 | 116 | // debugging |
117 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
117 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
118 | 118 | $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
119 | 119 | } else { |
120 | 120 | $this->server->addPlugin(new DummyGetResponsePlugin()); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
137 | 137 | $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
138 | 138 | $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
139 | - if(\OC::$server->getConfig()->getSystemValue('caldav_send_invitations', true)) { |
|
139 | + if (\OC::$server->getConfig()->getSystemValue('caldav_send_invitations', true)) { |
|
140 | 140 | $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone)); |
141 | 141 | } |
142 | 142 | $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | |
170 | 170 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
171 | 171 | // we do not provide locking we emulate it using a fake locking plugin. |
172 | - if($request->isUserAgent([ |
|
172 | + if ($request->isUserAgent([ |
|
173 | 173 | '/WebDAVFS/', |
174 | 174 | '/Microsoft Office OneNote 2013/', |
175 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
175 | + '/^Microsoft-WebDAV/', // Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
176 | 176 | ])) { |
177 | 177 | $this->server->addPlugin(new FakeLockerPlugin()); |
178 | 178 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | // wait with registering these until auth is handled and the filesystem is setup |
185 | - $this->server->on('beforeMethod', function () { |
|
185 | + $this->server->on('beforeMethod', function() { |
|
186 | 186 | // custom properties plugin must be the last one |
187 | 187 | $userSession = \OC::$server->getUserSession(); |
188 | 188 | $user = $userSession->getUser(); |
@@ -48,144 +48,144 @@ |
||
48 | 48 | */ |
49 | 49 | class IMipPlugin extends SabreIMipPlugin { |
50 | 50 | |
51 | - /** @var IMailer */ |
|
52 | - private $mailer; |
|
53 | - |
|
54 | - /** @var ILogger */ |
|
55 | - private $logger; |
|
56 | - |
|
57 | - /** @var ITimeFactory */ |
|
58 | - private $timeFactory; |
|
59 | - |
|
60 | - const MAX_DATE = '2038-01-01'; |
|
61 | - |
|
62 | - /** |
|
63 | - * Creates the email handler. |
|
64 | - * |
|
65 | - * @param IMailer $mailer |
|
66 | - * @param ILogger $logger |
|
67 | - * @param ITimeFactory $timeFactory |
|
68 | - */ |
|
69 | - function __construct(IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory) { |
|
70 | - parent::__construct(''); |
|
71 | - $this->mailer = $mailer; |
|
72 | - $this->logger = $logger; |
|
73 | - $this->timeFactory = $timeFactory; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Event handler for the 'schedule' event. |
|
78 | - * |
|
79 | - * @param ITip\Message $iTipMessage |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - function schedule(ITip\Message $iTipMessage) { |
|
83 | - |
|
84 | - // Not sending any emails if the system considers the update |
|
85 | - // insignificant. |
|
86 | - if (!$iTipMessage->significantChange) { |
|
87 | - if (!$iTipMessage->scheduleStatus) { |
|
88 | - $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
89 | - } |
|
90 | - return; |
|
91 | - } |
|
92 | - |
|
93 | - $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
94 | - |
|
95 | - if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - // don't send out mails for events that already took place |
|
104 | - if ($this->isEventInThePast($iTipMessage->message)) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $sender = substr($iTipMessage->sender, 7); |
|
109 | - $recipient = substr($iTipMessage->recipient, 7); |
|
110 | - |
|
111 | - $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null; |
|
112 | - $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null; |
|
113 | - |
|
114 | - $subject = 'SabreDAV iTIP message'; |
|
115 | - switch (strtoupper($iTipMessage->method)) { |
|
116 | - case 'REPLY' : |
|
117 | - $subject = 'Re: ' . $summary; |
|
118 | - break; |
|
119 | - case 'REQUEST' : |
|
120 | - $subject = $summary; |
|
121 | - break; |
|
122 | - case 'CANCEL' : |
|
123 | - $subject = 'Cancelled: ' . $summary; |
|
124 | - break; |
|
125 | - } |
|
126 | - |
|
127 | - $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method; |
|
128 | - |
|
129 | - $message = $this->mailer->createMessage(); |
|
130 | - |
|
131 | - $message->setReplyTo([$sender => $senderName]) |
|
132 | - ->setTo([$recipient => $recipientName]) |
|
133 | - ->setSubject($subject) |
|
134 | - ->setBody($iTipMessage->message->serialize(), $contentType); |
|
135 | - try { |
|
136 | - $failed = $this->mailer->send($message); |
|
137 | - if ($failed) { |
|
138 | - $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
139 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
140 | - } |
|
141 | - $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
142 | - } catch(\Exception $ex) { |
|
143 | - $this->logger->logException($ex, ['app' => 'dav']); |
|
144 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * check if event took place in the past already |
|
150 | - * @param VCalendar $vObject |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - private function isEventInThePast(VCalendar $vObject) { |
|
154 | - $component = $vObject->VEVENT; |
|
155 | - |
|
156 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
157 | - // Finding the last occurrence is a bit harder |
|
158 | - if (!isset($component->RRULE)) { |
|
159 | - if (isset($component->DTEND)) { |
|
160 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
161 | - } elseif (isset($component->DURATION)) { |
|
162 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
163 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
164 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
165 | - } elseif (!$component->DTSTART->hasTime()) { |
|
166 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
167 | - $endDate->modify('+1 day'); |
|
168 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
169 | - } else { |
|
170 | - $lastOccurrence = $firstOccurrence; |
|
171 | - } |
|
172 | - } else { |
|
173 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
174 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
175 | - if ($it->isInfinite()) { |
|
176 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
177 | - } else { |
|
178 | - $end = $it->getDtEnd(); |
|
179 | - while($it->valid() && $end < $maxDate) { |
|
180 | - $end = $it->getDtEnd(); |
|
181 | - $it->next(); |
|
182 | - |
|
183 | - } |
|
184 | - $lastOccurrence = $end->getTimestamp(); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - $currentTime = $this->timeFactory->getTime(); |
|
189 | - return $lastOccurrence < $currentTime; |
|
190 | - } |
|
51 | + /** @var IMailer */ |
|
52 | + private $mailer; |
|
53 | + |
|
54 | + /** @var ILogger */ |
|
55 | + private $logger; |
|
56 | + |
|
57 | + /** @var ITimeFactory */ |
|
58 | + private $timeFactory; |
|
59 | + |
|
60 | + const MAX_DATE = '2038-01-01'; |
|
61 | + |
|
62 | + /** |
|
63 | + * Creates the email handler. |
|
64 | + * |
|
65 | + * @param IMailer $mailer |
|
66 | + * @param ILogger $logger |
|
67 | + * @param ITimeFactory $timeFactory |
|
68 | + */ |
|
69 | + function __construct(IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory) { |
|
70 | + parent::__construct(''); |
|
71 | + $this->mailer = $mailer; |
|
72 | + $this->logger = $logger; |
|
73 | + $this->timeFactory = $timeFactory; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Event handler for the 'schedule' event. |
|
78 | + * |
|
79 | + * @param ITip\Message $iTipMessage |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + function schedule(ITip\Message $iTipMessage) { |
|
83 | + |
|
84 | + // Not sending any emails if the system considers the update |
|
85 | + // insignificant. |
|
86 | + if (!$iTipMessage->significantChange) { |
|
87 | + if (!$iTipMessage->scheduleStatus) { |
|
88 | + $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
89 | + } |
|
90 | + return; |
|
91 | + } |
|
92 | + |
|
93 | + $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
94 | + |
|
95 | + if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + // don't send out mails for events that already took place |
|
104 | + if ($this->isEventInThePast($iTipMessage->message)) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $sender = substr($iTipMessage->sender, 7); |
|
109 | + $recipient = substr($iTipMessage->recipient, 7); |
|
110 | + |
|
111 | + $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null; |
|
112 | + $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null; |
|
113 | + |
|
114 | + $subject = 'SabreDAV iTIP message'; |
|
115 | + switch (strtoupper($iTipMessage->method)) { |
|
116 | + case 'REPLY' : |
|
117 | + $subject = 'Re: ' . $summary; |
|
118 | + break; |
|
119 | + case 'REQUEST' : |
|
120 | + $subject = $summary; |
|
121 | + break; |
|
122 | + case 'CANCEL' : |
|
123 | + $subject = 'Cancelled: ' . $summary; |
|
124 | + break; |
|
125 | + } |
|
126 | + |
|
127 | + $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method; |
|
128 | + |
|
129 | + $message = $this->mailer->createMessage(); |
|
130 | + |
|
131 | + $message->setReplyTo([$sender => $senderName]) |
|
132 | + ->setTo([$recipient => $recipientName]) |
|
133 | + ->setSubject($subject) |
|
134 | + ->setBody($iTipMessage->message->serialize(), $contentType); |
|
135 | + try { |
|
136 | + $failed = $this->mailer->send($message); |
|
137 | + if ($failed) { |
|
138 | + $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
139 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
140 | + } |
|
141 | + $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
142 | + } catch(\Exception $ex) { |
|
143 | + $this->logger->logException($ex, ['app' => 'dav']); |
|
144 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * check if event took place in the past already |
|
150 | + * @param VCalendar $vObject |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + private function isEventInThePast(VCalendar $vObject) { |
|
154 | + $component = $vObject->VEVENT; |
|
155 | + |
|
156 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
157 | + // Finding the last occurrence is a bit harder |
|
158 | + if (!isset($component->RRULE)) { |
|
159 | + if (isset($component->DTEND)) { |
|
160 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
161 | + } elseif (isset($component->DURATION)) { |
|
162 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
163 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
164 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
165 | + } elseif (!$component->DTSTART->hasTime()) { |
|
166 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
167 | + $endDate->modify('+1 day'); |
|
168 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
169 | + } else { |
|
170 | + $lastOccurrence = $firstOccurrence; |
|
171 | + } |
|
172 | + } else { |
|
173 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
174 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
175 | + if ($it->isInfinite()) { |
|
176 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
177 | + } else { |
|
178 | + $end = $it->getDtEnd(); |
|
179 | + while($it->valid() && $end < $maxDate) { |
|
180 | + $end = $it->getDtEnd(); |
|
181 | + $it->next(); |
|
182 | + |
|
183 | + } |
|
184 | + $lastOccurrence = $end->getTimestamp(); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + $currentTime = $this->timeFactory->getTime(); |
|
189 | + return $lastOccurrence < $currentTime; |
|
190 | + } |
|
191 | 191 | } |
@@ -114,17 +114,17 @@ discard block |
||
114 | 114 | $subject = 'SabreDAV iTIP message'; |
115 | 115 | switch (strtoupper($iTipMessage->method)) { |
116 | 116 | case 'REPLY' : |
117 | - $subject = 'Re: ' . $summary; |
|
117 | + $subject = 'Re: '.$summary; |
|
118 | 118 | break; |
119 | 119 | case 'REQUEST' : |
120 | 120 | $subject = $summary; |
121 | 121 | break; |
122 | 122 | case 'CANCEL' : |
123 | - $subject = 'Cancelled: ' . $summary; |
|
123 | + $subject = 'Cancelled: '.$summary; |
|
124 | 124 | break; |
125 | 125 | } |
126 | 126 | |
127 | - $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method; |
|
127 | + $contentType = 'text/calendar; charset=UTF-8; method='.$iTipMessage->method; |
|
128 | 128 | |
129 | 129 | $message = $this->mailer->createMessage(); |
130 | 130 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
140 | 140 | } |
141 | 141 | $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
142 | - } catch(\Exception $ex) { |
|
142 | + } catch (\Exception $ex) { |
|
143 | 143 | $this->logger->logException($ex, ['app' => 'dav']); |
144 | 144 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
145 | 145 | } |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $lastOccurrence = $firstOccurrence; |
171 | 171 | } |
172 | 172 | } else { |
173 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
173 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
174 | 174 | $maxDate = new \DateTime(self::MAX_DATE); |
175 | 175 | if ($it->isInfinite()) { |
176 | 176 | $lastOccurrence = $maxDate->getTimestamp(); |
177 | 177 | } else { |
178 | 178 | $end = $it->getDtEnd(); |
179 | - while($it->valid() && $end < $maxDate) { |
|
179 | + while ($it->valid() && $end < $maxDate) { |
|
180 | 180 | $end = $it->getDtEnd(); |
181 | 181 | $it->next(); |
182 | 182 |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | use OCA\DAV\Connector\Sabre\Principal; |
34 | 34 | |
35 | 35 | $authBackend = new Auth( |
36 | - \OC::$server->getSession(), |
|
37 | - \OC::$server->getUserSession(), |
|
38 | - \OC::$server->getRequest(), |
|
39 | - \OC::$server->getTwoFactorAuthManager(), |
|
40 | - \OC::$server->getBruteForceThrottler(), |
|
41 | - 'principals/' |
|
36 | + \OC::$server->getSession(), |
|
37 | + \OC::$server->getUserSession(), |
|
38 | + \OC::$server->getRequest(), |
|
39 | + \OC::$server->getTwoFactorAuthManager(), |
|
40 | + \OC::$server->getBruteForceThrottler(), |
|
41 | + 'principals/' |
|
42 | 42 | ); |
43 | 43 | $principalBackend = new Principal( |
44 | - \OC::$server->getUserManager(), |
|
45 | - \OC::$server->getGroupManager(), |
|
46 | - 'principals/' |
|
44 | + \OC::$server->getUserManager(), |
|
45 | + \OC::$server->getGroupManager(), |
|
46 | + 'principals/' |
|
47 | 47 | ); |
48 | 48 | $db = \OC::$server->getDatabaseConnection(); |
49 | 49 | $userManager = \OC::$server->getUserManager(); |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
63 | 63 | |
64 | 64 | $nodes = array( |
65 | - $principalCollection, |
|
66 | - $addressBookRoot, |
|
65 | + $principalCollection, |
|
66 | + $addressBookRoot, |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | // Fire up server |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | |
80 | 80 | $server->addPlugin(new LegacyDAVACL()); |
81 | 81 | if ($debugging) { |
82 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
82 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
86 | 86 | $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
87 | 87 | $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
88 | 88 | if ($sendInvitations) { |
89 | - $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin(\OC::$server->getMailer(), |
|
90 | - \OC::$server->getLogger(), new \OC\AppFramework\Utility\TimeFactory())); |
|
89 | + $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin(\OC::$server->getMailer(), |
|
90 | + \OC::$server->getLogger(), new \OC\AppFramework\Utility\TimeFactory())); |
|
91 | 91 | } |
92 | 92 | $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); |
93 | 93 |