diff options
author | Simon Parri <simonparri@ganzeria.com> | 2020-09-18 11:04:53 -0500 |
---|---|---|
committer | Simon Parri <simonparri@ganzeria.com> | 2020-09-18 11:04:53 -0500 |
commit | 5f259c5091af7ece51b3427f0d8f3208fe7820fc (patch) | |
tree | def39e163b27948e3c17ea59c401e4bab2918592 | |
parent | d5734be281873c8ee62fc7fe56d08a50178629e7 (diff) | |
download | spelling-rbee-5f259c5091af7ece51b3427f0d8f3208fe7820fc.tar.gz spelling-rbee-5f259c5091af7ece51b3427f0d8f3208fe7820fc.zip |
Change spelling-rbead to use command-line options instead of ordered arguments
-rwxr-xr-x | spelling-rbead | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/spelling-rbead b/spelling-rbead index 4ea24c0..5945bc4 100755 --- a/spelling-rbead +++ b/spelling-rbead @@ -1,17 +1,31 @@ #!/usr/bin/ruby +%w[net/imap readline optparse].each do |m| require m end -require "net/imap" -require "base64" -server = ARGV[0] -user = ARGV[1] -password = Base64.decode64 ARGV[2] -from = ARGV[3] +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" +end.parse! + +$password = Readline.readline "Password: " +$subject ||= "Spelling:" #Net::IMAP.debug = true -imap = Net::IMAP.new(server) -imap.login(user, password) +imap = Net::IMAP.new($mailbox) +imap.login($user, $password) imap.select "inbox" -n = imap.search("FROM \"#{from}\" SUBJECT \"Spelling:\"").last +n = imap.search('FROM "#{$from}" SUBJECT "#{$subject}"').last if n msgs = imap.fetch n, "body[1.text]" c = msgs[0].attr["BODY[1.TEXT]"] |