From a quick search I found a SpamByas python app which would learn to distinguish spam from non-spam. Unfortunately is seams it is not in active development, but judging from some reviews it might at least help in that sense.
For email inbox? Seems like that should be the role of the email server, not ERPNext/Frappe.
I agree with @felix, spam filtering is very well implemented in mail servers. Assuming a Linux-based server, a good option is rspamd which shows very nice performance and a good interface for monitoring and learning. This works nicely in combination with ERPNext.
Thank you for suggestion.
Does erpnext synchronize imap account with say Spam subfolder? I.e. if one marks email as spam will that event be registered in Imap as moving email to INBOX.Spam subfolder?