Class: Hermeneutics::Cli::Pop

Inherits:
Object
  • Object
show all
Defined in:
lib/hermeneutics/cli/pop.rb

Direct Known Subclasses

Pops

Defined Under Namespace

Classes: Keep

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil) ⇒ Pop

Returns a new instance of Pop.



13
14
15
16
17
18
19
# File 'lib/hermeneutics/cli/pop.rb', line 13

def initialize host, port = nil
  if not port and host =~ /:(\d+)\z/ then
    host, port = $`, $1.to_i
  end
  @host, @port = host, port
  require "net/pop"
end

Instance Method Details

#countObject



41
# File 'lib/hermeneutics/cli/pop.rb', line 41

def count ; @pop.n_mails ; end

#eachObject



43
44
45
46
47
48
49
50
51
# File 'lib/hermeneutics/cli/pop.rb', line 43

def each
  @pop.mails.each do |m|
    begin
      yield m.pop
      m.delete
    rescue Keep
    end
  end
end

#login(user, password) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hermeneutics/cli/pop.rb', line 21

def  user, password
  do_apop do
    @pop = Net::POP3.new @host, @port, @apop
    do_ssl
    @pop.start user, password do |pop|
      @user = user
      yield
    end
  end
ensure
  @user = nil
end

#nameObject



34
35
36
37
38
39
# File 'lib/hermeneutics/cli/pop.rb', line 34

def name
  @user or raise "Not logged in."
  r = "#@user@#@host"
  r << ":#@port" if @port
  r
end