summaryrefslogtreecommitdiff
path: root/fake-service/lib/smail/search
diff options
context:
space:
mode:
Diffstat (limited to 'fake-service/lib/smail/search')
-rw-r--r--fake-service/lib/smail/search/and_match.rb25
-rw-r--r--fake-service/lib/smail/search/negate_match.rb22
-rw-r--r--fake-service/lib/smail/search/or_match.rb25
-rw-r--r--fake-service/lib/smail/search/scope_match.rb79
-rw-r--r--fake-service/lib/smail/search/string_match.rb37
-rw-r--r--fake-service/lib/smail/search/true_match.rb13
6 files changed, 201 insertions, 0 deletions
diff --git a/fake-service/lib/smail/search/and_match.rb b/fake-service/lib/smail/search/and_match.rb
new file mode 100644
index 00000000..2bc53f0d
--- /dev/null
+++ b/fake-service/lib/smail/search/and_match.rb
@@ -0,0 +1,25 @@
+module Smail
+ class Search
+ class AndMatch
+ attr_reader :data
+ def initialize(data = [])
+ @data = data
+ end
+ def <<(node)
+ @data << node
+ end
+
+ def to_s
+ "And(#{@data.join(", ")})"
+ end
+
+ def match?(mail)
+ self.data.all? { |mm| mm.match?(mail) }
+ end
+
+ def match_string?(str)
+ self.data.all? { |mm| mm.match_string?(str) }
+ end
+ end
+ end
+end
diff --git a/fake-service/lib/smail/search/negate_match.rb b/fake-service/lib/smail/search/negate_match.rb
new file mode 100644
index 00000000..f8bb59d4
--- /dev/null
+++ b/fake-service/lib/smail/search/negate_match.rb
@@ -0,0 +1,22 @@
+module Smail
+ class Search
+ class NegateMatch
+ attr_reader :data
+ def initialize(data)
+ @data = data
+ end
+
+ def to_s
+ "Negate(#@data)"
+ end
+
+ def match?(mail)
+ !self.data.match?(mail)
+ end
+
+ def match_string?(str)
+ !self.data.match_string?(str)
+ end
+ end
+ end
+end
diff --git a/fake-service/lib/smail/search/or_match.rb b/fake-service/lib/smail/search/or_match.rb
new file mode 100644
index 00000000..455923bf
--- /dev/null
+++ b/fake-service/lib/smail/search/or_match.rb
@@ -0,0 +1,25 @@
+module Smail
+ class Search
+ class OrMatch
+ attr_reader :left, :right
+ def initialize(left, right)
+ @left = left
+ @right = right
+ end
+ def <<(node)
+ @right << node
+ end
+ def to_s
+ "Or(#@left, #@right)"
+ end
+
+ def match?(mail)
+ [@left, @right].any? { |mm| mm.match?(mail) }
+ end
+
+ def match_string?(str)
+ [@left, @right].any? { |mm| mm.match_string?(str) }
+ end
+ end
+ end
+end
diff --git a/fake-service/lib/smail/search/scope_match.rb b/fake-service/lib/smail/search/scope_match.rb
new file mode 100644
index 00000000..4402674d
--- /dev/null
+++ b/fake-service/lib/smail/search/scope_match.rb
@@ -0,0 +1,79 @@
+
+module Smail
+ class Search
+ class ScopeMatch
+ def initialize(scope, data)
+ @scope = scope.downcase.gsub(/-/, '_').to_sym
+ @data = data
+ end
+
+ def to_s
+ "Scope(#@scope, #@data)"
+ end
+
+ def is_search_scope?
+ [:in, :tag, :is].include?(@scope) &&
+ %w(_default_ trash all sent drafts).include?(@data.match_string.downcase)
+ end
+
+ def search_scope
+ case @data.match_string.downcase
+ when '_default_'
+ Smail::MailScopeFilter::Default
+ when 'all'
+ Smail::MailScopeFilter::All
+ when 'trash'
+ Smail::MailScopeFilter::Trash
+ when 'sent'
+ Smail::MailScopeFilter::Sent
+ when 'drafts'
+ Smail::MailScopeFilter::Drafts
+ end
+ end
+
+ def match?(mail)
+ strs =
+ case @scope
+ when :to
+ mail.to
+ when :from, :sender
+ mail.from
+ when :cc
+ mail.headers[:cc]
+ when :bcc
+ mail.headers[:bcc]
+ when :subject
+ mail.subject
+ when :rcpt, :rcpts, :recipient, :recipients
+ [mail.to, mail.headers[:cc], mail.headers[:bcc]].flatten.compact
+ when :body
+ mail.body
+ when :tag, :tags, :in
+ return @data.match_exact_string?(mail.tag_names)
+ # has:seal, has:imprint, has:lock
+ when :is
+ case @data.str
+ when "starred"
+ return mail.starred?
+ when "read"
+ return mail.read?
+ when "replied"
+ return mail.replied?
+ # sealed, imprinted, signed, locked, encrypted,
+ else
+ raise "NOT IMPLEMENTED: is:#{@data}"
+ end
+ when :before
+ raise "NOT IMPLEMENTED"
+ when :after
+ raise "NOT IMPLEMENTED"
+ when :att, :attachment
+ raise "NOT IMPLEMENTED"
+ else
+ mail.headers[@scope] || (return false)
+ end
+ @data.match_string? strs
+ end
+ end
+ end
+end
diff --git a/fake-service/lib/smail/search/string_match.rb b/fake-service/lib/smail/search/string_match.rb
new file mode 100644
index 00000000..fc17ab59
--- /dev/null
+++ b/fake-service/lib/smail/search/string_match.rb
@@ -0,0 +1,37 @@
+module Smail
+ class Search
+ class StringMatch
+ attr_reader :str
+ def initialize(data, quoted=false)
+ @str = data
+ @quoted = quoted
+ @data = Regexp.new(Regexp.quote(self.match_string), Regexp::IGNORECASE)
+ @exact_match = /^#{@data}$/
+ end
+
+ def match_string
+ if @quoted
+ @str[1..-2]
+ else
+ @str
+ end
+ end
+
+ def to_s
+ "String(#@data)"
+ end
+
+ def match_string?(str)
+ Array(str).any? { |ff| !!(ff[@data]) }
+ end
+
+ def match_exact_string?(str)
+ Array(str).any? { |ff| @exact_match.match ff }
+ end
+
+ def match?(mail)
+ match_string? [mail.to, mail.from, mail.subject, mail.body]
+ end
+ end
+ end
+end
diff --git a/fake-service/lib/smail/search/true_match.rb b/fake-service/lib/smail/search/true_match.rb
new file mode 100644
index 00000000..7ac14923
--- /dev/null
+++ b/fake-service/lib/smail/search/true_match.rb
@@ -0,0 +1,13 @@
+module Smail
+ class Search
+ class TrueMatch
+ def match?(mail)
+ true
+ end
+
+ def match_string?(str)
+ true
+ end
+ end
+ end
+end