From 67874102d9e6cea209dea6421881393b3eb0f845 Mon Sep 17 00:00:00 2001 From: Simon Parri Date: Sat, 29 Apr 2023 17:04:45 -0500 Subject: spelling-rbead: Neaten up code + Use [].each &Kernel.method :require + Initialize $subject rather than doing $subject || + Change `if !' to `unless' + Remove superfluous parentheses --- spelling-rbead | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spelling-rbead b/spelling-rbead index 9df7414..8245c30 100755 --- a/spelling-rbead +++ b/spelling-rbead @@ -1,26 +1,28 @@ #!/usr/bin/ruby -%w[net/imap readline optparse].each do |m| require m end +%w[net/imap readline optparse] + .each &Kernel.method(:require) $file = nil +$subject = "Spelling:" + OptionParser.new do |opts| opts.banner = "Usage: spelling-rbead [options]" opts.on("-uUSER", "--user=USER", "Log in as USER") do |u| $user = u; end opts.on("-fADDR", "--from=ADDR", "Search from ADDR") do |a| $from = a; end opts.on("-sSUBJ", "--subject=SUBJ", "Search for SUBJ") do |s| $subject = s; end - opts.on("-mSERVER", "--mailserver=SERVER", "Connect to SERVER") do |m| $mailbox = m; end + opts.on("-mSERVER", "--mailserver=SERVER", "Connect to SERVER") do |m| $server = m; end opts.on("-o", "--output=FILE", "Output to FILE") do |f| $file = f; end opts.on("-h", "--help", "Get help") do puts opts; $help = true; end end.parse! -if !$help +unless $help $stderr.print "Password: " $password = Readline.readline $stderr.puts - $subject ||= "Spelling:" #Net::IMAP.debug = true - imap = Net::IMAP.new($mailbox) - imap.login($user, $password) + imap = Net::IMAP.new $server + imap.login $user, $password imap.select "inbox" n = imap.search("FROM \"#{$from}\" SUBJECT \"#{$subject}\"").last if n -- cgit v1.2.3