diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-21 15:25:37 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-21 15:25:37 +0000 |
commit | 3fef8bb12c0a82b49a89a29457818b28b2a000aa (patch) | |
tree | f899e8e8b7b726b98a43d3edbfd7e5bdbd6cf8ad /lib | |
parent | 3d6fde336547463461180b9be5b1730194764d9c (diff) |
o session.rb -> protocol.rb
o write, write_pendstr takes block
o smtp.ready
o popmail.pop takes block
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/http.rb | 12 | ||||
-rw-r--r-- | lib/net/pop.rb | 35 | ||||
-rw-r--r-- | lib/net/smtp.rb | 60 |
3 files changed, 91 insertions, 16 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index 4847f88bf7..4ae5349202 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -10,7 +10,7 @@ You can freely distribute/modify this library. =end -require 'net/session' +require 'net/protocol' module Net @@ -175,7 +175,15 @@ class HTTPBadResponse < HTTPError; end end - # def put + # not work + def post( path, u_header = nil ) + get_response sprintf( 'POST %s HTTP/%s', path, HTTPVersion ), u_header + end + + # not work + def put( path, u_header = nil ) + get_response sprintf( 'PUT %s HTTP/%s', path, HTTPVersion ), u_header + end # def delete diff --git a/lib/net/pop.rb b/lib/net/pop.rb index 0ec2481557..440f894f57 100644 --- a/lib/net/pop.rb +++ b/lib/net/pop.rb @@ -10,7 +10,7 @@ You can freely distribute/modify this library. =end -require 'net/session' +require 'net/protocol' require 'md5' @@ -101,10 +101,33 @@ Object === Method -: all +: all( dest = '' ) : pop : mail - This method fetches a mail and return it. + This method fetches a mail and write to 'dest' using '<<' method. + + # usage example + + mailarr = [] + POP3.start( 'localhost', 110 ) do |pop| + pop.each do |popm| + mailarr.push popm.pop # all() returns 'dest' (this time, string) + # or, you can also + # popm.pop( $stdout ) # write mail to stdout + end + end + +: all {|str| .... } + You can use all/pop/mail as the iterator. + argument 'str' is a read string (a part of mail). + + # usage example + + POP3.start( 'localhost', 110 ) do |pop| + pop.mails[0].pop do |str| # pop only first mail... + _do_anything_( str ) + end + end : header This method fetches only mail header. @@ -138,6 +161,9 @@ Object attr :size def all( dest = '' ) + if iterator? then + dest = ReadAdapter.new( Proc.new ) + end @command.retr( @num, dest ) end alias pop all @@ -172,7 +198,8 @@ Object == Net::APOP -This class has no new methods. Only way of authetication is changed. +This class defines no new methods. +Only difference from POP3 is using APOP authentification. === Super Class diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 7a04aa2aa2..4b2986dea2 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -10,7 +10,7 @@ You can freely distribute/modify this library. =end -require 'net/session' +require 'net/protocol' module Net @@ -47,6 +47,21 @@ Net::Protocol * Net::ProtoUnknownError: unknown error * Net::ProtoServerBusy: temporary error (errno.420/450) +: ready( from_domain, to_addrs ) {|adapter| .... } + This method stands by the SMTP object for sending mail. + In the block of this iterator, you can call ONLY 'write' method + for 'adapter'. + + # usage example + + SMTP.start( 'localhost', 25 ) do |smtp| + smtp.ready( from, to ) do |adapter| + adapter.write str1 + adapter.write str2 + adapter.write str3 + end + end + : finish This method ends SMTP. If protocol had not started, do nothind and return false. @@ -59,14 +74,21 @@ Net::Protocol protocol_param :command_type, '::Net::SMTPCommand' - def sendmail( mailsrc, fromaddr, toaddrs ) + def sendmail( mailsrc, fromaddr, toaddrs, &block ) @command.mailfrom fromaddr @command.rcpt toaddrs @command.data - @command.sendmail mailsrc + @command.write_mail( mailsrc, &block ) + end + + def ready( fromaddr, toaddrs, &block ) + sendmail nil, fromaddr, toaddrs, &block end + attr :esmtp + + private @@ -74,7 +96,14 @@ Net::Protocol unless helodom then raise ArgumentError, "cannot get hostname" end - @command.helo helodom + + @esmtp = false + begin + @command.ehlo helodom + @esmtp = true + rescue ProtocolError + @command.helo helodom + end end end @@ -110,9 +139,15 @@ Net::Command This method sends "RCPT TO" command. to_addrs is array of mail address(???@???) of destination. -: data( mailsrc ) - This method send 'mailsrc' as mail. SMTP reads strings from 'mailsrc' - by calling 'each' iterator. +: data + This method sends "DATA" command. + +: write_mail( mailsrc ) +: write_mail {|socket| ... } + send 'mailsrc' as mail. + SMTPCommand reads strings from 'mailsrc' by calling 'each' iterator. + When iterator, SMTPCommand only stand by socket and pass it. + (The socket will accepts only 'in_write' method in the block) : quit This method sends "QUIT" command and ends SMTP session. @@ -132,6 +167,11 @@ Net::Command end + def ehlo( fromdom ) + getok sprintf( 'EHLO %s', fromdom ) + end + + def mailfrom( fromaddr ) getok sprintf( 'MAIL FROM:<%s>', fromaddr ) end @@ -149,11 +189,11 @@ Net::Command end - def writemail( mailsrc ) - @socket.write_pendstr mailsrc + def write_mail( mailsrc, &block ) + @socket.write_pendstr mailsrc, &block check_reply SuccessCode end - alias sendmail writemail + alias sendmail write_mail private |