~afontaine/home

20fa799847f187fa09e373a41852ec7c6f33b82a — Andrew Fontaine 2 months ago f8f4507
Make Signature Removal a Little More Flexible

Turns out the idea of whitespace after the -- is a bit of a pain to keep
an eye on between email clients, so a small regex should make sure
things are a bit more flexible.

Add a little logging here while we're at it, but it's not very good
logging at the moment. It'll take a bit to work out a proper idea on how
to log.
A .gitattributes => .gitattributes +1 -0
@@ 0,0 1,1 @@
*.mail text eol=crlf

M apps/blog/lib/blog/mail/post.ex => apps/blog/lib/blog/mail/post.ex +1 -1
@@ 29,7 29,7 @@ defmodule Blog.Mail.Post do
      |> Mail.get_text()
      |> Map.get(:body, "")
      |> String.trim()
      |> String.split("\r\n-- \r\n")
      |> String.split(~r/^--\s+$/um)
      |> Enum.drop(-1)
      |> Enum.join("\n")
      |> String.trim()

M apps/home_web/lib/home_web/controllers/receive_controller.ex => apps/home_web/lib/home_web/controllers/receive_controller.ex +4 -4
@@ 6,6 6,10 @@ defmodule HomeWeb.ReceiveController do
  alias Blog.Content

  def receive(conn, post) do
    Logger.info(fn ->
      "Received post: #{inspect(post)}"
    end)

    {:ok, post} =
      case Mail.create_post(post) do
        {:ok, post} ->


@@ 17,10 21,6 @@ defmodule HomeWeb.ReceiveController do
          raise x
      end

    Logger.info(fn ->
      "New post: #{inspect(post)}"
    end)

    conn
    |> put_status(:ok)
    |> text("")

A apps/home_web/priv/fixtures/deploying_this_blog.mail => apps/home_web/priv/fixtures/deploying_this_blog.mail +40 -0
@@ 0,0 1,40 @@
From nobody Thu Jun 10 05:12:06 2021
Authentication-Results: mail-b.sr.ht; dkim=pass header.d=afontaine.ca header.i=@afontaine.ca
Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22])
	by mail-b.sr.ht (Postfix) with ESMTPS id CE20811EF40
	for <~afontaine/blog@lists.sr.ht>; Thu, 10 Jun 2021 05:12:04 +0000 (UTC)
Date: Thu, 10 Jun 2021 05:11:55 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=afontaine.ca;
	s=protonmail2; t=1623301922;
	bh=OImu+d+YzkUD32sg5Jj2wGXaKsXqXXM0VAz3igIbB4I=;
	h=Date:To:From:Reply-To:Subject:From;
	b=jpOxGkKOei9n/3eUgIJXBpo71ovTryTiUwcj6TzD3kDPIMy+7eDFajAnv2MLc9dX+
	 +vjlBNW7oyxQLTzhEEqv7IrMYj2E2c6qH97YBstup1XoUe81hmgFz8RY8YGmXZkhKW
	 D6Drs1aoS5hSMRj5K40AkWq6vZKWIblYMrBFa2p309/dFZ1CLHsPNUOW/p+5yFn0I7
	 KcE85115NMm+HDphmSh7O6whC4rvuvQS17bGjMV0H63e72SjTTPJq0OfZFKK0r9jLT
	 y0JJ+qQ1ZJeeUiLeuBsNH/ayH9EKsuE2eOiIMLOT1XNc0p1Tn9ucWp5TVJY2iueB0m
	 HISva8Cu5NREw==
To: ~afontaine/blog@lists.sr.ht
From: Andrew Fontaine <andrew@example.com>
Reply-To: Andrew Fontaine <andrew@example.com>
Subject: [nix] Deploying This Blog
Message-ID: <87eedunrky.fsf@afontaine.ca>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no
	autolearn=disabled version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
	mailout.protonmail.ch


test
post
test

--

Andrew Fontaine
afontaine.dev


M apps/home_web/test/home_web/controllers/receive_controller_test.exs => apps/home_web/test/home_web/controllers/receive_controller_test.exs +2 -30
@@ 20,35 20,7 @@ defmodule HomeWeb.ReceiveControllerTest do
    "is_request_pull" => false,
    "replies" => 0,
    "participants" => 0,
    "envelope" =>
      Enum.join(
        [
          "From nobody Sat Mar 27 17:31:05 2021",
          "Authentication-Results: mail-b.sr.ht; dkim=pass header.d=afontaine.ca header.i=@afontaine.ca",
          "Received: from mail.example.com (mail.example.com [127.0.0.1])",
          "\tby mail-b.sr.ht (Postfix) with ESMTPS id 9FE5811EF0E",
          "\tfor <~afontaine/example@lists.sr.ht>; Sat, 27 Mar 2021 17:31:03 +0000 (UTC)",
          "Date: Sat, 27 Mar 2021 17:30:53 +0000",
          "To: ~afontaine/blog-testing@lists.sr.ht",
          "From: Andrew Fontaine <andrew@example.com>",
          "Reply-To: Andrew Fontaine <andrew@example.com>",
          "Subject: Test Email Subject",
          "Message-ID: <87k0psv70b.fsf@example.com>",
          "MIME-Version: 1.0",
          "Content-Type: text/plain; charset=utf-8",
          "Content-Transfer-Encoding: quoted-printable",
          "",
          "",
          "test body",
          "",
          "--=20",
          "",
          "Andrew Fontaine",
          "",
          ""
        ],
        "\r\n"
      )
    "envelope" => File.read!("./priv/fixtures/deploying_this_blog.mail")
  }
  describe "POST /api/post/receive" do
    setup %{conn: conn} = context do


@@ 59,7 31,7 @@ defmodule HomeWeb.ReceiveControllerTest do

    test "creates a blog post", %{post: post} do
      assert @valid_attrs["subject"] =~ "#{post.subject}"
      assert post.text == "test body"
      assert post.text == "test\npost\ntest"
    end

    test "creates all the tags for a post", %{post: post} do

M flake.nix => flake.nix +1 -1
@@ 77,7 77,7 @@
          '';
        };
        packages = let
          version = "0.1.3";
          version = "0.1.4";
          src = ./.;
        in flake-utils.lib.flattenTree {
          home-elixir-deps = erlangPackages.fetchMixDeps {

M mix.exs => mix.exs +1 -1
@@ 4,7 4,7 @@ defmodule Home.Umbrella.MixProject do
  def project do
    [
      apps_path: "apps",
      version: "0.1.0",
      version: "0.1.4",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      aliases: aliases(),