Class: ImapGuard::Query
- Inherits:
-
Array
- Object
- Array
- ImapGuard::Query
- Defined in:
- lib/imap_guard/query.rb
Overview
All methods return self so they can be chained.
Query is a neat DSL to help you generate IMAP search queries.
Instance Method Summary collapse
-
#before(date) ⇒ self
Messages whose internal date (disregarding time and timezone) is earlier than the specified date.
-
#cc(string) ⇒ self
Messages that contain the specified string in the envelope structure’s CC field.
-
#deleted ⇒ self
Messages with the
\Deletedflag set. -
#from(string) ⇒ self
Messages that contain the specified string in the envelope structure’s FROM field.
-
#not(search_key = nil) ⇒ self
Messages that do not match the specified search key.
-
#or(search_key1 = nil, search_key2 = nil) ⇒ self
Messages that match either search key.
-
#seen ⇒ self
Messages that have the
\Seenflag set. -
#subject(string) ⇒ self
Messages that contain the specified string in the envelope structure’s SUBJECT field.
-
#to(string) ⇒ self
Messages that contain the specified string in the envelope structure’s TO field.
-
#unanswered ⇒ self
Messages that do not have the
\Answeredflag set. -
#unflagged ⇒ self
Messages that do not have the
\Flaggedflag set. -
#unseen ⇒ self
Messages that do not have the
\Seenflag set.
Instance Method Details
#before(date) ⇒ self
Messages whose internal date (disregarding time and timezone) is earlier than the specified date.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/imap_guard/query.rb', line 104 def before date case date when String # noop, uses it as is when Fixnum date = (Date.today - date).strftime '%e-%b-%Y' when Date date = date.strftime '%e-%b-%Y' else raise ArgumentError, "#{date.inspect} is invalid." end self << 'BEFORE' << date end |
#cc(string) ⇒ self
Messages that contain the specified string in the envelope structure’s CC field.
93 94 95 |
# File 'lib/imap_guard/query.rb', line 93 def cc string self << 'CC' << string end |
#deleted ⇒ self
Messages with the \Deleted flag set.
31 32 33 |
# File 'lib/imap_guard/query.rb', line 31 def deleted self << 'DELETED' end |
#from(string) ⇒ self
Messages that contain the specified string in the envelope structure’s FROM field.
79 80 81 |
# File 'lib/imap_guard/query.rb', line 79 def from string self << 'FROM' << string end |
#not(search_key = nil) ⇒ self
Messages that do not match the specified search key.
63 64 65 66 67 |
# File 'lib/imap_guard/query.rb', line 63 def not search_key = nil self << 'NOT' send(search_key) if search_key self end |
#or(search_key1 = nil, search_key2 = nil) ⇒ self
Reverse polish notation is expected, i.e. OR <search-key1> <search-key2>
Messages that match either search key.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/imap_guard/query.rb', line 44 def or search_key1 = nil, search_key2 = nil self << 'OR' if search_key1 and search_key2 send(search_key1) send(search_key2) elsif search_key1 or search_key2 raise ArgumentError, "You must give either zero or two arguments." end self end |
#seen ⇒ self
Messages that have the \Seen flag set.
7 8 9 |
# File 'lib/imap_guard/query.rb', line 7 def seen self << 'SEEN' end |
#subject(string) ⇒ self
Messages that contain the specified string in the envelope structure’s SUBJECT field.
72 73 74 |
# File 'lib/imap_guard/query.rb', line 72 def subject string self << 'SUBJECT' << string end |
#to(string) ⇒ self
Messages that contain the specified string in the envelope structure’s TO field.
86 87 88 |
# File 'lib/imap_guard/query.rb', line 86 def to string self << 'TO' << string end |
#unanswered ⇒ self
Messages that do not have the \Answered flag set.
19 20 21 |
# File 'lib/imap_guard/query.rb', line 19 def unanswered self << 'UNANSWERED' end |
#unflagged ⇒ self
Messages that do not have the \Flagged flag set.
25 26 27 |
# File 'lib/imap_guard/query.rb', line 25 def unflagged self << 'UNFLAGGED' end |
#unseen ⇒ self
Messages that do not have the \Seen flag set.
13 14 15 |
# File 'lib/imap_guard/query.rb', line 13 def unseen self << 'UNSEEN' end |