Skip to content

client: introduce DataCommand #263

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged

client: introduce DataCommand #263

merged 1 commit into from
Apr 28, 2025

Conversation

emersion
Copy link
Owner

@emersion emersion commented Apr 24, 2024

  • Tests
  • Docs
  • Fix Data on LMTP servers
  • Consider introducing LMTPDataCommand as well
  • Consider splitting Close and waiting for server reply? Not sure it's really necessary here. Would allow returning a DataResponse struct maybe.

Closes: #189

@emersion emersion marked this pull request as draft April 24, 2024 14:36
@davrux
Copy link

davrux commented Jul 22, 2024

Why not use a CloseWithResponse function?

func (d *dataCloser) CloseWithResponse() (code int, msg string, err error) {
	if d.closed {
		return 0, "", fmt.Errorf("smtp: data writer closed twice")
	}

	if err := d.WriteCloser.Close(); err != nil {
		return 0, "", err
	}

	d.c.conn.SetDeadline(time.Now().Add(d.c.SubmissionTimeout))
	defer d.c.conn.SetDeadline(time.Time{})

	expectedResponses := len(d.c.rcpts)
	if d.c.lmtp {
		for expectedResponses > 0 {
			rcpt := d.c.rcpts[len(d.c.rcpts)-expectedResponses]
			if _, _, err := d.c.readResponse(250); err != nil {
				if smtpErr, ok := err.(*SMTPError); ok {
					if d.statusCb != nil {
						d.statusCb(rcpt, smtpErr)
					}
				} else {
					return 0, "", err
				}
			} else if d.statusCb != nil {
				d.statusCb(rcpt, nil)
			}
			expectedResponses--
		}
	} else {
		code, msg, err = d.c.readResponse(250)
	}

	d.closed = true
	return code, msg, err
}

func (d *dataCloser) Close() error {
	_, _, err := d.CloseWithResponse()
	return err
}

@sapmli
Copy link

sapmli commented Jan 23, 2025

What is the status and forecast for this feature? Can we help in any way?

@emersion
Copy link
Owner Author

Why not use a CloseWithResponse function?

That sounds better indeed!

@emersion emersion force-pushed the data-cmd branch 2 times, most recently from 2ab90d4 to 9715c3c Compare March 30, 2025 12:23
@emersion emersion force-pushed the data-cmd branch 2 times, most recently from d68c0fc to b164a44 Compare April 27, 2025 16:12
@emersion emersion marked this pull request as ready for review April 27, 2025 16:13
@emersion emersion merged commit 495c409 into master Apr 28, 2025
1 check passed
@emersion emersion deleted the data-cmd branch April 28, 2025 20:10
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.

Client: read server response on DATA command
3 participants