Code Duplication    Length = 62-62 lines in 2 locations

lib/Circles/FileSharingBroadcaster.php 1 location

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

lib/GlobalScale/MemberAdd.php 1 location

@@ 381-442 (lines=62) @@
378
	 *
379
	 * @throws Exception
380
	 */
381
	protected function sendPasswordExistingShares(string $author, string $email, string $password) {
382
		if ($password === '') {
383
			return;
384
		}
385
386
		$message = $this->mailer->createMessage();
387
388
		$authorUser = $this->userManager->get($author);
389
		$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
390
		$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
391
392
		$this->miscService->log("Sending password mail about existing files to '" . $email . "'", 0);
393
394
		$plainBodyPart = $this->l10n->t(
395
			"%1\$s shared multiple files with you.\nYou should have already received a separate mail with a link to access them.\n",
396
			[$authorName]
397
		);
398
		$htmlBodyPart = $this->l10n->t(
399
			'%1$s shared multiple files with you. You should have already received a separate mail with a link to access them.',
400
			[$authorName]
401
		);
402
403
		$emailTemplate = $this->mailer->createEMailTemplate(
404
			'sharebymail.RecipientPasswordNotification', [
405
														   'password' => $password,
406
														   'author'   => $author
407
													   ]
408
		);
409
410
		$emailTemplate->setSubject(
411
			$this->l10n->t(
412
				'Password to access files shared to you by %1$s', [$authorName]
413
			)
414
		);
415
		$emailTemplate->addHeader();
416
		$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
417
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
418
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
419
		$emailTemplate->addBodyText($password);
420
421
		// The "From" contains the sharers name
422
		$instanceName = $this->defaults->getName();
423
		$senderName = $this->l10n->t(
424
			'%1$s via %2$s',
425
			[
426
				$authorName,
427
				$instanceName
428
			]
429
		);
430
431
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
432
		if ($authorEmail !== null) {
433
			$message->setReplyTo([$authorEmail => $authorName]);
434
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
435
		} else {
436
			$emailTemplate->addFooter();
437
		}
438
439
		$message->setTo([$email]);
440
		$message->useTemplate($emailTemplate);
441
		$this->mailer->send($message);
442
	}
443
444
}
445