From 6ad0245db6e354174a040b9674304e242c5c2e98 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 11 Dec 2015 15:11:34 +0100 Subject: [PATCH] Added support of references header in outgoing emails. --- app/models/channel/email_build.rb | 6 ++++- .../communicate_email/background_job.rb | 25 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 800300075..ce7ddbf1b 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -40,7 +40,11 @@ module Channel::EmailBuild next if key.to_s == 'attachments' next if key.to_s == 'body' next if key.to_s == 'content_type' - mail[key.to_s] = value.to_s + if value && value.class != Array + mail[key.to_s] = value.to_s + else + mail[key.to_s] = value + end end # add html part diff --git a/app/models/observer/ticket/article/communicate_email/background_job.rb b/app/models/observer/ticket/article/communicate_email/background_job.rb index 6873ebf94..6e8feb137 100644 --- a/app/models/observer/ticket/article/communicate_email/background_job.rb +++ b/app/models/observer/ticket/article/communicate_email/background_job.rb @@ -4,11 +4,11 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob end def perform - record = Ticket::Article.find( @article_id ) + record = Ticket::Article.find(@article_id) # build subject - ticket = Ticket.lookup( id: record.ticket_id ) - subject = ticket.subject_build( record.subject ) + ticket = Ticket.lookup(id: record.ticket_id) + subject = ticket.subject_build(record.subject) # send email if !ticket.group.email_address_id @@ -16,6 +16,24 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob elsif !ticket.group.email_address.channel_id fail "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'" end + + # get references headers + references = [] + if record.in_reply_to + references.push record.in_reply_to + end + + # add all other article message_ids + Ticket::Article.where(ticket_id: record.ticket_id).each {|article| + if article.in_reply_to && !article.in_reply_to.empty? + references.push article.in_reply_to + end + next if !article.message_id + next if !article.message_id.empty? + next if article.id == @article_id + references.push article.message_id + } + channel = ticket.group.email_address.channel # get linked channel and send @@ -23,6 +41,7 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob { message_id: record.message_id, in_reply_to: record.in_reply_to, + references: references, from: record.from, to: record.to, cc: record.cc,