#-- # _ # /_\ _ _ _ _ ___ _ _ _ _ __ ___ # / _ \| ' \| ' \/ _ \ || | ' \/ _/ -_) # /_/ \_\_||_|_||_\___/\_,_|_||_\__\___| # #++ require 'net/smtp' require 'facet/string/margin' require 'facet/string/tab' require 'facet/string/align_center' require 'facet/string/fold' require 'facet/string/word_wrap' module Reap # = Announce # # The announce task is intended for sending out a nice # formated email message to a mailing address, especially # mailing-lists. # # Announcement specific settings: # # server Email server to route message. # port Email server's port. # domain Email server's domain name. # account Email account name. # type Login type, either plain, cram_md5 or login. # secure Uses TLS security, true or false? # to Email address to send announcemnt. # from Email address sent from. # subject Subject of email message. # links Array of http links to related sites. # file File that contains announcement message. # memo Embedded announcement message. # slogan Motto for you project. # # Inherited settings: # # title Project title. # summary Brief one-line description. # description Long description of project. # homepage Project homepage web address. # class Announce include TaskUtils attr :anc def initialize( anc ) @anc = anc.to_openobject anc.to = (anc.to || 'ruby-talk@ruby-lang.org').to_s.strip anc.from = anc.from.to_s.strip anc.server = anc.server.to_s.strip anc.port = (anc.port || 25).to_i anc.domain = anc.domain.to_s.strip if anc.domain anc.account = anc.account.to_s.strip anc.type = (anc.type || 'plain').to_s.strip #cram_md5 #plain #login #anc.title ||= master.title #anc.version ||= master.version || master.date anc.links ||= [] anc.subject ||= "[ANN] #{anc.title}, v#{anc.version}" anc.address = anc.to # TODO end # Validate data. def valid? return false, "server is a require announce field" if anc.server.empty? return false, "account is a require announce field" if anc.account.empty? #return false, "DOMAIN is a required field" if anc.domain.empty? true end def call ; write_and_email ; end # Generate announcement and email it. def write_and_email message = build_message puts "\n#{message}\n\n" print "Send? [y/N] " until inp = $stdin.gets[0,1] ; sleep 1 ; end unless inp.downcase == 'y' puts "Reap announce task canceled." return nil end # ask for password print "Password for #{anc.account}: " until passwd = $stdin.gets.strip ; sleep 1 ; end mail = %Q{ |From: #{anc.from} |To: #{anc.address} |Subject: #{anc.subject} | |#{message} }.margin begin # --- Send using SMTP object and an adaptor Net::SMTP.enable_tls if Net::SMTP.respond_to?(:enable_tls) and anc.secure # == :tls Net::SMTP.start(anc.server, anc.port, anc.domain, anc.account, passwd, anc.type) do |s| s.send_message mail, anc.from, anc.address end puts "Email sent successfully to #{anc.address}." rescue => e puts "Email delivery failed." puts e end end private def build_message ver = anc.version.chomp('.0').chomp('.0') # header announce = %Q{ | |A N N O U N C I N G | |#{anc.title} #{ver} | |#{anc.summary} | |#{anc.homepage} }.margin.align_center(66) # abstract abstract = '' if anc.description abstract << "\n\n" abstract << "ABSTRACT\n--------\n\n#{anc.description}" abstract << "\n" end # more info info = '' unless anc.links.empty? info << "\n\n" info << "\nRELATED LINKS\n-------------\n\n" #.center(67) anc.links.each{ |mi| info << "#{mi}" << "\n" } #.center(67) << "\n" } info << "\n" end # slogan slogan = '' if anc.slogan slogan << "\n\n" slogan << anc.slogan.center(67) slogan << "\n\n" end # memo memo = '' if anc.memo memo = '' #memo << "\n---\n" #<< ('-' * 72) << "\n" memo << "\nRELEASE MEMO\n------------\n\n" memo << anc.memo.strip.fold(true) #.word_wrap(67) #memo << "\n" end # msg file msg = '' if anc.file and File.file?( anc.file ) msg << "\nRELEASE MEMO\n------------\n\n" #msg << "\n---\n" #<< ("-" * 68) << "\n" #msg << "(from #{anc.file})\n\n" mg = File.read( anc.file ) msg << mg.strip.fold(true) #.word_wrap(67) end # stamp stamp = "\n\n\n" #stamp << "\n\n---\n" #<< ("-" * 68) << "\n" stamp << %q{ ! Generated by ! ___ ! | _ \___ __ _ _ __ ! | ) -_) _` | '_ \ ! |_|_\___\__,_| .__) ! |_| ! ! The Ruby Project Assistant ! ! Do you Ruby? (http://www.ruby-lang.org) }.margin(12) #.indent(12) stamp << "\n" message = '' message << announce message << slogan message << abstract message << memo message << msg message << info message << stamp message end end end #module Reap