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:
//"[email protected]":"email-terminator2020!"@imap.ionos.de/Spam
archivemail -d 5 --delete imaps:
//"[email protected]":"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 
>

-- 
You received this message because you are subscribed to the Google Groups "The 
Sup email client" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/supmua/a2e8101d-3a3d-436f-88d3-158a7fd1a5fdo%40googlegroups.com.

Reply via email to