From 80388a261ea27f05a5b044d20dfa5d75cbaee185 Mon Sep 17 00:00:00 2001 From: Carlos Gant Date: Tue, 14 Mar 2017 00:20:20 +0100 Subject: [PATCH 1/2] inline image support --- app/views/helpdesk/note_edit.html.erb | 1 + app/views/helpdesk/note_edit.text.erb | 1 + lib/helpdesk_mailer.rb | 27 ++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 app/views/helpdesk/note_edit.html.erb create mode 100644 app/views/helpdesk/note_edit.text.erb diff --git a/app/views/helpdesk/note_edit.html.erb b/app/views/helpdesk/note_edit.html.erb new file mode 100644 index 0000000..df8c122 --- /dev/null +++ b/app/views/helpdesk/note_edit.html.erb @@ -0,0 +1 @@ +<%= @text.html_safe %> \ No newline at end of file diff --git a/app/views/helpdesk/note_edit.text.erb b/app/views/helpdesk/note_edit.text.erb new file mode 100644 index 0000000..c5dcb7d --- /dev/null +++ b/app/views/helpdesk/note_edit.text.erb @@ -0,0 +1 @@ +<%= ActionView::Base.full_sanitizer.sanitize(@text) %> \ No newline at end of file diff --git a/lib/helpdesk_mailer.rb b/lib/helpdesk_mailer.rb index e185453..a1e0171 100644 --- a/lib/helpdesk_mailer.rb +++ b/lib/helpdesk_mailer.rb @@ -3,6 +3,7 @@ # uses this method-name too in their mailer. This is the reason # why we need our own Mailer class. # + class HelpdeskMailer < ActionMailer::Base helper :application @@ -16,12 +17,12 @@ def self.default_url_options # Sending email notifications to the supportclient def email_to_supportclient(issue, params) - # issue, recipient, journal=nil, text='', copy_to=nil + # issue, recipient, journal=nil, text='', copy_to=nil recipient = params[:recipient] journal = params[:journal] text = params[:text] - carbon_copy = params[:carbon_copy] + carbon_copy = params[:carbon_copy] redmine_headers 'Project' => issue.project.identifier, 'Issue-Id' => issue.id, @@ -53,33 +54,49 @@ def email_to_supportclient(issue, params) if d.property == 'attachment' a = Attachment.find(d.prop_key) begin - attachments[a.filename] = File.read(a.diskfile) + if ['image/png', 'image/jpg', 'image/gif', 'image/jpeg'].include? a.content_type + attachments.inline[a.filename] = File.read(a.diskfile) + image_url = attachments.inline[a.filename].url + text = text.gsub("!#{a.filename}!", "") + else + attachments[a.filename] = File.read(a.diskfile) + end rescue # ignore rescue end end end end + if @message_id_object headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>" end if @references_objects headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') end + # create mail object to deliver mail = if text.present? || reply.present? + # sending out the journal note to the support client # or the first reply message - t = text.present? ? "#{text}\n\n#{footer}" : reply + t = text.present? ? expand_macros(text, issue, journal) : reply + t = "#{t}\n\n#{footer}" + + @text = t.gsub(/\n/,"
") mail( :from => sender.present? && sender || Setting.mail_from, :reply_to => sender.present? && sender || Setting.mail_from, :to => recipient, :subject => subject, - :body => expand_macros(t, issue, journal), + :template_path => 'helpdesk', + :template_name => 'note_edit', + # :body => expand_macros(t, issue, journal), + #:body => text, :date => Time.zone.now, :cc => carbon_copy ) + else # fallback to a regular notifications email with redmine view @issue = issue From 1d636d39e149049e20657d3330a22374037d3a32 Mon Sep 17 00:00:00 2001 From: Carlos Gant Date: Mon, 10 Apr 2017 19:39:09 +0200 Subject: [PATCH 2/2] optional-user-support --- lib/helpdesk_mailer.rb | 4 ++-- lib/macro_expander.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/helpdesk_mailer.rb b/lib/helpdesk_mailer.rb index a1e0171..3e621b4 100644 --- a/lib/helpdesk_mailer.rb +++ b/lib/helpdesk_mailer.rb @@ -80,8 +80,8 @@ def email_to_supportclient(issue, params) # sending out the journal note to the support client # or the first reply message - t = text.present? ? expand_macros(text, issue, journal) : reply - t = "#{t}\n\n#{footer}" + t = text.present? ? text : reply + t = expand_macros("#{t}\n\n#{footer}", issue, journal) @text = t.gsub(/\n/,"
") mail( diff --git a/lib/macro_expander.rb b/lib/macro_expander.rb index 20bfa0f..bb42ece 100644 --- a/lib/macro_expander.rb +++ b/lib/macro_expander.rb @@ -19,6 +19,7 @@ def expand expand_project end expand_user unless @journal.nil? + expand_optional_user expand_base @string @@ -48,6 +49,14 @@ def expand_user expand_user_cf(u) end + def expand_optional_user + if @journal.nil? + @string.gsub!("##user-name-optional##", "") + else + @string.gsub!("##user-name-optional##", @journal.user.name) + end + end + def expand_user_cf(user) CustomField.where( "type = 'UserCustomField'").each do |user_cf|