Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'clear' messages as a configurable option #447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/mail_catcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def log_exception(message, context, exception)
:daemon => !windows?,
:browse => false,
:quit => true,
:clear_messages => true,
}

def options
Expand All @@ -103,6 +104,10 @@ def quittable?
options[:quit]
end

def clear_messages_allowed?
options[:clear_messages]
end

def parse! arguments=ARGV, defaults=@defaults
@@defaults.dup.tap do |options|
OptionParser.new do |parser|
Expand Down Expand Up @@ -146,6 +151,10 @@ def parse! arguments=ARGV, defaults=@defaults
options[:quit] = false
end

parser.on("--no-clear-messages", "Don't allow clearning messages") do
options[:clear_messages] = false
end

if mac?
parser.on("--[no-]growl") do |growl|
puts "Growl is no longer supported"
Expand Down
22 changes: 15 additions & 7 deletions lib/mail_catcher/web/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ def asset_path(filename)
end

delete "/messages" do
Mail.delete!
status 204
if MailCatcher.clear_messages_allowed?
Mail.delete!
status 204
else
status 403
end
end

get "/messages/:id.json" do
Expand Down Expand Up @@ -162,12 +166,16 @@ def asset_path(filename)
end

delete "/messages/:id" do
id = params[:id].to_i
if Mail.message(id)
Mail.delete_message!(id)
status 204
if MailCatcher.clear_messages_allowed?
id = params[:id].to_i
if Mail.message(id)
Mail.delete_message!(id)
status 204
else
not_found
end
else
not_found
status 403
end
end

Expand Down
4 changes: 3 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<nav class="app">
<ul>
<li class="search"><input type="search" name="search" placeholder="Search messages..." incremental="true" /></li>
<li class="clear"><a href="#" title="Clear all messages">Clear</a></li>
<% if MailCatcher.clear_messages_allowed? %>
<li class="clear"><a href="#" title="Clear all messages">Clear</a></li>
<% end %>
<% if MailCatcher.quittable? %>
<li class="quit"><a href="#" title="Quit MailCatcher">Quit</a></li>
<% end %>
Expand Down