1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.27.
* lib/net/protocol.rb: writing methods returns written byte size.
* lib/net/smtp.rb: send_mail accepts many destinations.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2000-08-16 19:26:07 +00:00
parent 82178a5529
commit 79c2d60971
5 changed files with 56 additions and 38 deletions

View file

@ -1,3 +1,11 @@
Thu Aug 17 04:26:31 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.27.
* lib/net/protocol.rb: writing methods returns written byte size.
* lib/net/smtp.rb: send_mail accepts many destinations.
Tue Aug 15 17:30:59 2000 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Aug 15 17:30:59 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (frame_dup): should set flag FRAME_MALLOC after * eval.c (frame_dup): should set flag FRAME_MALLOC after

View file

@ -1,12 +1,13 @@
=begin =begin
= net/http.rb version 1.1.27 = net/http.rb version 1.1.28
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp> maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
This file is derived from "http-access.rb". This file is derived from "http-access.rb".
This library is distributed under the terms of the Ruby license. This program is free software.
You can freely distribute/modify this library. You can distribute/modify this program under
the terms of the Ruby Distribute License.
= class HTTP = class HTTP

View file

@ -1,11 +1,12 @@
=begin =begin
= net/pop.rb version 1.1.27 = net/pop.rb version 1.1.28
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
This library is distributed under the terms of the Ruby license. This program is free software.
You can freely distribute/modify this library. You can distribute/modify this program under
the terms of the Ruby Distribute License.
== Net::POP3 == Net::POP3

View file

@ -1,11 +1,12 @@
=begin =begin
= net/protocol.rb version 1.1.27 = net/protocol.rb version 1.1.28
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
This library is distributed under the terms of the Ruby license. This program is free software.
You can freely distribute/modify this library. You can distribute/modify this program under
the terms of the Ruby Distribute License.
== Net::Protocol == Net::Protocol
@ -64,7 +65,7 @@ module Net
class Protocol class Protocol
Version = '1.1.27' Version = '1.1.28'
class << self class << self
@ -75,7 +76,7 @@ module Net
if iterator? then if iterator? then
instance.start( *args ) { yield instance } instance.start( *args ) { yield instance }
else else
instance.start *args instance.start( *args )
instance instance
end end
end end
@ -164,7 +165,7 @@ module Net
begin begin
connect connect
do_start *args do_start( *args )
@active = true @active = true
yield self if iterator? yield self if iterator?
ensure ensure
@ -639,10 +640,13 @@ module Net
def wpend_in( src ) def wpend_in( src )
line = nil line = nil
pre = @writtensize
each_crlf_line( src ) do |line| each_crlf_line( src ) do |line|
do_write '.' if line[0] == ?. do_write '.' if line[0] == ?.
do_write line do_write line
end end
@writtensize - pre
end end
def use_each_crlf_line def use_each_crlf_line

View file

