Project

General

Profile

Bug #2241 ยป smtp_rcptto.patch

the proposed patch, comments welcome - keroami (Kero van Gelder), 10/21/2009 07:33 AM

View differences:

lib/net/smtp.rb (working copy)
include SMTPError
end
# Represents a fatal SMTP error (error code 5xx, except for 500)
# Represents SMTP error code 550, user unknown
class SMTPUnknownUser < ProtoFatalError
include SMTPError
end
# Represents a fatal SMTP error (error code 5xx, except for 500 and 550)
class SMTPFatalError < ProtoFatalError
include SMTPError
end
......
# * Net::SMTPAuthenticationError
# * Net::SMTPServerBusy
# * Net::SMTPSyntaxError
# * Net::SMTPUnknownUser
# * Net::SMTPFatalError
# * Net::SMTPUnknownError
# * IOError
......
# * Net::SMTPAuthenticationError
# * Net::SMTPServerBusy
# * Net::SMTPSyntaxError
# * Net::SMTPUnknownUser
# * Net::SMTPFatalError
# * Net::SMTPUnknownError
# * IOError
......
#
# * Net::SMTPServerBusy
# * Net::SMTPSyntaxError
# * Net::SMTPUnknownUser
# * Net::SMTPFatalError
# * Net::SMTPUnknownError
# * IOError
......
def send_message(msgstr, from_addr, *to_addrs)
raise IOError, 'closed session' unless @socket
mailfrom from_addr
rcptto_list to_addrs
data msgstr
ok_users, unknown_users = rcptto_list to_addrs.flatten
res = data msgstr
raise SMTPUnknownUser, "Unknown users: #{unknown_users.join', '}, mail delivered to #{ok_users.join', '}" if not unknown_users.empty?
res
end
alias send_mail send_message
......
#
# * Net::SMTPServerBusy
# * Net::SMTPSyntaxError
# * Net::SMTPUnknownUser
# * Net::SMTPFatalError
# * Net::SMTPUnknownError
# * IOError
......
def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
raise IOError, 'closed session' unless @socket
mailfrom from_addr
rcptto_list to_addrs
data(&block)
ok_users, unknown_users = rcptto_list to_addrs.flatten
res = data(&block)
raise SMTPUnknownUser, "Failed to deliver for #{unknown_users.join', '}, succesful for #{ok_users.join', '}" if not unknown_users.empty?
res
end
alias ready open_message_stream # obsolete
......
def rcptto_list(to_addrs)
raise ArgumentError, 'mail destination not given' if to_addrs.empty?
to_addrs.flatten.each do |addr|
rcptto addr
unknown_users = []
to_addrs.each do |addr|
begin
rcptto addr
rescue SMTPUnknownUser
unknown_users << addr
end
end
if unknown_users.length == to_addrs.flatten.length
raise SMTPUnknownUser, "Unknown users: #{unknown_users.join', '}"
else
[to_addrs - unknown_users, unknown_users]
end
end
def rcptto(to_addr)
......
when /\A4/ then SMTPServerBusy
when /\A50/ then SMTPSyntaxError
when /\A53/ then SMTPAuthenticationError
when /\A550/ then SMTPUnknownUser
when /\A5/ then SMTPFatalError
else SMTPUnknownError
end
    (1-1/1)