423c294cb77ed5fdd4232a05746362cc4ec8a9bf
[akkoma] / lib / pleroma / emails / admin_email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emails.AdminEmail do
6 @moduledoc "Admin emails"
7
8 import Swoosh.Email
9
10 alias Pleroma.Config
11 alias Pleroma.HTML
12 alias Pleroma.Web.Router.Helpers
13
14 defp instance_config, do: Config.get(:instance)
15 defp instance_name, do: instance_config()[:name]
16
17 defp instance_notify_email do
18 Keyword.get(instance_config(), :notify_email, instance_config()[:email])
19 end
20
21 defp user_url(user) do
22 Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
23 end
24
25 def test_email(mail_to \\ nil) do
26 html_body = """
27 <h3>Instance Test Email</h3>
28 <p>A test email was requested. Hello. :)</p>
29 """
30
31 new()
32 |> to(mail_to || Config.get([:instance, :email]))
33 |> from({instance_name(), instance_notify_email()})
34 |> subject("Instance Test Email")
35 |> html_body(html_body)
36 end
37
38 def report(to, reporter, account, statuses, comment) do
39 comment_html =
40 if comment do
41 "<p>Comment: #{comment}"
42 else
43 ""
44 end
45
46 statuses_html =
47 if is_list(statuses) && length(statuses) > 0 do
48 statuses_list_html =
49 statuses
50 |> Enum.map(fn
51 %{id: id} ->
52 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
53 "<li><a href=\"#{status_url}\">#{status_url}</li>"
54
55 %{"id" => id} when is_binary(id) ->
56 "<li><a href=\"#{id}\">#{id}</li>"
57
58 id when is_binary(id) ->
59 "<li><a href=\"#{id}\">#{id}</li>"
60 end)
61 |> Enum.join("\n")
62
63 """
64 <p> Statuses:
65 <ul>
66 #{statuses_list_html}
67 </ul>
68 </p>
69 """
70 else
71 ""
72 end
73
74 html_body = """
75 <p>Reported by: <a href="#{user_url(reporter)}">#{reporter.nickname}</a></p>
76 <p>Reported Account: <a href="#{user_url(account)}">#{account.nickname}</a></p>
77 #{comment_html}
78 #{statuses_html}
79 <p>
80 <a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/reports/index">View Reports in AdminFE</a>
81 """
82
83 new()
84 |> to({to.name, to.email})
85 |> from({instance_name(), instance_notify_email()})
86 |> subject("#{instance_name()} Report")
87 |> html_body(html_body)
88 end
89
90 def new_unapproved_registration(to, account) do
91 html_body = """
92 <p>New account for review: <a href="#{user_url(account)}">@#{account.nickname}</a></p>
93 <blockquote>#{HTML.strip_tags(account.registration_reason)}</blockquote>
94 <a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a>
95 """
96
97 new()
98 |> to({to.name, to.email})
99 |> from({instance_name(), instance_notify_email()})
100 |> subject("New account up for review on #{instance_name()} (@#{account.nickname})")
101 |> html_body(html_body)
102 end
103 end