77namespace OCA \Settings \Settings \Admin ;
88
99use OCP \AppFramework \Http \TemplateResponse ;
10+ use OCP \AppFramework \Services \IInitialState ;
1011use OCP \IBinaryFinder ;
1112use OCP \IConfig ;
1213use OCP \IL10N ;
14+ use OCP \IURLGenerator ;
1315use OCP \Server ;
1416use OCP \Settings \IDelegatedSettings ;
17+ use OCP \Util ;
1518
1619class Mail implements IDelegatedSettings {
17- /**
18- * @param IConfig $config
19- * @param IL10N $l
20- */
20+
2121 public function __construct (
2222 private IConfig $ config ,
2323 private IL10N $ l ,
24+ private IInitialState $ initialState ,
25+ private IURLGenerator $ urlGenerator ,
2426 ) {
2527 }
2628
@@ -30,30 +32,59 @@ public function __construct(
3032 public function getForm () {
3133 $ finder = Server::get (IBinaryFinder::class);
3234
33- $ parameters = [
34- // Mail
35- 'sendmail_is_available ' => $ finder ->findBinaryPath ('sendmail ' ) !== false ,
35+ $ smtpModeOptions = [
36+ ['label ' => 'SMTP ' , 'id ' => 'smtp ' ],
37+ ];
38+ if ($ finder ->findBinaryPath ('sendmail ' ) !== false ) {
39+ $ smtpModeOptions [] = ['label ' => 'Sendmail ' , 'id ' => 'sendmail ' ];
40+ }
41+ if ($ finder ->findBinaryPath ('qmail ' ) !== false ) {
42+ $ smtpModeOptions [] = ['label ' => 'qmail ' , 'id ' => 'qmail ' ];
43+ }
44+
45+ $ this ->initialState ->provideInitialState ('settingsAdminMail ' , [
46+ 'configIsReadonly ' => $ this ->config ->getSystemValueBool ('config_is_read_only ' , false ),
47+ 'docUrl ' => $ this ->urlGenerator ->linkToDocs ('admin-email ' ),
48+
49+ 'smtpModeOptions ' => $ smtpModeOptions ,
50+ 'smtpEncryptionOptions ' => [
51+ ['label ' => $ this ->l ->t ('None / STARTTLS ' ), 'id ' => '' ],
52+ ['label ' => 'SSL/TLS ' , 'id ' => 'ssl ' ],
53+ ],
54+ 'smtpSendmailModeOptions ' => [
55+ ['label ' => 'smtp (-bs) ' , 'id ' => 'smtp ' ],
56+ ['label ' => 'pipe (-t -i) ' , 'id ' => 'pipe ' ],
57+ ],
58+ ]);
59+
60+ $ smtpPassword = $ this ->config ->getSystemValue ('mail_smtppassword ' , '' );
61+ if ($ smtpPassword !== '' ) {
62+ $ smtpPassword = '******** ' ;
63+ }
64+
65+ $ smtpMode = $ this ->config ->getSystemValue ('mail_smtpmode ' , '' );
66+ if ($ smtpMode === '' || $ smtpMode === 'php ' ) {
67+ $ smtpMode = 'smtp ' ;
68+ }
69+
70+ $ smtpOptions = $ this ->config ->getSystemValue ('mail_smtpstreamoptions ' , []);
71+ $ this ->initialState ->provideInitialState ('settingsAdminMailConfig ' , [
3672 'mail_domain ' => $ this ->config ->getSystemValue ('mail_domain ' , '' ),
3773 'mail_from_address ' => $ this ->config ->getSystemValue ('mail_from_address ' , '' ),
38- 'mail_smtpmode ' => $ this -> config -> getSystemValue ( ' mail_smtpmode ' , '' ) ,
74+ 'mail_smtpmode ' => $ smtpMode ,
3975 'mail_smtpsecure ' => $ this ->config ->getSystemValue ('mail_smtpsecure ' , '' ),
4076 'mail_smtphost ' => $ this ->config ->getSystemValue ('mail_smtphost ' , '' ),
4177 'mail_smtpport ' => $ this ->config ->getSystemValue ('mail_smtpport ' , '' ),
4278 'mail_smtpauth ' => $ this ->config ->getSystemValue ('mail_smtpauth ' , false ),
4379 'mail_smtpname ' => $ this ->config ->getSystemValue ('mail_smtpname ' , '' ),
44- 'mail_smtppassword ' => $ this -> config -> getSystemValue ( ' mail_smtppassword ' , '' ) ,
80+ 'mail_smtppassword ' => $ smtpPassword ,
4581 'mail_sendmailmode ' => $ this ->config ->getSystemValue ('mail_sendmailmode ' , 'smtp ' ),
46- ];
47-
48- if ($ parameters ['mail_smtppassword ' ] !== '' ) {
49- $ parameters ['mail_smtppassword ' ] = '******** ' ;
50- }
5182
52- if ($ parameters ['mail_smtpmode ' ] === '' || $ parameters ['mail_smtpmode ' ] === 'php ' ) {
53- $ parameters ['mail_smtpmode ' ] = 'smtp ' ;
54- }
83+ 'mail_noverify ' => $ smtpOptions ['ssl ' ]['allow_self_signed ' ] ?? false ,
84+ ]);
5585
56- return new TemplateResponse ('settings ' , 'settings/admin/additional-mail ' , $ parameters , '' );
86+ Util::addScript ('settings ' , 'vue-settings-admin-mail ' );
87+ return new TemplateResponse ('settings ' , 'settings/admin/additional-mail ' , renderAs: '' );
5788 }
5889
5990 /**
0 commit comments