On Mon, 3 Jun 2019 at 00:08, <curc...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> curcuru pushed a commit to branch mail_ldap_notification
> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>
> commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
> Author: Shane Curcuru <a...@shanecurcuru.org>
> AuthorDate: Sun Jun 2 19:08:05 2019 -0400
>
>     Encapsulate sending mail from roster tool
>
>     In progress; currently gives "ReferenceError: Can't find variable: 
> __FILE__"

I think that is because the file is converted to Javascript (*.js.rb)
__FILE__ is a Ruby construct.

Is it intended that Javascript should send the email directly from the
browser client?

That seems odd.

S.
> ---
>  www/roster/views/utils.js.rb | 49 
> ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
>
> diff --git a/www/roster/views/utils.js.rb b/www/roster/views/utils.js.rb
> index 1d68c68..2ec2e94 100644
> --- a/www/roster/views/utils.js.rb
> +++ b/www/roster/views/utils.js.rb
> @@ -1,3 +1,4 @@
> +# Utility functions used throughout roster tool
>  class Utils
>
>    # Common processing to handle a response that is expected to be JSON
> @@ -23,4 +24,52 @@ class Utils
>        end
>      end
>    end
> +
> +  # Deliver an LDAP notification email, e.g. pmc/ppmc/group/etc. changes
> +  # Uses creates and mail.deliver! using a template for body
> +  # Includes X-headers to mark as Whimsy email
> +  # DEBUGGING: options: true to prevent actual mail sending
> +  def self.mail_ldap_notification(
> +    from,
> +    to,
> +    cc,
> +    bcc,
> +    subject,
> +    template,
> +    data, # Hash for ERB
> +    options
> +  )
> +    # TODO how should this method report problems?
> +    raise ArgumentError, "From must not be nil or blank" if from.nil? || 
> from == ''
> +    raise ArgumentError, "To or CC must not be nil" if to.nil? && cc.nil?
> +    raise ArgumentError, "Subject must not be nil or blank" if subject.nil? 
> || subject == ''
> +    raise ArgumentError, "Template must not be nil or blank" if 
> template.nil? || template == ''
> +
> +    path = File.expand_path("../../templates/#{template}", __FILE__.untaint)
> +    file = File.join(path, template)
> +    puts "-> #{path} #{template} #{file}"
> +    tmplt = File.read(file.untaint).untaint
> +    mail = Mail.new do
> +      from from
> +      to to
> +      cc cc
> +      bcc bcc
> +      subject subject
> +      b = binding # Bind the passed in data hash to send to ERB
> +      data.each do |key, val|
> +        b.local_variable_set(key.to_sym, val)
> +      end
> +      body ERB.new(tmplt).result(b)
> +    end
> +
> +    # Header for root@ mail filters, per request infra
> +    mail.header['X-For-Root'] = 'yes'
> +    # Header to denote automated mail from whimsy
> +    mail.header['X-Mailer'] = 'whimsy/www/roster/utils(0.1)'
> +
> +    # Deliver email
> +    mail.delivery_method :test if options # TODO DEBUGGING don't actually 
> send mail, just log it
> +    mail.deliver!
> +    return mail
> +  end
>  end
>

Reply via email to