Class: Server
- Inherits:
-
Object
- Object
- Server
- Defined in:
- lib/imap-feeder/server.rb
Instance Method Summary collapse
- #create_folder(folder) ⇒ Object
- #delete(message, folder = "INBOX") ⇒ Object
- #delete_folder(folder) ⇒ Object
- #disconnect ⇒ Object
- #has?(title, folder) ⇒ Boolean
- #has_folder?(folder) ⇒ Boolean
-
#initialize(params) ⇒ Server
constructor
A new instance of Server.
- #retrieve(title, folder = "INBOX") ⇒ Object
- #send(message, folder = "INBOX") ⇒ Object
Constructor Details
#initialize(params) ⇒ Server
Returns a new instance of Server.
9 10 11 12 13 |
# File 'lib/imap-feeder/server.rb', line 9 def initialize(params) @connection = Net::IMAP.new(params[:host], params[:port], params[:use_ssl]) result = @connection.login(params[:user], params[:pass]) @format = params[:format] end |
Instance Method Details
#create_folder(folder) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/imap-feeder/server.rb', line 65 def create_folder(folder) path = '' folder.split('.').each do |part| path << part @connection.create(path) unless has_folder?(path) path << '.' end end |
#delete(message, folder = "INBOX") ⇒ Object
80 81 82 83 84 |
# File 'lib/imap-feeder/server.rb', line 80 def delete(, folder="INBOX") @connection.select(folder) @connection.store(.id, "+FLAGS", [:Deleted]) @connection.expunge end |
#delete_folder(folder) ⇒ Object
74 75 76 77 78 |
# File 'lib/imap-feeder/server.rb', line 74 def delete_folder(folder) #Switch to root so we can delete the folder @connection.examine("INBOX") @connection.delete(folder) end |
#disconnect ⇒ Object
15 16 17 |
# File 'lib/imap-feeder/server.rb', line 15 def disconnect @connection.disconnect if @connection end |
#has?(title, folder) ⇒ Boolean
54 55 56 |
# File 'lib/imap-feeder/server.rb', line 54 def has?(title, folder) retrieve(title, folder) != nil end |
#has_folder?(folder) ⇒ Boolean
58 59 60 61 62 63 |
# File 'lib/imap-feeder/server.rb', line 58 def has_folder?(folder) @connection.examine(folder) true rescue Net::IMAP::NoResponseError false end |
#retrieve(title, folder = "INBOX") ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/imap-feeder/server.rb', line 32 def retrieve(title, folder="INBOX") @connection.examine(folder) found = @connection.search(["SUBJECT", title]).first return if not found imap_header = @connection.fetch([found], "BODY[HEADER.FIELDS (SUBJECT)]") retr_title = imap_header.first.attr["BODY[HEADER.FIELDS (SUBJECT)]"] retr_title.gsub!(/(^Subject: )|[\n\r]/, "") Message.new(:title => base64decode(retr_title), :id => found) end |
#send(message, folder = "INBOX") ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/imap-feeder/server.rb', line 19 def send(, folder="INBOX") @connection.select(folder) if @format == :html = .as_html else = .format end .gsub!(/\n/, "\r\n") @connection.append(folder, , nil, Time.now) end |