Mail.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Settings\Admin;
  7. use OCP\AppFramework\Http\TemplateResponse;
  8. use OCP\IBinaryFinder;
  9. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use OCP\Server;
  12. use OCP\Settings\IDelegatedSettings;
  13. class Mail implements IDelegatedSettings {
  14. /**
  15. * @param IConfig $config
  16. * @param IL10N $l
  17. */
  18. public function __construct(
  19. private IConfig $config,
  20. private IL10N $l,
  21. ) {
  22. }
  23. /**
  24. * @return TemplateResponse
  25. */
  26. public function getForm() {
  27. $parameters = [
  28. // Mail
  29. 'sendmail_is_available' => (bool)Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'),
  30. 'mail_domain' => $this->config->getSystemValue('mail_domain', ''),
  31. 'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''),
  32. 'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''),
  33. 'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''),
  34. 'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''),
  35. 'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''),
  36. 'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
  37. 'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
  38. 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
  39. 'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'),
  40. ];
  41. if ($parameters['mail_smtppassword'] !== '') {
  42. $parameters['mail_smtppassword'] = '********';
  43. }
  44. if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') {
  45. $parameters['mail_smtpmode'] = 'smtp';
  46. }
  47. return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, '');
  48. }
  49. /**
  50. * @return string the section ID, e.g. 'sharing'
  51. */
  52. public function getSection() {
  53. return 'server';
  54. }
  55. /**
  56. * @return int whether the form should be rather on the top or bottom of
  57. * the admin section. The forms are arranged in ascending order of the
  58. * priority values. It is required to return a value between 0 and 100.
  59. *
  60. * E.g.: 70
  61. */
  62. public function getPriority() {
  63. return 10;
  64. }
  65. public function getName(): ?string {
  66. return $this->l->t('Email server');
  67. }
  68. public function getAuthorizedAppConfig(): array {
  69. return [];
  70. }
  71. }