Browse files

Better block capability!

Now it's:

    listener.go do |cmd, message|
        case cmd
            when :mail
                unless message.origin_ip == "127.0.0.1"
                    raise Percolate::SMTP::Responder::ResponderError,
                            "550 go away, only localhost gets to send mail"
                end
        end
    end

(or things along those lines)
  • Loading branch information...
1 parent 453e659 commit 6505868d83acf8924057ce0ce3ab32b63906b333 @dagbrown committed with Dave Brown Nov 11, 2008
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/percolate/smtp/responder.rb
View
15 lib/percolate/smtp/responder.rb
@@ -59,7 +59,7 @@ def initialize(mailhostname, opts={})
# the RFC says, be any old crap at all! Don't
# even expect an RFC2822-formatted message)
def process_message message_object
- yield message_object if block_given?
+ yield :data, message_object if block_given?
return true
end
@@ -241,7 +241,7 @@ def ehlo remotehost
respond "250 #{@mailhostname}"
end
- def mail sender
+ def mail sender, &block
validate_state :smtp_mail_started
matchdata=sender.match(/^From:\<(.*)\>$/i);
unless matchdata
@@ -251,6 +251,7 @@ def mail sender
mail_from = matchdata[1]
validated, message = validate_sender mail_from
+
unless validated
raise ResponderError, "551 #{message || 'no'}"
end
@@ -259,10 +260,13 @@ def mail sender
:heloname => @heloname,
:origin_ip => @originating_ip,
:myhostname => @mailhostname)
+
+ yield :mail, @mail_object if block_given?
+
respond "250 #{message || 'ok'}"
end
- def rcpt recipient
+ def rcpt recipient, &block
validate_state :smtp_rcpt_received
matchdata=recipient.match(/^To:\<(.*)\>$/i);
unless matchdata
@@ -274,15 +278,20 @@ def rcpt recipient
@mail_object.envelope_to ||= []
validated, message = validate_recipient rcpt_to
+
unless validated
raise ResponderError, "551 #{message || 'no'}"
end
+
+ yield :mail, @mail_object if block_given?
+
@mail_object.envelope_to << rcpt_to
respond "250 #{message || 'ok'}"
end
def data
validate_state :data
+
@mail_object.content ||= ""
respond "354 end data with <cr><lf>.<cr><lf>"
end

0 comments on commit 6505868

Please sign in to comment.