diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Mail/Mailer.php | 53 | ||||
-rw-r--r-- | lib/private/Settings/Admin/Mail.php | 4 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 37 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 27 |
4 files changed, 88 insertions, 33 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 001f7bd75c9..6f148bc0c6e 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -26,6 +26,8 @@ declare(strict_types=1); namespace OC\Mail; +use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Validation\RFCValidation; use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; @@ -55,7 +57,7 @@ use OCP\Mail\IMessage; * @package OC\Mail */ class Mailer implements IMailer { - /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ + /** @var \Swift_Mailer Cached mailer */ private $instance = null; /** @var IConfig */ private $config; @@ -105,7 +107,7 @@ class Mailer implements IMailer { * @since 13.0.0 */ public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { - return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); + return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); } /** @@ -194,7 +196,10 @@ class Mailer implements IMailer { * @return bool True if the mail address is valid, false otherwise */ public function validateMailAddress(string $email): bool { - return \Swift_Validate::email($this->convertEmail($email)); + $validator = new EmailValidator(); + $validation = new RFCValidation(); + + return $validator->isValid($this->convertEmail($email), $validation); } /** @@ -215,32 +220,24 @@ class Mailer implements IMailer { return $name.'@'.$domain; } - /** - * Returns whatever transport is configured within the config - * - * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport - */ - protected function getInstance() { + protected function getInstance(): \Swift_Mailer { if (!is_null($this->instance)) { return $this->instance; } - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { - case 'smtp': - $this->instance = $this->getSmtpInstance(); - break; + $transport = null; + + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'sendmail': - // FIXME: Move into the return statement but requires proper testing - // for SMTP and mail as well. Thus not really doable for a - // minor release. - $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); + $transport = $this->getSendMailInstance(); break; + case 'smtp': default: - $this->instance = $this->getMailInstance(); + $transport = $this->getSmtpInstance(); break; } - return $this->instance; + return new \Swift_Mailer($transport); } /** @@ -249,7 +246,7 @@ class Mailer implements IMailer { * @return \Swift_SmtpTransport */ protected function getSmtpInstance(): \Swift_SmtpTransport { - $transport = \Swift_SmtpTransport::newInstance(); + $transport = new \Swift_SmtpTransport(); $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); @@ -262,7 +259,7 @@ class Mailer implements IMailer { if (!empty($smtpSecurity)) { $transport->setEncryption($smtpSecurity); } - $transport->start(); + return $transport; } @@ -272,7 +269,7 @@ class Mailer implements IMailer { * @return \Swift_SendmailTransport */ protected function getSendMailInstance(): \Swift_SendmailTransport { - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'qmail': $binaryPath = '/var/qmail/bin/sendmail'; break; @@ -281,16 +278,6 @@ class Mailer implements IMailer { break; } - return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); + return new \Swift_SendmailTransport($binaryPath . ' -bs'); } - - /** - * Returns the mail transport - * - * @return \Swift_MailTransport - */ - protected function getMailInstance(): \Swift_MailTransport { - return \Swift_MailTransport::newInstance(); - } - } diff --git a/lib/private/Settings/Admin/Mail.php b/lib/private/Settings/Admin/Mail.php index 74a94a4c7a0..fc20b7eeb3f 100644 --- a/lib/private/Settings/Admin/Mail.php +++ b/lib/private/Settings/Admin/Mail.php @@ -63,6 +63,10 @@ class Mail implements ISettings { $parameters['mail_smtppassword'] = '********'; } + if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') { + $parameters['mail_smtpmode'] = 'smtp'; + } + return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, ''); } diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 3c56b24707c..5e52156d1d0 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -31,6 +31,7 @@ namespace OC\Share20; use OC\Files\Cache\Cache; use OCP\Files\Folder; +use OCP\Share\IShare; use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; @@ -412,6 +413,41 @@ class DefaultShareProvider implements IShareProvider { /** * @inheritdoc + * + * For now this only works for group shares + * If this gets implemented for normal shares we have to extend it + */ + public function restore(IShare $share, string $recipient): IShare { + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('permissions') + ->from('share') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($share->getId())) + ); + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + $originalPermission = $data['permissions']; + + $qb = $this->dbConn->getQueryBuilder(); + $qb->update('share') + ->set('permissions', $qb->createNamedParameter($originalPermission)) + ->where( + $qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent())) + )->andWhere( + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) + )->andWhere( + $qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)) + ); + + $qb->execute(); + + return $this->getShareById($share->getId(), $recipient); + } + + /** + * @inheritdoc */ public function move(\OCP\Share\IShare $share, $recipient) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { @@ -922,6 +958,7 @@ class DefaultShareProvider implements IShareProvider { while($data = $stmt->fetch()) { $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); $shareMap[$data['parent']]->setTarget($data['file_target']); + $shareMap[$data['parent']]->setParent($data['parent']); } $stmt->closeCursor(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index cddd8c8d92b..5116351a6bc 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -61,6 +61,7 @@ use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share\IProviderFactory; +use OCP\Share\IShare; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; use OCP\Share\IShareProvider; @@ -978,6 +979,13 @@ class Manager implements IManager { $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); } + public function restoreShare(IShare $share, string $recipientId): IShare { + list($providerId, ) = $this->splitFullId($share->getFullId()); + $provider = $this->factory->getProvider($providerId); + + return $provider->restore($share, $recipientId); + } + /** * @inheritdoc */ @@ -1124,6 +1132,25 @@ class Manager implements IManager { /** * @inheritdoc */ + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); + + // Only get deleted shares + $shares = array_filter($shares, function(IShare $share) { + return $share->getPermissions() === 0; + }); + + // Only get shares where the owner still exists + $shares = array_filter($shares, function (IShare $share) { + return $this->userManager->userExists($share->getShareOwner()); + }); + + return $shares; + } + + /** + * @inheritdoc + */ public function getShareById($id, $recipient = null) { if ($id === null) { throw new ShareNotFound(); |