]> git.mxchange.org Git - friendica.git/blob - src/Model/APContact.php
Avoid local network communication / invalid url requests
[friendica.git] / src / Model / APContact.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Model;
23
24 use Friendica\Content\Text\HTML;
25 use Friendica\Core\Cache\Enum\Duration;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\System;
29 use Friendica\Database\DBA;
30 use Friendica\DI;
31 use Friendica\Model\Item;
32 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
33 use Friendica\Network\HTTPException;
34 use Friendica\Network\Probe;
35 use Friendica\Protocol\ActivityNamespace;
36 use Friendica\Protocol\ActivityPub;
37 use Friendica\Protocol\ActivityPub\Transmitter;
38 use Friendica\Util\Crypto;
39 use Friendica\Util\DateTimeFormat;
40 use Friendica\Util\HTTPSignature;
41 use Friendica\Util\JsonLD;
42 use Friendica\Util\Network;
43 use GuzzleHttp\Psr7\Uri;
44
45 class APContact
46 {
47         /**
48          * Fetch webfinger data
49          *
50          * @param string $addr Address
51          * @return array webfinger data
52          */
53         private static function fetchWebfingerData(string $addr): array
54         {
55                 $addr_parts = explode('@', $addr);
56                 if (count($addr_parts) != 2) {
57                         return [];
58                 }
59
60                 if (Contact::isLocal($addr) && ($local_uid = User::getIdForURL($addr)) && ($local_owner = User::getOwnerDataById($local_uid))) {
61                         $data = [
62                                 'addr'      => $local_owner['addr'],
63                                 'baseurl'   => $local_owner['baseurl'],
64                                 'url'       => $local_owner['url'],
65                                 'subscribe' => $local_owner['baseurl'] . '/contact/follow?url={uri}'];
66
67                         if (!empty($local_owner['alias']) && ($local_owner['url'] != $local_owner['alias'])) {
68                                 $data['alias'] = $local_owner['alias'];
69                         }
70
71                         return $data;
72                 }
73
74                 $data = ['addr' => $addr];
75                 $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
76                 $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON);
77                 if (empty($webfinger['links'])) {
78                         $template = 'http://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
79                         $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON);
80                         if (empty($webfinger['links'])) {
81                                 return [];
82                         }
83                         $data['baseurl'] = 'http://' . $addr_parts[1];
84                 } else {
85                         $data['baseurl'] = 'https://' . $addr_parts[1];
86                 }
87
88                 foreach ($webfinger['links'] as $link) {
89                         if (empty($link['rel'])) {
90                                 continue;
91                         }
92
93                         if (!empty($link['template']) && ($link['rel'] == ActivityNamespace::OSTATUSSUB)) {
94                                 $data['subscribe'] = $link['template'];
95                         }
96
97                         if (!empty($link['href']) && !empty($link['type']) && ($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) {
98                                 $data['url'] = $link['href'];
99                         }
100
101                         if (!empty($link['href']) && !empty($link['type']) && ($link['rel'] == 'http://webfinger.net/rel/profile-page') && ($link['type'] == 'text/html')) {
102                                 $data['alias'] = $link['href'];
103                         }
104                 }
105
106                 if (!empty($data['url']) && !empty($data['alias']) && ($data['url'] == $data['alias'])) {
107                         unset($data['alias']);
108                 }
109
110                 return $data;
111         }
112
113         /**
114          * Fetches a profile from a given url
115          *
116          * @param string  $url    profile url
117          * @param boolean $update true = always update, false = never update, null = update when not found or outdated
118          * @return array profile array
119          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
120          * @throws \ImagickException
121          * @todo Rewrite parameter $update to avoid true|false|null (boolean is binary, null adds a third case)
122          */
123         public static function getByURL(string $url, $update = null): array
124         {
125                 if (empty($url) || Network::isUrlBlocked($url)) {
126                         Logger::info('Domain is blocked', ['url' => $url]);
127                         return [];
128                 }
129
130                 $fetched_contact = [];
131
132                 if (empty($update)) {
133                         if (is_null($update)) {
134                                 $ref_update = DateTimeFormat::utc('now - 1 month');
135                         } else {
136                                 $ref_update = DBA::NULL_DATETIME;
137                         }
138
139                         $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]);
140                         if (!DBA::isResult($apcontact)) {
141                                 $apcontact = DBA::selectFirst('apcontact', [], ['alias' => $url]);
142                         }
143
144                         if (!DBA::isResult($apcontact)) {
145                                 $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]);
146                         }
147
148                         if (DBA::isResult($apcontact) && ($apcontact['updated'] > $ref_update) && !empty($apcontact['pubkey']) && !empty($apcontact['uri-id'])) {
149                                 return $apcontact;
150                         }
151
152                         if (!is_null($update)) {
153                                 return DBA::isResult($apcontact) ? $apcontact : [];
154                         }
155
156                         if (DBA::isResult($apcontact)) {
157                                 $fetched_contact = $apcontact;
158                         }
159                 }
160
161                 $apcontact = [];
162
163                 $webfinger = empty(parse_url($url, PHP_URL_SCHEME));
164                 if ($webfinger) {
165                         $apcontact = self::fetchWebfingerData($url);
166                         if (empty($apcontact['url'])) {
167                                 return $fetched_contact;
168                         }
169                         $url = $apcontact['url'];
170                 } elseif (empty(parse_url($url, PHP_URL_PATH))) {
171                         $apcontact['baseurl'] = $url;
172                 }
173
174                 // Detect multiple fast repeating request to the same address
175                 // See https://github.com/friendica/friendica/issues/9303
176                 $cachekey = 'apcontact:' . ItemURI::getIdByURI($url);
177                 $result = DI::cache()->get($cachekey);
178                 if (!is_null($result)) {
179                         Logger::notice('Multiple requests for the address', ['url' => $url, 'update' => $update, 'callstack' => System::callstack(20), 'result' => $result]);
180                         if (!empty($fetched_contact)) {
181                                 return $fetched_contact;
182                         }
183                 } else {
184                         DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES);
185                 }
186
187                 if (Network::isLocalLink($url) && ($local_uid = User::getIdForURL($url))) {
188                         try {
189                                 $data = Transmitter::getProfile($local_uid);
190                                 $local_owner = User::getOwnerDataById($local_uid);
191                         } catch(HTTPException\NotFoundException $e) {
192                                 $data = null;
193                         }
194                 }
195
196                 if (empty($data)) {
197                         $local_owner = [];
198
199                         $curlResult = HTTPSignature::fetchRaw($url);
200                         $failed = empty($curlResult) || empty($curlResult->getBody()) ||
201                                 (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
202
203                         if (!$failed) {
204                                 $data = json_decode($curlResult->getBody(), true);
205                                 $failed = empty($data) || !is_array($data);
206                         }
207
208                         if (!$failed && ($curlResult->getReturnCode() == 410)) {
209                                 $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
210                         }
211
212                         if ($failed) {
213                                 self::markForArchival($fetched_contact ?: []);
214                                 return $fetched_contact;
215                         }
216                 }
217
218                 $compacted = JsonLD::compact($data);
219                 if (empty($compacted['@id'])) {
220                         return $fetched_contact;
221                 }
222
223                 $apcontact['url'] = $compacted['@id'];
224                 $apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
225                 $apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
226                 $apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
227                 $apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
228                 $apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
229                 $apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
230
231                 $apcontact['sharedinbox'] = '';
232                 if (!empty($compacted['as:endpoints'])) {
233                         $apcontact['sharedinbox'] = (JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id') ?? '');
234                 }
235
236                 $apcontact['featured']      = JsonLD::fetchElement($compacted, 'toot:featured', '@id');
237                 $apcontact['featured-tags'] = JsonLD::fetchElement($compacted, 'toot:featuredTags', '@id');
238
239                 $apcontact['nick'] = JsonLD::fetchElement($compacted, 'as:preferredUsername', '@value') ?? '';
240                 $apcontact['name'] = JsonLD::fetchElement($compacted, 'as:name', '@value');
241
242                 if (empty($apcontact['name'])) {
243                         $apcontact['name'] = $apcontact['nick'];
244                 }
245
246                 $apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value') ?? '');
247
248                 $ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
249
250                 if (!empty($ims)) {
251                         foreach ($ims as $link) {
252                                 if (substr($link, 0, 5) == 'xmpp:') {
253                                         $apcontact['xmpp'] = substr($link, 5);
254                                 }
255                                 if (substr($link, 0, 7) == 'matrix:') {
256                                         $apcontact['matrix'] = substr($link, 7);
257                                 }
258                         }
259                 }
260
261                 $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id');
262                 if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) {
263                         $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id');
264                 }
265
266                 $apcontact['header'] = JsonLD::fetchElement($compacted, 'as:image', '@id');
267                 if (is_array($apcontact['header']) || !empty($compacted['as:image']['as:url']['@id'])) {
268                         $apcontact['header'] = JsonLD::fetchElement($compacted['as:image'], 'as:url', '@id');
269                 }
270
271                 if (empty($apcontact['alias'])) {
272                         $apcontact['alias'] = JsonLD::fetchElement($compacted, 'as:url', '@id');
273                         if (is_array($apcontact['alias'])) {
274                                 $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id');
275                         }
276                 }
277
278                 // Quit if none of the basic values are set
279                 if (empty($apcontact['url']) || empty($apcontact['type']) || (($apcontact['type'] != 'Tombstone') && empty($apcontact['inbox']))) {
280                         return $fetched_contact;
281                 } elseif ($apcontact['type'] == 'Tombstone') {
282                         // The "inbox" field must have a content
283                         $apcontact['inbox'] = '';
284                 }
285
286                 // Quit if this doesn't seem to be an account at all
287                 if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) {
288                         return $fetched_contact;
289                 }
290
291                 if (empty($apcontact['addr'])) {
292                         try {
293                                 $apcontact['addr'] = $apcontact['nick'] . '@' . (new Uri($apcontact['url']))->getAuthority();
294                         } catch (\Throwable $e) {
295                                 Logger::warning('Unable to coerce APContact URL into a UriInterface object', ['url' => $apcontact['url'], 'error' => $e->getMessage()]);
296                                 $apcontact['addr'] = '';
297                         }
298                 }
299
300                 $apcontact['pubkey'] = null;
301                 if (!empty($compacted['w3id:publicKey'])) {
302                         $apcontact['pubkey'] = trim(JsonLD::fetchElement($compacted['w3id:publicKey'], 'w3id:publicKeyPem', '@value') ?? '');
303                         if (strpos($apcontact['pubkey'], 'RSA ') !== false) {
304                                 $apcontact['pubkey'] = Crypto::rsaToPem($apcontact['pubkey']);
305                         }
306                 }
307
308                 $apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
309
310                 $apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
311
312                 if (!empty($compacted['as:generator'])) {
313                         $apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
314                         $apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
315                 }
316
317                 if (!empty($apcontact['following'])) {
318                         if (!empty($local_owner)) {
319                                 $following = ActivityPub\Transmitter::getContacts($local_owner, [Contact::SHARING, Contact::FRIEND], 'following');
320                         } else {
321                                 $following = ActivityPub::fetchContent($apcontact['following']);
322                         }
323                         if (!empty($following['totalItems'])) {
324                                 // Mastodon seriously allows for this condition?
325                                 // Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
326                                 if ($following['totalItems'] < 0) {
327                                         $following['totalItems'] = 0;
328                                 }
329                                 $apcontact['following_count'] = $following['totalItems'];
330                         }
331                 }
332
333                 if (!empty($apcontact['followers'])) {
334                         if (!empty($local_owner)) {
335                                 $followers = ActivityPub\Transmitter::getContacts($local_owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers');
336                         } else {
337                                 $followers = ActivityPub::fetchContent($apcontact['followers']);
338                         }
339                         if (!empty($followers['totalItems'])) {
340                                 // Mastodon seriously allows for this condition?
341                                 // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
342                                 if ($followers['totalItems'] < 0) {
343                                         $followers['totalItems'] = 0;
344                                 }
345                                 $apcontact['followers_count'] = $followers['totalItems'];
346                         }
347                 }
348
349                 if (!empty($apcontact['outbox'])) {
350                         if (!empty($local_owner)) {
351                                 $statuses_count = self::getStatusesCount($local_owner);
352                         } else {
353                                 $outbox = ActivityPub::fetchContent($apcontact['outbox']);
354                                 $statuses_count = $outbox['totalItems'] ?? 0;
355                         }
356                         if (!empty($statuses_count)) {
357                                 // Mastodon seriously allows for this condition?
358                                 // Jul 20 2021 - See https://chaos.social/@m11 for a negative posts count
359                                 if ($statuses_count < 0) {
360                                         $statuses_count = 0;
361                                 }
362                                 $apcontact['statuses_count'] = $statuses_count;
363                         }
364                 }
365
366                 $apcontact['discoverable'] = JsonLD::fetchElement($compacted, 'toot:discoverable', '@value');
367
368                 // To-Do
369
370                 // Unhandled
371                 // tag, attachment, image, nomadicLocations, signature, movedTo, liked
372
373                 // Unhandled from Misskey
374                 // sharedInbox, isCat
375
376                 // Unhandled from Kroeg
377                 // kroeg:blocks, updated
378
379                 if (!empty($apcontact['photo']) && !Network::isValidHttpUrl($apcontact['photo'])) {
380                         Logger::info('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]);
381                         $apcontact['photo'] = null;
382                 }
383
384                 // When the photo is too large, try to shorten it by removing parts
385                 if (strlen($apcontact['photo'] ?? '') > 255) {
386                         $parts = parse_url($apcontact['photo']);
387                         unset($parts['fragment']);
388                         $apcontact['photo'] = (string)Uri::fromParts($parts);
389
390                         if (strlen($apcontact['photo']) > 255) {
391                                 unset($parts['query']);
392                                 $apcontact['photo'] = (string)Uri::fromParts($parts);
393                         }
394
395                         if (strlen($apcontact['photo']) > 255) {
396                                 $apcontact['photo'] = substr($apcontact['photo'], 0, 255);
397                         }
398                 }
399
400                 if (!$webfinger && !empty($apcontact['addr'])) {
401                         $data = self::fetchWebfingerData($apcontact['addr']);
402                         if (!empty($data)) {
403                                 $apcontact['baseurl'] = $data['baseurl'];
404
405                                 if (empty($apcontact['alias']) && !empty($data['alias'])) {
406                                         $apcontact['alias'] = $data['alias'];
407                                 }
408                                 if (!empty($data['subscribe'])) {
409                                         $apcontact['subscribe'] = $data['subscribe'];
410                                 }
411                         } else {
412                                 $apcontact['addr'] = null;
413                         }
414                 }
415
416                 if (empty($apcontact['baseurl'])) {
417                         $apcontact['baseurl'] = null;
418                 }
419
420                 if (empty($apcontact['subscribe'])) {
421                         $apcontact['subscribe'] = null;
422                 }
423
424                 if (!empty($apcontact['baseurl']) && empty($fetched_contact['gsid'])) {
425                         $apcontact['gsid'] = GServer::getID($apcontact['baseurl']);
426                 } elseif (!empty($fetched_contact['gsid'])) {
427                         $apcontact['gsid'] = $fetched_contact['gsid'];
428                 } else {
429                         $apcontact['gsid'] = null;
430                 }
431
432                 self::unarchiveInbox($apcontact['inbox'], false, $apcontact['gsid']);
433
434                 if (!empty($apcontact['sharedinbox'])) {
435                         self::unarchiveInbox($apcontact['sharedinbox'], true, $apcontact['gsid']);
436                 }
437
438                 if ($apcontact['url'] == $apcontact['alias']) {
439                         $apcontact['alias'] = null;
440                 }
441
442                 if (empty($apcontact['uuid'])) {
443                         $apcontact['uri-id'] = ItemURI::getIdByURI($apcontact['url']);
444                 } else {
445                         $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]);
446                 }
447
448                 foreach (APContact\Endpoint::ENDPOINT_NAMES as $type => $name) {
449                         $value = JsonLD::fetchElement($compacted, $name, '@id');
450                         if (empty($value)) {
451                                 continue;
452                         }
453                         APContact\Endpoint::update($apcontact['uri-id'], $type, $value);
454                 }
455
456                 if (!empty($compacted['as:endpoints'])) {
457                         foreach ($compacted['as:endpoints'] as $name => $endpoint) {
458                                 if (empty($endpoint['@id']) || !is_string($endpoint['@id'])) {
459                                         continue;
460                                 }
461
462                                 if (in_array($name, APContact\Endpoint::ENDPOINT_NAMES)) {
463                                         $key = array_search($name, APContact\Endpoint::ENDPOINT_NAMES);
464                                         APContact\Endpoint::update($apcontact['uri-id'], $key, $endpoint['@id']);
465                                         Logger::debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]);
466                                 } elseif (!in_array($name, ['as:sharedInbox', 'as:uploadMedia', 'as:oauthTokenEndpoint', 'as:oauthAuthorizationEndpoint', 'litepub:oauthRegistrationEndpoint'])) {
467                                         Logger::debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]);
468                                 }
469                         }
470                 }
471
472                 $apcontact['updated'] = DateTimeFormat::utcNow();
473
474                 // We delete the old entry when the URL is changed
475                 if ($url != $apcontact['url']) {
476                         Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
477                         DBA::delete('apcontact', ['url' => $url]);
478                 }
479
480                 // Limit the length on incoming fields
481                 $apcontact = DI::dbaDefinition()->truncateFieldsForTable('apcontact', $apcontact);
482
483                 if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
484                         DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
485                 } else {
486                         DBA::replace('apcontact', $apcontact);
487                 }
488
489                 Logger::info('Updated profile', ['url' => $url]);
490
491                 return DBA::selectFirst('apcontact', [], ['url' => $apcontact['url']]) ?: [];
492         }
493
494         /**
495          * Fetch the number of statuses for the given owner
496          *
497          * @param array $owner
498          *
499          * @return integer
500          */
501         private static function getStatusesCount(array $owner): int
502         {
503                 $condition = [
504                         'private'        => [Item::PUBLIC, Item::UNLISTED],
505                         'author-id'      => Contact::getIdForURL($owner['url'], 0, false),
506                         'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
507                         'network'        => Protocol::DFRN,
508                         'parent-network' => Protocol::FEDERATED,
509                         'deleted'        => false,
510                         'visible'        => true,
511                 ];
512
513                 $count = Post::countPosts($condition);
514
515                 return $count;
516         }
517
518         /**
519          * Mark the given AP Contact as "to archive"
520          *
521          * @param array $apcontact
522          * @return void
523          */
524         public static function markForArchival(array $apcontact)
525         {
526                 if (!empty($apcontact['inbox'])) {
527                         Logger::info('Set inbox status to failure', ['inbox' => $apcontact['inbox']]);
528                         HTTPSignature::setInboxStatus($apcontact['inbox'], false, false, $apcontact['gsid']);
529                 }
530
531                 if (!empty($apcontact['sharedinbox'])) {
532                         // Check if there are any available inboxes
533                         $available = DBA::exists('apcontact', ["`sharedinbox` = ? AnD `inbox` IN (SELECT `url` FROM `inbox-status` WHERE `success` > `failure`)",
534                                 $apcontact['sharedinbox']]);
535                         if (!$available) {
536                                 // If all known personal inboxes are failing then set their shared inbox to failure as well
537                                 Logger::info('Set shared inbox status to failure', ['sharedinbox' => $apcontact['sharedinbox']]);
538                                 HTTPSignature::setInboxStatus($apcontact['sharedinbox'], false, true, $apcontact['gsid']);
539                         }
540                 }
541         }
542
543         /**
544          * Unmark the given AP Contact as "to archive"
545          *
546          * @param array $apcontact
547          * @return void
548          */
549         public static function unmarkForArchival(array $apcontact)
550         {
551                 if (!empty($apcontact['inbox'])) {
552                         Logger::info('Set inbox status to success', ['inbox' => $apcontact['inbox']]);
553                         HTTPSignature::setInboxStatus($apcontact['inbox'], true, false, $apcontact['gsid']);
554                 }
555                 if (!empty($apcontact['sharedinbox'])) {
556                         Logger::info('Set shared inbox status to success', ['sharedinbox' => $apcontact['sharedinbox']]);
557                         HTTPSignature::setInboxStatus($apcontact['sharedinbox'], true, true, $apcontact['gsid']);
558                 }
559         }
560
561         /**
562          * Unarchive inboxes
563          *
564          * @param string  $url    inbox url
565          * @param boolean $shared Shared Inbox
566          * @param int     $gsid   Global server id
567          * @return void
568          */
569         private static function unarchiveInbox(string $url, bool $shared, int $gsid = null)
570         {
571                 if (empty($url)) {
572                         return;
573                 }
574
575                 HTTPSignature::setInboxStatus($url, true, $shared, $gsid);
576         }
577
578         /**
579          * Check if the apcontact is a relay account
580          *
581          * @param array $apcontact
582          *
583          * @return bool
584          */
585         public static function isRelay(array $apcontact): bool
586         {
587                 if (empty($apcontact['nick']) || $apcontact['nick'] != 'relay') {
588                         return false;
589                 }
590
591                 if (!empty($apcontact['type']) && $apcontact['type'] == 'Application') {
592                         return true;
593                 }
594
595                 if (!empty($apcontact['type']) && in_array($apcontact['type'], ['Group', 'Service']) && is_null($apcontact['outbox'])) {
596                         return true;
597                 }
598
599                 return false;
600         }
601 }