class Mailroute::EmailAccount

Public Class Methods

create(*args) click to toggle source
# File lib/mailroute/models/email_account.rb, line 83
def create(*args)
  if args.size == 1 && args.first.is_a?(String)
    localpart, domain_name = *args.first.split('@')
    domain = Domain.get(domain_name)
    raise ActiveResource::ResourceNotFound, "Domain with name #{domain_name} not found" unless domain
    create_by_attributes(:localpart => localpart, :domain => domain, :create_opt => 'generate_pwd')
  else
    create_by_attributes(*args)
  end
end
Also aliased as: create_by_attributes
create_by_attributes(*args)
Alias for: create
get(*args) click to toggle source
# File lib/mailroute/models/email_account.rb, line 64
def get(*args)
  if args.size == 1
    get_by_id(*args)
  else
    localpart, domain = *args
    case domain
    when Domain
      get(localpart, domain.id)
    when String
      get(localpart, Domain.get(domain))
    when Integer
      EmailAccount.filter(:domain => domain, :localpart => localpart).first or raise ActiveResource::ResourceNotFound
    else
      raise 'Unknown argument type'
    end
  end
end
Also aliased as: get_by_id
get_by_id(*args)
Alias for: get

Public Instance Methods

active_notification_tasks() click to toggle source
# File lib/mailroute/models/email_account.rb, line 46
def active_notification_tasks
  if use_domain_notifications
    domain.notification_tasks
  else
    notification_tasks
  end
end
add_alias(localpart) click to toggle source
# File lib/mailroute/models/email_account.rb, line 37
def add_alias(localpart)
  LocalpartAlias.create(:email_account => self, :localpart => localpart)
end
add_to_blacklist(address) click to toggle source
# File lib/mailroute/models/email_account.rb, line 19
def add_to_blacklist(address)
  create_wblist(:wb => 'b', :email => address)
end
add_to_whitelist(address) click to toggle source
# File lib/mailroute/models/email_account.rb, line 23
def add_to_whitelist(address)
  create_wblist(:wb => 'w', :email => address)
end
blacklist() click to toggle source
# File lib/mailroute/models/email_account.rb, line 11
def blacklist
  WBList.filter(:email_account => id, :wb => 'b').map(&:email)
end
bulk_add_aliases(localparts) click to toggle source
# File lib/mailroute/models/email_account.rb, line 41
def bulk_add_aliases(localparts)
  request_body = self.class.format.encode(:aliases => localparts)
  connection.post(element_path(prefix_options) + 'mass_add_aliases/', request_body, self.class.headers)
end
regenerate_api_key() click to toggle source
# File lib/mailroute/models/email_account.rb, line 32
def regenerate_api_key
  response = connection.post(element_path(prefix_options) + 'regenerate_api_key/', nil, self.class.headers)
  self.class.format.decode(response.body)['api_key']
end
set_password(new_password) click to toggle source
# File lib/mailroute/models/email_account.rb, line 27
def set_password(new_password)
  self.password = self.confirm_password = new_password
  save!
end
use_domain_notifications!() click to toggle source
# File lib/mailroute/models/email_account.rb, line 54
def use_domain_notifications!
  update_attribute(:use_domain_notifications, true)
end
use_self_notifications!() click to toggle source
# File lib/mailroute/models/email_account.rb, line 58
def use_self_notifications!
  update_attribute(:use_domain_notifications, false)
end
whitelist() click to toggle source
# File lib/mailroute/models/email_account.rb, line 15
def whitelist
  WBList.filter(:email_account => id, :wb => 'w').map(&:email)
end