You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/03/05 13:05:31 UTC
[whimsy.git] [1/1] Commit c407730: refactor out common mail configuration
Commit c407730a9c0babdc34200be691470b7b63937be5:
refactor out common mail configuration
Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>
------------------------------------------------------------
DEVELOPMENT.md | ++++++++
lib/whimsy/asf/mail.rb | ++++++++++++
www/board/agenda/views/actions/feedback.json.rb | ++ -----
www/board/agenda/views/actions/send-reminders.json.rb | ++ -----
www/roster/main.rb | + ----
------------------------------------------------------------
74 changes: 60 additions, 14 deletions.
------------------------------------------------------------
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 41097b1..db85bc4 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -116,6 +116,37 @@ Skip this section if you are running a Docker container or a Vagrant VM.
See comments in that file for running the script as a standalone server.
+6. Configuring sending of mail (optional):
+
+ Configuration of outbound mail delivery is done through the `.whimsy`
+ file. Three examples are provided below, followed by links to where
+ documentation of the parameters can be found.
+
+ :sendmail:
+ delivery_method: sendmail
+
+ :sendmail:
+ delivery_method: smtp
+ address: smtp-server.nc.rr.com
+ domain: intertwingly.net
+
+ :sendmail:
+ delivery_method: smtp
+ address: smtp.gmail.com
+ port: 587
+ domain: apache.org
+ user_name: username
+ password: password
+ authentication: plain
+ enable_starttls_auto: true
+
+ For more details, see the mail gem documention for
+ [smtp](http://www.rubydoc.info/github/mikel/mail/Mail/SMTP),
+ [exim](http://www.rubydoc.info/github/mikel/mail/Mail/Exim),
+ [sendmail](http://www.rubydoc.info/github/mikel/mail/Mail/Sendmail),
+ [testmailer](http://www.rubydoc.info/github/mikel/mail/Mail/TestMailer), and
+ [filedelivery](http://www.rubydoc.info/github/mikel/mail/Mail/FileDelivery)
+
Running Scripts/Applications
============================
diff --git a/lib/whimsy/asf/mail.rb b/lib/whimsy/asf/mail.rb
index b47fbbc..98aff2a 100644
--- a/lib/whimsy/asf/mail.rb
+++ b/lib/whimsy/asf/mail.rb
@@ -48,6 +48,30 @@ def self.lists(public_private= false)
public_private ? @lists : @lists.keys
end
+
+ # common configuration for sending mail
+ def self.configure
+ # fetch overrides
+ sendmail = ASF::Config.get(:sendmail)
+
+ if sendmail
+ # convert string keys to symbols
+ options = Hash[options.map {|key, value| [key.to_sym, value]}]
+
+ # extract delivery method
+ method = options.delete(:delivery_method).to_s.to_sym
+ else
+ # provide defaults that work on whimsy-vm* infrastructure. Since
+ # procmail is configured with a self-signed certificate, verification
+ # isn't a possibility
+ method = :smtp
+ options = {openssl_verify_mode: 'none'}
+ end
+
+ ::Mail.defaults do
+ delivery_method method, options
+ end
+ end
end
class Person < Base
diff --git a/www/board/agenda/views/actions/feedback.json.rb b/www/board/agenda/views/actions/feedback.json.rb
index b4de899..1a710f6 100644
--- a/www/board/agenda/views/actions/feedback.json.rb
+++ b/www/board/agenda/views/actions/feedback.json.rb
@@ -2,6 +2,8 @@
# send feedback on reports
#
+ASF::Mail.configure
+
# fetch minutes
@minutes = @agenda.sub('_agenda_', '_minutes_')
minutes_file = "#{AGENDA_WORK}/#{@minutes.sub('.txt', '.yml')}"
@@ -14,11 +16,6 @@
minutes = {}
end
-# utilize smtp without certificate verification
-Mail.defaults do
- delivery_method :smtp, openssl_verify_mode: 'none'
-end
-
# extract values for common fields
unless @from
sender = ASF::Person.find(env.user || ENV['USER'])
diff --git a/www/board/agenda/views/actions/send-reminders.json.rb b/www/board/agenda/views/actions/send-reminders.json.rb
index a75c2b4..dc5766a 100644
--- a/www/board/agenda/views/actions/send-reminders.json.rb
+++ b/www/board/agenda/views/actions/send-reminders.json.rb
@@ -2,14 +2,11 @@
# send reminders
#
+ASF::Mail.configure
+
sent = {}
unsent = []
-# utilize smtp without certificate verification
-Mail.defaults do
- delivery_method :smtp, openssl_verify_mode: 'none'
-end
-
# extract values for common fields
subject = @subject.untaint
from = @from
diff --git a/www/roster/main.rb b/www/roster/main.rb
index 0c16b19..217fb41 100755
--- a/www/roster/main.rb
+++ b/www/roster/main.rb
@@ -20,10 +20,7 @@
require_relative 'banner'
require_relative 'models'
-# Disable smtp certificate verification
-Mail.defaults do
- delivery_method :smtp, openssl_verify_mode: 'none'
-end
+ASF::Mail.configure
get '/' do
if env['REQUEST_URI'].end_with? '/'