@@ -270,15 +270,6 @@ public function update()
270270 throw new Exception ("You cannot access this resource " , 405 );
271271 }
272272
273- // if enabling catchall is not allowed by settings, we do not need
274- // to run update()
275- if (Settings::Get ('catchall.catchall_enabled ' ) != '1 ' ) {
276- Response::standardError ([
277- 'operationnotpermitted ' ,
278- 'featureisdisabled '
279- ], 'catchall ' , true );
280- }
281-
282273 $ id = $ this ->getParam ('id ' , true , 0 );
283274 $ ea_optional = $ id > 0 ;
284275 $ emailaddr = $ this ->getParam ('emailaddr ' , $ ea_optional , '' );
@@ -297,30 +288,41 @@ public function update()
297288 $ iscatchall = $ this ->getBoolParam ('iscatchall ' , true , $ result ['iscatchall ' ]);
298289 $ description = $ this ->getParam ('description ' , true , $ result ['description ' ]);
299290
291+ // if enabling catchall is not allowed by settings, we do not need
292+ // to run update()
293+ if ($ iscatchall && $ result ['iscatchall ' ] == 0 && Settings::Get ('catchall.catchall_enabled ' ) != '1 ' ) {
294+ Response::standardError ([
295+ 'operationnotpermitted ' ,
296+ 'featureisdisabled '
297+ ], 'catchall ' , true );
298+ }
299+
300300 // get needed customer info to reduce the email-address-counter by one
301301 $ customer = $ this ->getCustomerData ();
302302
303303 // check for catchall-flag
304+ $ email = $ result ['email_full ' ];
304305 if ($ iscatchall ) {
305306 $ iscatchall = '1 ' ;
306- $ email_parts = explode ('@ ' , $ result ['email_full ' ]);
307- $ email = '@ ' . $ email_parts [1 ];
308- // catchall check
309- $ stmt = Database::prepare ("
310- SELECT `email_full` FROM ` " . TABLE_MAIL_VIRTUAL . "`
311- WHERE `email` = :email AND `customerid` = :cid AND `iscatchall` = '1'
312- " );
313- $ params = [
314- "email " => $ email ,
315- "cid " => $ customer ['customerid ' ]
316- ];
317- $ email_check = Database::pexecute_first ($ stmt , $ params , true , true );
318- if ($ email_check ) {
319- Response::standardError ('youhavealreadyacatchallforthisdomain ' , '' , true );
307+ $ email = $ result ['email ' ];
308+ // update only required if it was not a catchall before
309+ if ($ result ['iscatchall ' ] == 0 ) {
310+ $ email_parts = explode ('@ ' , $ result ['email_full ' ]);
311+ $ email = '@ ' . $ email_parts [1 ];
312+ // catchall check
313+ $ stmt = Database::prepare ("
314+ SELECT `email_full` FROM ` " . TABLE_MAIL_VIRTUAL . "`
315+ WHERE `email` = :email AND `customerid` = :cid AND `iscatchall` = '1'
316+ " );
317+ $ params = [
318+ "email " => $ email ,
319+ "cid " => $ customer ['customerid ' ]
320+ ];
321+ $ email_check = Database::pexecute_first ($ stmt , $ params , true , true );
322+ if ($ email_check ) {
323+ Response::standardError ('youhavealreadyacatchallforthisdomain ' , '' , true );
324+ }
320325 }
321- } else {
322- $ iscatchall = '0 ' ;
323- $ email = $ result ['email_full ' ];
324326 }
325327
326328 $ spam_tag_level = Validate::validate ($ spam_tag_level , 'spam_tag_level ' , '/^\d{1,}(\.\d{1,2})?$/ ' , '' , [7.0 ], true );
0 commit comments