зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
3d6fde3365
Коммит
3fef8bb12c
|
@ -10,7 +10,7 @@ You can freely distribute/modify this library.
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
require 'net/session'
|
require 'net/protocol'
|
||||||
|
|
||||||
|
|
||||||
module Net
|
module Net
|
||||||
|
@ -175,7 +175,15 @@ class HTTPBadResponse < HTTPError; end
|
||||||
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
|
# def delete
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ You can freely distribute/modify this library.
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
||||||
require 'net/session'
|
require 'net/protocol'
|
||||||
require 'md5'
|
require 'md5'
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,10 +101,33 @@ Object
|
||||||
|
|
||||||
=== Method
|
=== Method
|
||||||
|
|
||||||
: all
|
: all( dest = '' )
|
||||||
: pop
|
: pop
|
||||||
: mail
|
: 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
|
: header
|
||||||
This method fetches only mail header.
|
This method fetches only mail header.
|
||||||
|
@ -138,6 +161,9 @@ Object
|
||||||
attr :size
|
attr :size
|
||||||
|
|
||||||
def all( dest = '' )
|
def all( dest = '' )
|
||||||
|
if iterator? then
|
||||||
|
dest = ReadAdapter.new( Proc.new )
|
||||||
|
end
|
||||||
@command.retr( @num, dest )
|
@command.retr( @num, dest )
|
||||||
end
|
end
|
||||||
alias pop all
|
alias pop all
|
||||||
|
@ -172,7 +198,8 @@ Object
|
||||||
|
|
||||||
== Net::APOP
|
== 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
|
=== Super Class
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ You can freely distribute/modify this library.
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
||||||
require 'net/session'
|
require 'net/protocol'
|
||||||
|
|
||||||
|
|
||||||
module Net
|
module Net
|
||||||
|
@ -47,6 +47,21 @@ Net::Protocol
|
||||||
* Net::ProtoUnknownError: unknown error
|
* Net::ProtoUnknownError: unknown error
|
||||||
* Net::ProtoServerBusy: temporary error (errno.420/450)
|
* 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
|
: finish
|
||||||
This method ends SMTP.
|
This method ends SMTP.
|
||||||
If protocol had not started, do nothind and return false.
|
If protocol had not started, do nothind and return false.
|
||||||
|
@ -59,13 +74,20 @@ Net::Protocol
|
||||||
protocol_param :command_type, '::Net::SMTPCommand'
|
protocol_param :command_type, '::Net::SMTPCommand'
|
||||||
|
|
||||||
|
|
||||||
def sendmail( mailsrc, fromaddr, toaddrs )
|
def sendmail( mailsrc, fromaddr, toaddrs, &block )
|
||||||
@command.mailfrom fromaddr
|
@command.mailfrom fromaddr
|
||||||
@command.rcpt toaddrs
|
@command.rcpt toaddrs
|
||||||
@command.data
|
@command.data
|
||||||
@command.sendmail mailsrc
|
@command.write_mail( mailsrc, &block )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ready( fromaddr, toaddrs, &block )
|
||||||
|
sendmail nil, fromaddr, toaddrs, &block
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
attr :esmtp
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -74,7 +96,14 @@ Net::Protocol
|
||||||
unless helodom then
|
unless helodom then
|
||||||
raise ArgumentError, "cannot get hostname"
|
raise ArgumentError, "cannot get hostname"
|
||||||
end
|
end
|
||||||
@command.helo helodom
|
|
||||||
|
@esmtp = false
|
||||||
|
begin
|
||||||
|
@command.ehlo helodom
|
||||||
|
@esmtp = true
|
||||||
|
rescue ProtocolError
|
||||||
|
@command.helo helodom
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -110,9 +139,15 @@ Net::Command
|
||||||
This method sends "RCPT TO" command.
|
This method sends "RCPT TO" command.
|
||||||
to_addrs is array of mail address(???@???) of destination.
|
to_addrs is array of mail address(???@???) of destination.
|
||||||
|
|
||||||
: data( mailsrc )
|
: data
|
||||||
This method send 'mailsrc' as mail. SMTP reads strings from 'mailsrc'
|
This method sends "DATA" command.
|
||||||
by calling 'each' iterator.
|
|
||||||
|
: 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
|
: quit
|
||||||
This method sends "QUIT" command and ends SMTP session.
|
This method sends "QUIT" command and ends SMTP session.
|
||||||
|
@ -132,6 +167,11 @@ Net::Command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def ehlo( fromdom )
|
||||||
|
getok sprintf( 'EHLO %s', fromdom )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def mailfrom( fromaddr )
|
def mailfrom( fromaddr )
|
||||||
getok sprintf( 'MAIL FROM:<%s>', fromaddr )
|
getok sprintf( 'MAIL FROM:<%s>', fromaddr )
|
||||||
end
|
end
|
||||||
|
@ -149,11 +189,11 @@ Net::Command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def writemail( mailsrc )
|
def write_mail( mailsrc, &block )
|
||||||
@socket.write_pendstr mailsrc
|
@socket.write_pendstr mailsrc, &block
|
||||||
check_reply SuccessCode
|
check_reply SuccessCode
|
||||||
end
|
end
|
||||||
alias sendmail writemail
|
alias sendmail write_mail
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Загрузка…
Ссылка в новой задаче