Created
October 9, 2019 18:33
-
-
Save seven1m/82ac194bc8c894a44bff54a16f43bf9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
poll mail.morgn.net protocol POP3 | |
user "tim" with password "blablablabla" is tim here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* * * * * $HOME/myfetchmail.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/imap' | |
DEBUG = ARGV.include?('-d') | |
PASS = File.read(File.expand_path('.password', __dir__)).strip | |
imap = Net::IMAP.new('localhost') | |
imap.authenticate('LOGIN', 'tim', PASS) | |
imap.select('INBOX') | |
imap.search(['ALL']).each do |message_id| | |
headers = imap.fetch(message_id, 'BODY.PEEK[HEADER.FIELDS (X-Spam-Status Subject)]')[0].attr.values.first | |
if headers =~ /X-Spam-Status: Yes/ | |
subject = headers.match(/Subject: (.*)/)[1] rescue nil | |
puts "moving to Spam: [#{message_id}] #{subject}" if DEBUG | |
imap.copy(message_id, 'Spam') | |
imap.store(message_id, '+FLAGS', [:Deleted]) | |
end | |
end | |
imap.expunge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#tim@morgn:~ $ fetchmail | |
#1 message for tim at mail.morgn.net (2316 octets). | |
#reading message tim@mail.morgn.net:1 of 1 (2316 octets) flushed | |
#tim@morgn:~ $ fetchmail | |
#fetchmail: No mail for tim at mail.morgn.net | |
out=$(fetchmail 2>&1) | |
if echo "$out" | egrep "[0-9]+ message" &>/dev/null; then | |
sleep 2 # not sure if this is really needed | |
ruby $HOME/move_spam.rb | |
elif echo "$out" | egrep "No mail" &>/dev/null; then | |
exit | |
else | |
echo "$out" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment