Frederick888 / external-editor-revived

External Editor Revived is a Thunderbird MailExtension which allows editing emails in programs such as Vim, Neovim, Emacs, etc.
GNU General Public License v3.0
113 stars 6 forks source link

How to suppress X-ExtEditorR-* headers or all headers #139

Open reagle opened 11 months ago

reagle commented 11 months ago

I recently upgraded to the new plugin and message host and now see lots of X-ExtEditorR-* headers I'd rather not see. How to suppress them?

Environment

| macOS 13.6.1 22G313 arm64 | thunderbird: 115.5.1 | External Editor 1.0 | External Editor Revived native messaging host for macos (aarch64) v1.0.0

SCR-20231205-nzsh SCR-20231205-oadn
Frederick888 commented 11 months ago

This is not possible directly in EER.

However you can:

  1. Fold them in your editor (best) In Vim/Neovim this is as simple as

    setl foldexpr=getline(v:lnum)=~'^X-ExtEditorR'?1:0
    setl foldmethod=expr
    setl foldlevel=0

    I'd be surprised if Sublime doesn't support something similar. A more complete setup in Neovim Lua can be (screen recording below):

    local M              = {}
    local api            = vim.api
    
    local MAX_SCAN_LINES = 50
    function M.first_empty_line(bufnr)
      local lines = api.nvim_buf_get_lines(bufnr, 0, MAX_SCAN_LINES, false)
      for i, l in ipairs(lines) do
        if l:len() == 0 then
          return i - 1
        end
      end
      return nil
    end
    
    function M.foldexpr(lnum)
      local line_num = lnum - 1
      local first_empty = M.first_empty_line(0)
      if first_empty ~= nil and line_num >= first_empty then
        return 0
      end
      local line = api.nvim_buf_get_lines(0, line_num, line_num + 1, false)[1]
      if (line:match('^X%-ExtEditorR:') or line:match('^X%-ExtEditorR%-')) and not line:match('^X%-ExtEditorR%-X%-ExtEditorR') then
        return 2
      end
      if line:match('^Cc:') or line:match('^Bcc:') or line:match('^Reply%-To:') then
        return 1
      end
      return 0
    end
    
    function M.setup()
      api.nvim_create_autocmd({ 'FileType' }, {
        pattern = { 'mail' },
        callback = function()
          vim.opt_local.foldmethod = 'expr'
          vim.opt_local.foldexpr = 'v:lua.require("user/mail").foldexpr(v:lnum)'
          --- set to 1 to fold X-ExtEditorR headers; set to 0 to fold Cc/Bcc/Reply-To as well
          vim.opt_local.foldlevel = 1
        end
      })
    end
  2. Have you tried 'Meta Headers'? (better) Is it still too overwhelming with it on?
  3. Use a custom script to remove them (meh) You can delete the headers if you don't need them. EER won't touch those options just because they are missing. Simply something like rg -v '^X-ExtEditorR-' <"$1" | sponge "$1", then start your editor.

https://github.com/Frederick888/external-editor-revived/assets/4507647/13b27403-a42b-492c-840c-71c34ceb264c


While I agree the headers certainly take a bit more space now, the 'meta headers' were the best I could come up with to ameliorate it.

Offering a 'compact mode' with a subset of the headers? But how do I know which headers are more important? Personally I use Send-On-Exit quite often. Attach-vCard and Delivery-Status-Notification? Maybe. Priority? Rarer. Delivery-Format? You probably don't want to change that. Anyway these are all what I think. I do not know what users think. And I do not want them to manually type up the headers.

Making headers individually configurable? That'd be quite some effort for a very small gain. It won't be as nice as the Vim/Neovim folds, and it'll be a lot more noise in EER's configurations.

reagle commented 11 months ago

@Frederick888, yikes! I appreciate the help but I want to keep it simple. I'd go back a version if I could but I try to stay up to date with TB and had to upgrade. Some questions.

  1. Could all of these headers be called verbose/advanced mode and disabled with a toggle?
  2. Why is your multi-line format called "meta"?
