Reopening mailcontent file to fix #166

Because editors like vim use backupfiles and rename them to the original
name, the file handle used can point to the wrong file. Reopening the
file should fix this.
This commit is contained in:
Stefan Rakel 2019-06-27 11:06:50 +02:00 committed by Drew DeVault
parent 963d251289
commit 59df06fe28

View file

@ -278,7 +278,13 @@ func (c *Composer) PrepareHeader() (*mail.Header, []string, error) {
} }
func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error { func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {
c.email.Seek(0, os.SEEK_SET) name := c.email.Name()
c.email.Close()
file, err := os.Open(name)
if err != nil {
return errors.Wrap(err, "FileOpen")
}
c.email = file
var body io.Reader var body io.Reader
reader, err := mail.CreateReader(c.email) reader, err := mail.CreateReader(c.email)
if err == nil { if err == nil {