lib/hyla/commands/sendmail.rb in hyla-1.0.3 vs lib/hyla/commands/sendmail.rb in hyla-1.0.4
- old
+ new
@@ -2,13 +2,14 @@
module Commands
class Sendmail < Command
def self.process(args, options)
- location = options[:location] if check_mandatory_option?('-s / --location', options[:location])
+ location = options[:source] if self.check_mandatory_option?('-s / --source', options[:source])
file_name = options[:file] if check_mandatory_option?('-f / --file', options[:file])
email_attributes = options[:email_attributes] if check_mandatory_option?('-e / --email_attributes', options[:email_attributes])
+ attachment = options[:attachment]
sender = email_attributes[:from]
recipients = email_attributes[:to]
subject = email_attributes[:subject]
file_path = [location, file_name] * '/'
@@ -44,25 +45,27 @@
</div>
</body>
</html>
EOS
- mail = Mail.new do
- to recipients
- from sender
- subject subject
- content_type 'multipart/related'
- end
+ mail = populate_email(recipients, sender, subject)
- attachment = File.read(file_path)
- mail.attachments[file_name] = {
- :mime_type => 'application/x-html',
- :content => attachment,
- :Content_Transfer_Encoding => 'quoted-printable'}
+ case attachment
+ when true
- inline_html = inline_body_with_attachments(body, mail.attachments)
+ attachment = File.read(file_path)
+ mail.attachments[file_name] = {
+ :mime_type => 'application/x-html',
+ :content => attachment,
+ :Content_Transfer_Encoding => 'quoted-printable'}
+ inline_html = inline_body_with_attachments(body, mail.attachments)
+
+ when false
+ inline_html = File.read(file_path)
+ end
+
html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body inline_html
end
@@ -71,10 +74,28 @@
mail.delivery_method :smtp, parameters()
mail.deliver!
Hyla.logger.info "Email send to SMTP server from #{sender} with this subject : #{subject}"
end
+ #
+ # Create Mail using
+ # Recipients, Sender and subject
+ #
+ def self.populate_email(recipients, sender, subject)
+ mail = Mail.new do
+ to recipients
+ from sender
+ subject subject
+ content_type 'multipart/related'
+ end
+ return mail
+ end
+
+ #
+ # Generate the Hash of the parameters
+ # used by mail compoent nto send email
+ #
def self.parameters()
parameters = {}
parameters[:address] = @smtp_server unless @smtp_server.nil?
parameters[:port] = @port_number unless @port_number.nil?
parameters[:enable_starttls] = @enable_starttls unless @enable_starttls.nil?
@@ -82,9 +103,12 @@
parameters[:password] = @password unless @password.nil?
parameters[:authentication] = @authentication unless @authentication.nil?
return parameters
end
+ #
+ # Substitute filename with cid
+ #
def self.inline_body_with_attachments(html, attachments)
attachments.each do |attachment|
if (html =~ /#{attachment.filename}/)
html = html.sub(attachment.filename, "cid:#{attachment.cid}")
end
\ No newline at end of file