Class: Maildir::WebQueue

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/maildir/web_queue.rb

Constant Summary collapse

KEY_VALIDATORS =
[
  /^cur\/\d{10}\.[\w-]+(\.[\w-]+)+:2,(\w+)?$/, # cur keys, with info
  /^new\/\d{10}\.[\w-]+(\.[\w-]+)+$/ # new keys, no info
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.path=(path) ⇒ Object



12
13
14
# File 'lib/maildir/web_queue.rb', line 12

def self.path=(path)
  @@queue = Maildir::Queue.new(path)
end

Instance Method Details

#json(body) ⇒ Object

Set the content type to JSON and returns the body as JSON



35
36
37
38
# File 'lib/maildir/web_queue.rb', line 35

def json(body)
  content_type "application/json"
  body.to_json
end

#no_contentObject

Return a 204 No Content response



30
31
32
# File 'lib/maildir/web_queue.rb', line 30

def no_content
  halt 204, ""
end

#queueObject



16
17
18
# File 'lib/maildir/web_queue.rb', line 16

def queue
  @@queue
end

#sanitize(key) ⇒ Object

Test that key is well-formed. If not, return 403 Forbidden error.



21
22
23
24
25
26
27
# File 'lib/maildir/web_queue.rb', line 21

def sanitize(key)
  # E.g. cur/1263444769.M975543P58179Q11.gnt.local:2,
  unless KEY_VALIDATORS.any?{|validator| key.match(validator) }
    content_type "text/plain"
    halt 403, "Malformed key: #{key}"
  end
end