Skip to content

Commit

Permalink
add host envs to make it works with proxy
Browse files Browse the repository at this point in the history
add github link
add searching in to and from headers
add confirm modal for deleting mails
fix submit event on search input
fix notifications
  • Loading branch information
adrid committed Jan 27, 2021
1 parent 34ae77a commit 93a0cc8
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
fi
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
TAGS="$TAGS"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ Email testing tool for developers. Works as a SMTP server to catch sent mails an
* OpenSSL

## ENV options
* PORT - default 4000 - web ui port
* SMTP_PORT - default 2525 - SMPT server port
* SIZE_LIMIT - default 1GB - limits the size of the storage for mails. After passing this limit the app will start removing oldest mails until the size will be under the limit again. Accepts MB and GB postfix (for example 4GB, 100MB).
* PORT - default `4000` - web ui port
* SMTP_PORT - default `2525` - SMPT server port
* SIZE_LIMIT - default `1GB` - limits the size of the storage for mails. After passing this limit the app will start removing oldest mails until the size will be under the limit again. Accepts MB and GB postfix (for example 4GB, 100MB).
* HOST_URL - default `localhost` - url to generate internal urls - to use if you using some proxy
* HOST_PORT - default `80` - like above
* HOST_SCHEME - default `http` - like above

## Docker
Available on [Docker Hub](https://hub.docker.com/r/adrid/mailsniffex)

Data is saved to `/opt/app/data`

## TODO
* Downloading an original email
Expand Down
Binary file added assets/static/images/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions config/releases.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ config :mail_sniffex,
size_limit: System.get_env("SIZE_LIMIT") || "1GB"

config :mail_sniffex, MailSniffexWeb.Endpoint,
url: [
host: System.get_env("HOST_URL") || "localhost",
port: System.get_env("HOST_PORT") || System.get_env("PORT") || "4000",
scheme: System.get_env("HOST_SCHEME") || "http"
],
http: [
port: String.to_integer(System.get_env("PORT") || "4000"),
transport_options: [socket_opts: [:inet6]]
Expand Down
2 changes: 1 addition & 1 deletion lib/mail_sniffex/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule MailSniffex.DB do
if options.search_text === "" do
true
else
el.headers["Subject"]
el.headers["Subject"] <> el.headers["From"] <> el.headers["To"]
|> String.downcase()
|> String.contains?(options.search_text |> String.downcase())
end
Expand Down
46 changes: 46 additions & 0 deletions lib/mail_sniffex_web/live/confirm_modal.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule MailSniffexWeb.Live.ConfirmModal do
use Surface.LiveComponent

prop title, :string, required: true
prop confirmEvent, :event, required: true

data show, :boolean, default: false


def render(assigns) do
~H"""
<div class={{ "modal", "is-active": @show }}>
<div class="modal-background" :on-click="hide"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">{{ @title }}</p>
<button class="delete" aria-label="close" :on-click="hide"></button>
</header>
<section class="modal-card-body">
<slot/>
</section>
<footer class="modal-card-foot" style="justify-content: flex-end">
<button class="button is-success" :on-click={{@confirmEvent}}>Yes</button>
<button class="button" :on-click="hide">Cancel</button>
</footer>
</div>
</div>
"""
end

def show(dialog_id) do
send_update(__MODULE__, id: dialog_id, show: true)
end

def hide(dialog_id) do
send_update(__MODULE__, id: dialog_id, show: false)
end

def handle_event("show", _, socket) do
{:noreply, assign(socket, show: true)}
end

def handle_event("hide", _, socket) do
{:noreply, assign(socket, show: false)}
end
end
18 changes: 17 additions & 1 deletion lib/mail_sniffex_web/live/header.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule MailSniffexWeb.Live.Header do
use Surface.LiveView
alias Surface.Components.LiveRedirect
alias MailSniffexWeb.Live.ConfirmModal

@env Application.compile_env(:mail_sniffex, :environment)

Expand All @@ -24,7 +25,7 @@ defmodule MailSniffexWeb.Live.Header do
limit = MailSniffex.SizeWatcher.get_size_limit()
env = @env
~H"""
<header phx-hook="Header" class="header">
<header phx-hook="Header" class="header" id="header">
<div class="content">
<div class="columns">
<div class="column">
Expand All @@ -43,10 +44,19 @@ defmodule MailSniffexWeb.Live.Header do
<a href="#" class="button is-inline-block" :on-click="clear_btn_click">Clear inbox</a>
</div>
<div class="column has-text-right">
<a href="https://github.com/adrid/MailSniffex" target="_blank" class="button is-text">
<span class="icon">
<img src="/images/github.png">
</span>
<span>GitHub</span>
</a>
</div>
</div>
</div>
</header>
<ConfirmModal id="clear-confirm" title="Confirm action" confirmEvent="clear_mails">
Do you really want to delete all mails?
</ConfirmModal>
"""
end

Expand All @@ -55,9 +65,15 @@ defmodule MailSniffexWeb.Live.Header do
end

def handle_event("clear_btn_click", _, socket) do
ConfirmModal.show("clear-confirm")
{:noreply, socket}
end

def handle_event("clear_mails", _, socket) do
MailSniffex.DB.clean_db()
MailSniffex.SizeWatcher.request_current_size()
Phoenix.PubSub.broadcast(MailSniffex.PubSub, "messages", {:messages_cleared})
ConfirmModal.hide("clear-confirm")
{:noreply, socket}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mail_sniffex_web/live/message_list_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule MailSniffexWeb.Live.MessageListLive do
<div id="message-list-view">
<div class="is-flex">
<div class="is-flex-grow-1">
<Form for={{ :search_form }} change="change" opts={{ autocomplete: "off" }}>
<Form for={{ :search_form }} change="change" submit="change" opts={{ autocomplete: "off" }}>
<Field name="text">
<div class="control">
<TextInput opts={{placeholder: "Search...", "phx-debounce": "500"}} class="input is-primary" value={{ @search_form.text }} />
Expand Down

0 comments on commit 93a0cc8

Please sign in to comment.