Improved api for signature detection of article.
This commit is contained in:
parent
0ee32d3104
commit
8d71977e0f
4 changed files with 144 additions and 7 deletions
|
@ -52,10 +52,9 @@ class Transaction::SignatureDetection
|
||||||
return if !user
|
return if !user
|
||||||
return if !user.preferences
|
return if !user.preferences
|
||||||
return if !user.preferences[:signature_detection]
|
return if !user.preferences[:signature_detection]
|
||||||
article.preferences[:signature_detection] = SignatureDetection.find_signature_line(
|
article.preferences[:signature_detection] = SignatureDetection.find_signature_line_by_article(
|
||||||
user.preferences[:signature_detection],
|
user,
|
||||||
article.body,
|
article
|
||||||
article.content_type,
|
|
||||||
)
|
)
|
||||||
article.save
|
article.save
|
||||||
end
|
end
|
||||||
|
|
|
@ -143,6 +143,31 @@ returns
|
||||||
|
|
||||||
=begin
|
=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
|
this function will search for a signature string in all articles of a given user_id
|
||||||
|
|
||||||
signature = SignatureDetection.by_user_id(user_id)
|
signature = SignatureDetection.by_user_id(user_id)
|
||||||
|
|
106
test/fixtures/email_signature_detection/example1.html
vendored
Normal file
106
test/fixtures/email_signature_detection/example1.html
vendored
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=3Diso-8859-1">
|
||||||
|
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
|
||||||
|
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
|
||||||
|
o\:* {behavior:url(#default#VML);}
|
||||||
|
w\:* {behavior:url(#default#VML);}
|
||||||
|
.shape {behavior:url(#default#VML);}
|
||||||
|
</style><![endif]--><style><!--
|
||||||
|
/* Font Definitions */
|
||||||
|
@font-face
|
||||||
|
{font-family:Calibri;
|
||||||
|
panose-1:2 15 5 2 2 2 4 3 2 4;}
|
||||||
|
@font-face
|
||||||
|
{font-family:Tahoma;
|
||||||
|
panose-1:2 11 6 4 3 5 4 4 2 4;}
|
||||||
|
/* Style Definitions */
|
||||||
|
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||||
|
{margin:0cm;
|
||||||
|
margin-bottom:.0001pt;
|
||||||
|
font-size:11.0pt;
|
||||||
|
font-family:"Calibri","sans-serif";
|
||||||
|
mso-fareast-language:EN-US;}
|
||||||
|
a:link, span.MsoHyperlink
|
||||||
|
{mso-style-priority:99;
|
||||||
|
color:blue;
|
||||||
|
text-decoration:underline;}
|
||||||
|
a:visited, span.MsoHyperlinkFollowed
|
||||||
|
{mso-style-priority:99;
|
||||||
|
color:purple;
|
||||||
|
text-decoration:underline;}
|
||||||
|
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
|
||||||
|
{mso-style-priority:99;
|
||||||
|
mso-style-link:"Sprechblasentext Zchn";
|
||||||
|
margin:0cm;
|
||||||
|
margin-bottom:.0001pt;
|
||||||
|
font-size:8.0pt;
|
||||||
|
font-family:"Tahoma","sans-serif";
|
||||||
|
mso-fareast-language:EN-US;}
|
||||||
|
span.E-MailFormatvorlage17
|
||||||
|
{mso-style-type:personal-compose;
|
||||||
|
font-family:"Calibri","sans-serif";
|
||||||
|
color:windowtext;}
|
||||||
|
span.SprechblasentextZchn
|
||||||
|
{mso-style-name:"Sprechblasentext Zchn";
|
||||||
|
mso-style-priority:99;
|
||||||
|
mso-style-link:Sprechblasentext;
|
||||||
|
font-family:"Tahoma","sans-serif";}
|
||||||
|
.MsoChpDefault
|
||||||
|
{mso-style-type:export-only;
|
||||||
|
font-family:"Calibri","sans-serif";
|
||||||
|
mso-fareast-language:EN-US;}
|
||||||
|
@page WordSection1
|
||||||
|
{size:612.0pt 792.0pt;
|
||||||
|
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
|
||||||
|
div.WordSection1
|
||||||
|
{page:WordSection1;}
|
||||||
|
--></style><!--[if gte mso 9]><xml>
|
||||||
|
<o:shapedefaults v:ext="edit" spidmax="1026" />
|
||||||
|
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||||
|
<o:shapelayout v:ext="edit">
|
||||||
|
<o:idmap v:ext="edit" data="1" />
|
||||||
|
</o:shapelayout></xml><![endif]-->
|
||||||
|
</head>
|
||||||
|
<body lang="DE" link="blue" vlink="purple">
|
||||||
|
<div class="WordSection1">
|
||||||
|
<p class="MsoNormal">Hallo Support,<o:p></o:p></p>
|
||||||
|
<p class="MsoNormal"><o:p> </o:p></p>
|
||||||
|
<p class="MsoNormal">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?<o:p></o:p></p>
|
||||||
|
<p class="MsoNormal"><o:p> </o:p></p>
|
||||||
|
<p class="MsoNormal"><span style="mso-fareast-language:DE"><img width="1886" height="494" id="Grafik_x0020_1" src="cid:image001.png@01D1D2BD.ED75B060"></span><o:p></o:p></p>
|
||||||
|
<p class="MsoNormal"><o:p> </o:p></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">In der Splitmaske steht dann IT Support als Kunde…<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="mso-fareast-language:DE"><img width="1029" height="527" id="Grafik_x0020_2" src="cid:image002.png@01D1D2BE.0C2956B0"></span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">Freundliche Grü=DFe,<br>
|
||||||
|
Bob Smith<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">~~~~~~~~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">Bob Smith<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">ABC Organisation<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">EXAMPLE IT-Service GmbH<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">Dorten 5 F&E<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">12345 Da / Germany<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">Phone: +49 (0) 1234 567 890 / +49 (0) 1234 567 891<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="FR" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">Fax: +49 (0) 1234 567 892<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><a href="mailto:Bob.Smith@example.de"><span lang="FR" style="color:blue">mailto:Bob.Smith@example.de</span></a></span><span lang="FR" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><a href="http://www.example.de/"><span lang="DE" style="color:blue">http://www.example.de</span></a></span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">~~~~~~~~~~~~~~~~~~~~~~~~~~~~<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language: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.
|
||||||
|
<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">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. <o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE"><o:p> </o:p></span></p>
|
||||||
|
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:black;mso-fareast-language:DE">EXAMPLE IT Service GmbH - Sitz: Dorten 5, 12345 Da - Registergericht: Amtsgericht Da, HRB 1234 -
|
||||||
|
Geschäftsführer: Macht ist Macht, Inovation is Future<o:p></o:p></span></p>
|
||||||
|
<p class="MsoNormal"><o:p> </o:p></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -3,7 +3,7 @@ require 'test_helper'
|
||||||
|
|
||||||
class EmailSignaturDetectionTest < ActiveSupport::TestCase
|
class EmailSignaturDetectionTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'test case I - sender a' do
|
test 'test case 1 - sender a' do
|
||||||
|
|
||||||
# fixtures of sender a
|
# fixtures of sender a
|
||||||
fixture_files = {
|
fixture_files = {
|
||||||
|
@ -27,7 +27,7 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'test case II - sender b' do
|
test 'test case 2 - sender b' do
|
||||||
|
|
||||||
fixture_files = {
|
fixture_files = {
|
||||||
'email_signature_detection/client_b_1.txt' => { line: 26, content_type: 'text/plain' },
|
'email_signature_detection/client_b_1.txt' => { line: 26, content_type: 'text/plain' },
|
||||||
|
@ -50,7 +50,14 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
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 = {
|
fixture_files = {
|
||||||
'email_signature_detection/client_c_1.html' => { line: 8, content_type: 'text/html' },
|
'email_signature_detection/client_c_1.html' => { line: 8, content_type: 'text/html' },
|
||||||
|
|
Loading…
Reference in a new issue