@@ -22,70 +22,83 @@ set_postfix() {
2222 local debug=" ${7} "
2323
2424 local php_ini_file=" ${php_ini_dir} /devilbox-runtime-sendmail.ini"
25- local catch_all =
25+ local enable_mail =
2626
27+ # Verify env value
2728 if ! env_set " ${env_varname} " ; then
2829 log " info" " \$ ${env_varname} not set." " ${debug} "
2930 log " info" " Postfix will not be started." " ${debug} "
3031 echo " " > " ${php_ini_file} "
31- else
32- catch_all=" $( env_get " ${env_varname} " ) "
33- if [ " ${catch_all} " = " 1" ]; then
34- log " info" " \$ ${env_varname} set to 1. Enabling postfix catch-all" " ${debug} "
35-
36- # Configure PHP
37- {
38- echo " [mail function]" ;
39- echo " sendmail_path = $( which sendmail ) -t -i" ;
40- echo " ;mail.force_extra_parameters =" ;
41- echo " mail.add_x_header = On" ;
42- echo " mail.log = ${php_mail_log} " ;
43- } > " ${php_ini_file} "
44-
45- # PHP mail function logs to file
46- if [ " ${docker_logs} " != " 1" ]; then
47- # Fix PHP mail log file dir/file and permissions
48- if [ ! -d " $( dirname " ${php_mail_log} " ) " ]; then
49- run " mkdir -p $( dirname " ${php_mail_log} " ) " " ${debug} "
50- fi
51- if [ ! -f " ${php_mail_log} " ]; then
52- run " touch ${php_mail_log} " " ${debug} "
53- fi
54- run " chown ${username} :${groupname} $( dirname " ${php_mail_log} " ) " " ${debug} "
55- run " chown ${username} :${groupname} ${php_mail_log} " " ${debug} "
56- run " chmod 0644 ${php_mail_log} " " ${debug} "
57- fi
32+ return
33+ fi
34+
35+ # Retrieve env value
36+ enable_mail=" $( env_get " ${env_varname} " ) "
37+
38+ # Enable postfix
39+ if [ " ${enable_mail} " = " 1" ] || [ " ${enable_mail} " = " 2" ]; then
5840
59- # Add Mail dir/file if it does not exist
60- if [ ! -d " /var/mail" ]; then
61- run " mkdir /var/mail" " ${debug} "
41+ if [ " ${enable_mail} " = " 1" ]; then
42+ log " info" " \$ ${env_varname} set to 1. Enabling postfix" " ${debug} "
43+ else
44+ log " info" " \$ ${env_varname} set to 2. Enabling postfix catch-all" " ${debug} "
45+ fi
46+
47+ # Configure PHP
48+ {
49+ echo " [mail function]" ;
50+ echo " sendmail_path = $( command -v sendmail ) -t -i" ;
51+ echo " ;mail.force_extra_parameters =" ;
52+ echo " mail.add_x_header = On" ;
53+ echo " mail.log = ${php_mail_log} " ;
54+ } > " ${php_ini_file} "
55+
56+ # PHP mail function logs to file
57+ if [ " ${docker_logs} " != " 1" ]; then
58+ # Fix PHP mail log file dir/file and permissions
59+ if [ ! -d " $( dirname " ${php_mail_log} " ) " ]; then
60+ run " mkdir -p $( dirname " ${php_mail_log} " ) " " ${debug} "
6261 fi
63- if [ ! -f " /var/mail/ ${username }" ]; then
64- run " touch /var/mail/ ${username }" " ${debug} "
62+ if [ ! -f " ${php_mail_log }" ]; then
63+ run " touch ${php_mail_log }" " ${debug} "
6564 fi
65+ run " chown ${username} :${groupname} $( dirname " ${php_mail_log} " ) " " ${debug} "
66+ run " chown ${username} :${groupname} ${php_mail_log} " " ${debug} "
67+ run " chmod 0644 ${php_mail_log} " " ${debug} "
68+ fi
6669
67- # Fix mail dir/file permissions after mount
68- run " chmod 0644 /var/mail/${username} " " ${debug} "
69- run " chown ${username} :${groupname} /var/mail" " ${debug} "
70- run " chown ${username} :${groupname} /var/mail/${username} " " ${debug} "
70+ # Add Mail dir/file if it does not exist
71+ if [ ! -d " /var/mail" ]; then
72+ run " mkdir /var/mail" " ${debug} "
73+ fi
74+ if [ ! -f " /var/mail/${username} " ]; then
75+ run " touch /var/mail/${username} " " ${debug} "
76+ fi
77+
78+ # Fix mail dir/file permissions after mount
79+ run " chmod 0644 /var/mail/${username} " " ${debug} "
80+ run " chown ${username} :${groupname} /var/mail" " ${debug} "
81+ run " chown ${username} :${groupname} /var/mail/${username} " " ${debug} "
7182
72- # warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch
73- run " postconf -e 'strict_mailbox_ownership=no'" " ${debug} "
83+ # warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch
84+ run " postconf -e 'strict_mailbox_ownership=no'" " ${debug} "
7485
75- # Postfix configuration
76- run " postconf -e 'inet_protocols=ipv4'" " ${debug} "
86+ # Postfix configuration
87+ run " postconf -e 'inet_protocols=ipv4'" " ${debug} "
88+
89+ # Postfix catch-all
90+ if [ " ${enable_mail} " = " 2" ]; then
7791 run " postconf -e 'virtual_alias_maps=pcre:/etc/postfix/virtual'" " ${debug} "
7892 run " echo '/.*@.*/ ${username} ' >> /etc/postfix/virtual" " ${debug} "
79-
8093 run " newaliases" " ${debug} "
94+ fi
8195
82- elif [ " ${catch_all } " = " 0" ]; then
83- log " info" " \$ ${env_varname} set to 0. Disabling postfix catch-all " " ${debug} "
96+ elif [ " ${enable_mail } " = " 0" ]; then
97+ log " info" " \$ ${env_varname} set to 0. Disabling postfix" " ${debug} "
8498
85- else
86- log " err" " Invalid value for \$ ${env_varname} . Can only be 0 or 1. Prodived: ${catch_all} " " ${debug} "
87- exit 1
88- fi
99+ else
100+ log " err" " Invalid value for \$ ${env_varname} . Can only be 0, 1 or 2. Prodived: ${enable_mail} " " ${debug} "
101+ exit 1
89102 fi
90103}
91104
0 commit comments