From 8d71977e0f28f45f977baacaf92208f88f18ed6a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 30 Jun 2016 11:53:13 +0200 Subject: [PATCH] Improved api for signature detection of article. --- app/models/transaction/signature_detection.rb | 7 +- lib/signature_detection.rb | 25 +++++ .../email_signature_detection/example1.html | 106 ++++++++++++++++++ test/unit/email_signatur_detection_test.rb | 13 ++- 4 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/email_signature_detection/example1.html diff --git a/app/models/transaction/signature_detection.rb b/app/models/transaction/signature_detection.rb index 58f6dec78..7f85183cb 100644 --- a/app/models/transaction/signature_detection.rb +++ b/app/models/transaction/signature_detection.rb @@ -52,10 +52,9 @@ class Transaction::SignatureDetection return if !user return if !user.preferences return if !user.preferences[:signature_detection] - article.preferences[:signature_detection] = SignatureDetection.find_signature_line( - user.preferences[:signature_detection], - article.body, - article.content_type, + article.preferences[:signature_detection] = SignatureDetection.find_signature_line_by_article( + user, + article ) article.save end diff --git a/lib/signature_detection.rb b/lib/signature_detection.rb index 215c8dab5..18594b4cd 100644 --- a/lib/signature_detection.rb +++ b/lib/signature_detection.rb @@ -143,6 +143,31 @@ returns =begin +find signature line of message by user and article + + signature_line = SignatureDetection.find_signature_line_by_article(user, article) + +returns + + signature_line = 123 + + or + + signature_line = nil + +=end + + def find_signature_line_by_article(user, article) + return if !user.preferences[:signature_detection] + SignatureDetection.find_signature_line( + user.preferences[:signature_detection], + article.body, + article.content_type, + ) + 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) diff --git a/test/fixtures/email_signature_detection/example1.html b/test/fixtures/email_signature_detection/example1.html new file mode 100644 index 000000000..fa9b6e29a --- /dev/null +++ b/test/fixtures/email_signature_detection/example1.html @@ -0,0 +1,106 @@ + + + + + + + +
+

Hallo Support,

+

 

+

sobald wir ein Artikel teilen wollen, wird in der Splittelefonmaske komischerweise der Empfänger als Kunde und nicht der eigentliche Kunde eingetragen. Handelt es sich hier um einen Bug? Kann man das beeinflussen?

+

 

+

+

 

+

In der Splitmaske steht dann IT Support als Kunde…

+

 

+

+

 

+

Freundliche Grü=DFe,
+Bob Smith

+

 

+

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+

Bob Smith

+

ABC Organisation

+

 

+

EXAMPLE IT-Service GmbH

+

Dorten 5 F&E

+

12345 Da / Germany

+

Phone: +49 (0) 1234 567 890 / +49 (0) 1234 567 891

+

Fax:     +49 (0) 1234 567 892

+

mailto:Bob.Smith@example.de

+

http://www.example.de

+

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+

Diese E-Mail und mögliche Anhänge enthalten vertrauliche Informationen, die rechtlich besonders geschützt sein + können. Wenn Sie nicht der beabsichtigte Empfänger bzw. Adressat dieser E-mail sind und diese E-Mail etwa aufgrund eines technischen Fehlers oder eines Versehens erhalten haben, informieren Sie uns bitte sofort und löschen Sie anschlie=DFend die E-Mail. Das + unbefugte Kopieren dieser E-Mail, etwaiger Anhänge sowie die unbefugte Weitergabe der enthaltenen Informationen an Dritte ist nicht gestattet. +

+

 

+

This e-mail message together with its attachments, if any, is confidential and may contain information + subject to legal privilege (e.g. attorney-client-privilege). If you are not the intended recipient or have received this e-mail in error, please inform us immediately and delete this message. Any unauthorised copying of this message (and attachments) or unauthorised + distribution of the information contained herein is prohibited.

+

 

+

EXAMPLE IT Service GmbH - Sitz: Dorten 5, 12345 Da - Registergericht: Amtsgericht Da, HRB 1234 - + Geschäftsführer: Macht ist Macht, Inovation is Future

+

 

+
+ + diff --git a/test/unit/email_signatur_detection_test.rb b/test/unit/email_signatur_detection_test.rb index d960b544d..1c75d3b3d 100644 --- a/test/unit/email_signatur_detection_test.rb +++ b/test/unit/email_signatur_detection_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class EmailSignaturDetectionTest < ActiveSupport::TestCase - test 'test case I - sender a' do + test 'test case 1 - sender a' do # fixtures of sender a fixture_files = { @@ -27,7 +27,7 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase end end - test 'test case II - sender b' do + test 'test case 2 - sender b' do fixture_files = { 'email_signature_detection/client_b_1.txt' => { line: 26, content_type: 'text/plain' }, @@ -50,7 +50,14 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase end end - test 'test case III - sender c' do + test 'test case 3 - just tests' do + signature = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nBob Smith\nABC Organisation\n\nEXAMPLE IT-Service GmbH\nDorten 5 F&E\n12345 Da / Germany\nPhone: +49 (0) 1234 567 890 / +49 (0) 1234 567 891\nFax:     +49 (0) 1234 567 892" + message = File.new("#{Rails.root}/test/fixtures/email_signature_detection/example1.html", 'r').read + signature_line = SignatureDetection.find_signature_line(signature, message, 'text/html') + assert_equal(11, signature_line) + end + + test 'test case 4 - sender c' do fixture_files = { 'email_signature_detection/client_c_1.html' => { line: 8, content_type: 'text/html' },