Skip to content

Commit

Permalink
compose: prevent trailing spaces on empty headers
Browse files Browse the repository at this point in the history
When using format-flowed=true, you need to configure your editor to
format the text accordingly. With (neo)vim, this is achieved by setting
formatoptions+=w (trailing whitespace indicates paragraph continuation).
This may also be combined with +=a (automatically reflow paragraphs as
you edit).

When also using edit-headers=true, empty header lines are considered
part of the same paragraph (by vim) if they have a trailing space. This
can make editing the headers difficult (the editor may mistakenly join
them together).

To prevent this, vary the separator between header field name and body
depending on whether the body is empty. If so, only use the ":".  This
is valid syntax for the populated case too, but including a space is
aesthetically pleasing, so for that case use ": " as the separator.

Signed-off-by: Jonathan Dowland <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
Jonathan Dowland authored and rjarry committed Dec 16, 2024
1 parent 6736cf0 commit 4f7f5d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,14 @@ func (c *Composer) setContents(reader io.Reader) error {
}
}
key := textproto.CanonicalMIMEHeaderKey(h)
_, err = fmt.Fprintf(c.email, "%s: %s"+lineEnding, key, value)

var sep string
if value == "" {
sep = ":"
} else {
sep = ": "
}
_, err = fmt.Fprintf(c.email, "%s%s%s%s", key, sep, value, lineEnding)
if err != nil {
return err
}
Expand Down

0 comments on commit 4f7f5d4

Please sign in to comment.