Intuition
One of our clients requests that the webform send emails with the files uploaded through the form (which is feasible via Webform > Email / Handlers), but they do not want the Drupal system to store any submission data (form data) or uploaded files (including in Drupal’s private file system). In other words, they require the webform submission to self-destruct immediately after the email is sent.
While turning off the submission data is simple, by going to “Webform > Settings > General” and check the “Disable saving of submissions” toggle (see screenshot: link), there is no built-in feature to delete the private files upon email submission.
I thought about deleting it via a CRON job (e.g. rm -rf site/default/files/private/webform/webform_machine_name/* -> cron_bash.sh) , but then if a user would to submit an email just the second before the CRON job ran, his files might have a chance to be deleted before the webform triggers the email send (the files may be lost during this process). Moreover, this does not guarantee the timeliness of the deletion, the CRON job can only run as frequent as 1min/execution, and that’s just not good enough !
(Scribble) My Process of Exploration
Randomly adding XDebug breakpoint / logging to find an entry point (since I can find nothing on the official document about the presence of any hook that is capable of overriding the default webform email behaviour):

Found this
sendMessage()function in file:<root>/modules/contrib/webform/src/Plugin/WebformHandler/EmailWebformHandler.phpbeing trigged upon webform submission that is responsible for sending the email:
Making some inline modification to attempt to modify the default behaviour in
Drupal\webform\Plugin\WebformHandler\EmailWebformHandler(to delete all files in the corresponding private directory upon successful email submission):
Turning the changes into a installable custom module that extends the
Drupal\webform\Plugin\WebformHandler\EmailWebformHandlerto modify itssendMessagebehaviour:

Solution
Custom module webform_email_cleanup that purge the private system of webform upon successful email sending: module / custom / webform_email_cleanup.zip
*to container additional webform, please modify the sendMessage() function to include your webform machine name at line-33 :
| |
Final outcome showcase:
