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

@@ 326-387 (lines=62) @@
323
	 *
324
	 * @throws Exception
325
	 */
326
	protected function sendPasswordExistingShares(string $author, string $email, string $password) {
327
		if ($password === '') {
328
			return;
329
		}
330
331
		$message = $this->mailer->createMessage();
332
333
		$authorUser = $this->userManager->get($author);
334
		$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
335
		$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
336
337
		$this->miscService->log("Sending password mail about existing files to '" . $email . "'", 0);
338
339
		$plainBodyPart = $this->l10n->t(
340
			"%1\$s shared multiple files with you.\nYou should have already received a separate mail with a link to access them.\n",
341
			[$authorName]
342
		);
343
		$htmlBodyPart = $this->l10n->t(
344
			'%1$s shared multiple files with you. You should have already received a separate mail with a link to access them.',
345
			[$authorName]
346
		);
347
348
		$emailTemplate = $this->mailer->createEMailTemplate(
349
			'sharebymail.RecipientPasswordNotification', [
350
														   'password' => $password,
351
														   'author'   => $author
352
													   ]
353
		);
354
355
		$emailTemplate->setSubject(
356
			$this->l10n->t(
357
				'Password to access files shared to you by %1$s', [$authorName]
358
			)
359
		);
360
		$emailTemplate->addHeader();
361
		$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
362
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
363
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
364
		$emailTemplate->addBodyText($password);
365
366
		// The "From" contains the sharers name
367
		$instanceName = $this->defaults->getName();
368
		$senderName = $this->l10n->t(
369
			'%1$s via %2$s',
370
			[
371
				$authorName,
372
				$instanceName
373
			]
374
		);
375
376
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
377
		if ($authorEmail !== null) {
378
			$message->setReplyTo([$authorEmail => $authorName]);
379
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
380
		} else {
381
			$emailTemplate->addFooter();
382
		}
383
384
		$message->setTo([$email]);
385
		$message->useTemplate($emailTemplate);
386
		$this->mailer->send($message);
387
	}
388
389
390
}