sieve-parser 0.0.3 → 0.0.4
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 +1 -1
- data/lib/sieve-parser/filter.rb +13 -2
- data/lib/sieve-parser/filterset.rb +43 -2
- data/sieve-parser.gemspec +1 -1
- metadata +2 -2
data/lib/sieve-parser/action.rb
CHANGED
data/lib/sieve-parser/filter.rb
CHANGED
@@ -16,6 +16,9 @@ module Sieve
|
|
16
16
|
#@return [object] Object of self
|
17
17
|
def initialize params={}
|
18
18
|
@text = params[:text]
|
19
|
+
@type = (params[:type]) ? params[:name] : "if"
|
20
|
+
@name = params[:name]
|
21
|
+
@join = params[:join]
|
19
22
|
@conditions = (params[:conditions]) ? params[:conditions] : []
|
20
23
|
@actions = (params[:actions]) ? params[:actions] : []
|
21
24
|
parse unless @text.nil?
|
@@ -39,10 +42,18 @@ module Sieve
|
|
39
42
|
@name
|
40
43
|
end
|
41
44
|
|
45
|
+
# Add object of Action to filter
|
46
|
+
#@param [Sieve::Action]
|
47
|
+
def add_action(action)
|
48
|
+
types = ["Sieve::Action", "Sieve::Vacation"]
|
49
|
+
raise "the param is not a Action" unless types.index(action.class.to_s)
|
50
|
+
@actions << action
|
51
|
+
end
|
52
|
+
|
42
53
|
# Add object of Condition to filter
|
43
54
|
#@param [Sieve::Condition]
|
44
55
|
def add_condition(condition)
|
45
|
-
raise "the param is not a Condition" unless condition.class.to_s == "Sieve::
|
56
|
+
raise "the param is not a Condition" unless condition.class.to_s == "Sieve::Condition"
|
46
57
|
@conditions << condition
|
47
58
|
end
|
48
59
|
|
@@ -50,7 +61,7 @@ module Sieve
|
|
50
61
|
#@return [string] text of filter
|
51
62
|
def to_s
|
52
63
|
text = "# #{name}\n"
|
53
|
-
text += "#{@type}"
|
64
|
+
text += ((disabled?) ? "false #" : "") + "#{@type}"
|
54
65
|
if conditions.count > 1
|
55
66
|
text += " #{@join} (" + conditions.join(", ") + ")"
|
56
67
|
else
|
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
module Sieve
|
15
15
|
class FilterSet
|
16
|
-
attr_accessor :text_sieve
|
16
|
+
attr_accessor :text_sieve, :auto_require
|
17
17
|
|
18
18
|
#Create FilterSet
|
19
19
|
#@param [String] text of sieve
|
@@ -22,6 +22,7 @@ module Sieve
|
|
22
22
|
@text_sieve = text_sieve
|
23
23
|
@requires = []
|
24
24
|
@filters = []
|
25
|
+
@auto_require = true;
|
25
26
|
parse unless @text_sieve.nil?
|
26
27
|
end
|
27
28
|
|
@@ -31,16 +32,42 @@ module Sieve
|
|
31
32
|
@filters
|
32
33
|
end
|
33
34
|
|
35
|
+
# Return filter by name
|
36
|
+
# @param [String] name of filter
|
37
|
+
# @return [integer] index of filter
|
38
|
+
def find_filter_by_name(name)
|
39
|
+
@filters[filter_index_by_name(name)]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return filter index by name
|
43
|
+
# @param [String] name of filter
|
44
|
+
# @return [Sieve::Filter]
|
45
|
+
def filter_index_by_name(name)
|
46
|
+
key = @filters.index{|f| f.name==name}
|
47
|
+
raise Exception.new("Filter not found") unless key
|
48
|
+
key
|
49
|
+
end
|
50
|
+
|
51
|
+
# Remove filter by name
|
52
|
+
# @param [String] name of filter
|
53
|
+
# @return [Array] @filter array
|
54
|
+
def remove_filter_by_name(name)
|
55
|
+
filter_index_by_name(name)
|
56
|
+
@filters.delete_if {|f| f.name == name }
|
57
|
+
end
|
58
|
+
|
34
59
|
# Add filter to filters of filterset
|
35
60
|
#@param [Filter] filter object
|
36
61
|
def add_filter(filter)
|
37
62
|
raise Exception.new("The param is not a Filter!") unless filter.class.to_s == "Sieve::Filter"
|
63
|
+
load_requires(filter) if @auto_require == true
|
38
64
|
@filters << filter
|
39
65
|
end
|
40
66
|
|
41
67
|
# Requires inside the script
|
42
68
|
#@return [array] names of requires
|
43
69
|
def requires
|
70
|
+
@requires.uniq!
|
44
71
|
@requires
|
45
72
|
end
|
46
73
|
|
@@ -50,12 +77,13 @@ module Sieve
|
|
50
77
|
#TODO: Implement config of requires allowed
|
51
78
|
raise Exception.new("Is not a require valid!") unless req =~ /\S+/
|
52
79
|
@requires << req
|
80
|
+
@requires.uniq!
|
53
81
|
end
|
54
82
|
|
55
83
|
# Return a text of filterset
|
56
84
|
#@return [string] text of filterset
|
57
85
|
def to_s
|
58
|
-
text = "require [\"#{requires.join('","')}\"];\n"
|
86
|
+
text = "require [\"#{requires.join('","')}\"];\n" if @requires.count > 0
|
59
87
|
text += filters.join("")
|
60
88
|
end
|
61
89
|
|
@@ -72,5 +100,18 @@ module Sieve
|
|
72
100
|
end
|
73
101
|
|
74
102
|
end
|
103
|
+
|
104
|
+
#Load requires by filter
|
105
|
+
#@param [Sieve::Filter] object of filter
|
106
|
+
def load_requires(filter)
|
107
|
+
text_requires = "fileinto reject envelope encoded-character vacation "
|
108
|
+
text_requires += "subaddress comparator-i;ascii-numeric relational regex "
|
109
|
+
text_requires += "imap4flags copy include variables body enotify environment mailbox date"
|
110
|
+
text_requires.split(" ").each do |search|
|
111
|
+
if filter.to_s.index(search)
|
112
|
+
add_require(search)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
75
116
|
end
|
76
117
|
end
|
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.4
|
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-
|
12
|
+
date: 2012-10-01 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"
|