Code Duplication    Length = 71-71 lines in 2 locations

lib/Circles/FileSharingBroadcaster.php 1 location

@@ 482-552 (lines=71) @@
479
	 * @throws NotFoundException
480
	 * @throws Exception
481
	 */
482
	protected function sendPasswordByMail(IShare $share, $circleName, $email, $password) {
483
		if (!$this->configService->sendPasswordByMail() || $password === '') {
484
			return;
485
		}
486
487
		$message = $this->mailer->createMessage();
488
489
		$this->logger->log(0, "Sending password mail to circle '" . $circleName . "': " . $email);
490
491
		$filename = $share->getNode()
492
						  ->getName();
493
		$initiator = $share->getSharedBy();
494
		$shareWith = $share->getSharedWith();
495
496
		$initiatorUser = $this->userManager->get($initiator);
497
		$initiatorDisplayName =
498
			($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
499
		$initiatorEmailAddress =
500
			($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
501
502
		$plainBodyPart = $this->l10n->t(
503
			"%1\$s shared »%2\$s« with you.\nYou should have already received a separate mail with a link to access it.\n",
504
			[$initiatorDisplayName, $filename]
505
		);
506
		$htmlBodyPart = $this->l10n->t(
507
			'%1$s shared »%2$s« with you. You should have already received a separate mail with a link to access it.',
508
			[$initiatorDisplayName, $filename]
509
		);
510
511
		$emailTemplate = $this->mailer->createEMailTemplate(
512
			'sharebymail.RecipientPasswordNotification', [
513
														   'filename'       => $filename,
514
														   'password'       => $password,
515
														   'initiator'      => $initiatorDisplayName,
516
														   'initiatorEmail' => $initiatorEmailAddress,
517
														   'shareWith'      => $shareWith,
518
													   ]
519
		);
520
521
		$emailTemplate->setSubject(
522
			$this->l10n->t(
523
				'Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName]
524
			)
525
		);
526
		$emailTemplate->addHeader();
527
		$emailTemplate->addHeading($this->l10n->t('Password to access »%s«', [$filename]), false);
528
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
529
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
530
		$emailTemplate->addBodyText($password);
531
532
		// The "From" contains the sharers name
533
		$instanceName = $this->defaults->getName();
534
		$senderName = $this->l10n->t(
535
			'%1$s via %2$s',
536
			[
537
				$initiatorDisplayName,
538
				$instanceName
539
			]
540
		);
541
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
542
		if ($initiatorEmailAddress !== null) {
543
			$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
544
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
545
		} else {
546
			$emailTemplate->addFooter();
547
		}
548
549
		$message->setTo([$email]);
550
		$message->useTemplate($emailTemplate);
551
		$this->mailer->send($message);
552
	}
553
554
555
	/**

lib/GlobalScale/FileShare.php 1 location

@@ 355-425 (lines=71) @@
352
	 * @throws NotFoundException
353
	 * @throws Exception
354
	 */
355
	protected function sendPasswordByMail(IShare $share, $circleName, $email, $password) {
356
		if (!$this->configService->sendPasswordByMail() || $password === '') {
357
			return;
358
		}
359
360
		$message = $this->mailer->createMessage();
361
362
		$this->miscService->log("Sending password mail to circle '" . $circleName . "': " . $email, 0);
363
364
		$filename = $share->getNode()
365
						  ->getName();
366
		$initiator = $share->getSharedBy();
367
		$shareWith = $share->getSharedWith();
368
369
		$initiatorUser = $this->userManager->get($initiator);
370
		$initiatorDisplayName =
371
			($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
372
		$initiatorEmailAddress =
373
			($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
374
375
		$plainBodyPart = $this->l10n->t(
376
			"%1\$s shared »%2\$s« with you.\nYou should have already received a separate mail with a link to access it.\n",
377
			[$initiatorDisplayName, $filename]
378
		);
379
		$htmlBodyPart = $this->l10n->t(
380
			'%1$s shared »%2$s« with you. You should have already received a separate mail with a link to access it.',
381
			[$initiatorDisplayName, $filename]
382
		);
383
384
		$emailTemplate = $this->mailer->createEMailTemplate(
385
			'sharebymail.RecipientPasswordNotification', [
386
														   'filename'       => $filename,
387
														   'password'       => $password,
388
														   'initiator'      => $initiatorDisplayName,
389
														   'initiatorEmail' => $initiatorEmailAddress,
390
														   'shareWith'      => $shareWith,
391
													   ]
392
		);
393
394
		$emailTemplate->setSubject(
395
			$this->l10n->t(
396
				'Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName]
397
			)
398
		);
399
		$emailTemplate->addHeader();
400
		$emailTemplate->addHeading($this->l10n->t('Password to access »%s«', [$filename]), false);
401
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
402
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
403
		$emailTemplate->addBodyText($password);
404
405
		// The "From" contains the sharers name
406
		$instanceName = $this->defaults->getName();
407
		$senderName = $this->l10n->t(
408
			'%1$s via %2$s',
409
			[
410
				$initiatorDisplayName,
411
				$instanceName
412
			]
413
		);
414
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
415
		if ($initiatorEmailAddress !== null) {
416
			$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
417
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
418
		} else {
419
			$emailTemplate->addFooter();
420
		}
421
422
		$message->setTo([$email]);
423
		$message->useTemplate($emailTemplate);
424
		$this->mailer->send($message);
425
	}
426
427
428
	/**