The "spam" and "ham" IMAP folders correspond to a certain file or folder(1) on the server. Email users have the learning commands in crontab. These are as simple as "sa-learn --spam /path/to/spam_folder; sa-learn --ham /path/to/ham_folder".
(1) file if the backend is mbox, folder if the backend is Maildir.
(1) file if the backend is mbox, folder if the backend is Maildir.