aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/net/smtp
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
commitaf146490bb04205107cb23e301ec7a8ff927b5fc (patch)
tree13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/net/smtp
parent725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff)
downloadgcc-af146490bb04205107cb23e301ec7a8ff927b5fc.zip
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.gz
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.bz2
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field. Reviewed-on: https://go-review.googlesource.com/16525 From-SVN: r229616
Diffstat (limited to 'libgo/go/net/smtp')
-rw-r--r--libgo/go/net/smtp/smtp.go35
-rw-r--r--libgo/go/net/smtp/smtp_test.go44
2 files changed, 75 insertions, 4 deletions
diff --git a/libgo/go/net/smtp/smtp.go b/libgo/go/net/smtp/smtp.go
index 87dea44..0988350 100644
--- a/libgo/go/net/smtp/smtp.go
+++ b/libgo/go/net/smtp/smtp.go
@@ -41,7 +41,7 @@ type Client struct {
}
// Dial returns a new Client connected to an SMTP server at addr.
-// The addr must include a port number.
+// The addr must include a port, as in "mail.example.com:smtp".
func Dial(addr string) (*Client, error) {
conn, err := net.Dial("tcp", addr)
if err != nil {
@@ -157,6 +157,17 @@ func (c *Client) StartTLS(config *tls.Config) error {
return c.ehlo()
}
+// TLSConnectionState returns the client's TLS connection state.
+// The return values are their zero values if StartTLS did
+// not succeed.
+func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) {
+ tc, ok := c.conn.(*tls.Conn)
+ if !ok {
+ return
+ }
+ return tc.ConnectionState(), true
+}
+
// Verify checks the validity of an email address on the server.
// If Verify returns nil, the address is valid. A non-nil return
// does not necessarily indicate an invalid address. Many servers
@@ -253,9 +264,9 @@ func (d *dataCloser) Close() error {
}
// Data issues a DATA command to the server and returns a writer that
-// can be used to write the data. The caller should close the writer
-// before calling any more methods on c.
-// A call to Data must be preceded by one or more calls to Rcpt.
+// can be used to write the mail headers and body. The caller should
+// close the writer before calling any more methods on c. A call to
+// Data must be preceded by one or more calls to Rcpt.
func (c *Client) Data() (io.WriteCloser, error) {
_, _, err := c.cmd(354, "DATA")
if err != nil {
@@ -270,6 +281,22 @@ var testHookStartTLS func(*tls.Config) // nil, except for tests
// possible, authenticates with the optional mechanism a if possible,
// and then sends an email from address from, to addresses to, with
// message msg.
+// The addr must include a port, as in "mail.example.com:smtp".
+//
+// The addresses in the to parameter are the SMTP RCPT addresses.
+//
+// The msg parameter should be an RFC 822-style email with headers
+// first, a blank line, and then the message body. The lines of msg
+// should be CRLF terminated. The msg headers should usually include
+// fields such as "From", "To", "Subject", and "Cc". Sending "Bcc"
+// messages is accomplished by including an email address in the to
+// parameter but not including it in the msg headers.
+//
+// The SendMail function and the the net/smtp package are low-level
+// mechanisms and provide no support for DKIM signing, MIME
+// attachments (see the mime/multipart package), or other mail
+// functionality. Higher-level packages exist outside of the standard
+// library.
func SendMail(addr string, a Auth, from string, to []string, msg []byte) error {
c, err := Dial(addr)
if err != nil {
diff --git a/libgo/go/net/smtp/smtp_test.go b/libgo/go/net/smtp/smtp_test.go
index 5c659e8..3ae0d5b 100644
--- a/libgo/go/net/smtp/smtp_test.go
+++ b/libgo/go/net/smtp/smtp_test.go
@@ -571,6 +571,50 @@ func TestTLSClient(t *testing.T) {
}
}
+func TestTLSConnState(t *testing.T) {
+ ln := newLocalListener(t)
+ defer ln.Close()
+ clientDone := make(chan bool)
+ serverDone := make(chan bool)
+ go func() {
+ defer close(serverDone)
+ c, err := ln.Accept()
+ if err != nil {
+ t.Errorf("Server accept: %v", err)
+ return
+ }
+ defer c.Close()
+ if err := serverHandle(c, t); err != nil {
+ t.Errorf("server error: %v", err)
+ }
+ }()
+ go func() {
+ defer close(clientDone)
+ c, err := Dial(ln.Addr().String())
+ if err != nil {
+ t.Errorf("Client dial: %v", err)
+ return
+ }
+ defer c.Quit()
+ cfg := &tls.Config{ServerName: "example.com"}
+ testHookStartTLS(cfg) // set the RootCAs
+ if err := c.StartTLS(cfg); err != nil {
+ t.Errorf("StartTLS: %v", err)
+ return
+ }
+ cs, ok := c.TLSConnectionState()
+ if !ok {
+ t.Errorf("TLSConnectionState returned ok == false; want true")
+ return
+ }
+ if cs.Version == 0 || !cs.HandshakeComplete {
+ t.Errorf("ConnectionState = %#v; expect non-zero Version and HandshakeComplete", cs)
+ }
+ }()
+ <-clientDone
+ <-serverDone
+}
+
func newLocalListener(t *testing.T) net.Listener {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {