logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

admin_email.ex (2837B)


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