summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Parri <simonparri@ganzeria.com>2020-09-29 10:37:44 -0500
committerSimon Parri <simonparri@ganzeria.com>2020-09-29 10:37:44 -0500
commit55caa437159a70760d4a03f5a45c9802805e202a (patch)
treeb321d22c371ee18b16bb3cc96c8454c6c6967741
parentb4f1ff32e0025a677b41f36446d7fbcbb5c183b0 (diff)
downloadspelling-rbee-55caa437159a70760d4a03f5a45c9802805e202a.tar.gz
spelling-rbee-55caa437159a70760d4a03f5a45c9802805e202a.zip
Fix regressions in spelling-rbead (in short, make it work)
-rwxr-xr-xspelling-rbead48
1 files changed, 21 insertions, 27 deletions
diff --git a/spelling-rbead b/spelling-rbead
index 5945bc4..980a7bb 100755
--- a/spelling-rbead
+++ b/spelling-rbead
@@ -3,34 +3,28 @@
OptionParser.new do |opts|
opts.banner = "Usage: spelling-rbead [options]"
- def opt(short, long, doc, opts = opts)
- opts.on(name, doc) do
- short = "-#{name[0]}"
- long = "--#{name}"
- opts.on(short, long, doc) do |opt|
- eval "$#{name} = #{opt}"
- end
- end
- end
- opt "mailbox", "Imap server to connect to"
- opt "user", "User to log in as"
- opt "subject", "Subject to look for"
- opt "from", "Address to look for"
+ opts.on("-uUSER", "--user=USER", "User to log in as") 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("-h", "--help", "Get help") do puts opts; $help = true; end
end.parse!
-$password = Readline.readline "Password: "
-$subject ||= "Spelling:"
+if !$help
+ $password = Readline.readline "Password: "
+ $subject ||= "Spelling:"
-#Net::IMAP.debug = true
-imap = Net::IMAP.new($mailbox)
-imap.login($user, $password)
-imap.select "inbox"
-n = imap.search('FROM "#{$from}" SUBJECT "#{$subject}"').last
-if n
- msgs = imap.fetch n, "body[1.text]"
- c = msgs[0].attr["BODY[1.TEXT]"]
- words = c.split("\n")
-end
-imap.logout
+ #Net::IMAP.debug = true
+ imap = Net::IMAP.new($mailbox)
+ imap.login($user, $password)
+ imap.select "inbox"
+ n = imap.search("FROM \"#{$from}\" SUBJECT \"#{$subject}\"").last
+ if n
+ msgs = imap.fetch n, "body[1.text]"
+ c = msgs[0].attr["BODY[1.TEXT]"]
+ words = c.split("\n")
+ end
+ imap.logout
-puts words
+ puts words
+end