From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6846438166349479936 X-Gmail-Labels: Topic type: DISCUSSION Date: Fri, 24 Jul 2020 03:38:27 -0700 (PDT) From: Robert Winkler To: The Sup email client Message-Id: <4b899a9b-6df8-4a03-95f2-368a604ed294o@googlegroups.com> In-Reply-To: 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_286_553554205.1595587107331" X-Google-Token: EKP06vgFUYk55rRsTPU0 X-Google-IP: 177.248.136.112 ------=_Part_286_553554205.1595587107331 Content-Type: multipart/alternative; boundary="----=_Part_287_2031964489.1595587107332" ------=_Part_287_2031964489.1595587107332 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 >> > ------=_Part_287_2031964489.1595587107332 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Correction: The :unread label of spam mails has to be remo= ved 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<= /span>::InboxMode
=C2=A0 def label_spamassassin_spam=C2=A0 =C2=A0 thread =3D cursor_thread or return=
=C2=A0= =C2=A0 spamassassin_maildir_path
=3D "/home/rob/Maildir/SpamAssassin/Spam/cur/"
=C2=A0 =C2=A0 message= _file
=3D<= /span> 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
FileUtils.cp
(message_file, spamassassin_maildir_path)
=C2=A0 =C2=A0 BufferManager= .flash
"Copied to SpamAss= assin Spam file: #{File.basename message_file}"
=C2=A0 =C2=A0 toggle_spam
= =C2=A0 =C2=A0 thread
.remove_label :unrea= d
=C2=A0 =C2=A0 flush_index
=C2=A0
end
end


Best, Robe= rt


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

Here the final solution= . Explication: Spam (=3D 'undesired') messages and Ham (=3D 'de= sired') messages are copied into separate Maildir folders.=C2=A0
<= div>Those are synchronized with an IMAP server (using OfflineImap) for trai= ning a SpamAssassin filter (running daily on a server, using CRON):
The last message of a thread is chosen by 's' (Spam) or 'h&#= 39; (Ham) in the Inbox or Search Results Mode (e.g. in the display of unrea= d messages).
Spam messages are removed from the Inbox listing. Ha= m messages get a label 'ham' which indicates that the message was a= lready sent to training.
The SpamAssassin folders are not observe= d by sup. Mails older than 5 days are automatically deleted by (email and p= assword are different, of course):

archive-mails.s= h
echo 'cleaning Spam/H= am folders'
archivemail
-d 5 --delete imaps://"spamass@bioprocess.org":= "email-terminator2020!"@imap.ionos.de/Spam
archivemail
-d 5 --delete imaps://"spa= mass@bioprocess.org":"email-terminator2020!"@imap.ionos.de/H= am

keybindings.rb
modes["inbox-mode"].= keymap.= add :label_spamassassin_spam, "Label as SpamAssassin Spam",= 's= '
modes
["inbox-mode"].keymap.add :label_spamassassin= _ham, <= /span>"Label as SpamAssassin Ham", 'h'
mo= des
[&qu= ot;search-results-mode"].keymap.add :<= span style=3D"color:#000">label_spamassassin_spam, "Label as SpamAssassin Spam"= , '= s'
modes
["search-results-mode"<= /span>].k= eymap.a= dd :lab= el_spamassassin_ham, "Label as SpamAssassin= Ham", 'h'

startup.rb
class Redwood::InboxMode
=C2=A0
def label_spamassassin_spam
=C2=A0 =C2=A0 thread
=3D cursor_thread= or return
= =C2=A0 =C2=A0 spamassassin_maildir_path
= =3D &qu= ot;/home/rob/Maildir/SpamAssassin/Spam/cur/"
=C2=A0 =C2=A0 message_file
=3D = File.jo= in(
= =C2=A0 =C2=A0 =C2=A0 thread
.latest_message.source.file_path,
=C2=A0 =C2=A0 =C2=A0 thread
= .latest_messag= e.sourc= e_info.to_s)
=C2=A0 =C2=A0 toggle_spam
=C2=A0 =C2=A0
FileUtils.cp(message_file, spamassassin_maildir_path)
=C2=A0 =C2=A0
BufferManager.flash "Copied to= SpamAssassin Spam file: #{File.basename message_file}"
=C2=A0
end<= span style=3D"color:#000">
end<= span style=3D"color:#000">

class Redwood<= /span>::InboxM= ode
=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=A0message_file
=3D File.= join(=C2=A0thread.latest_message.source.file_path,
=C2=A0thread
.= latest_message.source_info.to_s)
=C2=A0thread
<= span style=3D"color:#660">.
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 mess= age_file}"
=C2=A0
end
end

class Redwood::SearchResultsMode=
=C2=A0
def label_spamassassin_spam
=C2=A0 =C2=A0 thread
=3D cursor_thread = or return
=C2=A0 = =C2=A0 spamassassin_maildir_path
=3D
"/home= /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 toggle_spam
=C2=A0 =C2=A0
FileUtils.cp(message_file, spamassassin_maildir_path)

=C2=A0 =C2=A0
BufferManager.flash "Copied to SpamAs= sassin Spam file: #{File.basename message_file}"
=C2=A0
end
end

class Redwood<= span style=3D"color:#660">::SearchResults= Mode
=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=A0message_file =3D File.= join(=C2=A0thread.latest_message.source.file_path,
=C2=A0thread.= latest_message.source_info.to_s)
=C2=A0thread
<= span style=3D"color:#660">.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 mess= age_file}"
=C2=A0
end
end

n= ote: The=C2=A0source_info needed a conversion to string:=C2=A0.to_s

Thanks a lot again; sup is really mi= ghty!

Best regards,=C2=A0

Robert=C2=A0


On Friday, 10 July 2020 15:29:19 UTC-5, Iai= n 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_287_2031964489.1595587107332-- ------=_Part_286_553554205.1595587107331--