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