Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline image support #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/views/helpdesk/note_edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @text.html_safe %>
1 change: 1 addition & 0 deletions app/views/helpdesk/note_edit.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= ActionView::Base.full_sanitizer.sanitize(@text) %>
27 changes: 22 additions & 5 deletions lib/helpdesk_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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}!", "<img src='#{image_url}' />")
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? ? text : reply
t = expand_macros("#{t}\n\n#{footer}", issue, journal)

@text = t.gsub(/\n/,"<br/>")
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
Expand Down
9 changes: 9 additions & 0 deletions lib/macro_expander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def expand
expand_project
end
expand_user unless @journal.nil?
expand_optional_user
expand_base

@string
Expand Down Expand Up @@ -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|
Expand Down