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

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