Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smtp buildMessage(): flush quotedprintable writer buff explicitly #682

Merged

Conversation

ttys3
Copy link
Contributor

@ttys3 ttys3 commented Apr 13, 2020

I found this problem when I was refactoring the email provider code ( the PR which got rejected by umputun).

a simple test run under my local machine ( 6 core 12 thread CPU with 4.7GHz freq) failed, the test code looks like:

	htmlContent := "<strong>simple HTML body goes here</strong>"
	t.Logf("try send via SMTP from %s to %s", fromEmail, toEmail)

	msg, err := buildMessage(toEmail, htmlContent, "text/html")
	if err != nil {
		t.Error(err)
	}
        // now only got the headers, body is missing
	t.Logf("mail msg: %s", msg)
	if !strings.Contains(msg, htmlContent) {
		t.Errorf("BuildMessage lost body")
	}

look into quotedprintable.Close() function, you' find it implicitly called flush():

// Close closes the Writer, flushing any unwritten data to the underlying
// io.Writer, but does not close the underlying io.Writer.
func (w *Writer) Close() error {
	if err := w.checkLastByte(); err != nil {
		return err
	}

	return w.flush()
}

the old buggy code is

defer qp.Close()
m := buff.String()
message += "\n" + m
return message, nil
}

it called buff.String() after defer qp.Close() but the buff actrully got flushed after the m := buff.String() call

@ttys3 ttys3 requested a review from umputun as a code owner April 13, 2020 12:20
Copy link
Collaborator

@paskal paskal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@umputun umputun merged commit 200f464 into umputun:master Apr 13, 2020
@umputun umputun added this to the v1.6 milestone Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants