Class: Reap::Announce

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/task/announce.rb

Overview

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.

Constant Summary

Constants inherited from Task

Task::RUBY

Instance Method Summary collapse

Methods inherited from Task

#ask, #execute, inherited, #initialize, #initiate, master, #master, #provide_setup_rb, #section, section_required, section_required?, #section_required?, #sh, #task, task_attr, #task_desc, task_desc, #task_help, task_help, task_list, #task_name, task_name, #tell, #use_subsection, verify?

Constructor Details

This class inherits a constructor from Reap::Task

Instance Method Details

#runObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/reap/task/announce.rb', line 75

def run

  # setup

  anc.to       = (anc.to || '[email protected]').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.  = anc..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..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.}: "
  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., 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