sieve-parser 0.0.5 → 0.0.6

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.
@@ -1,3 +1,5 @@
1
+ require "split-where"
2
+
1
3
  module Sieve
2
4
  %w(filterset filter action condition vacation).each do |entity|
3
5
  require_relative "sieve-parser/#{entity}"
@@ -3,7 +3,7 @@
3
3
  module Sieve
4
4
  # This class contains the attributes of conditions/tests
5
5
  class Condition
6
- attr_accessor :test,:not,:arg1,:arg2,:type, :text
6
+ attr_accessor :test,:not,:arg1,:arg2,:type,:type_value, :comparator, :text
7
7
 
8
8
  # Create Condition object by text of condition or params
9
9
  #@note Example:
@@ -22,6 +22,7 @@ module Sieve
22
22
  @arg1=params[:arg1]
23
23
  @arg2=params[:arg2]
24
24
  @type= params[:type]
25
+ @comparator= params[:comparator] ? params[:comparator] : "i;ascii-numeric"
25
26
  parse unless @text.nil?
26
27
  end
27
28
  # Return a array of conditions after parse the text
@@ -32,8 +33,9 @@ module Sieve
32
33
  #@return [Array(Contition)] array of Condition
33
34
  def self.parse_all(text)
34
35
  contitions = []
35
- text.scan(/([\s\w:]*\"\S+\"\s\"[\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*\")/).each do |item|
36
- contitions << self.new(text:item[0])
36
+ #text.scan(/([\s\w:]*\"\S+\"\s\"[\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*\")/).each do |item|
37
+ text.split_where(value:",",outside:'"').each do |item|
38
+ contitions << self.new(text:item.strip)
37
39
  end
38
40
  contitions
39
41
  end
@@ -42,7 +44,16 @@ module Sieve
42
44
  #@return [string] text of action
43
45
  def to_s
44
46
  text =""
45
- {"not"=>@not,'test'=>@test,'type'=>@type,'arg1'=>@arg1,'arg2'=>@arg2}.each do |name, item|
47
+ {
48
+ 'not'=>@not,
49
+ 'test'=>@test,
50
+ 'type'=>@type,
51
+ 'type_value'=>@type_value,
52
+ 'comparator_name'=>(":comparator" if [":count", ":value"].index(@type)),
53
+ 'comparator'=>(@comparator if [":count", ":value"].index(@type)),
54
+ 'arg1'=>@arg1,
55
+ 'arg2'=>@arg2
56
+ }.each do |name, item|
46
57
  if ['arg1','arg2'].index(name)
47
58
  text += "\"#{item}\" " unless item.nil?
48
59
  else
@@ -63,22 +74,39 @@ module Sieve
63
74
  return
64
75
  end
65
76
 
66
- res = @text.scan(/(([\s\w:]+)\"(\S+)\"\s\"([\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*)\"|true)/)
77
+ #res = @text.scan(/(([\s\w:]+)\"(\S+)\"\s\"([\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*)\"|true)/)
78
+ params = @text.split_where(value:" ",outside:'"')
67
79
 
68
- params = res[0][1].strip.split(" ")
69
- params += [res[0][2]] + [res[0][3]]
70
-
80
+ # header :contains "Subject" "lala"
81
+ # not header :contains "Subject" "popo"
82
+ # not exists "Subject"
83
+ # exists "Subject"
84
+ # header :count "ge" :comparator "i;ascii-numeric" "Subject" "1"
85
+ # header :count "gt" :comparator "i;ascii-numeric" "Subject" "3"
86
+ # header :count "lt" :comparator "i;ascii-numeric" "Subject" "5"
87
+ # header :count "eq" :comparator "i;ascii-numeric" "Subject" "7"
88
+ # header :value "gt" :comparator "i;ascii-numeric" "Subject" "9"
89
+ # header :value "eq" :comparator "i;ascii-numeric" "Subject" "11"
90
+ x = -1
71
91
  if params[0] == "not"
72
- @not = params[0]
73
- @test = params[1]
74
- @type = params[2]
75
- @arg1 = params[3]
76
- @arg2 = params[4]
77
- else
78
- @test = params[0]
79
- @type = params[1]
80
- @arg1 = params[2]
81
- @arg2 = params[3]
92
+ @not = params[x+=1]
93
+ end
94
+
95
+ if @text =~ /contains/
96
+ @test = params[x+=1]
97
+ @type = params[x+=1]
98
+ @arg1 = params[x+=1].delete('"')
99
+ @arg2 = params[x+=1].delete('"')
100
+ elsif @text =~ /exists/
101
+ @test = params[x+=1]
102
+ @arg1 = params[x+=1].delete('"')
103
+ elsif @text =~ /count/ && @text =~ /comparator/
104
+ @test = params[x+=1]
105
+ @type = params[x+=1]
106
+ @type_value = params[x+=1]
107
+ @comparator = params[x+=2]
108
+ @arg1 = params[x+=1].delete('"')
109
+ @arg2 = params[x+=1].delete('"')
82
110
  end
83
111
  end
84
112
  end
@@ -1,9 +1,11 @@
1
1
  # -*- coding: UTF-8 -*-
2
2
  # This class implements a parse of sieve filter and returns a object
3
3
  # to manipulate
4
+ #
4
5
  # @author Thiago Coutinho<thiago @ osfeio.com>(selialkile)
5
6
  # @note This code folow de "THE BEER-WARE LICENSE"
6
7
  module Sieve
8
+ #TODO:For future, Filter will be has a childrem, and make more complex filter
7
9
  class Filter
8
10
 
9
11
  #@note [join] can be: any, allof or anyof
@@ -2,12 +2,13 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = 'sieve-parser'
5
- s.version = '0.0.5'
5
+ s.version = '0.0.6'
6
6
  s.summary = 'A Ruby library for sieve parser'
7
7
  s.description = <<-EOF
8
8
  sieve-parser is a pure-ruby implementation for parsing and
9
9
  manipulate the sieve scripts.
10
10
  EOF
11
+ s.add_dependency 'split-where'
11
12
  s.requirements << 'A sieve script to parse and gem ruby-managesieve to connect on server.'
12
13
  s.files = [
13
14
  'lib/sieve-parser',
@@ -21,8 +22,8 @@ spec = Gem::Specification.new do |s|
21
22
  ]
22
23
 
23
24
  s.has_rdoc = true
24
- s.author = 'Thiago Coutinho'
25
- s.email = 'thiago.coutinho@locaweb.com.br'
25
+ s.author = 'Thiago Coutinho (www.locaweb.com.br)'
26
+ s.email = 'thiago@osfeio.com'
26
27
  s.rubyforge_project = 'sieve-parser'
27
28
  s.homepage = "http://github.com/selialkile/sieve-parser"
28
29
  end
metadata CHANGED
@@ -1,19 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sieve-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Thiago Coutinho
8
+ - Thiago Coutinho (www.locaweb.com.br)
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-10-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: split-where
16
+ requirement: &2160457600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2160457600
14
25
  description: ! " sieve-parser is a pure-ruby implementation for parsing and \n
15
26
  \ manipulate the sieve scripts.\n"
16
- email: thiago.coutinho@locaweb.com.br
27
+ email: thiago@osfeio.com
17
28
  executables: []
18
29
  extensions: []
19
30
  extra_rdoc_files: []