aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/aerc.conf7
-rw-r--r--config/compose.go1
-rw-r--r--doc/aerc-config.5.scd7
-rw-r--r--widgets/compose.go40
4 files changed, 46 insertions, 9 deletions
diff --git a/config/aerc.conf b/config/aerc.conf
index 46b24f1c..00c8501f 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -383,6 +383,13 @@
#editor=
#
+# When set, aerc will create and read .eml files for composing that have
+# non-standard \n linebreaks. This is only relevant if the used editor does not
+# support CRLF linebreaks.
+#
+#lf-editor=false
+
+#
# Default header fields to display when composing a message. To display
# multiple headers in the same row, separate them with a pipe, e.g. "To|From".
#
diff --git a/config/compose.go b/config/compose.go
index 37e46f96..463723cf 100644
--- a/config/compose.go
+++ b/config/compose.go
@@ -17,6 +17,7 @@ type ComposeConfig struct {
FilePickerCmd string `ini:"file-picker-cmd"`
FormatFlowed bool `ini:"format-flowed"`
EditHeaders bool `ini:"edit-headers"`
+ LFEditor bool `ini:"lf-editor"`
}
var Compose = new(ComposeConfig)
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index b09ce53e..3f0b076a 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -615,6 +615,13 @@ These options are configured in the *[compose]* section of _aerc.conf_.
Default: _false_
+*lf-editor* = _true_|_false_
+ When set, aerc will create and read .eml files for composing that have
+ non-standard \n linebreaks. This is only relevant if the used editor
+ does not support CRLF linebreaks.
+
+ Default: _false_
+
# MULTIPART CONVERTERS
Converters allow generating _multipart/alternative_ messages by converting the
diff --git a/widgets/compose.go b/widgets/compose.go
index f7bce6d4..1c0aaab5 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -462,11 +462,18 @@ func (c *Composer) updateCrypto() error {
return nil
}
-func (c *Composer) writeCRLF(reader io.Reader) error {
- // .eml files must always use '\r\n' line endings
+func (c *Composer) writeEml(reader io.Reader) error {
+ // .eml files must always use '\r\n' line endings, but some editors
+ // don't support these, so if they are using one of those, the
+ // line-endings are transformed
+ lineEnding := "\r\n"
+ if config.Compose.LFEditor {
+ lineEnding = "\n"
+ }
+
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
- _, err := c.email.WriteString(scanner.Text() + "\r\n")
+ _, err := c.email.WriteString(scanner.Text() + lineEnding)
if err != nil {
return err
}
@@ -488,6 +495,11 @@ func (c *Composer) setContents(reader io.Reader) error {
if err != nil {
return err
}
+ lineEnding := "\r\n"
+ if config.Compose.LFEditor {
+ lineEnding = "\n"
+ }
+
if c.editHeaders {
for _, h := range c.headerOrder() {
var value string
@@ -506,7 +518,7 @@ func (c *Composer) setContents(reader io.Reader) error {
for _, a := range addresses {
addr = append(addr, format.AddressForHumans(a))
}
- value = strings.Join(addr, ",\r\n\t")
+ value = strings.Join(addr, ","+lineEnding+"\t")
}
default:
value, err = c.header.Text(h)
@@ -516,17 +528,17 @@ func (c *Composer) setContents(reader io.Reader) error {
}
}
key := textproto.CanonicalMIMEHeaderKey(h)
- _, err = fmt.Fprintf(c.email, "%s: %s\r\n", key, value)
+ _, err = fmt.Fprintf(c.email, "%s: %s"+lineEnding, key, value)
if err != nil {
return err
}
}
- _, err = c.email.WriteString("\r\n")
+ _, err = c.email.WriteString(lineEnding)
if err != nil {
return err
}
}
- return c.writeCRLF(reader)
+ return c.writeEml(reader)
}
func (c *Composer) appendContents(reader io.Reader) error {
@@ -534,7 +546,7 @@ func (c *Composer) appendContents(reader io.Reader) error {
if err != nil {
return err
}
- return c.writeCRLF(reader)
+ return c.writeEml(reader)
}
func (c *Composer) AppendPart(mimetype string, params map[string]string, body io.Reader) error {
@@ -904,7 +916,17 @@ func (c *Composer) parseEmbeddedHeader() (*mail.Header, error) {
if err != nil {
return nil, errors.Wrap(err, "Seek")
}
- msg, err := mail.CreateReader(c.email)
+
+ buf := bytes.NewBuffer([]byte{})
+ _, err = io.Copy(buf, c.email)
+ if err != nil {
+ return nil, fmt.Errorf("mail.ReadMessageCopy: %w", err)
+ }
+ if config.Compose.LFEditor {
+ bytes.ReplaceAll(buf.Bytes(), []byte{'\n'}, []byte{'\r', '\n'})
+ }
+
+ msg, err := mail.CreateReader(buf)
if errors.Is(err, io.EOF) { // completely empty
h := mail.HeaderFromMap(make(map[string][]string))
return &h, nil