Code Duplication    Length = 62-62 lines in 2 locations

lib/Circles/FileSharingBroadcaster.php 1 location

@@ 637-698 (lines=62) @@
634
	 *
635
	 * @throws Exception
636
	 */
637
	protected function sendPasswordExistingShares($author, $email, $password) {
638
		if (!$this->configService->sendPasswordByMail() || $password === '') {
639
			return;
640
		}
641
642
		$message = $this->mailer->createMessage();
643
644
		$authorUser = $this->userManager->get($author);
645
		$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
646
		$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
647
648
		$this->logger->log(0, "Sending password mail about existing files to '" . $email . "'");
649
650
		$plainBodyPart = $this->l10n->t(
651
			"%1\$s shared multiple files with you.\nYou should have already received a separate mail with a link to access them.\n",
652
			[$authorName]
653
		);
654
		$htmlBodyPart = $this->l10n->t(
655
			'%1$s shared multiple files with you. You should have already received a separate mail with a link to access them.',
656
			[$authorName]
657
		);
658
659
		$emailTemplate = $this->mailer->createEMailTemplate(
660
			'sharebymail.RecipientPasswordNotification', [
661
														   'password' => $password,
662
														   'author'   => $author
663
													   ]
664
		);
665
666
		$emailTemplate->setSubject(
667
			$this->l10n->t(
668
				'Password to access files shared to you by %1$s', [$authorName]
669
			)
670
		);
671
		$emailTemplate->addHeader();
672
		$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
673
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
674
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
675
		$emailTemplate->addBodyText($password);
676
677
		// The "From" contains the sharers name
678
		$instanceName = $this->defaults->getName();
679
		$senderName = $this->l10n->t(
680
			'%1$s via %2$s',
681
			[
682
				$authorName,
683
				$instanceName
684
			]
685
		);
686
687
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
688
		if ($authorEmail !== null) {
689
			$message->setReplyTo([$authorEmail => $authorName]);
690
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
691
		} else {
692
			$emailTemplate->addFooter();
693
		}
694
695
		$message->setTo([$email]);
696
		$message->useTemplate($emailTemplate);
697
		$this->mailer->send($message);
698
	}
699
700
	/**
701
	 * @param array $share

lib/GlobalScale/MemberAdd.php 1 location

@@ 354-415 (lines=62) @@
351
	 *
352
	 * @throws Exception
353
	 */
354
	protected function sendPasswordExistingShares(string $author, string $email, string $password) {
355
		if ($password === '') {
356
			return;
357
		}
358
359
		$message = $this->mailer->createMessage();
360
361
		$authorUser = $this->userManager->get($author);
362
		$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
363
		$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
364
365
		$this->miscService->log("Sending password mail about existing files to '" . $email . "'", 0);
366
367
		$plainBodyPart = $this->l10n->t(
368
			"%1\$s shared multiple files with you.\nYou should have already received a separate mail with a link to access them.\n",
369
			[$authorName]
370
		);
371
		$htmlBodyPart = $this->l10n->t(
372
			'%1$s shared multiple files with you. You should have already received a separate mail with a link to access them.',
373
			[$authorName]
374
		);
375
376
		$emailTemplate = $this->mailer->createEMailTemplate(
377
			'sharebymail.RecipientPasswordNotification', [
378
														   'password' => $password,
379
														   'author'   => $author
380
													   ]
381
		);
382
383
		$emailTemplate->setSubject(
384
			$this->l10n->t(
385
				'Password to access files shared to you by %1$s', [$authorName]
386
			)
387
		);
388
		$emailTemplate->addHeader();
389
		$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
390
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
391
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
392
		$emailTemplate->addBodyText($password);
393
394
		// The "From" contains the sharers name
395
		$instanceName = $this->defaults->getName();
396
		$senderName = $this->l10n->t(
397
			'%1$s via %2$s',
398
			[
399
				$authorName,
400
				$instanceName
401
			]
402
		);
403
404
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
405
		if ($authorEmail !== null) {
406
			$message->setReplyTo([$authorEmail => $authorName]);
407
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
408
		} else {
409
			$emailTemplate->addFooter();
410
		}
411
412
		$message->setTo([$email]);
413
		$message->useTemplate($emailTemplate);
414
		$this->mailer->send($message);
415
	}
416
417
}
418