Merge branch 'fix/eldap-warnings' into 'develop'
[akkoma] / lib / pleroma / emails / admin_email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.AdminEmail do
6 @moduledoc "Admin emails"
7
8 import Swoosh.Email
9
10 alias Pleroma.Web.Router.Helpers
11
12 defp instance_config, do: Pleroma.Config.get(:instance)
13 defp instance_name, do: instance_config()[:name]
14 defp instance_email, do: instance_config()[:email]
15
16 defp user_url(user) do
17 Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.nickname)
18 end
19
20 def report(to, reporter, account, statuses, comment) do
21 comment_html =
22 if comment do
23 "<p>Comment: #{comment}"
24 else
25 ""
26 end
27
28 statuses_html =
29 if length(statuses) > 0 do
30 statuses_list_html =
31 statuses
32 |> Enum.map(fn
33 %{id: id} ->
34 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
35 "<li><a href=\"#{status_url}\">#{status_url}</li>"
36
37 id when is_binary(id) ->
38 "<li><a href=\"#{id}\">#{id}</li>"
39 end)
40 |> Enum.join("\n")
41
42 """
43 <p> Statuses:
44 <ul>
45 #{statuses_list_html}
46 </ul>
47 </p>
48 """
49 else
50 ""
51 end
52
53 html_body = """
54 <p>Reported by: <a href="#{user_url(reporter)}">#{reporter.nickname}</a></p>
55 <p>Reported Account: <a href="#{user_url(account)}">#{account.nickname}</a></p>
56 #{comment_html}
57 #{statuses_html}
58 """
59
60 new()
61 |> to({to.name, to.email})
62 |> from({instance_name(), instance_email()})
63 |> reply_to({reporter.name, reporter.email})
64 |> subject("#{instance_name()} Report")
65 |> html_body(html_body)
66 end
67 end