Detect signature for users. Added signature lookup for new customer articles.
This commit is contained in:
parent
7a7d9471c9
commit
4029987caa
5 changed files with 99 additions and 7 deletions
|
@ -108,11 +108,25 @@ class ArticleViewItem extends App.Controller
|
|||
return
|
||||
|
||||
# prepare html body
|
||||
signatureDetected = false
|
||||
if @article.content_type is 'text/html'
|
||||
@article['html'] = @article.body
|
||||
else
|
||||
@article['html'] = App.Utils.textCleanup( @article.body )
|
||||
@article['html'] = App.Utils.text2html( @article.body )
|
||||
|
||||
# check if signature got detected in backend
|
||||
body = @article.body
|
||||
if @article.preferences && @article.preferences.signature_detection
|
||||
signatureDetected = '########SIGNATURE########'
|
||||
body = body.split("\n")
|
||||
body.splice(@article.preferences.signature_detection, 0, signatureDetected)
|
||||
body = body.join("\n")
|
||||
body = App.Utils.textCleanup(body)
|
||||
@article['html'] = App.Utils.text2html(body)
|
||||
|
||||
if signatureDetected
|
||||
@article['html'] = @article['html'].replace(signatureDetected, '<span class="js-signatureMarker"></span>')
|
||||
else
|
||||
@article['html'] = App.Utils.signatureIdentify( @article['html'] )
|
||||
|
||||
@html App.view('ticket_zoom/article_view')(
|
||||
ticket: @ticket
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<div class="textBubble">
|
||||
<div class="bubble-arrow"></div>
|
||||
<div class="textBubble-content" id="article-content-<%= @article.id %>" data-id="<%= @article.id %>">
|
||||
<%- App.Utils.signatureIdentify( @article.html ) %>
|
||||
<%- @article.html %>
|
||||
<div class="textBubble-overflowContainer hide">
|
||||
<div class="btn btn--text js-unfold"><%- @T('See more') %></div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class Observer::Ticket::Article::EmailSignatureDetection < ActiveRecord::Observer
|
||||
observe 'ticket::_article'
|
||||
|
||||
def before_create(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
|
||||
# if sender is not customer, do not change anything
|
||||
sender = Ticket::Article::Sender.lookup( id: record.sender_id )
|
||||
return if !sender
|
||||
return if sender['name'] != 'Customer'
|
||||
|
||||
# set email attributes
|
||||
type = Ticket::Article::Type.lookup( id: record.type_id )
|
||||
return if type['name'] != 'email'
|
||||
|
||||
# user
|
||||
user = User.lookup(id: record.created_by_id)
|
||||
return if !user
|
||||
return if !user.preferences
|
||||
return if !user.preferences[:signature_detection]
|
||||
|
||||
record.preferences[:signature_detection] = SignatureDetection.find_signature_line(user.preferences[:signature_detection], record.body)
|
||||
|
||||
end
|
||||
end
|
|
@ -30,6 +30,7 @@ module Zammad
|
|||
'observer::_ticket::_article::_communicate_email',
|
||||
'observer::_ticket::_article::_communicate_facebook',
|
||||
'observer::_ticket::_article::_communicate_twitter',
|
||||
'observer::_ticket::_article::_email_signature_detection',
|
||||
'observer::_ticket::_notification',
|
||||
'observer::_ticket::_reset_new_state',
|
||||
'observer::_ticket::_escalation_calculation',
|
||||
|
|
|
@ -18,7 +18,6 @@ returns
|
|||
possible_signatures = {}
|
||||
|
||||
# loop all strings in array
|
||||
#for main_string_index in 0 .. string_list.length - 1
|
||||
( 0..string_list.length - 1 ).each {|main_string_index|
|
||||
break if main_string_index + 1 > string_list.length - 1
|
||||
|
||||
|
@ -76,6 +75,7 @@ returns
|
|||
possible_signatures[match_content] ||= 0
|
||||
possible_signatures[match_content] += 1
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
match_block = nil
|
||||
|
@ -115,8 +115,56 @@ returns
|
|||
return if search_position.nil?
|
||||
|
||||
# count new lines up to signature
|
||||
search_newlines = string[0..search_position].split("\n").length + 1
|
||||
|
||||
search_newlines
|
||||
string[0..search_position].split("\n").length + 1
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
this function will search for a signature string in all articles of a given user_id
|
||||
|
||||
signature = SignatureDetection.by_user_id(user_id)
|
||||
|
||||
returns
|
||||
|
||||
signature = '...signature possible match...'
|
||||
|
||||
=end
|
||||
|
||||
def self.by_user_id(user_id)
|
||||
|
||||
article_type = Ticket::Article::Type.lookup(name: 'email')
|
||||
article_bodies = []
|
||||
tickets = Ticket.where(created_by_id: user_id, create_article_type_id: article_type.id).limit(10).order(id: :desc)
|
||||
tickets.each {|ticket|
|
||||
article = ticket.articles.first
|
||||
article_bodies.push article.body
|
||||
}
|
||||
find_signature( article_bodies )
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
rebuild signature for each user
|
||||
|
||||
SignatureDetection.rebuild_all
|
||||
|
||||
returns
|
||||
|
||||
true/false
|
||||
|
||||
=end
|
||||
|
||||
def self.rebuild_all
|
||||
|
||||
User.select('id').where(active: true).each {|local_user|
|
||||
signature_detection = by_user_id(local_user.id)
|
||||
next if !signature_detection
|
||||
user = User.find(local_user.id)
|
||||
next if user.preferences[:signature_detection] == signature_detection
|
||||
user.preferences[:signature_detection] = signature_detection
|
||||
user.save
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue