+-- {{{ markdown in mail
+local i, _ = string.find(vim.bo.filetype, "markdown")
+if not i then
+  vim.opt_local.filetype = "mail.markdown"
+  -- this should trigger a reload of the ftplugin
+  return
+end
+
+-- There are no diagnostics for mail, but we do not want the
+-- Markdown standards imposed on mail header and signature…
+vim.diagnostic.enable(false)
+vim.b.autoformat = false
+
+-- disable Treesitter format expression for Mail
+vim.opt_local.formatexpr = ""
+-- }}}
+
+-- {{{ formatting
+vim.opt_local.formatoptions:remove("o") -- would insert current comment leader for o/O
+vim.opt_local.formatoptions:remove("r") -- would insert current comment leader for <CR>
+vim.opt_local.formatoptions:remove("l") -- would not break lines that were long before insert
+
+vim.opt_local.commentstring = "> %s" -- commenting means quoting in mails
+-- }}}
+
+-- {{{ autocmds
+vim.api.nvim_create_autocmd({ "BufWrite" }, {
+  buffer = 0,
+  group = vim.api.nvim_create_augroup("squashemptylines", { clear = true }),
+  callback = function()
+    local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
+    local ret = {}
+    local count = 0
+    local squash = false
+    for _, line in ipairs(lines) do
+      if line == "" then
+        if not squash then
+          squash = true
+          table.insert(ret, line)
+        else
+          count = count + 1
+        end
+      else
+        squash = false
+        table.insert(ret, line)
+      end
+    end
+    if count > 0 then
+      vim.notify("Squashed " .. count .. " empty line(s)")
+    end
+    vim.api.nvim_buf_set_lines(0, 0, -1, false, ret)
+  end,
+})
+-- }}}
+
+-- {{{ keymaps
+vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
+vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
+
+vim.keymap.set(
+  "n",
+  "<leader>msn",
+  ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1  (was: \\4),e<CR>:set nohls<CR>Whi",
+  -- <CR><cmd>set nohls<CR>f li",
+  { buffer = true, desc = "make a new subject" }
+)
+vim.keymap.set(
+  "n",
+  "<leader>msd",
+  '1G/\\v^Subject:(.|\\_s\\s+)+was:/e<CR>:set nohls<CR>"_dab',
+  { buffer = true, desc = "remove old subjects" }
+)
+
+-- {{{ profiles