ondohotola commented 11 months ago

This is really a nuisance for me as well.

Frederick888 commented 11 months ago

@Frederick888, yikes!

'How is this a "yikes"?! It's an elegant solution where a mostly presentation problem was taken care of by the presentation layer. Not only did it achieve this without any information loss, but also gave users the flexibility... (bla bla bla)'

This was my first reaction to your comment; this is how different people can be; and this is how different the users of EER, despite the small number, can be.

So I think we must not jump the gun and deliver any half-baked features. For example,

  1. Could all of these headers be called verbose/advanced mode and disabled with a toggle?

This is not very different from the 'compact mode' I described above. If there were such a toggle, users might well just ask something similar along the lines of 'I like the non-verbose mode, but I also need one of those headers, can I have just one of them in this mode?' I know I would've asked, for Send-On-Exit at least.

But anyway, all fluffy talks aside, for a niche project like EER, it first and foremost has to fit my vision and schedule. And for three more lines of headers I simply don't think it's worth implementing or maintaining a new feature, especially considering it can be very easily tackled by a few lines of Bash script.

However let's say the deal is not completely off the table. When the X-ExtEditorR headers grow beyond 5 lines with the Meta Headers on, I can re-evaluate this. I've actually been considering some so-called 'focus mode' or 'zen mode', where EER writes only the subject and the body to a file, since it's unlikely someone wants to change From/To/etc. without TB's auto-completion. To me this sounds more like a proper feature. (I've taken the liberty to change the title of this issue.)

For now I'd like to help people discover the Meta Headers first. I've added a new section to the FAQs [1].

  1. Why is your multi-line format called "meta"?

Since the 'X-ExtEditorR' header by itself does nothing. It's a header solely about other headers, therefore a 'meta' header :)

[1] https://github.com/Frederick888/external-editor-revived/wiki#there-are-too-many-x-exteditorr--headers-what-can-i-do

ondohotola commented 11 months ago

Frederick,

whether it is a niche project or not, it is highly addictive once discovered :-)-O

I like the Zen Mode idea, as I do all my To/CC/BCC in TBird itself anyway.

I have been unable to find a nice Sublime Text extension to format emails, are you aware of one?

el

reagle commented 11 months ago

@Frederick888, my apologies, I didn't mean to offend.

I'll simply note that body, Subject, To, CC, and BCC are the only headers I care to edit and see.

@ondohotola, I find editing To, CC, BCC in TB a nuisance and wonder how you manage? I often have to resort to using my pointer to select addresses (which can be fiddly) or repeatedly alt-clicking to get to "move to". I love editing those in a text editor with keyboard only.

ondohotola commented 11 months ago

Joseph

I have a large address book and doing this by keyboard (only) is impossible for me :-)-O

reagle commented 11 months ago

Ah. I don't create many new emails nor add addresses. I do spend a fair amount of time rearranging addresses between the To and CC to be polite, which I do like doing in the text editor.

Frederick888 commented 10 months ago

Frederick, whether it is a niche project or not, it is highly addictive once discovered :-)-O

Thank you.

I have been unable to find a nice Sublime Text extension to format emails, are you aware of one?

I don't use Sublime so I have no idea ¯\_(ツ)_/¯. Sublime does seem to have some EML syntax support, maybe you can pair one of them with rulers like https://forum.sublimetext.com/t/support-the-popular-git-commit-message-format/39104/2.

@Frederick888, my apologies, I didn't mean to offend.

Nah, I was kinda joking.

I do spend a fair amount of time rearranging addresses between the To and CC to be polite, which I do like doing in the text editor.

Well, case in point... :P

ondohotola commented 10 months ago

I found (after a little prompting on the Usenet :-)-O) the Command-R 'Rewrap' command in TBird, which in combination with Sublime Text works so well that so would like if you added it to the defaults :-)-O

/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -w "/path/to/temp.eml"

(one line, note the \ before the space) works very well though.

Will be playing on the MacBook for a while and if it works well enough will toss Alpha and reconfigure the iMac.

Thank you again, el