require 'reap/task' 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' # _ _____ _ # /_\ _ _ _ _ ___ _ _ _ _ __ ___ |_ _|_ _ __| |__ # / _ \| ' \| ' \/ _ \ || | ' \/ _/ -_) | |/ _` (_-< / / # /_/ \_\_||_|_||_\___/\_,_|_||_\__\___| |_|\__,_/__/_\_\ # # = Announcement Task # # The announce task is intended for sending out a nice # formated email message to a mailing address, especially # mailing-lists. ProjectInfo uses these parameters: # # announce: # 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. # title Project title. # summary Brief onl-liner description. # description Long description of project. # homespage Project homepage web address. # links Array of http links to related sites. # file File that contains announcement message. # memo Embedded announcement message. # slogan: Motto for you project. # class Reap::Announce < Reap::Task section_required true task_desc "Email project announcement." task_help %{ reap announce Send an announcement to a mailaing list or other email address. Server settings are 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? Message settings are to Email address to send announcemnt. from Email address sent from. subject Subject of email message. file File that contains announcement message. memo Embedded announcement message. } alias_method :anc, :task def run # setup anc.to = (anc.to || 'ruby-talk@ruby-lang.org').to_s.strip anc.from = (anc.from || master['email']).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 raise "server is a require announce field" if anc.server.empty? raise "account is a require announce field" if anc.account.empty? 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 # validate #raise "DOMAIN is a required field" if anc.domain.empty? # announce 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 # header announce = %Q{ | |A N N O U N C I N G | |#{anc.title}, v#{anc.version} | |#{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 | | o)o)o) o)o)o)o) o)o) o)o)o) | o) o) o) o) o) o) o) | o)o)o) o)o)o) o)o)o)o) o)o)o) | o) o) o) o) o) o) | o) o) o)o)o)o) o) o) o) | | The Ruby Project Assistant | | Do you Ruby? (http://www.ruby-lang.org) }.margin.indent(12) stamp << "\n" message = '' message << announce message << slogan message << abstract message << memo message << msg message << info message << stamp message end end