Class ManageSieve
In: managesieve.rb
Parent: Object

ManageSieve implements MANAGESIEVE, a protocol for remote management of Sieve scripts.

The following MANAGESIEVE commands are implemented:

  • CAPABILITY
  • DELETESCRIPT
  • GETSCRIPT
  • HAVESPACE
  • LISTSCRIPTS
  • LOGOUT
  • PUTSCRIPT
  • SETACTIVE

The AUTHENTICATE command is partially implemented. Currently the LOGIN and PLAIN authentication mechanisms are implemented.

Example

 # 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

Methods

Constants

SIEVE_PORT = 2000

Attributes

capabilities  [R] 
euser  [R] 
host  [R] 
login_mechs  [R] 
port  [R] 
user  [R] 

Public Class methods

Create a new ManageSieve instance. The info parameter is a hash with the following keys:

:host
the sieve server
:port
the sieve port (defaults to 2000)
:user
the name of the user
:euser
the name of the effective user (defaults to +:user+)
:password
the password of the user
:auth_mech
the authentication mechanism (defaults to +"ANONYMOUS"+)

[Source]

     # File managesieve.rb, line 119
119:   def initialize(info)
120:     @host      = info[:host]
121:     @port      = info[:port] || 2000
122:     @user      = info[:user]
123:     @euser     = info[:euser] || @user
124:     @password  = info[:password]
125:     @auth_mech = info[:auth] || 'ANONYMOUS'
126: 
127:     @capabilities   = []
128:     @login_mechs    = []
129:     @implementation = ''
130:     @supports_tls   = false
131:     @socket = TCPSocket.new(@host, @port)
132: 
133:     data = get_response
134:     server_features(data)
135:     authenticate
136:     @password = nil
137:   end

Public Instance methods

Deletes script from the server.

[Source]

     # File managesieve.rb, line 173
173:   def delete_script(script)
174:     send_command('DELETESCRIPT', sieve_name(script))
175:   end
each_script()

Alias for scripts

Returns the contents of script as a string.

[Source]

     # File managesieve.rb, line 156
156:   def get_script(script)
157:     begin
158:       data = send_command('GETSCRIPT', sieve_name(script))
159:     rescue SieveCommandError => e
160:       raise e, "Cannot get script: #{e}"
161:     end
162:     return data.to_s.chomp
163:   end

Returns true if there is space on the server to store script with size size and false otherwise.

[Source]

     # File managesieve.rb, line 184
184:   def have_space?(script, size)
185:     begin
186:       args = sieve_name(script) + ' ' + size.to_s
187:       send_command('HAVESPACE', args)
188:       return true
189:     rescue SieveCommandError
190:       return false
191:     end
192:   end

Disconnect from the server.

[Source]

     # File managesieve.rb, line 200
200:   def logout
201:     send_command('LOGOUT')
202:     @socket.close
203:   end

Uploads script to the server, using data as its contents.

[Source]

     # File managesieve.rb, line 166
166:   def put_script(script, data)
167:     args = sieve_name(script)
168:     args += ' ' + sieve_string(data) if data
169:     send_command('PUTSCRIPT', args)
170:   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.

[Source]

     # File managesieve.rb, line 144
144:   def scripts
145:     begin
146:       scripts = send_command('LISTSCRIPTS')
147:     rescue SieveCommandError => e
148:       raise e, "Cannot list scripts: #{e}"
149:     end
150:     return scripts unless block_given?
151:     scripts.each { |name, status| yield(name, status) }
152:   end

Sets script as active.

[Source]

     # File managesieve.rb, line 178
178:   def set_active(script)
179:     send_command('SETACTIVE', sieve_name(script))
180:   end

Returns true if the server supports TLS and false otherwise.

[Source]

     # File managesieve.rb, line 195
195:   def supports_tls?
196:     @supports_tls
197:   end

[Validate]