Class | ManageSieve |
In: |
managesieve.rb
|
Parent: | Object |
ManageSieve implements MANAGESIEVE, a protocol for remote management of Sieve scripts.
The following MANAGESIEVE commands are implemented:
The AUTHENTICATE command is partially implemented. Currently the LOGIN and PLAIN authentication mechanisms are implemented.
# Create a new ManageSieve instance m = ManageSieve.new( :host => 'sievehost.mydomain.com', :port => 2000, :user => 'johndoe', :password => 'secret', :auth => 'PLAIN' ) # List installed scripts m.scripts.sort do |name, active| print name print active ? " (active)\n" : "\n" end script = <<__EOF__ require "fileinto"; if header :contains ["to", "cc"] "ruby-talk@ruby-lang.org" { fileinto "Ruby-talk"; } __EOF__ # Test if there's enough space for script 'foobar' puts m.have_space?('foobar', script.length) # Upload it m.put_script('foobar', script) # Show its contents puts m.get_script('foobar') # Close the connection m.logout
SIEVE_PORT | = | 2000 |
capabilities | [R] | |
euser | [R] | |
host | [R] | |
login_mechs | [R] | |
port | [R] | |
tls | [R] | |
user | [R] |
Create a new ManageSieve instance. The info parameter is a hash with the following keys:
# File managesieve.rb, line 125 125: def initialize(info) 126: @host = info[:host] 127: @port = info[:port] || 2000 128: @user = info[:user] 129: @euser = info[:euser] || @user 130: @password = info[:password] 131: @auth_mech = info[:auth] || 'ANONYMOUS' 132: @tls = info.has_key?(:tls) ? !!info[:tls] : nil 133: 134: @capabilities = [] 135: @login_mechs = [] 136: @implementation = '' 137: @supports_tls = false 138: @socket = TCPSocket.new(@host, @port) 139: 140: data = get_response 141: server_features(data) 142: 143: if @tls and not supports_tls? 144: raise SieveNetworkError, 'Server does not support TLS' 145: @socket.close 146: elsif @tls != false 147: @tls = supports_tls? 148: starttls if @tls 149: end 150: 151: authenticate 152: @password = nil 153: end
Deletes script from the server.
# File managesieve.rb, line 189 189: def delete_script(script) 190: send_command('DELETESCRIPT', sieve_name(script)) 191: end
Returns the contents of script as a string.
# File managesieve.rb, line 172 172: def get_script(script) 173: begin 174: data = send_command('GETSCRIPT', sieve_name(script)) 175: rescue SieveCommandError => e 176: raise e, "Cannot get script: #{e}" 177: end 178: return data.to_s.chomp 179: end
Returns true if there is space on the server to store script with size size and false otherwise.
# File managesieve.rb, line 200 200: def have_space?(script, size) 201: begin 202: args = sieve_name(script) + ' ' + size.to_s 203: send_command('HAVESPACE', args) 204: return true 205: rescue SieveCommandError 206: return false 207: end 208: end
Disconnect from the server.
# File managesieve.rb, line 216 216: def logout 217: send_command('LOGOUT') 218: @socket.close 219: end
Uploads script to the server, using data as its contents.
# File managesieve.rb, line 182 182: def put_script(script, data) 183: args = sieve_name(script) 184: args += ' ' + sieve_string(data) if data 185: send_command('PUTSCRIPT', args) 186: end
If a block is given, calls it for each script stored on the server, passing its name and status as parameters. Else, and array of [ name, status ] arrays is returned. The status is either ‘ACTIVE’ or nil.
# File managesieve.rb, line 160 160: def scripts 161: begin 162: scripts = send_command('LISTSCRIPTS') 163: rescue SieveCommandError => e 164: raise e, "Cannot list scripts: #{e}" 165: end 166: return scripts unless block_given? 167: scripts.each { |name, status| yield(name, status) } 168: end
Sets script as active.
# File managesieve.rb, line 194 194: def set_active(script) 195: send_command('SETACTIVE', sieve_name(script)) 196: end