Skip to content

Commit d811a97

Browse files
authored
Merge pull request #9 from modalsource/slobodangacesa-postal-sg-enhanced-search
Replica: Add Subject: search and wildcard support for from:, to:, subject:
2 parents 13436f9 + af39c50 commit d811a97

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

app/controllers/messages_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ def get_messages(scope)
180180
options[:where].delete(:spam)
181181
options[:where].delete(:scope)
182182
end
183+
if qs[:subject]
184+
options[:where][:subject] = {}
185+
options[:where][:subject][:like] = qs[:subject]
186+
end
187+
if qs[:to]
188+
options[:where][:rcpt_to] = {}
189+
options[:where][:rcpt_to][:like] = qs[:to]
190+
end
191+
if qs[:from]
192+
options[:where][:mail_from] = {}
193+
options[:where][:mail_from][:like] = qs[:from]
194+
end
183195
options[:where][:tag] = qs[:tag] if qs[:tag]
184196
options[:where][:id] = qs[:id] if qs[:id]
185197
options[:where][:spam] = true if qs[:spam] == "yes" || qs[:spam] == "y"

app/views/messages/_search.html.haml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
as shown opposite into the box above and press enter.
1414
.messageSearch__right
1515
%dl.messageSearch__definition
16-
%dt to: rachel@example.com
17-
%dd Returns all mail addressed to the address provided.
16+
%dt to: rachel@example.com or to: %rachel%
17+
%dd Returns all mail addressed to the address provided. Use % as wildcard anywhere.
1818
%dl.messageSearch__definition
19-
%dt from: tom@example.com
20-
%dd Returns all mail sent from to the address provided.
19+
%dt from: tom@example.com or from: %@example.com
20+
%dd Returns all mail sent from to the address provided. Use % as wildcard anywhere.
21+
%dl.messageSearch__definition
22+
%dt subject: "any string" or subject: "%any string%"
23+
%dd Returns all mail which subject contains the substring provided. Use % as wildcard anywhere.
2124
%dl.messageSearch__definition
2225
%dt status: pending
2326
%dd Returns all messages with the status provided. The suitable statuses are: <code>pending</code>, <code>sent</code>, <code>held</code>, <code>softfail</code>, <code>hardfail</code> and <code>bounced</code>.

lib/postal/message_db/database.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ def hash_to_sql(hash, joiner = ", ")
368368
sql << "`#{key}` <= #{escape(inner_value)}"
369369
when :greater_than_or_equal_to
370370
sql << "`#{key}` >= #{escape(inner_value)}"
371+
when :like
372+
sql << "`#{key}` LIKE #{escape(inner_value)}"
371373
end
372374
end
373375
sql.empty? ? "1=1" : sql.join(joiner)

0 commit comments

Comments
 (0)