diff --git a/lib/tasks/e_paper_tasks.rake b/lib/tasks/e_paper_tasks.rake index db443b9..0c41957 100644 --- a/lib/tasks/e_paper_tasks.rake +++ b/lib/tasks/e_paper_tasks.rake @@ -64,79 +64,80 @@ namespace :epaper do paper.save end end -end -def verify_email(from_addr,check_emails,tls) #true if check_email is ok - s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do - TCPSocket.open(@address, @port) - end - @socket = new_internet_message_io(tls ? tlsconnect(s) : s) - res = get_response("MAIL FROM:<#{from_addr}>") - invalid_emails = [] - check_list = [] - if check_emails.class == String - if check_emails.include?(",") - check_list = check_emails.split(",") - else - check_list << check_emails - end - else - check_list = check_emails - end - check_list.each do |check_email| - res1 = get_response("RCPT TO:<#{check_email}>") - res2 = get_response("RCPT TO:<#{check_email}>") - if !(res1.success? && res2.success?) - invalid_emails << check_email - puts [check_email,res1.message,res2.message] + def verify_email(from_addr,check_emails,tls) #true if check_email is ok + s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do + TCPSocket.open(@address, @port) end + @socket = new_internet_message_io(tls ? tlsconnect(s) : s) + res = get_response("MAIL FROM:<#{from_addr}>") + invalid_emails = [] + check_list = [] + if check_emails.class == String + if check_emails.include?(",") + check_list = check_emails.split(",") + else + check_list << check_emails + end + else + check_list = check_emails + end + check_list.each do |check_email| + res1 = get_response("RCPT TO:<#{check_email}>") + res2 = get_response("RCPT TO:<#{check_email}>") + if !(res1.success? && res2.success?) + invalid_emails << check_email + puts [check_email,res1.message,res2.message] + end + end + s.close + invalid_emails + end + def get_response(reqline) + res = critical { + @socket.writeline reqline + recv_response() + } + return res + end + def recv_response + buf = '' + while true + line = @socket.readline + buf << line << "\n" + break unless line[3,1] == '-' # "210-PIPELINING" + end + Net::SMTP::Response.parse(buf) + end + def critical + return Net::SMTP::Response.parse('200 dummy reply code') if @error_occurred + begin + return yield() + rescue Exception + @error_occurred = true + raise + end + end + def ssl_socket(socket, context) + OpenSSL::SSL::SSLSocket.new socket, context + end + def tlsconnect(s) + verified = false + s = ssl_socket(s, @ssl_context) + s.sync_close = true + s.connect + if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE + s.post_connection_check(@address) + end + verified = true + s + ensure + s.close unless verified + end + def new_internet_message_io(s) + io = Net::InternetMessageIO.new(s) + io.read_timeout = @read_timeout + io.debug_output = @debug_output + io end - s.close - invalid_emails end -def get_response(reqline) - res = critical { - @socket.writeline reqline - recv_response() - } - return res -end -def recv_response - buf = '' - while true - line = @socket.readline - buf << line << "\n" - break unless line[3,1] == '-' # "210-PIPELINING" - end - Net::SMTP::Response.parse(buf) -end -def critical - return Net::SMTP::Response.parse('200 dummy reply code') if @error_occurred - begin - return yield() - rescue Exception - @error_occurred = true - raise - end -end -def ssl_socket(socket, context) - OpenSSL::SSL::SSLSocket.new socket, context -end -def tlsconnect(s) - verified = false - s = ssl_socket(s, @ssl_context) - s.sync_close = true - s.connect - if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE - s.post_connection_check(@address) - end - verified = true - s - ensure - s.close unless verified -end -def new_internet_message_io(s) - io = Net::InternetMessageIO.new(s) - io.read_timeout = @read_timeout - io.debug_output = @debug_output - io -end \ No newline at end of file + \ No newline at end of file