class Sakura::Cli::Mail
Public Instance Methods
create(local_part, password = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 23 def create(local_part, password = nil) preprocess password ||= ask_password begin MailAddress.create local_part, password rescue raise if options[:verbose] abort $! end end
delete(local_part)
click to toggle source
# File lib/sakura/cli/mail.rb, line 38 def delete(local_part) preprocess begin find(local_part).delete rescue raise if options[:verbose] abort $! end end
filter(local_part, value = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 160 def filter(local_part, value = nil) preprocess self.class.handle_argument_error if value && value !~ /mark|disable|discard|quarantine/ mail = find(local_part) begin case value when nil puts mail.spam_filter else mail.spam_filter = value.to_sym end rescue raise if options[:verbose] abort $! end end
forward(local_part, operation = nil, mail_to_forward = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 110 def forward(local_part, operation = nil, mail_to_forward = nil) preprocess if (operation && operation !~ /add|remove/) || (!mail_to_forward && operation) self.class.handle_argument_error end mail = find(local_part) begin case operation when 'add' mail.forward_to mail_to_forward when 'remove' mail.delete_forward_to mail_to_forward when nil mail.forward_list.each { |m| puts m } end rescue raise if options[:verbose] abort $! end end
keep(local_part, value = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 136 def keep(local_part, value = nil) preprocess self.class.handle_argument_error if value && value !~ /enable|disable/ mail = find(local_part) begin case value when 'enable' mail.keep = true when 'disable' mail.keep = false when nil puts mail.keep end rescue raise if options[:verbose] abort $! end end
list()
click to toggle source
# File lib/sakura/cli/mail.rb, line 11 def list preprocess addrs = MailAddress.all puts "# domain: #{Client.current_session.domain}" puts MailAddress.header addrs.each { |addr| puts addr.to_s } end
password(local_part, password = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 70 def password(local_part, password = nil) preprocess password ||= ask_password mail = find(local_part) begin mail.password = password rescue raise if options[:verbose] abort $! end end
quota(local_part, value = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 51 def quota(local_part, value = nil) preprocess mail = find(local_part) begin if value mail.quota = value else puts mail.quota end rescue raise if options[:verbose] abort $! end end
scan(local_part, value = nil)
click to toggle source
# File lib/sakura/cli/mail.rb, line 86 def scan(local_part, value = nil) preprocess self.class.handle_argument_error if value && value !~ /enable|disable/ mail = find(local_part) begin case value when 'enable' mail.virus_scan = true when 'disable' mail.virus_scan = false when nil puts mail.virus_scan end rescue raise if options[:verbose] abort $! end end
show(local_part)
click to toggle source
# File lib/sakura/cli/mail.rb, line 182 def show(local_part) preprocess puts find(local_part).detail end
Private Instance Methods
abort(message)
click to toggle source
Calls superclass method
# File lib/sakura/cli/mail.rb, line 215 def abort(message) super "\nERROR: #{message}" end
ask_password()
click to toggle source
# File lib/sakura/cli/mail.rb, line 205 def ask_password password = ask('password?', echo: false) puts confirm = ask('password(confirm)?', echo: false) puts abort "password doesn't match" unless password == confirm password end
find(local_part)
click to toggle source
# File lib/sakura/cli/mail.rb, line 194 def find(local_part) begin mail = MailAddress.find(local_part) rescue Capybara::ElementNotFound raise if options[:verbose] abort %(No mail address: "#{local_part}") end mail end
preprocess()
click to toggle source
# File lib/sakura/cli/mail.rb, line 190 def preprocess Client.verbose = true if options[:verbose] end