@@ -542,4 +582,54 @@ class WooCow_Admin {
$this->json_ok();
}
+
+ public function ajax_woocow_admin_mailbox_edit(): void {
+ $this->verify();
+
+ $server_id = absint( $_POST['server_id'] ?? 0 );
+ $email = sanitize_email( $_POST['email'] ?? '' );
+ $type = sanitize_text_field( $_POST['type'] ?? '' ); // 'password' or 'quota'
+
+ if ( ! $email ) {
+ $this->json_err( 'Email address is required.' );
+ }
+
+ $server = $this->get_server( $server_id );
+ if ( ! $server ) {
+ $this->json_err( 'Server not found.' );
+ }
+
+ $api = WooCow_API::from_server( $server );
+ $attr = [];
+
+ if ( $type === 'password' ) {
+ $pass = $_POST['password'] ?? '';
+ $pass2 = $_POST['password2'] ?? '';
+ if ( ! $pass ) {
+ $this->json_err( 'Password cannot be empty.' );
+ }
+ if ( $pass !== $pass2 ) {
+ $this->json_err( 'Passwords do not match.' );
+ }
+ $attr = [ 'password' => $pass, 'password2' => $pass2 ];
+
+ } elseif ( $type === 'quota' ) {
+ $quota = absint( $_POST['quota'] ?? 0 );
+ if ( $quota < 1 ) {
+ $this->json_err( 'Quota must be at least 1 MB.' );
+ }
+ $attr = [ 'quota' => $quota ];
+
+ } else {
+ $this->json_err( 'Unknown edit type.' );
+ }
+
+ $result = $api->edit_mailbox( [ $email ], $attr );
+
+ if ( ! $result['success'] ) {
+ $this->json_err( $result['error'] ?? 'Failed to update mailbox.' );
+ }
+
+ $this->json_ok();
+ }
}