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
This commit is contained in:
aamine 2000-02-21 15:25:37 +00:00
Родитель 3d6fde3365
Коммит 3fef8bb12c
3 изменённых файлов: 91 добавлений и 16 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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,13 +74,20 @@ 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