class PostDB::MailLocation

Attributes

components[R]
path[R]
type[R]

Public Class Methods

new(location) click to toggle source
# File lib/postdb/mail_location.rb, line 7
def initialize(location)
  unless location =~ /^[A-Za-z0-9]+:(.*)$/
    raise PostDB::MailLocationError.new(:malformed_location)
  end

  components = location.split(':')

  @type = components[0].to_sym
  @path = components[1]

  begin
    @components = Hash[*components[2..-1].map { |c| c.split('=') }.flatten]
  rescue => e
    raise PostDB::MailLocationError.new(:malformed_location)
  end
end

Public Instance Methods

get_path(username, domain, home_dir = nil) click to toggle source
# File lib/postdb/mail_location.rb, line 24
def get_path(username, domain, home_dir = nil)
  path = @path.dup
  path.gsub!('%u', username)
  path.gsub!('%n', username.split('@')[0])
  path.gsub!('%d', domain)
  path.gsub!('%h', home_dir) if home_dir
  path
end