Class: BBMB::Util::PopMission

Inherits:
Object
  • Object
show all
Defined in:
lib/bbmb/util/polling_manager.rb

Constant Summary collapse

@@ptrn =
/name=(?:(?:(?<quote>['"])(?:=\?.+?\?[QB]\?)?(?<file>.*?)(\?=)?(?<!\\)\k<quote>)|(?:(?<file>.+?)(?:;|$)))/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deleteObject

Returns the value of attribute delete.



47
48
49
# File 'lib/bbmb/util/polling_manager.rb', line 47

def delete
  @delete
end

#hostObject

Returns the value of attribute host.



47
48
49
# File 'lib/bbmb/util/polling_manager.rb', line 47

def host
  @host
end

#passObject

Returns the value of attribute pass.



47
48
49
# File 'lib/bbmb/util/polling_manager.rb', line 47

def pass
  @pass
end

#portObject

Returns the value of attribute port.



47
48
49
# File 'lib/bbmb/util/polling_manager.rb', line 47

def port
  @port
end

#userObject

Returns the value of attribute user.



47
48
49
# File 'lib/bbmb/util/polling_manager.rb', line 47

def user
  @user
end

Instance Method Details

#poll(&block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/bbmb/util/polling_manager.rb', line 49

def poll(&block)
  Net::POP3.start(@host, @port || 110, @user, @pass) { |pop|
    pop.each_mail { |mail|
      poll_mail(mail, &block)
    }
  }
end

#poll_mail(mail, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/bbmb/util/polling_manager.rb', line 56

def poll_mail(mail, &block)
  source = mail.pop
  ## work around a bug in RMail::Parser that cannot deal with
  ## RFC-2822-compliant CRLF..
  source.gsub!(/\r\n/, "\n")
  poll_message(RMail::Parser.read(source), &block)
  mail.delete if(@delete)
rescue StandardError => err
  BBMB::Util::Mail.notify_error(err)
end

#poll_message(message, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/bbmb/util/polling_manager.rb', line 66

def poll_message(message, &block)
  if(message.multipart?)
    message.each_part { |part|
      poll_message(part, &block)
    }
  elsif(match = @@ptrn.match(message.header["Content-Type"]))
    block.call(match["file"], message.decode)
  end
end