@ -1,11 +1,12 @@
=begin =begin
= net/smtp.rb version 1.1.27 = net/smtp.rb version 1.1.28
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
This library is distributed under the terms of the Ruby license. This program is free software.
You can freely distribute/modify this library. You can distribute/modify this program under
the terms of the Ruby Distribute License.
== Net::SMTP == Net::SMTP
@ -21,7 +22,7 @@ Net::Protocol
: start( address = 'localhost', port = 25, *protoargs ) : start( address = 'localhost', port = 25, *protoargs )
: start( address = 'localhost', port = 25, *protoargs ) {|smtp| .... } : start( address = 'localhost', port = 25, *protoargs ) {|smtp| .... }
same to Net::SMTP.new( address, port ).start( *protoargs ) is equal to Net::SMTP.new( address, port ).start( *protoargs )
=== Methods === Methods
@ -38,14 +39,14 @@ Net::Protocol
If account and password are given, is trying to get authentication If account and password are given, is trying to get authentication
by using AUTH command. "authtype" is :plain (symbol) or :cram_md5. by using AUTH command. "authtype" is :plain (symbol) or :cram_md5.
: send_mail( mailsrc, from_addr, to_addrs ) : send_mail( mailsrc, from_addr, *to_addrs )
: sendmail( mailsrc, from_addr, to_addrs ) : sendmail( mailsrc, from_addr, *to_addrs )
This method sends 'mailsrc' as mail. SMTPSession read strings This method sends 'mailsrc' as mail. SMTP read strings
from 'mailsrc' by calling 'each' iterator, and convert them from 'mailsrc' by calling 'each' iterator, and convert them
into "\r\n" terminated string when write. into "\r\n" terminated string when write.
from_addr must be String. from_addr must be String.
to_addrs must be Array of String, or String. to_addrs must be a String(s) or an Array of String.
Exceptions which SMTP raises are: Exceptions which SMTP raises are:
* Net::ProtoSyntaxError: syntax error (errno.500) * Net::ProtoSyntaxError: syntax error (errno.500)
@ -53,6 +54,12 @@ Net::Protocol
* Net::ProtoUnknownError: unknown error * Net::ProtoUnknownError: unknown error
* Net::ProtoServerBusy: temporary error (errno.420/450) * Net::ProtoServerBusy: temporary error (errno.420/450)
# usage example
Net::SMTP.start( 'localhost', 25 ) do |smtp|
smtp.send_mail mail_string, 'from-addr@foo.or.jp', 'to-addr@bar.or.jp'
end
: ready( from_addr, to_addrs ) {|adapter| .... } : ready( from_addr, to_addrs ) {|adapter| .... }
This method stands by the SMTP object for sending mail. This method stands by the SMTP object for sending mail.
In the block of this iterator, you can call ONLY 'write' method In the block of this iterator, you can call ONLY 'write' method
@ -60,7 +67,7 @@ Net::Protocol
# usage example # usage example
SMTP.start( 'localhost', 25 ) do |smtp| Net::SMTP.start( 'localhost', 25 ) do |smtp|
smtp.ready( from, to ) do |adapter| smtp.ready( from, to ) do |adapter|
adapter.write str1 adapter.write str1
adapter.write str2 adapter.write str2
@ -69,8 +76,8 @@ Net::Protocol
end end
: finish : finish
This method ends SMTP. finishes SMTP session.
If protocol had not started, do nothind and return false. If SMTP session had not started, do nothing and return false.
=end =end
@ -92,17 +99,17 @@ module Net
@esmtp = true @esmtp = true
end end
attr :esmtp attr :esmtp
def send_mail( mailsrc, from_addr, to_addrs ) def send_mail( mailsrc, from_addr, *to_addrs )
do_ready from_addr, to_addrs do_ready from_addr, to_addrs.flatten
@command.write_mail mailsrc, nil @command.write_mail mailsrc, nil
end end
alias sendmail send_mail alias sendmail send_mail
def ready( from_addr, to_addrs, &block ) def ready( from_addr, *to_addrs, &block )
do_ready from_addr, to_addrs do_ready from_addr, to_addrs.flatten
@command.write_mail nil, block @command.write_mail nil, block
end end
@ -111,7 +118,9 @@ module Net
def do_ready( from_addr, to_addrs ) def do_ready( from_addr, to_addrs )
to_addrs = [to_addrs] if String === to_addrs if to_addrs.empty? then
raise ArgumentError, 'mail destination does not given'
end
@command.mailfrom from_addr @command.mailfrom from_addr
@command.rcpt to_addrs @command.rcpt to_addrs
@command.data @command.data
@ -119,12 +128,10 @@ module Net
def do_start( helodom = nil, def do_start( helodom = nil,
user = nil, secret = nil, authtype = nil ) user = nil, secret = nil, authtype = nil )
helodom ||= ::Socket.gethostname
unless helodom then unless helodom then
helodom = ::Socket.gethostname raise ArgumentError,
unless helodom then "cannot get localhost name; try 'smtp.start(local_host_name)'"
raise ArgumentError,
"cannot get localhost name; try 'smtp.start(local_host_name)'"
end
end end
begin begin
@ -234,13 +241,11 @@ module Net
getok 'DATA', ContinueCode getok 'DATA', ContinueCode
end end
def write_mail( mailsrc, block ) def write_mail( mailsrc, block )
@socket.write_pendstr mailsrc, block @socket.write_pendstr mailsrc, block
check_reply SuccessCode check_reply SuccessCode
end_critical end_critical
end end
alias sendmail write_mail
def quit def quit
@ -276,7 +281,6 @@ module Net
def read_reply def read_reply
arr = [] arr = []
while true do while true do
str = @socket.readline str = @socket.readline
break unless str[3] == ?- # ex: "210-..." break unless str[3] == ?- # ex: "210-..."
@ -284,7 +288,7 @@ module Net
end end
arr.push str arr.push str
return arr arr
end end
end end