summaryrefslogtreecommitdiff
path: root/spelling-rbead
blob: 5945bc4f66ae1544ea31f313da8e49c94d28fcca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/ruby
%w[net/imap readline optparse].each do |m| require m end

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($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