- <%- App.Utils.signatureIdentify( @article.html ) %>
+ <%- @article.html %>
diff --git a/app/models/observer/ticket/article/email_signature_detection.rb b/app/models/observer/ticket/article/email_signature_detection.rb
new file mode 100644
index 000000000..595da2296
--- /dev/null
+++ b/app/models/observer/ticket/article/email_signature_detection.rb
@@ -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
diff --git a/config/application.rb b/config/application.rb
index 7f77e647f..4417a999c 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -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',
diff --git a/lib/signature_detection.rb b/lib/signature_detection.rb
index 81f55e665..435d21066 100644
--- a/lib/signature_detection.rb
+++ b/lib/signature_detection.rb
@@ -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