diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index ea0e940ce..e470e22ff 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -180,6 +180,18 @@ def get_messages(scope)
options[:where].delete(:spam)
options[:where].delete(:scope)
end
+ if qs[:subject]
+ options[:where][:subject] = {}
+ options[:where][:subject][:like] = qs[:subject]
+ end
+ if qs[:to]
+ options[:where][:rcpt_to] = {}
+ options[:where][:rcpt_to][:like] = qs[:to]
+ end
+ if qs[:from]
+ options[:where][:mail_from] = {}
+ options[:where][:mail_from][:like] = qs[:from]
+ end
options[:where][:tag] = qs[:tag] if qs[:tag]
options[:where][:id] = qs[:id] if qs[:id]
options[:where][:spam] = true if qs[:spam] == "yes" || qs[:spam] == "y"
diff --git a/app/views/messages/_search.html.haml b/app/views/messages/_search.html.haml
index 415612e00..46c8764b2 100644
--- a/app/views/messages/_search.html.haml
+++ b/app/views/messages/_search.html.haml
@@ -13,11 +13,14 @@
as shown opposite into the box above and press enter.
.messageSearch__right
%dl.messageSearch__definition
- %dt to: rachel@example.com
- %dd Returns all mail addressed to the address provided.
+ %dt to: rachel@example.com or to: %rachel%
+ %dd Returns all mail addressed to the address provided. Use % as wildcard anywhere.
%dl.messageSearch__definition
- %dt from: tom@example.com
- %dd Returns all mail sent from to the address provided.
+ %dt from: tom@example.com or from: %@example.com
+ %dd Returns all mail sent from to the address provided. Use % as wildcard anywhere.
+ %dl.messageSearch__definition
+ %dt subject: "any string" or subject: "%any string%"
+ %dd Returns all mail which subject contains the substring provided. Use % as wildcard anywhere.
%dl.messageSearch__definition
%dt status: pending
%dd Returns all messages with the status provided. The suitable statuses are: pending, sent, held, softfail, hardfail and bounced.
diff --git a/lib/postal/message_db/database.rb b/lib/postal/message_db/database.rb
index 52f456986..d197fd7ae 100644
--- a/lib/postal/message_db/database.rb
+++ b/lib/postal/message_db/database.rb
@@ -368,6 +368,8 @@ def hash_to_sql(hash, joiner = ", ")
sql << "`#{key}` <= #{escape(inner_value)}"
when :greater_than_or_equal_to
sql << "`#{key}` >= #{escape(inner_value)}"
+ when :like
+ sql << "`#{key}` LIKE #{escape(inner_value)}"
end
end
sql.empty? ? "1=1" : sql.join(joiner)