| @@ 480-550 (lines=71) @@ | ||
| 477 | * @throws NotFoundException |
|
| 478 | * @throws Exception |
|
| 479 | */ |
|
| 480 | protected function sendPasswordByMail(IShare $share, $circleName, $email, $password) { |
|
| 481 | if (!$this->configService->sendPasswordByMail() || $password === '') { |
|
| 482 | return; |
|
| 483 | } |
|
| 484 | ||
| 485 | $message = $this->mailer->createMessage(); |
|
| 486 | ||
| 487 | $this->logger->log(0, "Sending password mail to circle '" . $circleName . "': " . $email); |
|
| 488 | ||
| 489 | $filename = $share->getNode() |
|
| 490 | ->getName(); |
|
| 491 | $initiator = $share->getSharedBy(); |
|
| 492 | $shareWith = $share->getSharedWith(); |
|
| 493 | ||
| 494 | $initiatorUser = $this->userManager->get($initiator); |
|
| 495 | $initiatorDisplayName = |
|
| 496 | ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 497 | $initiatorEmailAddress = |
|
| 498 | ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 499 | ||
| 500 | $plainBodyPart = $this->l10n->t( |
|
| 501 | "%1\$s shared »%2\$s« with you.\nYou should have already received a separate mail with a link to access it.\n", |
|
| 502 | [$initiatorDisplayName, $filename] |
|
| 503 | ); |
|
| 504 | $htmlBodyPart = $this->l10n->t( |
|
| 505 | '%1$s shared »%2$s« with you. You should have already received a separate mail with a link to access it.', |
|
| 506 | [$initiatorDisplayName, $filename] |
|
| 507 | ); |
|
| 508 | ||
| 509 | $emailTemplate = $this->mailer->createEMailTemplate( |
|
| 510 | 'sharebymail.RecipientPasswordNotification', [ |
|
| 511 | 'filename' => $filename, |
|
| 512 | 'password' => $password, |
|
| 513 | 'initiator' => $initiatorDisplayName, |
|
| 514 | 'initiatorEmail' => $initiatorEmailAddress, |
|
| 515 | 'shareWith' => $shareWith, |
|
| 516 | ] |
|
| 517 | ); |
|
| 518 | ||
| 519 | $emailTemplate->setSubject( |
|
| 520 | $this->l10n->t( |
|
| 521 | 'Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName] |
|
| 522 | ) |
|
| 523 | ); |
|
| 524 | $emailTemplate->addHeader(); |
|
| 525 | $emailTemplate->addHeading($this->l10n->t('Password to access »%s«', [$filename]), false); |
|
| 526 | $emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart); |
|
| 527 | $emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:')); |
|
| 528 | $emailTemplate->addBodyText($password); |
|
| 529 | ||
| 530 | // The "From" contains the sharers name |
|
| 531 | $instanceName = $this->defaults->getName(); |
|
| 532 | $senderName = $this->l10n->t( |
|
| 533 | '%1$s via %2$s', |
|
| 534 | [ |
|
| 535 | $initiatorDisplayName, |
|
| 536 | $instanceName |
|
| 537 | ] |
|
| 538 | ); |
|
| 539 | $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 540 | if ($initiatorEmailAddress !== null) { |
|
| 541 | $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
| 542 | $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
| 543 | } else { |
|
| 544 | $emailTemplate->addFooter(); |
|
| 545 | } |
|
| 546 | ||
| 547 | $message->setTo([$email]); |
|
| 548 | $message->useTemplate($emailTemplate); |
|
| 549 | $this->mailer->send($message); |
|
| 550 | } |
|
| 551 | ||
| 552 | ||
| 553 | /** |
|
| @@ 314-384 (lines=71) @@ | ||
| 311 | * @throws NotFoundException |
|
| 312 | * @throws Exception |
|
| 313 | */ |
|
| 314 | protected function sendPasswordByMail(IShare $share, $circleName, $email, $password) { |
|
| 315 | if (!$this->configService->sendPasswordByMail() || $password === '') { |
|
| 316 | return; |
|
| 317 | } |
|
| 318 | ||
| 319 | $message = $this->mailer->createMessage(); |
|
| 320 | ||
| 321 | $this->miscService->log("Sending password mail to circle '" . $circleName . "': " . $email, 0); |
|
| 322 | ||
| 323 | $filename = $share->getNode() |
|
| 324 | ->getName(); |
|
| 325 | $initiator = $share->getSharedBy(); |
|
| 326 | $shareWith = $share->getSharedWith(); |
|
| 327 | ||
| 328 | $initiatorUser = $this->userManager->get($initiator); |
|
| 329 | $initiatorDisplayName = |
|
| 330 | ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 331 | $initiatorEmailAddress = |
|
| 332 | ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
| 333 | ||
| 334 | $plainBodyPart = $this->l10n->t( |
|
| 335 | "%1\$s shared »%2\$s« with you.\nYou should have already received a separate mail with a link to access it.\n", |
|
| 336 | [$initiatorDisplayName, $filename] |
|
| 337 | ); |
|
| 338 | $htmlBodyPart = $this->l10n->t( |
|
| 339 | '%1$s shared »%2$s« with you. You should have already received a separate mail with a link to access it.', |
|
| 340 | [$initiatorDisplayName, $filename] |
|
| 341 | ); |
|
| 342 | ||
| 343 | $emailTemplate = $this->mailer->createEMailTemplate( |
|
| 344 | 'sharebymail.RecipientPasswordNotification', [ |
|
| 345 | 'filename' => $filename, |
|
| 346 | 'password' => $password, |
|
| 347 | 'initiator' => $initiatorDisplayName, |
|
| 348 | 'initiatorEmail' => $initiatorEmailAddress, |
|
| 349 | 'shareWith' => $shareWith, |
|
| 350 | ] |
|
| 351 | ); |
|
| 352 | ||
| 353 | $emailTemplate->setSubject( |
|
| 354 | $this->l10n->t( |
|
| 355 | 'Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName] |
|
| 356 | ) |
|
| 357 | ); |
|
| 358 | $emailTemplate->addHeader(); |
|
| 359 | $emailTemplate->addHeading($this->l10n->t('Password to access »%s«', [$filename]), false); |
|
| 360 | $emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart); |
|
| 361 | $emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:')); |
|
| 362 | $emailTemplate->addBodyText($password); |
|
| 363 | ||
| 364 | // The "From" contains the sharers name |
|
| 365 | $instanceName = $this->defaults->getName(); |
|
| 366 | $senderName = $this->l10n->t( |
|
| 367 | '%1$s via %2$s', |
|
| 368 | [ |
|
| 369 | $initiatorDisplayName, |
|
| 370 | $instanceName |
|
| 371 | ] |
|
| 372 | ); |
|
| 373 | $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
| 374 | if ($initiatorEmailAddress !== null) { |
|
| 375 | $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
| 376 | $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
| 377 | } else { |
|
| 378 | $emailTemplate->addFooter(); |
|
| 379 | } |
|
| 380 | ||
| 381 | $message->setTo([$email]); |
|
| 382 | $message->useTemplate($emailTemplate); |
|
| 383 | $this->mailer->send($message); |
|
| 384 | } |
|
| 385 | ||
| 386 | ||
| 387 | /** |
|