Coder Social home page Coder Social logo

Comments (3)

emersion avatar emersion commented on September 2, 2024

You can pass your own net.Listener wrapper to go-smtp, and drop connections before go-smtp handles them.

from go-smtp.

aine-etke avatar aine-etke commented on September 2, 2024

Thank you for suggestion!
Unfortunately, it doesn't solve the mentioned issue, because go-smtp server will crash completely if net.Listener.Accept() returns error and/or nil connection. You have to return something that won't crash it.

We managed that by implying the following workaround:

// Accept waits for and returns the next connection to the listener.
func (l *Listener) Accept() (net.Conn, error) {
	conn, err := l.listener.Accept()
	if err != nil {
		return conn, err
	}
	if l.isBanned(conn.RemoteAddr()) {
		conn.Close()
		l.log.Info("rejected connection from %q (already banned)", conn.RemoteAddr())
		return &net.TCPConn{}, nil
	}

	return conn, nil
}

but as you can see, it's not ideal.

May I ask you to re-open the issue, please? Right now there is no straitforward way without forging connection to actually drop it. If you don't want to implement a hook, could you perform error check without crashing the whole server (latest release/git tag) or stopping the whole server (master branch), please?

from go-smtp.

emersion avatar emersion commented on September 2, 2024

You can just loop until you get a non-nil connection.

from go-smtp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.