ruby-managesieve 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sievectl +23 -21
- data/lib/managesieve.rb +30 -5
- metadata +38 -31
data/bin/sievectl
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2009 Andre Nathan <andre@digirati.com.br>
|
5
5
|
#
|
6
6
|
# Permission to use, copy, modify, and distribute this software for any
|
7
7
|
# purpose with or without fee is hereby granted, provided that the above
|
@@ -38,10 +38,13 @@
|
|
38
38
|
# user: john
|
39
39
|
# password: secret
|
40
40
|
# auth: PLAIN
|
41
|
+
# tls: false
|
41
42
|
#
|
42
43
|
# The +port+ and +euser+ parameters can be ommited, and will respectively
|
43
44
|
# default to 2000 and the value of the +user+ parameter. If the +auth+
|
44
|
-
# parameter is ommited, it will default to +ANONYMOUS+.
|
45
|
+
# parameter is ommited, it will default to +ANONYMOUS+. If the +tls+ parameter
|
46
|
+
# is ommited, a TLS connection will be used if the server supports it.
|
47
|
+
# Otherwise, a plain text connection will be used.
|
45
48
|
#
|
46
49
|
# == Usage and examples
|
47
50
|
#
|
@@ -75,7 +78,7 @@
|
|
75
78
|
# sievectl myaccount del scriptname
|
76
79
|
#
|
77
80
|
#--
|
78
|
-
# $Id: sievectl,v 1.
|
81
|
+
# $Id: sievectl,v 1.30 2009/01/13 21:29:52 andre Exp $
|
79
82
|
#++
|
80
83
|
#
|
81
84
|
|
@@ -87,13 +90,9 @@ require 'managesieve'
|
|
87
90
|
|
88
91
|
$has_termios = true
|
89
92
|
begin
|
90
|
-
|
93
|
+
require 'termios'
|
91
94
|
rescue LoadError
|
92
|
-
|
93
|
-
require 'termios'
|
94
|
-
rescue LoadError
|
95
|
-
$has_termios = false
|
96
|
-
end
|
95
|
+
$has_termios = false
|
97
96
|
end
|
98
97
|
|
99
98
|
require 'yaml'
|
@@ -129,14 +128,14 @@ class ConfigFile < File # :nodoc:
|
|
129
128
|
begin
|
130
129
|
conf = nil
|
131
130
|
super(name) do |file|
|
132
|
-
conf = YAML
|
131
|
+
conf = YAML.load(file)
|
133
132
|
end
|
134
133
|
conf.each_key do |acct|
|
135
|
-
conf[acct].each_key { |k| conf[acct][k] = conf[acct][k]
|
134
|
+
conf[acct].each_key { |k| conf[acct][k] = conf[acct][k] }
|
136
135
|
end
|
137
136
|
conf
|
138
137
|
rescue Errno::ENOENT
|
139
|
-
ConfigFile
|
138
|
+
ConfigFile.create_template(name)
|
140
139
|
exit 0
|
141
140
|
end
|
142
141
|
end
|
@@ -146,7 +145,7 @@ class ConfigFile < File # :nodoc:
|
|
146
145
|
STDERR.puts <<-__EOF__
|
147
146
|
* Could not find configuration file #{name}.
|
148
147
|
* A template file will be created. Please edit the values to fit your
|
149
|
-
* local configuration and run `#{File
|
148
|
+
* local configuration and run `#{File.basename($0)}' again.
|
150
149
|
__EOF__
|
151
150
|
|
152
151
|
begin
|
@@ -159,6 +158,7 @@ accountname:
|
|
159
158
|
euser: effectiveusername
|
160
159
|
password: password
|
161
160
|
auth: authmethod
|
161
|
+
tls: true
|
162
162
|
__EOF__
|
163
163
|
rescue => e
|
164
164
|
raise TemplateError, e
|
@@ -228,7 +228,7 @@ class SieveCtl
|
|
228
228
|
end
|
229
229
|
|
230
230
|
def usage(quit=true, out=STDERR) # :nodoc: #
|
231
|
-
prog = File.basename
|
231
|
+
prog = File.basename($0)
|
232
232
|
out.puts <<-__EOF__
|
233
233
|
Usage: #{prog} <account> <action> [script name]
|
234
234
|
Action is one of:
|
@@ -240,7 +240,7 @@ You can also try `#{prog} help' for usage examples.
|
|
240
240
|
end
|
241
241
|
|
242
242
|
def help # :nodoc:
|
243
|
-
prog = File
|
243
|
+
prog = File.basename($0)
|
244
244
|
usage(false, STDOUT)
|
245
245
|
puts <<-__EOF__
|
246
246
|
|
@@ -282,7 +282,7 @@ account, action, name, file = ARGV
|
|
282
282
|
usage if action.nil?
|
283
283
|
|
284
284
|
begin
|
285
|
-
conf = ConfigFile
|
285
|
+
conf = ConfigFile.open(ENV['HOME'] + '/.sievectlrc')
|
286
286
|
rescue TemplateError => e
|
287
287
|
STDERR.puts "Cannot create template configuration file: #{e}"
|
288
288
|
exit 1
|
@@ -319,14 +319,16 @@ end
|
|
319
319
|
info['password'].chomp!
|
320
320
|
|
321
321
|
begin
|
322
|
-
|
322
|
+
config = {
|
323
323
|
:host => info['host'],
|
324
324
|
:port => info['port'] || 2000,
|
325
|
-
:user => info['user'],
|
326
|
-
:euser => info['euser'] || info['user'],
|
327
|
-
:password => info['password'],
|
325
|
+
:user => info['user'].to_s,
|
326
|
+
:euser => info['euser'].to_s || info['user'].to_s,
|
327
|
+
:password => info['password'].to_s,
|
328
328
|
:auth => info['auth']
|
329
|
-
|
329
|
+
}
|
330
|
+
config.merge!({:tls => info['tls']}) if info.has_key? 'tls'
|
331
|
+
sievectl = SieveCtl.new(config)
|
330
332
|
rescue SieveNetworkError => e
|
331
333
|
STDERR.puts "* #{e}"
|
332
334
|
exit 1
|
data/lib/managesieve.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2009 Andre Nathan <andre@digirati.com.br>
|
5
5
|
#
|
6
6
|
# Permission to use, copy, modify, and distribute this software for any
|
7
7
|
# purpose with or without fee is hereby granted, provided that the above
|
@@ -25,13 +25,18 @@
|
|
25
25
|
# See the ManageSieve class for documentation and examples.
|
26
26
|
#
|
27
27
|
#--
|
28
|
-
# $Id: managesieve.rb,v 1.
|
28
|
+
# $Id: managesieve.rb,v 1.14 2009/01/13 19:22:08 andre Exp $
|
29
29
|
#++
|
30
30
|
#
|
31
31
|
|
32
32
|
require 'base64'
|
33
33
|
require 'socket'
|
34
34
|
|
35
|
+
begin
|
36
|
+
require 'openssl'
|
37
|
+
rescue LoadError
|
38
|
+
end
|
39
|
+
|
35
40
|
#
|
36
41
|
# Define our own Base64.encode64 for compatibility with ruby <= 1.8.1, which
|
37
42
|
# defines encode64() at the top level.
|
@@ -104,7 +109,7 @@ class SieveResponseError < Exception; end
|
|
104
109
|
class ManageSieve
|
105
110
|
SIEVE_PORT = 2000
|
106
111
|
|
107
|
-
attr_reader :host, :port, :user, :euser, :capabilities, :login_mechs
|
112
|
+
attr_reader :host, :port, :user, :euser, :capabilities, :login_mechs, :tls
|
108
113
|
|
109
114
|
# Create a new ManageSieve instance. The +info+ parameter is a hash with the
|
110
115
|
# following keys:
|
@@ -115,6 +120,7 @@ class ManageSieve
|
|
115
120
|
# [<i>:euser</i>] the name of the effective user (defaults to +:user+)
|
116
121
|
# [<i>:password</i>] the password of the user
|
117
122
|
# [<i>:auth_mech</i>] the authentication mechanism (defaults to +"ANONYMOUS"+)
|
123
|
+
# [<i>:tls</i>] use TLS (defaults to use it if the server supports it)
|
118
124
|
#
|
119
125
|
def initialize(info)
|
120
126
|
@host = info[:host]
|
@@ -123,15 +129,25 @@ class ManageSieve
|
|
123
129
|
@euser = info[:euser] || @user
|
124
130
|
@password = info[:password]
|
125
131
|
@auth_mech = info[:auth] || 'ANONYMOUS'
|
132
|
+
@tls = info.has_key?(:tls) ? !!info[:tls] : nil
|
126
133
|
|
127
134
|
@capabilities = []
|
128
135
|
@login_mechs = []
|
129
136
|
@implementation = ''
|
130
137
|
@supports_tls = false
|
131
|
-
@socket
|
138
|
+
@socket = TCPSocket.new(@host, @port)
|
132
139
|
|
133
140
|
data = get_response
|
134
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
|
+
|
135
151
|
authenticate
|
136
152
|
@password = nil
|
137
153
|
end
|
@@ -261,7 +277,7 @@ class ManageSieve
|
|
261
277
|
def send_command(cmd, args=nil, wait_response=true) # :nodoc:
|
262
278
|
cmd += ' ' + args if args
|
263
279
|
begin
|
264
|
-
@socket.
|
280
|
+
@socket.write(cmd + "\r\n")
|
265
281
|
resp = get_response if wait_response
|
266
282
|
rescue SieveResponseError => e
|
267
283
|
raise SieveCommandError, "Command error: #{e}"
|
@@ -326,4 +342,13 @@ class ManageSieve
|
|
326
342
|
return "{#{string.length}+}\r\n#{string}"
|
327
343
|
end
|
328
344
|
|
345
|
+
private
|
346
|
+
def starttls
|
347
|
+
send_command('STARTTLS')
|
348
|
+
@socket = OpenSSL::SSL::SSLSocket.new(@socket)
|
349
|
+
@socket.sync_close = true
|
350
|
+
@socket.connect
|
351
|
+
data = get_response
|
352
|
+
server_features(data)
|
353
|
+
end
|
329
354
|
end
|
metadata
CHANGED
@@ -1,46 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: ruby-managesieve
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-08-30 00:00:00 -03:00
|
8
|
-
summary: A Ruby library for the MANAGESIEVE protocol
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: andre@digirati.com.br
|
12
|
-
homepage: http://managesieve.rubyforge.org
|
13
|
-
rubyforge_project: ruby-managesieve
|
14
|
-
description: ruby-managesieve is a pure-ruby implementation of the MANAGESIEVE protocol, allowing remote management of Sieve scripts from ruby.
|
15
|
-
autorequire: managesieve
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.4.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Andre Nathan
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
rdoc_options: []
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
36
11
|
|
37
|
-
|
12
|
+
date: 2009-01-13 00:00:00 -02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
38
15
|
|
16
|
+
description: ruby-managesieve is a pure-ruby implementation of the MANAGESIEVE protocol, allowing remote management of Sieve scripts from ruby.
|
17
|
+
email: andre@digirati.com.br
|
39
18
|
executables:
|
40
19
|
- sievectl
|
41
20
|
extensions: []
|
42
21
|
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/managesieve.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://managesieve.rubyforge.org
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
43
45
|
requirements:
|
44
46
|
- A network connection and a MANAGESIEVE server.
|
45
|
-
|
47
|
+
rubyforge_project: ruby-managesieve
|
48
|
+
rubygems_version: 1.3.0
|
49
|
+
signing_key:
|
50
|
+
specification_version: 2
|
51
|
+
summary: A Ruby library for the MANAGESIEVE protocol
|
52
|
+
test_files: []
|
46
53
|
|