@@ -67,67 +67,81 @@ function update($event_name,$data) {
6767
6868 // Check if the config directory exists.
6969 if (!is_dir ($ this ->mailfilter_config_dir )) {
70- $ app ->log ("Mailfilter config directory ' " .$ this ->mailfilter_config_dir ."' does not exist. " ,LOGLEVEL_ERROR );
70+ $ app ->log ("Mailfilter config directory ' " .$ this ->mailfilter_config_dir ."' does not exist. Creating it now. " ,LOGLEVEL_WARN );
71+ mkdir ($ this ->mailfilter_config_dir );
72+ exec ("chown vmail " .$ this ->mailfilter_config_dir );
73+ exec ("chmod 770 " .$ this ->mailfilter_config_dir );
74+ }
75+
76+ if (isset ($ data ["new " ]["email " ])) {
77+ $ email_parts = explode ("@ " ,$ data ["new " ]["email " ]);
7178 } else {
72- // Check if something has been changed regarding the autoresponders
73- if ($ data ["old " ]["autoresponder_text " ] != $ data ["new " ]["autoresponder_text " ]
79+ $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
80+ }
81+
82+ // make sure that the config directories exist
83+ if (!is_dir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ])) {
84+ mkdir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
85+ exec ("chown vmail " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
86+ exec ("chmod 770 " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
87+ }
88+ if (!is_dir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ])) {
89+ mkdir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
90+ exec ("chown vmail " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
91+ exec ("chmod 770 " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
92+ }
93+
94+
95+ // Check if something has been changed regarding the autoresponders
96+ if ($ data ["old " ]["autoresponder_text " ] != $ data ["new " ]["autoresponder_text " ]
7497 or $ data ["old " ]["autoresponder " ] != $ data ["new " ]["autoresponder " ]
7598 or (isset ($ data ["new " ]["email " ]) and $ data ["old " ]["email " ] != $ data ["new " ]["email " ])) {
7699
77- // We delete the old autoresponder, if it exists
78- $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
79- $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.lock ' ;
80- if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
81- $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.lst ' ;
82- if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
83- $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.msg ' ;
84- if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
85- $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.autoresponder ' ;
86- if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
100+ // We delete the old autoresponder, if it exists
101+ $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
102+ $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.lock ' ;
103+ if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
104+ $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.lst ' ;
105+ if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
106+ $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.msg ' ;
107+ if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
108+ $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.autoresponder ' ;
109+ if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
87110
88- //Now we create the new autoresponder, if it is enabled
89- if ($ data ["new " ]["autoresponder " ] == 'y ' ) {
90- if (isset ($ data ["new " ]["email " ])) {
91- $ email_parts = explode ("@ " ,$ data ["new " ]["email " ]);
92- } else {
93- $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
94- }
95-
96- // make sure that the config directories exist
97- if (!is_dir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ])) {
98- mkdir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
99- exec ("chown vmail " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
100- exec ("chmod 400 " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ]);
101- }
102- if (!is_dir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ])) {
103- mkdir ($ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
104- exec ("chown vmail " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
105- exec ("chmod 400 " .$ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ]);
106- }
111+ //Now we create the new autoresponder, if it is enabled
112+ if ($ data ["new " ]["autoresponder " ] == 'y ' ) {
113+ if (isset ($ data ["new " ]["email " ])) {
114+ $ email_parts = explode ("@ " ,$ data ["new " ]["email " ]);
115+ } else {
116+ $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
117+ }
107118
108- // Load the master template
109- $ tpl = file_get_contents ($ conf ["rootpath " ].'/conf/autoresponder.master ' );
110- $ tpl = str_replace ('{vmail_mailbox_base} ' ,$ mail_config ["homedir_path " ],$ tpl );
111- // Write the config file.
112- $ config_file_path = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.autoresponder ' ;
113- file_put_contents ($ config_file_path ,$ tpl );
114- $ app ->log ("Writing Autoresponder mailfilter file: $ config_file_path " ,LOGLEVEL_DEBUG );
115- exec ("chmod 400 $ config_file_path " );
116- exec ("chown vmail $ config_file_path " );
117- unset($ tpl );
118- unset($ config_file_path );
119+ // Load the master template
120+ $ tpl = file_get_contents ($ conf ["rootpath " ].'/conf/autoresponder.master ' );
121+ $ tpl = str_replace ('{vmail_mailbox_base} ' ,$ mail_config ["homedir_path " ],$ tpl );
122+ // Write the config file.
123+ $ config_file_path = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.autoresponder ' ;
124+ file_put_contents ($ config_file_path ,$ tpl );
125+ $ app ->log ("Writing Autoresponder mailfilter file: $ config_file_path " ,LOGLEVEL_DEBUG );
126+ exec ("chmod 770 $ config_file_path " );
127+ exec ("chown vmail $ config_file_path " );
128+ unset($ tpl );
129+ unset($ config_file_path );
119130
120- // Write the autoresponder message file
121- $ config_file_path = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.msg ' ;
122- file_put_contents ($ config_file_path ,$ data ["new " ]["autoresponder_text " ]);
123- exec ("chmod 400 $ config_file_path " );
124- exec ("chown vmail $ config_file_path " );
125- $ app ->log ("Writing Autoresponder message file: $ config_file_path " ,LOGLEVEL_DEBUG );
126- }
131+ // Write the autoresponder message file
132+ $ config_file_path = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.vacation.msg ' ;
133+ file_put_contents ($ config_file_path ,$ data ["new " ]["autoresponder_text " ]);
134+ exec ("chmod 770 $ config_file_path " );
135+ exec ("chown vmail $ config_file_path " );
136+ $ app ->log ("Writing Autoresponder message file: $ config_file_path " ,LOGLEVEL_DEBUG );
127137 }
138+ }
139+
140+ $ app ->log ("HERE " ,LOGLEVEL_DEBUG );
128141
129142 // Write the custom mailfilter script, if mailfilter recipe has changed
130143 if ($ data ["old " ]["custom_mailfilter " ] != $ data ["new " ]["custom_mailfilter " ]) {
144+ $ app ->log ("Mailfilter config has been changed " ,LOGLEVEL_DEBUG );
131145 if (trim ($ data ["new " ]["custom_mailfilter " ]) != '' ) {
132146 // Delete the old filter recipe
133147 $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
@@ -142,16 +156,18 @@ function update($event_name,$data) {
142156 }
143157 $ config_file_path = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.mailfilter ' ;
144158 file_put_contents ($ config_file_path ,$ data ["new " ]["custom_mailfilter " ]);
145- exec ("chmod 400 $ config_file_path " );
159+ $ app ->log ("Writing new custom Mailfiter " .$ config_file_path ,LOGLEVEL_DEBUG );
160+ exec ("chmod 770 $ config_file_path " );
146161 exec ("chown vmail $ config_file_path " );
147162 unset($ config_file_path );
148163 } else {
149164 // Delete the mailfilter recipe
150165 $ email_parts = explode ("@ " ,$ data ["old " ]["email " ]);
151166 $ file = $ this ->mailfilter_config_dir .'/ ' .$ email_parts [1 ].'/ ' .$ email_parts [0 ].'/.mailfilter ' ;
152167 if (is_file ($ file )) unlink ($ file ) or $ app ->log ("Unable to delete file: $ file " ,LOGLEVEL_WARN );
168+ $ app ->log ("Deleting custom Mailfiter " .$ file ,LOGLEVEL_DEBUG );
153169 }
154- }
170+ // }
155171 }
156172 }
157173
0 commit comments