Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Changed a couple of SMTP protocol items #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

greinacker
Copy link

Made some changes to get this working consistently with certain mail agents. Specifically:

  1. responds to NOOP with an OK
  2. responds to RSET by clearing all state and message buffers; this is required by the SMTP spec
  3. responds to the message-ending "." by processing the pending message and resetting; according to SMTP spec this is appropriate behavior. This is necessary because some senders will re-use the existing connection to send additional messages, and also they may not QUIT for quite some time. From the spec:

"The end of mail data indication requires that the receiver
must now process the stored mail transaction information.
This processing consumes the information in the reverse-path
buffer, the forward-path buffer, and the mail data buffer,
and on the completion of this command these buffers are
cleared." - http://www.ietf.org/rfc/rfc0821.txt

Specifically: responds to NOOP with an OK, responds to RSET by clearing
all state and message buffers, and responds to . by processing the
pending message and resetting.
@greinacker
Copy link
Author

Oh by the way, this is my first time contributing on github and doing a pull request, so definitely let me know if I did something wrong! :-)

@aarongough
Copy link
Owner

Hey Greg!
Looks great, nothing to worry about there, I'm happy to see that you're getting use out of it.

Before I merge your changes would you be able to write tests for the new code? Does the old test suite still pass with your code changes?

Regards,
Aaron

@greinacker
Copy link
Author

Hey Aaron,

The original tests still pass. I just figured out a way to test the most important change, which is the multiple-emails on a single connection before a QUIT; just committed that test. As for the NOOP and the RSET changes, I'm not sure how to test those without pushing the bytes in myself. I did test them locally with a mail agent and telnet, with @Audit=true, so they should be working fine...just not sure how to automate the testing without writing a whole bunch more code.

-GR

@aarongough
Copy link
Owner

That definitely sounds reasonable, I think there's always a point of
diminishing returns with this stuff.

Thank again for your contribution! Would you like to change the README to
list yourself as a contributor? That way I can pull the changes verbatim,
and push a new Gem version in short order.

Regards,
Aaron


Aaron Gough
Software Developer

+1-647-746-7083
www.thingsaaronmade.com

On Fri, May 6, 2011 at 4:05 PM, greinacker <
reply@reply.github.com>wrote:

Hey Aaron,

The original tests still pass. I just figured out a way to test the most
important change, which is the multiple-emails on a single connection before
a QUIT; just committed that test. As for the NOOP and the RSET changes, I'm
not sure how to test those without pushing the bytes in myself. I did test
them locally with a mail agent and telnet, with @Audit=true, so they should
be working fine...just not sure how to automate the testing without writing
a whole bunch more code.

-GR

Reply to this email directly or view it on GitHub:
#1 (comment)

@greinacker
Copy link
Author

Done - thanks!

@aarongough
Copy link
Owner

Just a very small side-note:

def send_multiple_mails(message = $example_mail, from_address = "smtp@test.com", to_address = "some1@test.com", count = 1)
  Net::SMTP.start('127.0.0.1', 2525) do |smtp|
    msg_num = 0
    while (msg_num < count) do
      smtp.send_message(message, from_address, to_address)
      msg_num += 1
    end
    smtp.finish
    sleep 0.01
  end
end

Would be be more idiomatic in Ruby written like so:

def send_multiple_mails(message, from_address, to_address, count)
  Net::SMTP.start('127.0.0.1', 2525) do |smtp|
    count.times do
      smtp.send_message(message, from_address, to_address)
    end
    smtp.finish
    sleep 0.01
  end
end

Looking back at my test code I definitely should not have been using a global variable as the default for a parameter, I must have been having an off day :-p

The rest of the code looks great! Good work on your first open-source contribution!

@aarongough
Copy link
Owner

There's no need to change that by the way, it's more a case of me thinking out loud! :-)

@greinacker
Copy link
Author

Ooh, I like that a lot better; not sure why I didn't think of it. I guess you can tell my background is in C/C++/C# -style languages. :-)

@aarongough
Copy link
Owner

Haha, well there's no harm in that! You almost never see while loops used in Ruby code which is the only reason it stood out...

I'm going the other way language-wise. My day job is all Ruby but most of the personal work I'm doing right now is in C, it's kind of painful going the other way as I'm sure you can imagine :-p

@aarongough
Copy link
Owner

This was already merged...

@aarongough aarongough closed this May 27, 2011
@greinacker
Copy link
Author

Hey Aaron - I'm not all that worried about it, but I was cleaning up some of my repos, and it looks like this never actually got merged...

@aarongough aarongough reopened this Feb 29, 2012
@aarongough
Copy link
Owner

Hey Greg!
Sorry, it looks like you're right... Not sure why that happened.

Is it ok with you if I leave it for the moment? If I merge the code now I'm not going to have the time to test it and I don't want to run the risk of breaking the gem for existing users...

Thanks,
Aaron

@greinacker
Copy link
Author

Ok with me - perhaps just keep this PR open so folks know it's there if they want it. Thanks!

@aarongough
Copy link
Owner

No worries, thanks for understanding!

-Aaron


Aaron Gough
Software Developer

+1-647-746-7083
www.thingsaaronmade.com

On Wed, Feb 29, 2012 at 7:49 PM, Greg Reinacker <
reply@reply.github.com

wrote:

Ok with me - perhaps just keep this PR open so folks know it's there if
they want it. Thanks!


Reply to this email directly or view it on GitHub:
#1 (comment)

@mindware
Copy link

mindware commented Nov 4, 2013

Was this ever merged? If so, the ticket can be closed.

@TomFreudenberg
Copy link

Hi @greinacker @mindware

even that this is a very old pull request you still might be interested in such a component. After a lot of improvements and work, I would like to inform you about enhanced MidiSmtpServer library. Your pull request is already addressed there.

Cheers,
Tom

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants