*/ class PreparingShareSendMail implements IEventListener { use TStringTools; use TNCLogger; /** @var IHasher */ private $hasher; /** @var ShareWrapperService */ private $shareWrapperService; /** @var ShareTokenService */ private $shareTokenService; /** @var SendMailService */ private $sendMailService; /** @var ConfigService */ private $configService; /** @var ContactService */ private $contactService; public function __construct( IHasher $hasher, ShareWrapperService $shareWrapperService, ShareTokenService $shareTokenService, SendMailService $sendMailService, ContactService $contactService, ConfigService $configService, ) { $this->hasher = $hasher; $this->shareWrapperService = $shareWrapperService; $this->shareTokenService = $shareTokenService; $this->sendMailService = $sendMailService; $this->contactService = $contactService; $this->configService = $configService; $this->setup('app', Application::APP_ID); } /** * @throws FederatedItemException * @throws RemoteInstanceException * @throws RemoteNotFoundException * @throws RemoteResourceNotFoundException * @throws RequestBuilderException * @throws UnknownRemoteException */ public function handle(Event $event): void { if (!$event instanceof PreparingFileShareEvent) { return; } $circle = $event->getCircle(); if (!$this->configService->enforcePasswordOnSharedFile($circle)) { return; } $federatedEvent = $event->getFederatedEvent(); $hashedPasswords = $clearPasswords = []; foreach ($circle->getInheritedMembers(false, true) as $member) { if (($member->getUserType() !== Member::TYPE_MAIL && $member->getUserType() !== Member::TYPE_CONTACT) || array_key_exists($member->getSingleId(), $clearPasswords) ) { // Ignore members that are not 'mail' or the one we already generated a password continue; } [$clearPassword, $hashedPassword] = $this->sendMailService->getPassword($circle); $clearPasswords[$member->getSingleId()] = $clearPassword; $hashedPasswords[$member->getSingleId()] = $hashedPassword; } $federatedEvent->getInternal()->aArray('clearPasswords', $clearPasswords); $federatedEvent->getParams()->aArray('hashedPasswords', $hashedPasswords); } }