ruby-managesieve 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sievectl +82 -42
- data/lib/managesieve.rb +9 -4
- metadata +22 -15
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-2006 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
|
@@ -51,41 +51,51 @@
|
|
51
51
|
# capabilities, list, show, activate, deactivate, add, addactive, delete
|
52
52
|
#
|
53
53
|
# Short forms for some actions are also accepted:
|
54
|
-
# caps (capabilities), act (activate), deact (deactivate),
|
55
|
-
# del (delete)
|
54
|
+
# caps (capabilities), act (activate), deact (deactivate),
|
55
|
+
# addact (addactive), del (delete)
|
56
56
|
#
|
57
57
|
# Examples:
|
58
58
|
# List server capabilities:
|
59
|
-
# sievectl caps
|
59
|
+
# sievectl myaccount caps
|
60
60
|
#
|
61
61
|
# List available scripts:
|
62
|
-
# sievectl list
|
62
|
+
# sievectl myaccount list
|
63
63
|
#
|
64
64
|
# Show contents of a script:
|
65
|
-
# sievectl show scriptname
|
65
|
+
# sievectl myaccount show scriptname
|
66
66
|
#
|
67
67
|
# Add a script:
|
68
|
-
# sievectl add scriptname script.txt
|
68
|
+
# sievectl myaccount add scriptname script.txt
|
69
69
|
# or
|
70
|
-
# sievectl add scriptname < script.txt
|
70
|
+
# sievectl myaccount add scriptname < script.txt
|
71
71
|
# or
|
72
|
-
# cat script.txt | sievectl add scriptname
|
72
|
+
# cat script.txt | sievectl myaccount add scriptname
|
73
73
|
#
|
74
74
|
# Delete a script:
|
75
|
-
# sievectl del scriptname
|
75
|
+
# sievectl myaccount del scriptname
|
76
76
|
#
|
77
77
|
#--
|
78
|
-
# $Id: sievectl,v 1.
|
78
|
+
# $Id: sievectl,v 1.27 2006/08/30 18:06:21 andre Exp $
|
79
79
|
#++
|
80
80
|
#
|
81
81
|
|
82
82
|
begin
|
83
83
|
require 'rubygems'
|
84
84
|
rescue LoadError
|
85
|
-
nil
|
86
85
|
end
|
87
|
-
|
88
86
|
require 'managesieve'
|
87
|
+
|
88
|
+
$has_termios = true
|
89
|
+
begin
|
90
|
+
require_gem 'termios'
|
91
|
+
rescue LoadError
|
92
|
+
begin
|
93
|
+
require 'termios'
|
94
|
+
rescue LoadError
|
95
|
+
$has_termios = false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
89
99
|
require 'yaml'
|
90
100
|
|
91
101
|
class ManageSieve # :nodoc:
|
@@ -111,16 +121,20 @@ class ManageSieve # :nodoc:
|
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
114
|
-
class TemplateError # :nodoc:
|
124
|
+
class TemplateError < Exception # :nodoc:
|
115
125
|
end
|
116
126
|
|
117
127
|
class ConfigFile < File # :nodoc:
|
118
128
|
def ConfigFile.open(name)
|
119
129
|
begin
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
130
|
+
conf = nil
|
131
|
+
super(name) do |file|
|
132
|
+
conf = YAML::load(file)
|
133
|
+
end
|
134
|
+
conf.each_key do |acct|
|
135
|
+
conf[acct].each_key { |k| conf[acct][k] = conf[acct][k].to_s }
|
136
|
+
end
|
137
|
+
conf
|
124
138
|
rescue Errno::ENOENT
|
125
139
|
ConfigFile::create_template(name)
|
126
140
|
exit 0
|
@@ -136,7 +150,7 @@ class ConfigFile < File # :nodoc:
|
|
136
150
|
__EOF__
|
137
151
|
|
138
152
|
begin
|
139
|
-
file = File
|
153
|
+
file = File.new(name, 'w', 0600)
|
140
154
|
file.puts <<-__EOF__
|
141
155
|
accountname:
|
142
156
|
host: servername
|
@@ -197,8 +211,12 @@ class SieveCtl
|
|
197
211
|
def add(script, file=nil, active=false)
|
198
212
|
action = "add#{active ? 'active' : ''}"
|
199
213
|
raise ArgumentError, "`#{action}' requires a script name" unless script
|
200
|
-
data = file ? File.open(file).readlines : STDIN.readlines
|
201
|
-
@manage_sieve.
|
214
|
+
data = file ? File.open(file).readlines.to_s : STDIN.readlines.to_s
|
215
|
+
unless @manage_sieve.have_space?(script, data.length)
|
216
|
+
raise SieveCommandError, "not enough space for script `#{script}' " +
|
217
|
+
"(#{data.length} bytes)"
|
218
|
+
end
|
219
|
+
@manage_sieve.put_script(script, data)
|
202
220
|
activate script if active
|
203
221
|
end
|
204
222
|
|
@@ -209,9 +227,9 @@ class SieveCtl
|
|
209
227
|
end
|
210
228
|
end
|
211
229
|
|
212
|
-
def usage(quit=true) # :nodoc: #
|
213
|
-
prog = File
|
214
|
-
|
230
|
+
def usage(quit=true, out=STDERR) # :nodoc: #
|
231
|
+
prog = File.basename $0
|
232
|
+
out.puts <<-__EOF__
|
215
233
|
Usage: #{prog} <account> <action> [script name]
|
216
234
|
Action is one of:
|
217
235
|
capabilities, list, show, activate, deactivate, add, addactive, delete
|
@@ -223,7 +241,7 @@ end
|
|
223
241
|
|
224
242
|
def help # :nodoc:
|
225
243
|
prog = File::basename $0
|
226
|
-
usage(false)
|
244
|
+
usage(false, STDOUT)
|
227
245
|
puts <<-__EOF__
|
228
246
|
|
229
247
|
Short forms for some actions are also accepted:
|
@@ -232,23 +250,23 @@ Short forms for some actions are also accepted:
|
|
232
250
|
|
233
251
|
Examples:
|
234
252
|
List server capabilities:
|
235
|
-
#{prog} caps
|
253
|
+
#{prog} myaccount caps
|
236
254
|
|
237
255
|
List available scripts:
|
238
|
-
#{prog} list
|
256
|
+
#{prog} myaccount list
|
239
257
|
|
240
258
|
Show contents of a script:
|
241
|
-
#{prog} show scriptname
|
259
|
+
#{prog} myaccount show scriptname
|
242
260
|
|
243
261
|
Add a script:
|
244
|
-
#{prog} add scriptname script.txt
|
262
|
+
#{prog} myaccount add scriptname script.txt
|
245
263
|
or
|
246
|
-
#{prog} add scriptname < script.txt
|
264
|
+
#{prog} myaccount add scriptname < script.txt
|
247
265
|
or
|
248
|
-
cat script.txt | #{prog} add scriptname
|
266
|
+
cat script.txt | #{prog} myaccount add scriptname
|
249
267
|
|
250
268
|
Delete a script:
|
251
|
-
#{prog} del scriptname
|
269
|
+
#{prog} myaccount del scriptname
|
252
270
|
__EOF__
|
253
271
|
exit 0
|
254
272
|
end
|
@@ -283,14 +301,36 @@ end
|
|
283
301
|
|
284
302
|
info = conf[account]
|
285
303
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
:
|
292
|
-
|
293
|
-
)
|
304
|
+
if $has_termios and info['password'].nil?
|
305
|
+
oldt = Termios.tcgetattr(STDIN)
|
306
|
+
newt = oldt.dup
|
307
|
+
newt.lflag &= ~Termios::ECHO
|
308
|
+
Termios.tcsetattr(STDIN, Termios::TCSANOW, newt)
|
309
|
+
print 'Password: '
|
310
|
+
info['password'] = STDIN.gets
|
311
|
+
Termios.tcsetattr(STDIN, Termios::TCSANOW, oldt)
|
312
|
+
end
|
313
|
+
|
314
|
+
if info['password'].nil?
|
315
|
+
STDERR.puts "* Password not given."
|
316
|
+
exit 1
|
317
|
+
end
|
318
|
+
|
319
|
+
info['password'].chomp!
|
320
|
+
|
321
|
+
begin
|
322
|
+
sievectl = SieveCtl.new(
|
323
|
+
:host => info['host'],
|
324
|
+
:port => info['port'] || 2000,
|
325
|
+
:user => info['user'],
|
326
|
+
:euser => info['euser'] || info['user'],
|
327
|
+
:password => info['password'],
|
328
|
+
:auth => info['auth']
|
329
|
+
)
|
330
|
+
rescue SieveNetworkError => e
|
331
|
+
STDERR.puts "* #{e}"
|
332
|
+
exit 1
|
333
|
+
end
|
294
334
|
|
295
335
|
begin
|
296
336
|
case action
|
@@ -313,6 +353,6 @@ begin
|
|
313
353
|
else
|
314
354
|
usage
|
315
355
|
end
|
316
|
-
rescue SieveCommandError => e
|
317
|
-
STDERR.puts "* #{e}"
|
356
|
+
rescue ArgumentError, SieveCommandError => e
|
357
|
+
STDERR.puts "* sievectl: #{e}"
|
318
358
|
end
|
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-2006 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,7 +25,7 @@
|
|
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.13 2006/08/30 14:23:58 andre Exp $
|
29
29
|
#++
|
30
30
|
#
|
31
31
|
|
@@ -45,6 +45,7 @@ end
|
|
45
45
|
|
46
46
|
class SieveAuthError < Exception; end
|
47
47
|
class SieveCommandError < Exception; end
|
48
|
+
class SieveNetworkError < Exception; end
|
48
49
|
class SieveResponseError < Exception; end
|
49
50
|
|
50
51
|
#
|
@@ -249,7 +250,11 @@ class ManageSieve
|
|
249
250
|
|
250
251
|
private
|
251
252
|
def get_line # :nodoc:
|
252
|
-
|
253
|
+
begin
|
254
|
+
return @socket.readline.chomp
|
255
|
+
rescue EOFError => e
|
256
|
+
raise SieveNetworkError, "Network error: #{e}"
|
257
|
+
end
|
253
258
|
end
|
254
259
|
|
255
260
|
private
|
@@ -270,7 +275,7 @@ class ManageSieve
|
|
270
275
|
data = get_line
|
271
276
|
|
272
277
|
# server ok
|
273
|
-
m = /^OK
|
278
|
+
m = /^OK(.*)?$/.match(data)
|
274
279
|
yield :ok, m.captures.values_at(0, 3) and next if m
|
275
280
|
|
276
281
|
# server error
|
metadata
CHANGED
@@ -1,39 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-managesieve
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2006-08-30 00:00:00 -03:00
|
8
8
|
summary: A Ruby library for the MANAGESIEVE protocol
|
9
9
|
require_paths:
|
10
|
-
|
11
|
-
author: Andre Nathan
|
10
|
+
- lib
|
12
11
|
email: andre@digirati.com.br
|
13
12
|
homepage: http://managesieve.rubyforge.org
|
14
13
|
rubyforge_project: ruby-managesieve
|
15
|
-
description:
|
16
|
-
allowing remote management of Sieve scripts from ruby."
|
14
|
+
description: ruby-managesieve is a pure-ruby implementation of the MANAGESIEVE protocol, allowing remote management of Sieve scripts from ruby.
|
17
15
|
autorequire: managesieve
|
18
16
|
default_executable:
|
19
17
|
bindir: bin
|
20
18
|
has_rdoc: true
|
21
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
20
|
requirements:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
27
24
|
version:
|
28
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Andre Nathan
|
29
31
|
files:
|
30
|
-
|
32
|
+
- lib/managesieve.rb
|
31
33
|
test_files: []
|
34
|
+
|
32
35
|
rdoc_options: []
|
36
|
+
|
33
37
|
extra_rdoc_files: []
|
38
|
+
|
34
39
|
executables:
|
35
|
-
|
40
|
+
- sievectl
|
36
41
|
extensions: []
|
42
|
+
|
37
43
|
requirements:
|
38
|
-
|
39
|
-
dependencies: []
|
44
|
+
- A network connection and a MANAGESIEVE server.
|
45
|
+
dependencies: []
|
46
|
+
|