Class: Sakura::Cli::Mail

Inherits:
Thor
  • Object
show all
Defined in:
lib/sakura/cli/mail.rb

Instance Method Summary collapse

Instance Method Details

#create(local_part, password = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sakura/cli/mail.rb', line 26

def create(local_part, password = nil)
  preprocess

  password ||= ask_password

  begin
    MailAddress.create local_part, password
  rescue StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#delete(local_part) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sakura/cli/mail.rb', line 42

def delete(local_part)
  preprocess

  begin
    find(local_part).delete
  rescue StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#filter(local_part, value = nil) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/sakura/cli/mail.rb', line 168

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 StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#forward(local_part, operation = nil, mail_to_forward = nil) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/sakura/cli/mail.rb', line 118

def forward(local_part, operation = nil, mail_to_forward = nil)
  preprocess

  self.class.handle_argument_error if (operation && operation !~ /add|remove/) || (!mail_to_forward && operation)

  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 StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#keep(local_part, value = nil) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/sakura/cli/mail.rb', line 143

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 StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#listObject



14
15
16
17
18
19
20
21
22
# File 'lib/sakura/cli/mail.rb', line 14

def list
  preprocess

  addrs = MailAddress.all

  puts "# domain: #{Client.current_session.domain}"
  puts MailAddress.header
  addrs.each { |addr| puts addr }
end

#password(local_part, password = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sakura/cli/mail.rb', line 76

def password(local_part, password = nil)
  preprocess

  password ||= ask_password
  mail = find(local_part)

  begin
    mail.password = password
  rescue StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#quota(local_part, value = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sakura/cli/mail.rb', line 56

def quota(local_part, value = nil)
  preprocess

  mail = find(local_part)

  begin
    if value
      mail.quota = value
    else
      puts mail.quota
    end
  rescue StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#scan(local_part, value = nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/sakura/cli/mail.rb', line 93

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 StandardError
    raise if options[:verbose]

    abort $ERROR_INFO
  end
end

#show(local_part) ⇒ Object



191
192
193
194
195
# File 'lib/sakura/cli/mail.rb', line 191

def show(local_part)
  preprocess

  puts find(local_part).detail
end