Class: Detroit::Email
- Inherits:
-
Tool
- Object
- Tool
- Detroit::Email
- Includes:
- EmailUtils, Standard
- Defined in:
- lib/detroit-email.rb
Overview
The Email tool is used to send out project announcements to a set of email addresses.
By default it generates a *release announcement* based on a projects metadata. Release announcements can be customized via parts, including a project’s README file.
Fully custom messages can also be sent by setting the message field, and or by using a message file.
Email account settings default to environment variables so they need not be set independently for every project.
@server ENV['EMAIL_SERVER']
@from ENV['EMAIL_FROM']
@account ENV['EMAIL_ACCOUNT'] || ENV['EMAIL_FROM']
@password ENV['EMAIL_PASSWORD']
@port ENV['EMAIL_PORT']
@domain ENV['EMAIL_DOMAIN']
@login ENV['EMAIL_LOGIN']
@secure ENV['EMAIL_SECURE']
This tool ties into the ‘prepare` and `promote` stations of the standard toolchain.
Constant Summary collapse
- MANPAGE =
Location of manpage for this tool.
File.dirname(__FILE__) + '/../man/detroit-email.5'
Instance Attribute Summary collapse
-
#account ⇒ Object
Email account name (defaults to from).
-
#domain ⇒ Object
User domain (not sure why SMTP requires this?).
-
#file ⇒ Object
Message file to send.
-
#from ⇒ Object
Email address from whom.
-
#login ⇒ Object
Login type (plain, login).
-
#mailto ⇒ Object
(also: #to)
List of email addresses to whom to email.
-
#noenv ⇒ Object
Do not use environment variables for email defaults.
-
#parts ⇒ Object
Components of announcment.
-
#port ⇒ Object
Emails server port (default is usually correct).
-
#secure ⇒ Object
Use TLS/SSL true or false?.
-
#server ⇒ Object
Email server.
-
#subject ⇒ Object
Subject line (default is “ANN: title version”).
Instance Method Summary collapse
-
#announce ⇒ Object
Send announcement message.
-
#apply_environment ⇒ Object
Apply environment settings.
-
#approve ⇒ Object
Ask developer if the mail should be sent.
- #assemble?(station, options = {}) ⇒ Boolean
-
#mail_confirm? ⇒ Boolean
Confirm announcement.
- #mailopts ⇒ Object
-
#message ⇒ Object
Message to send.
-
#prepare ⇒ Object
Alias for #approve.
-
#prerequisite ⇒ void
Load any special requirements and set attribute defaults.
-
#promote ⇒ Object
Alias for #announce.
Instance Attribute Details
#account ⇒ Object
Email account name (defaults to from).
91 92 93 |
# File 'lib/detroit-email.rb', line 91 def account @account end |
#domain ⇒ Object
User domain (not sure why SMTP requires this?).
94 95 96 |
# File 'lib/detroit-email.rb', line 94 def domain @domain end |
#file ⇒ Object
Message file to send.
70 71 72 |
# File 'lib/detroit-email.rb', line 70 def file @file end |
#from ⇒ Object
Email address from whom.
79 80 81 |
# File 'lib/detroit-email.rb', line 79 def from @from end |
#login ⇒ Object
Login type (plain, login).
97 98 99 |
# File 'lib/detroit-email.rb', line 97 def login @login end |
#mailto ⇒ Object Also known as: to
List of email addresses to whom to email.
73 74 75 |
# File 'lib/detroit-email.rb', line 73 def mailto @mailto end |
#noenv ⇒ Object
Do not use environment variables for email defaults.
106 107 108 |
# File 'lib/detroit-email.rb', line 106 def noenv @noenv end |
#parts ⇒ Object
Components of announcment.
103 104 105 |
# File 'lib/detroit-email.rb', line 103 def parts @parts end |
#port ⇒ Object
Emails server port (default is usually correct).
88 89 90 |
# File 'lib/detroit-email.rb', line 88 def port @port end |
#secure ⇒ Object
Use TLS/SSL true or false?
100 101 102 |
# File 'lib/detroit-email.rb', line 100 def secure @secure end |
#server ⇒ Object
Email server.
85 86 87 |
# File 'lib/detroit-email.rb', line 85 def server @server end |
#subject ⇒ Object
Subject line (default is “ANN: title version”).
82 83 84 |
# File 'lib/detroit-email.rb', line 82 def subject @subject end |
Instance Method Details
#announce ⇒ Object
Send announcement message.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/detroit-email.rb', line 125 def announce apply_environment unless @approved mailopts = self.mailopts if mailto.empty? report "No recipents given." else if trial? subject = mailopts['subject'] mailto = mailopts['to'].flatten.join(", ") report "email '#{subject}' to #{mailto}" else #emailer = Emailer.new(mailopts) #emailer.email if @approved email(mailopts) else exit -1 end end end end |
#apply_environment ⇒ Object
Apply environment settings.
208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/detroit-email.rb', line 208 def apply_environment return if noenv @server ||= ENV['EMAIL_SERVER'] @from ||= ENV['EMAIL_FROM'] || ENV['EMAIL_ACCOUNT'] @account ||= ENV['EMAIL_ACCOUNT'] || ENV['EMAIL_FROM'] @password ||= ENV['EMAIL_PASSWORD'] @port ||= ENV['EMAIL_PORT'] @domain ||= ENV['EMAIL_DOMAIN'] @login ||= ENV['EMAIL_LOGIN'] @secure ||= ENV['EMAIL_SECURE'] end |
#approve ⇒ Object
Ask developer if the mail should be sent.
114 115 116 117 118 119 |
# File 'lib/detroit-email.rb', line 114 def approve apply_environment @approved = mail_confirm? # TODO: better way to terminate? exit -1 unless @approved end |
#assemble?(station, options = {}) ⇒ Boolean
237 238 239 240 241 |
# File 'lib/detroit-email.rb', line 237 def assemble?(station, ={}) return true if station == :prepare && approve?() return true if station == :promote return false end |
#mail_confirm? ⇒ Boolean
Confirm announcement
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/detroit-email.rb', line 168 def mail_confirm? if mailto return true if force? to = [mailto].flatten.join(", ") ans = ask("Announce to #{to} [(v)iew (y)es (N)o]? ") case ans.downcase when 'y', 'yes' true when 'v', 'view' puts "From: #{from}" puts "To: #{to}" puts "Subject: #{subject}" puts puts mail_confirm? else false end end end |
#mailopts ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/detroit-email.rb', line 190 def mailopts = { 'message' => self., 'to' => self.to, 'from' => self.from, 'subject' => self.subject, 'server' => self.server, 'port' => self.port, 'account' => self.account, 'domain' => self.domain, 'login' => self.login, 'secure' => self.secure } .delete_if{|k,v| v.nil?} end |
#message ⇒ Object
Message to send. Defaults to a generated release announcement.
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/detroit-email.rb', line 155 def @message ||= ( path = Dir[file].first if file if path project.announcement(File.new(file)) else parts.map{ |part| /^file:\/\// =~ part.to_s ? $' : part } project.announcement(*parts) end ) end |
#prepare ⇒ Object
Alias for #approve.
122 |
# File 'lib/detroit-email.rb', line 122 def prepare; approve; end |
#prerequisite ⇒ void
This method returns an undefined value.
Load any special requirements and set attribute defaults.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/detroit-email.rb', line 51 def prerequisite require 'facets/boolean' # TODO: should this universal? @mailto = ['[email protected]'] @subject = "[ANN] %s v%s released" % [.title, .version] @file = nil #'doc/ANN{,OUNCE}{,.txt,.rdoc}' TODO: default announcment file? @parts = [:message, :description, :resources, :notes, :changes] #mailopts = Ratch::Emailer.environment_options.rekey(&:to_s) # FIXME #@port = mailopts['port'] #@server = mailopts['server'] #@account = mailopts['account'] #|| metadata.email #@domain = mailopts['domain'] #|| metadata.domain #@login = mailopts['login'] #@secure = mailopts['secure'] #@from = mailopts['from'] #|| metadata.email end |
#promote ⇒ Object
Alias for #announce.
150 151 152 |
# File 'lib/detroit-email.rb', line 150 def promote announce end |