@@ -53,17 +53,105 @@ class page_action extends tform_actions {
5353 function onSubmit () {
5454 global $ app , $ conf ;
5555
56- // Get the parent soa record of the domain
56+ // Get the parent mail_user record
5757 $ mailuser = $ app ->db ->queryOneRecord ("SELECT * FROM mail_user WHERE mailuser_id = ' " .intval ($ _REQUEST ["mailuser_id " ])."' AND " .$ app ->tform ->getAuthSQL ('r ' ));
58+
5859 // Check if Domain belongs to user
5960 if ($ mailuser ["mailuser_id " ] != $ _POST ["mailuser_id " ]) $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["no_mailuser_perm " ];
6061
61- // Set the server ID of the rr record to the same server ID as the parent record.
62+ // Set the mailuser_id
6263 $ this ->dataRecord ["mailuser_id " ] = $ mailuser ["mailuser_id " ];
6364
6465 parent ::onSubmit ();
6566 }
6667
68+ function onAfterInsert () {
69+ global $ app , $ conf ;
70+
71+ $ mailuser = $ app ->db ->queryOneRecord ("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = " .$ this ->dataRecord ["mailuser_id " ]);
72+ $ rule_content = $ mailuser ['custom_mailfilter ' ]."\n" .$ app ->db ->quote ($ this ->getRule ());
73+ $ app ->db ->datalogUpdate ('mail_user ' , "custom_mailfilter = ' $ rule_content' " , 'mailuser_id ' , $ this ->dataRecord ["mailuser_id " ]);
74+
75+ }
76+
77+ function onAfterUpdate () {
78+ global $ app , $ conf ;
79+
80+ $ mailuser = $ app ->db ->queryOneRecord ("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = " .$ this ->dataRecord ["mailuser_id " ]);
81+ $ skip = false ;
82+ $ lines = explode ("\n" ,$ mailuser ['custom_mailfilter ' ]);
83+ $ out = '' ;
84+ $ found = false ;
85+
86+ foreach ($ lines as $ line ) {
87+ $ line = trim ($ line );
88+ if ($ line == '### BEGIN FILTER_ID: ' .$ this ->id ) {
89+ $ skip = true ;
90+ $ found = true ;
91+ }
92+ if ($ skip == false && $ line != '' ) $ out .= $ line ."\n" ;
93+ if ($ line == '### END FILTER_ID: ' .$ this ->id ) {
94+ $ out .= $ this ->getRule ();
95+ $ skip = false ;
96+ }
97+ }
98+
99+ // We did not found our rule, so we add it now.
100+ if ($ found == false ) {
101+ $ out .= $ this ->getRule ();
102+ }
103+
104+ $ out = addslashes ($ out );
105+ $ app ->db ->datalogUpdate ('mail_user ' , "custom_mailfilter = ' $ out' " , 'mailuser_id ' , $ this ->dataRecord ["mailuser_id " ]);
106+
107+ }
108+
109+ function getRule () {
110+
111+ $ content = '' ;
112+ $ content .= '### BEGIN FILTER_ID: ' .$ this ->id ."\n" ;
113+
114+ if ($ this ->dataRecord ["action " ] == 'move ' ) {
115+
116+ $ content .= "
117+ `test -e " .'$DEFAULT/ ' .$ this ->dataRecord ["target " ]."`
118+ if ( " .'$RETURNCODE ' ." != 0 )
119+ {
120+ `maildirmake -f " .$ this ->dataRecord ["target " ].' $DEFAULT ' ."`
121+ `chmod -R 0700 " .'$DEFAULT/ ' .$ this ->dataRecord ["target " ]."`
122+ }
123+ " ;
124+ }
125+
126+ $ content .= "if (/^ " .$ this ->dataRecord ["source " ].": " ;
127+
128+ if ($ this ->dataRecord ["op " ] == 'contains ' ) {
129+ $ content .= ".* " .$ this ->dataRecord ["searchterm " ]."/:h) \n" ;
130+ } elseif ($ this ->dataRecord ["op " ] == 'is ' ) {
131+ $ content .= $ this ->dataRecord ["searchterm " ]."$/:h) \n" ;
132+ } elseif ($ this ->dataRecord ["op " ] == 'begins ' ) {
133+ $ content .= $ this ->dataRecord ["searchterm " ]."/:h) \n" ;
134+ } elseif ($ this ->dataRecord ["op " ] == 'ends ' ) {
135+ $ content .= ".* " .$ this ->dataRecord ["searchterm " ]."$/:h) \n" ;
136+ }
137+
138+ $ content .= "{ \n" ;
139+ $ content .= "exception { \n" ;
140+
141+ if ($ this ->dataRecord ["action " ] == 'move ' ) {
142+ $ content .= 'to $DEFAULT/ ' .$ this ->dataRecord ["target " ]."/ \n" ;
143+ } else {
144+ $ content .= "to /dev/null \n" ;
145+ }
146+
147+ $ content .= "} \n" ;
148+ $ content .= "} \n" ;
149+
150+ $ content .= '### END FILTER_ID: ' .$ this ->id ."\n" ;
151+
152+ return $ content ;
153+ }
154+
67155}
68156
69157$ page = new page_action ;
0 commit comments