Correction: The :unread label of spam mails has to be removed after copyingl. Why? If you remove :unread, the mail file is moved from the /new directory and not found any more. My working function looks like this:

class Redwood::InboxMode
 
def label_spamassassin_spam
    thread
= cursor_thread or return
    spamassassin_maildir_path
= "/home/rob/Maildir/SpamAssassin/Spam/cur/"
    message_file
= File.join(
      thread
.latest_message.source.file_path,
      thread
.latest_message.source_info.to_s)
   
FileUtils.cp(message_file, spamassassin_maildir_path)
   
BufferManager.flash "Copied to SpamAssassin Spam file: #{File.basename message_file}"
    toggle_spam
    thread
.remove_label :unread
    flush_index
 
end
end


Best, Robert


On Friday, 10 July 2020 16:58:16 UTC-5, Robert Winkler wrote:
Thanks for all the useful code, Iain.

Here the final solution. Explication: Spam (= 'undesired') messages and Ham (= 'desired') messages are copied into separate Maildir folders. 
Those are synchronized with an IMAP server (using OfflineImap) for training a SpamAssassin filter (running daily on a server, using CRON):
The last message of a thread is chosen by 's' (Spam) or 'h' (Ham) in the Inbox or Search Results Mode (e.g. in the display of unread messages).
Spam messages are removed from the Inbox listing. Ham messages get a label 'ham' which indicates that the message was already sent to training.
The SpamAssassin folders are not observed by sup. Mails older than 5 days are automatically deleted by (email and password are different, of course):

archive-mails.sh
echo 'cleaning Spam/Ham folders'
archivemail
-d 5 --delete imaps://"spamass@bioprocess.org":"email-terminator2020!"@imap.ionos.de/Spam
archivemail
-d 5 --delete imaps://"spamass@bioprocess.org":"email-terminator2020!"@imap.ionos.de/Ham

keybindings.rb
modes["inbox-mode"].keymap.add :label_spamassassin_spam, "Label as SpamAssassin Spam", 's'
modes
["inbox-mode"].keymap.add :label_spamassassin_ham, "Label as SpamAssassin Ham", 'h'
modes
["search-results-mode"].keymap.add :label_spamassassin_spam, "Label as SpamAssassin Spam", 's'
modes
["search-results-mode"].keymap.add :label_spamassassin_ham, "Label as SpamAssassin Ham", 'h'

startup.rb
class Redwood::InboxMode
 
def label_spamassassin_spam
    thread
= cursor_thread or return
    spamassassin_maildir_path
= "/home/rob/Maildir/SpamAssassin/Spam/cur/"
    message_file
= File.join(
      thread
.latest_message.source.file_path,
      thread
.latest_message.source_info.to_s)
    toggle_spam
   
FileUtils.cp(message_file, spamassassin_maildir_path)
   
BufferManager.flash "Copied to SpamAssassin Spam file: #{File.basename message_file}"
 
end
end

class Redwood::InboxMode
 
def label_spamassassin_ham
 thread
= cursor_thread or return
 spamassassin_maildir_path
= "/home/rob/Maildir/SpamAssassin/Ham/cur/"
 message_file
= File.join(
 thread
.latest_message.source.file_path,
 thread
.latest_message.source_info.to_s)
 thread
.apply_label :ham
 
FileUtils.cp(message_file, spamassassin_maildir_path)
   
BufferManager.flash "Copied to SpamAssassin Ham file: #{File.basename message_file}"
 
end
end

class Redwood::SearchResultsMode
 
def label_spamassassin_spam
    thread
= cursor_thread or return
    spamassassin_maildir_path
= "/home/rob/Maildir/SpamAssassin/Spam/cur/"
    message_file
= File.join(
      thread
.latest_message.source.file_path,
      thread
.latest_message.source_info.to_s)
    toggle_spam
   
FileUtils.cp(message_file, spamassassin_maildir_path)
   
BufferManager.flash "Copied to SpamAssassin Spam file: #{File.basename message_file}"
 
end
end

class Redwood::SearchResultsMode
 
def label_spamassassin_ham
 thread
= cursor_thread or return
 spamassassin_maildir_path
= "/home/rob/Maildir/SpamAssassin/Ham/cur/"
 message_file
= File.join(
 thread
.latest_message.source.file_path,
 thread
.latest_message.source_info.to_s)
 thread
.apply_label :ham
 
FileUtils.cp(message_file, spamassassin_maildir_path)
   
BufferManager.flash "Copied to SpamAssassin Ham file: #{File.basename message_file}"
 
end
end

note: The source_info needed a conversion to string: .to_s

Thanks a lot again; sup is really mighty!

Best regards, 

Robert 


On Friday, 10 July 2020 15:29:19 UTC-5, Iain Parris wrote:
Excerpts from Iain Parris's message of 2020-07-10 21:26:12 +0100:
> Assuming your source is also another Maildir, then we can find the full
> path for the original message file. Then we can do a direct file copy of
> this file into your SpamAssassin Spam Maildir.

I should add: in this demo, we copy only the *latest* message in the
thread.

Kind regards,
Iain