From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6846438166349479936 Date: Fri, 10 Jul 2020 14:58:16 -0700 (PDT) From: Robert Winkler To: The Sup email client Message-Id: In-Reply-To: <1594412886-sup-3215@ceres> References: <7c75d917-b99e-4e95-af72-d308acfcb7ado@googlegroups.com> <1594076857-sup-7295@ceres> <5048bacc-c026-45c3-b145-52226916491co@googlegroups.com> <1594233819-sup-5407@ceres> <1594412084-sup-1850@ceres> <1594412886-sup-3215@ceres> Subject: Re: [sup] SpamAssassin (Spam/Ham) support for Sup MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_494_1135631891.1594418296367" X-Google-Token: EPjIo_gFOCRd0eBiKF40 X-Google-IP: 177.248.136.112 ------=_Part_494_1135631891.1594418296367 Content-Type: multipart/alternative; boundary="----=_Part_495_1839281949.1594418296368" ------=_Part_495_1839281949.1594418296368 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > ------=_Part_495_1839281949.1594418296368 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Thanks for all the useful code, Iain.

H= ere the final solution. Explication: Spam (=3D 'undesired') message= s and Ham (=3D 'desired') messages are copied into separate Maildir= folders.=C2=A0
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&#= 39; (Spam) or 'h' (Ham) in the Inbox or Search Results Mode (e.g. i= n 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 f= olders are not observed by sup. Mails older than 5 days are automatically d= eleted 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/Spamarchivemail -d 5 --delete imaps://"spamass@bioprocess.org":"email-terminat= or2020!"@imap.ionos.de/Ham

keybindings.rb
modes["inbox-mode"].keymap.add :label_spamas= sassin_spam, = "Label as Sp= amAssassin Spam", 's&= #39;
mo= des
["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 :labe= l_spamassassin_ham, = "Labe= l as SpamAssassin Ham", &= #39;h'

startup.rb
class Redwood::InboxMode
=C2=A0
def label_spamassassin_spam
=C2=A0 =C2=A0 t= hread
=3D<= /span> cursor_thr= ead or return
=C2=A0 =C2=A0 spamassas= sin_maildir_path
=3D= "/ho= me/rob/Maildir/SpamAssassin/Spam/cur/"
=C2=A0 =C2=A0 message_file
=3D
File.join(
=C2=A0 =C2=A0 =C2=A0 thread
.latest_message.source.file_path,
=C2= =A0 =C2=A0 =C2=A0 thread
.latest_message.= source_info.to_s)
=C2=A0 =C2=A0 toggl= e_spam
=C2=A0 =C2=A0
FileUtils.cp(message_file<= /span>, spamassassin_maildi= r_path)
=C2=A0 = =C2=A0
Buf= ferManager= .flash "Copied = to SpamAssassin Spam file: #{File.basename message_file}"
=C2=A0
end

end

class Redwood::InboxMode
=C2=A0
def= label_spamassassin_ham
=C2=A0thread
=3D cursor_thread or return
=C2=A0spamassassin_maildir_path
=3D "/home/rob/Maildir/SpamAssassin/Ham/cur/"
=C2=A0messag= e_file
=3D= File
.join(
=C2=A0thread
.latest_message.source.file_path,
= =C2=A0thread
.latest_= message.source_info<= /span>.to_s)
=C2=A0thread
.apply_label :ham
=C2=A0
FileUtils.cp(message_file,= spamassassin_maildir_path)
=C2=A0 =C2=A0
BufferManager.flash "Copied to SpamAssassin Ham file: #{File.basename message_file}&q= uot;
= =C2=A0
end=
end

class Redwood::SearchResultsMode
=C2=A0
def label_spamassassin_spam
=C2=A0 =C2=A0 threa= d
=3D cursor_thread = or<= span style=3D"color: #000;" class=3D"styled-by-prettify"> return
=C2=A0 =C2=A0 spamassassin_= maildir_path
=3D "/home/r= ob/Maildir/SpamAssassin/Spam/cur/"
=C2=A0 =C2=A0 message_file
=3D File.join(
=C2=A0 =C2=A0 =C2=A0 thread
.latest_message.source.fi= le_path,
=C2=A0 = =C2=A0 =C2=A0 thread
.latest_message.sour= ce_info.to_s<= span style=3D"color: #660;" class=3D"styled-by-prettify">)
=C2=A0 =C2=A0 toggle_sp= am
=C2=A0 =C2=A0
FileUtils.= cp(= message_file, spamassassin_maildir_pa= th)=
=C2=A0 =C2=A0=
BufferMan= ager.flash "Copied to Spa= mAssassin Spam file: #{File.basename message_file}"
=C2=A0
end
end

class Redwood::SearchResultsMode
=C2=A0
def label_spamassassin_ham
=C2=A0thread
=3D cursor_thread or return
=C2=A0spamassassin_maildir_path
=3D "/home/rob/Maildir/SpamAssassin/Ham/cur/"
=C2=A0mes= sage_file
= =3D File.join(
=C2=A0thread
.latest_message.source.file_path,=C2=A0thread.lates= t_message.= source_inf= o.<= span style=3D"color: #000;" class=3D"styled-by-prettify">to_s
)
=C2=A0thread
.apply_label :ham
=C2=A0
FileUtils.cp(message_file, spamassassin_maildir_path)
=C2=A0 =C2=A0
BufferManager.flash "Copied to SpamAssassin Ham file: #{File.basename message_file}&= quot;
= =C2=A0
end=
end
=

note: The=C2=A0source_info needed a conversion to string:=C2=A0.to_s
<= br>
Thanks a lot again; sup is really mighty!

Best regards,=C2=A0

Robert=C2=A0
<= br>
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 c= opy 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
------=_Part_495_1839281949.1594418296368-- ------=_Part_494_1135631891.1594418296367--