1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# -*- coding: UTF-8 -*-
#
begin
require 'bones/smtp_tls'
rescue LoadError
require 'net/smtp'
end
require 'time'
namespace :ann do
# A prerequisites task that all other tasks depend upon
task :prereqs
file PROJ.ann.file do
ann = PROJ.ann
puts "Generating #{ann.file}"
File.open(ann.file,'w') do |fd|
fd.puts("#{PROJ.name} version #{PROJ.version}")
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
fd.puts
fd.puts("== DESCRIPTION")
fd.puts
fd.puts(PROJ.description)
fd.puts
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
fd.puts
ann.paragraphs.each do |p|
fd.puts "== #{p.upcase}"
fd.puts
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
fd.puts
end
fd.puts ann.text if ann.text
end
end
desc "Create an announcement file"
task :announcement => ['ann:prereqs', PROJ.ann.file]
desc "Send an email announcement"
task :email => ['ann:prereqs', PROJ.ann.file] do
ann = PROJ.ann
from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
to = Array(ann.email[:to])
### build a mail header for RFC 822
rfc822msg = "From: #{from}\n"
rfc822msg << "To: #{to.join(',')}\n"
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
rfc822msg << "\n"
rfc822msg << "Date: #{Time.new.rfc822}\n"
rfc822msg << "Message-Id: "
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
rfc822msg << File.read(ann.file)
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
ann.email[key]
end
params[3] = (PROJ.ann.email[:from] || PROJ.email) if params[3].nil?
# if ann.email[:tls] and params[4].nil?
if params[4].nil?
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
params[4] = STDIN.gets.chomp
end
# params = params.shift 2 if not ann.email[:tls]
### send email
# TODO find a way to bypass /var/lib/gems/1.9/gems/bones-3.6.5/lib/bones/smtp_tls.rb which forces starttls usage
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
end
end # namespace :ann
desc 'Alias to ann:announcement'
task :ann => 'ann:announcement'
CLOBBER << PROJ.ann.file
# EOF
|