sieve-parser 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sieve-parser/action.rb +8 -4
- data/lib/sieve-parser/condition.rb +15 -10
- data/lib/sieve-parser/filter.rb +25 -25
- data/lib/sieve-parser/filterset.rb +19 -1
- data/lib/sieve-parser.rb +1 -1
- data/sieve-parser.gemspec +1 -1
- metadata +2 -2
data/lib/sieve-parser/action.rb
CHANGED
@@ -27,10 +27,14 @@ module Sieve
|
|
27
27
|
#@param [string] text of actions
|
28
28
|
#@return [Array(Action)] array of Actions
|
29
29
|
def self.parse_all(text)
|
30
|
-
lines = text.
|
30
|
+
lines = text.scan(/^[\s]*(.+;)$|^[\s]*(.+\n\S+.*;\s*.*\n\.\n\;)/)
|
31
31
|
actions = []
|
32
32
|
lines.each do |line|
|
33
|
-
|
33
|
+
if !line[0].nil?
|
34
|
+
actions << self.new(line[0])
|
35
|
+
else
|
36
|
+
actions << Sieve::Vacation.parse_text(line[1])
|
37
|
+
end
|
34
38
|
end
|
35
39
|
actions
|
36
40
|
end
|
@@ -39,7 +43,7 @@ module Sieve
|
|
39
43
|
#@return [string] text of action
|
40
44
|
def to_s
|
41
45
|
text =""
|
42
|
-
{'type'=>@type, 'copy'
|
46
|
+
{'type'=>@type, 'copy'=>(@copy) ? ":copy" : nil, 'target'=>@target}.each do |name,item|
|
43
47
|
if ['target'].index(name)
|
44
48
|
text += "\"#{item}\" " unless item.nil?
|
45
49
|
else
|
@@ -60,7 +64,7 @@ module Sieve
|
|
60
64
|
params = @text.split(" ")
|
61
65
|
@type = params[0]
|
62
66
|
if params[1]==":copy"
|
63
|
-
@copy =
|
67
|
+
@copy = true
|
64
68
|
@target = params[2]
|
65
69
|
else
|
66
70
|
@target = params[1]
|
@@ -5,18 +5,23 @@ module Sieve
|
|
5
5
|
class Condition
|
6
6
|
attr_accessor :test,:not,:arg1,:arg2,:type, :text
|
7
7
|
|
8
|
-
# Create Condition object by text of condition
|
8
|
+
# Create Condition object by text of condition or params
|
9
9
|
#@note Example:
|
10
10
|
# header :contains "Subject" "teste"
|
11
|
-
#@param [
|
11
|
+
#@param [String](:text) text of condition
|
12
|
+
#@param [String](:test) test of condition
|
13
|
+
#@param [String](:not) not of condition
|
14
|
+
#@param [String](:arg1) arg1 of condition
|
15
|
+
#@param [String](:arg2) arg2 of condition
|
16
|
+
#@param [String](:type) type of condition
|
12
17
|
#@return [Condition] Condition object parsed
|
13
|
-
def initialize
|
14
|
-
@text = text
|
15
|
-
@test=
|
16
|
-
@not=
|
17
|
-
@arg1=
|
18
|
-
@arg2=
|
19
|
-
@type=
|
18
|
+
def initialize params={}
|
19
|
+
@text = params[:text]
|
20
|
+
@test=params[:test]
|
21
|
+
@not=params[:not]
|
22
|
+
@arg1=params[:arg1]
|
23
|
+
@arg2=params[:arg2]
|
24
|
+
@type= params[:type]
|
20
25
|
parse unless @text.nil?
|
21
26
|
end
|
22
27
|
# Return a array of conditions after parse the text
|
@@ -28,7 +33,7 @@ module Sieve
|
|
28
33
|
def self.parse_all(text)
|
29
34
|
contitions = []
|
30
35
|
text.scan(/([\s\w:]*\"\S+\"\s\"[\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*\")/).each do |item|
|
31
|
-
contitions << self.new(item[0])
|
36
|
+
contitions << self.new(text:item[0])
|
32
37
|
end
|
33
38
|
contitions
|
34
39
|
end
|
data/lib/sieve-parser/filter.rb
CHANGED
@@ -7,16 +7,18 @@ module Sieve
|
|
7
7
|
class Filter
|
8
8
|
|
9
9
|
#@note [join] can be: any, allof or anyof
|
10
|
-
attr_accessor :name, :type, :join, :
|
10
|
+
attr_accessor :name, :type, :join, :disabled, :text
|
11
11
|
|
12
12
|
# Initialize the class
|
13
|
-
#@param [
|
13
|
+
#@param [String](:text) String of filter text
|
14
|
+
#@param [Array](:conditions) Array of Conditions
|
15
|
+
#@param [Array](:actions) Array of Actions
|
14
16
|
#@return [object] Object of self
|
15
|
-
def initialize
|
16
|
-
@
|
17
|
-
@conditions = []
|
18
|
-
@actions = []
|
19
|
-
parse unless @
|
17
|
+
def initialize params={}
|
18
|
+
@text = params[:text]
|
19
|
+
@conditions = (params[:conditions]) ? params[:conditions] : []
|
20
|
+
@actions = (params[:actions]) ? params[:actions] : []
|
21
|
+
parse unless @text.nil?
|
20
22
|
end
|
21
23
|
|
22
24
|
# Return the conditions of filter
|
@@ -54,25 +56,31 @@ module Sieve
|
|
54
56
|
else
|
55
57
|
text += " " + conditions[0].to_s
|
56
58
|
end
|
57
|
-
text += "\n{\n
|
58
|
-
text += actions.join("\n
|
59
|
+
text += "\n{\n\t"
|
60
|
+
text += actions.join("\n\t")
|
59
61
|
text += "\n}\n"
|
60
62
|
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
def
|
65
|
-
@
|
64
|
+
# Is disabled or not? Return the status of filter
|
65
|
+
#@return [boolean] true for disabled and false for enabled
|
66
|
+
def disabled?
|
67
|
+
@disabled == true
|
68
|
+
end
|
69
|
+
|
70
|
+
def disable!
|
71
|
+
@disabled = true
|
66
72
|
end
|
67
73
|
|
68
74
|
private
|
69
|
-
# Parse
|
70
|
-
def
|
75
|
+
# Parse conditions, call the parse_common or parse_vacation
|
76
|
+
def parse
|
71
77
|
#regex_rules_params = "(^#.*)\nif([\s\w\:\"\.\;\(\)\,\-]+)\{([\@\<>=a-zA-Z0-9\s\[\]\_\:\"\.\;\(\)\,\-\/]+)\}$"
|
72
78
|
#regex_rules_params2 = "(^#.*)\n(\S+)(.+)\n\{\n([\s\S]*)\}"
|
73
|
-
parts = @
|
79
|
+
parts = @text.scan(/(^#.*)\n(\S+)\s(.+)\n\{\n([\s\S]*;)\n\}/)[0]
|
74
80
|
parse_name(parts[0])
|
75
81
|
@type = parts[1]
|
82
|
+
|
83
|
+
self.disable! if parts[2] =~ /.*false #/
|
76
84
|
#if the join is true, dont have conditions...
|
77
85
|
if parts[2] =~ /true/
|
78
86
|
@conditions << Condition.new(type:"true")
|
@@ -80,24 +88,16 @@ module Sieve
|
|
80
88
|
@join = parts[2][/^\S+/]
|
81
89
|
@conditions.concat(Condition.parse_all( parts[2].scan(/\(([\S\s]+)\)/)[0][0] ))
|
82
90
|
else
|
83
|
-
@conditions << Condition.new(parts[2])
|
91
|
+
@conditions << Condition.new(text:parts[2])
|
84
92
|
end
|
85
93
|
|
86
94
|
@actions.concat(Action.parse_all(parts[3]))
|
87
95
|
end
|
88
96
|
|
89
|
-
private
|
90
|
-
# Parse the vacation filter
|
91
|
-
def parse_vacation
|
92
|
-
|
93
|
-
end
|
94
97
|
|
95
98
|
def parse_name(text_name)
|
96
99
|
@name = text_name.match(/#(.*)/)[1].strip
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
|
-
class Vacation
|
101
|
-
attr_accessor :days, :subject, :content
|
102
|
-
end
|
103
103
|
end
|
@@ -15,6 +15,9 @@ module Sieve
|
|
15
15
|
class FilterSet
|
16
16
|
attr_accessor :text_sieve
|
17
17
|
|
18
|
+
#Create FilterSet
|
19
|
+
#@param [String] text of sieve
|
20
|
+
#@return [FilterSet]
|
18
21
|
def initialize(text_sieve=nil)
|
19
22
|
@text_sieve = text_sieve
|
20
23
|
@requires = []
|
@@ -28,12 +31,27 @@ module Sieve
|
|
28
31
|
@filters
|
29
32
|
end
|
30
33
|
|
34
|
+
# Add filter to filters of filterset
|
35
|
+
#@param [Filter] filter object
|
36
|
+
def add_filter(filter)
|
37
|
+
raise Exception.new("The param is not a Filter!") unless filter.class.to_s == "Sieve::Filter"
|
38
|
+
@filters << filter
|
39
|
+
end
|
40
|
+
|
31
41
|
# Requires inside the script
|
32
42
|
#@return [array] names of requires
|
33
43
|
def requires
|
34
44
|
@requires
|
35
45
|
end
|
36
46
|
|
47
|
+
# Add require to requires of filterset
|
48
|
+
#@param [string] name of require
|
49
|
+
def add_require(req)
|
50
|
+
#TODO: Implement config of requires allowed
|
51
|
+
raise Exception.new("Is not a require valid!") unless req =~ /\S+/
|
52
|
+
@requires << req
|
53
|
+
end
|
54
|
+
|
37
55
|
# Return a text of filterset
|
38
56
|
#@return [string] text of filterset
|
39
57
|
def to_s
|
@@ -50,7 +68,7 @@ module Sieve
|
|
50
68
|
end
|
51
69
|
|
52
70
|
@text_sieve.scan(/(^#.*\nif[\s\w\:\"\.\;\(\)\,\-]*\n\{[a-zA-Z0-9\s\@\<>=\:\[\]\_\"\.\;\(\)\,\-\/]*\n\}$)/).each do |f|
|
53
|
-
@filters << Sieve::Filter.new(f[0])
|
71
|
+
@filters << Sieve::Filter.new(text:f[0])
|
54
72
|
end
|
55
73
|
|
56
74
|
end
|
data/lib/sieve-parser.rb
CHANGED
data/sieve-parser.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sieve-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-26 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! " sieve-parser is a pure-ruby implementation for parsing and \n
|
15
15
|
\ manipulate the sieve scripts.\n"
|