From af39c500a40e80d0220e15b875dd48fe2665b44f Mon Sep 17 00:00:00 2001 From: Slobodan Gacesa Date: Thu, 19 Jun 2025 18:45:42 +0200 Subject: [PATCH] Add Subject: search and wildcard support for from:, to:, subject: --- app/controllers/messages_controller.rb | 12 ++++++++++++ app/views/messages/_search.html.haml | 11 +++++++---- lib/postal/message_db/database.rb | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) 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)