replyr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +14 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +94 -0
  6. data/Rakefile +32 -0
  7. data/lib/email_reply_parser/LICENSE +22 -0
  8. data/lib/email_reply_parser/email_reply_parser.rb +475 -0
  9. data/lib/generators/replyr/install_generator.rb +15 -0
  10. data/lib/generators/replyr/templates/mailman_daemon +12 -0
  11. data/lib/generators/replyr/templates/mailman_server +50 -0
  12. data/lib/generators/replyr/templates/replyr.rb.erb +8 -0
  13. data/lib/replyr/config.rb +22 -0
  14. data/lib/replyr/engine.rb +14 -0
  15. data/lib/replyr/handle_reply.rb +36 -0
  16. data/lib/replyr/reply_address.rb +111 -0
  17. data/lib/replyr/reply_email.rb +50 -0
  18. data/lib/replyr/version.rb +3 -0
  19. data/lib/replyr.rb +26 -0
  20. data/lib/tasks/replyr_tasks.rake +4 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/javascripts/application.js +13 -0
  24. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  25. data/test/dummy/app/controllers/application_controller.rb +5 -0
  26. data/test/dummy/app/helpers/application_helper.rb +2 -0
  27. data/test/dummy/app/models/comment.rb +7 -0
  28. data/test/dummy/app/models/user.rb +3 -0
  29. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/test/dummy/bin/bundle +3 -0
  31. data/test/dummy/bin/rails +4 -0
  32. data/test/dummy/bin/rake +4 -0
  33. data/test/dummy/config/application.rb +23 -0
  34. data/test/dummy/config/boot.rb +5 -0
  35. data/test/dummy/config/database.yml +8 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +29 -0
  38. data/test/dummy/config/environments/production.rb +80 -0
  39. data/test/dummy/config/environments/test.rb +36 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/test/dummy/config/initializers/inflections.rb +16 -0
  43. data/test/dummy/config/initializers/mime_types.rb +5 -0
  44. data/test/dummy/config/initializers/replyr.rb +2 -0
  45. data/test/dummy/config/initializers/secret_token.rb +12 -0
  46. data/test/dummy/config/initializers/session_store.rb +3 -0
  47. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/test/dummy/config/locales/en.yml +23 -0
  49. data/test/dummy/config/routes.rb +56 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/db/test.sqlite3 +0 -0
  52. data/test/dummy/log/development.log +0 -0
  53. data/test/dummy/log/test.log +12557 -0
  54. data/test/dummy/public/404.html +58 -0
  55. data/test/dummy/public/422.html +58 -0
  56. data/test/dummy/public/500.html +57 -0
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/email_reply_parser/email_reply_parser_test.rb +488 -0
  59. data/test/email_reply_parser/emails/correct_sig.txt +4 -0
  60. data/test/email_reply_parser/emails/email_1_1.txt +13 -0
  61. data/test/email_reply_parser/emails/email_1_2.txt +51 -0
  62. data/test/email_reply_parser/emails/email_1_3.txt +55 -0
  63. data/test/email_reply_parser/emails/email_1_4.txt +5 -0
  64. data/test/email_reply_parser/emails/email_1_5.txt +15 -0
  65. data/test/email_reply_parser/emails/email_1_6.txt +15 -0
  66. data/test/email_reply_parser/emails/email_1_7.txt +12 -0
  67. data/test/email_reply_parser/emails/email_1_8.txt +6 -0
  68. data/test/email_reply_parser/emails/email_1_9.txt +9 -0
  69. data/test/email_reply_parser/emails/email_2_1.txt +25 -0
  70. data/test/email_reply_parser/emails/email_2_2.txt +10 -0
  71. data/test/email_reply_parser/emails/email_2_3.txt +14 -0
  72. data/test/email_reply_parser/emails/email_2_4.txt +14 -0
  73. data/test/email_reply_parser/emails/email_2_5.txt +15 -0
  74. data/test/email_reply_parser/emails/email_2_6.txt +11 -0
  75. data/test/email_reply_parser/emails/email_2_7.txt +5 -0
  76. data/test/email_reply_parser/emails/email_2_7_1.txt +5 -0
  77. data/test/email_reply_parser/emails/email_2_7_de.txt +5 -0
  78. data/test/email_reply_parser/emails/email_2_8.txt +3 -0
  79. data/test/email_reply_parser/emails/email_2_9.txt +9 -0
  80. data/test/email_reply_parser/emails/email_2nd_paragraph_starting_with_on.txt +12 -0
  81. data/test/email_reply_parser/emails/email_BlackBerry.txt +3 -0
  82. data/test/email_reply_parser/emails/email_bullets.txt +22 -0
  83. data/test/email_reply_parser/emails/email_from_address_in_quote_header.txt +12 -0
  84. data/test/email_reply_parser/emails/email_from_name_in_quote_header.txt +12 -0
  85. data/test/email_reply_parser/emails/email_hyphens.txt +5 -0
  86. data/test/email_reply_parser/emails/email_iPhone.txt +3 -0
  87. data/test/email_reply_parser/emails/email_iPhone_de.txt +3 -0
  88. data/test/email_reply_parser/emails/email_iPhone_de_2.txt +3 -0
  89. data/test/email_reply_parser/emails/email_mentions_own_email_address.txt +6 -0
  90. data/test/email_reply_parser/emails/email_mentions_own_name.txt +6 -0
  91. data/test/email_reply_parser/emails/email_multi_word_sent_from_my_mobile_device.txt +3 -0
  92. data/test/email_reply_parser/emails/email_multiline_quote_header_de_mx.txt +8 -0
  93. data/test/email_reply_parser/emails/email_multiline_quote_header_es_mx.txt +8 -0
  94. data/test/email_reply_parser/emails/email_multiline_quote_header_fr.txt +8 -0
  95. data/test/email_reply_parser/emails/email_multiline_quote_header_from_first.txt +11 -0
  96. data/test/email_reply_parser/emails/email_multiline_quote_header_from_replyto_date_to_subject.txt +12 -0
  97. data/test/email_reply_parser/emails/email_multiline_quote_header_from_to_date_subject.txt +11 -0
  98. data/test/email_reply_parser/emails/email_multiline_quote_header_none.txt +11 -0
  99. data/test/email_reply_parser/emails/email_multiline_quote_header_pt_br.txt +8 -0
  100. data/test/email_reply_parser/emails/email_multiline_quote_header_with_asterisks.txt +21 -0
  101. data/test/email_reply_parser/emails/email_multiline_quote_header_with_cc.txt +9 -0
  102. data/test/email_reply_parser/emails/email_multiline_quote_header_with_multiline_headers.txt +14 -0
  103. data/test/email_reply_parser/emails/email_no_signature_deliminator.txt +7 -0
  104. data/test/email_reply_parser/emails/email_no_signature_deliminator_adds_a_middle_initial.txt +7 -0
  105. data/test/email_reply_parser/emails/email_one_is_not_on.txt +10 -0
  106. data/test/email_reply_parser/emails/email_sent_from_my_not_signature.txt +3 -0
  107. data/test/email_reply_parser/emails/email_was_showing_as_nothing_visible.txt +13 -0
  108. data/test/email_reply_parser/emails/new_content/email_1_2.txt +28 -0
  109. data/test/replyr/handle_reply_test.rb +46 -0
  110. data/test/replyr/reply_address_test.rb +77 -0
  111. data/test/replyr/reply_email_test.rb +19 -0
  112. data/test/replyr_test.rb +7 -0
  113. data/test/support/emails/reply_multipart.eml +35 -0
  114. data/test/support/emails/reply_plain.eml +11 -0
  115. data/test/support/emails/reply_with_attachment.eml +466 -0
  116. data/test/test_helper.rb +23 -0
  117. metadata +228 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,488 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require_relative '../test_helper'
3
+
4
+ EMAIL_FIXTURE_PATH = Pathname.new(File.expand_path(File.dirname(__FILE__))).join("emails")
5
+
6
+ describe EmailReplyParser do
7
+ it "test_does_not_modify_input_string" do
8
+ original = "The Quick Brown Fox Jumps Over The Lazy Dog"
9
+ EmailReplyParser.read original
10
+ assert_equal "The Quick Brown Fox Jumps Over The Lazy Dog", original
11
+ end
12
+
13
+ it "test_reads_simple_body" do
14
+ reply = email(:email_1_1)
15
+ assert_equal 3, reply.fragments.size
16
+
17
+ assert reply.fragments.none? { |f| f.quoted? }
18
+ assert_equal [false, true, true],
19
+ reply.fragments.map { |f| f.signature? }
20
+ assert_equal [false, true, true],
21
+ reply.fragments.map { |f| f.hidden? }
22
+
23
+ assert_equal "Hi folks
24
+
25
+ What is the best way to clear a Riak bucket of all key, values after
26
+ running a test?
27
+ I am currently using the Java HTTP API.\n", reply.fragments[0].to_s
28
+
29
+ assert_equal "-Abhishek Kona\n\n", reply.fragments[1].to_s
30
+ end
31
+
32
+ it "test_reads_top_post" do
33
+ reply = email(:email_1_3)
34
+ assert_equal 5, reply.fragments.size
35
+
36
+ assert_equal [false, false, true, false, false],
37
+ reply.fragments.map { |f| f.quoted? }
38
+ assert_equal [false, true, true, true, true],
39
+ reply.fragments.map { |f| f.hidden? }
40
+ assert_equal [false, true, false, false, true],
41
+ reply.fragments.map { |f| f.signature? }
42
+
43
+ assert_match /^Oh thanks.\n\nHaving/, reply.fragments[0].to_s
44
+ assert_match /^-A/, reply.fragments[1].to_s
45
+ assert_match /^On [^\:]+\:/, reply.fragments[2].to_s
46
+ assert_match /^_/, reply.fragments[4].to_s
47
+ end
48
+
49
+ it "test_reads_bottom_post" do
50
+ reply = email(:email_1_2)
51
+ assert_equal 6, reply.fragments.size
52
+
53
+ assert_equal [false, true, false, true, false, false],
54
+ reply.fragments.map { |f| f.quoted? }
55
+ assert_equal [false, false, false, false, false, true],
56
+ reply.fragments.map { |f| f.signature? }
57
+ assert_equal [false, false, false, true, true, true],
58
+ reply.fragments.map { |f| f.hidden? }
59
+
60
+ assert_equal "Hi,", reply.fragments[0].to_s
61
+ assert_match /^On [^\:]+\:/, reply.fragments[1].to_s
62
+ assert_match /^You can list/, reply.fragments[2].to_s
63
+ assert_match /^> /, reply.fragments[3].to_s
64
+ assert_match /^_/, reply.fragments[5].to_s
65
+ end
66
+
67
+ it "test_recognizes_date_string_above_quote" do
68
+ reply = email :email_1_4
69
+
70
+ assert_match /^Awesome/, reply.fragments[0].to_s
71
+ assert_match /^On/, reply.fragments[1].to_s
72
+ assert_match /Loader/, reply.fragments[1].to_s
73
+ end
74
+
75
+ it "test_a_complex_body_with_only_one_fragment" do
76
+ reply = email :email_1_5
77
+
78
+ assert_equal 1, reply.fragments.size
79
+ end
80
+
81
+ it "test_reads_email_with_correct_signature" do
82
+ reply = email :correct_sig
83
+
84
+ assert_equal 2, reply.fragments.size
85
+ assert_equal [false, false], reply.fragments.map { |f| f.quoted? }
86
+ assert_equal [false, true], reply.fragments.map { |f| f.signature? }
87
+ assert_equal [false, true], reply.fragments.map { |f| f.hidden? }
88
+ assert_match /^--\nrick/, reply.fragments[1].to_s
89
+ end
90
+
91
+ it "test_reads_email_containing_hyphens" do
92
+ reply = email :email_hyphens
93
+ assert_equal 1, reply.fragments.size
94
+ body = reply.fragments[0].to_s
95
+ assert_match /^Keep in mind/, body
96
+ assert_match /their physical exam.$/, body
97
+ end
98
+
99
+ it "test_arbitrary_hypens_and_underscores" do
100
+ assert_one_signature = lambda do |reply|
101
+ assert_equal 2, reply.fragments.size
102
+ assert_equal [false, true], reply.fragments.map { |f| f.hidden? }
103
+ end
104
+
105
+ reply = EmailReplyParser.read "here __and__ now.\n\n---\nSandro"
106
+ assert_one_signature.call reply
107
+
108
+ reply = EmailReplyParser.read "--okay\n\n-Sandro"
109
+ assert_one_signature.call reply
110
+
111
+ reply = EmailReplyParser.read "__okay\n\n-Sandro"
112
+ assert_one_signature.call reply
113
+
114
+ reply = EmailReplyParser.read "--1337\n\n-Sandro"
115
+ assert_one_signature.call reply
116
+
117
+ reply = EmailReplyParser.read "__1337\n\n-Sandro"
118
+ assert_one_signature.call reply
119
+
120
+ reply = EmailReplyParser.read "data -- __ foo\n\n-Sandro"
121
+ assert_one_signature.call reply
122
+ end
123
+
124
+ it "test_email_body_is_signature" do
125
+ reply = EmailReplyParser.parse_reply "-- \nLes Hill\nleshill@gmail.com"
126
+ assert_equal "", reply
127
+
128
+ reply = EmailReplyParser.parse_reply "From: abc\nTo: Les Hill\nDate: 31/01/2013\nSubject: foo"
129
+ assert_equal "", reply
130
+
131
+ reply = EmailReplyParser.parse_reply "On Fri, Feb 24, 2012 at 10:19 AM, <boris@example.com> wrote:\n\n> hello"
132
+ assert_equal "", reply
133
+
134
+ # German
135
+ reply = EmailReplyParser.parse_reply "Am 01.11.2013 um 15:35 schrieb Nico <nico@example.com>:\n\n> hello"
136
+ assert_equal "", reply
137
+
138
+ # French
139
+ reply = EmailReplyParser.parse_reply "Le 10.11.2013 19:22, Mo G a écrit:\n\n> hello"
140
+ assert_equal "", reply
141
+
142
+ reply = EmailReplyParser.parse_reply "Le 10.11.2013 19:22, Mo G a écrit :\n\n> hello"
143
+ assert_equal "", reply
144
+
145
+
146
+ # Hey Britta!
147
+ # Freu mich auch auf Samstag,wird bestimmt nen cooler Abend! 
148
+ # Dann hoffen wir mal,dass wir Vor-oder Nachspeise bekommen.Das wär am entspanntesten :)
149
+ #
150
+ # Von Samsung Mobile gesendet
151
+ #
152
+ # -------- Ursprüngliche Nachricht --------
153
+ # Von: "Britta N." <notifications@bote.rudirockt.de>
154
+ # Datum:
155
+ # An: corinna_paus@yahoo.de
156
+ # Betreff: Kein Betreff
157
+ #
158
+ # Hi Coy,
159
+ # voll cool, dass Du dabei bist! Freu mich auf den Abend mit Dir! Welchen Gang wir kochen müssen, entscheidet sich nach Ende der Anmeldung am 06.11. um 12 Uhr.
160
+ # Wird bestimmt lustig. Jetzt sind schon über 60 Leute angemeldet, das ist super, denn das verkürzt automatisch die Wege zwischen den Gängen.
161
+ # Könnte nur eng werden in der "After-Party" Location... mal schaun.
162
+ # Viele Grüße
163
+ # Britta
164
+
165
+
166
+ end
167
+
168
+ it "test_deals_with_multiline_reply_headers" do
169
+ reply = email :email_1_6
170
+
171
+ assert_match /^I get/, reply.fragments[0].to_s
172
+ assert_match /^On/, reply.fragments[1].to_s
173
+ assert_match /Was this/, reply.fragments[1].to_s
174
+ end
175
+
176
+ it "test_deals_with_windows_line_endings" do
177
+ reply = email :email_1_7
178
+
179
+ assert_match /:\+1:/, reply.fragments[0].to_s
180
+ assert_match /^On/, reply.fragments[1].to_s
181
+ assert_match /Steps 0-2/, reply.fragments[1].to_s
182
+ end
183
+
184
+ it "test_parse_out_date_name_email_header" do
185
+ assert_equal "Hello", visible_text(:email_1_8)
186
+ end
187
+
188
+ it "test_signature_prefixed_by_whitespace" do
189
+ assert_equal "Foo", visible_text(:email_1_9)
190
+ end
191
+
192
+ it "test_returns_only_the_visible_fragments_as_a_string" do
193
+ reply = email(:email_2_1)
194
+ assert_equal reply.fragments.select{|r| !r.hidden?}.map{|r| r.to_s}.join("\n").rstrip, reply.visible_text
195
+ end
196
+
197
+ it "test_parse_out_just_top_for_outlook_reply" do
198
+ assert_equal "Outlook with a reply", visible_text(:email_2_1)
199
+ end
200
+
201
+ it "test_parse_out_just_top_for_outlook_with_reply_directly_above_line" do
202
+ assert_equal "Outlook with a reply directly above line", visible_text(:email_2_2)
203
+ end
204
+
205
+ it "test_parse_out_just_top_for_windows_8_mail" do
206
+ assert_equal "This one is from Windows 8 Mail (preview).", visible_text(:email_2_3)
207
+ end
208
+
209
+ it "test_parse_out_just_top_for_outlook_2007" do
210
+ assert_equal "Here's one from Outlook 2007.", visible_text(:email_2_4)
211
+ end
212
+
213
+ it "test_parse_out_just_top_for_more_outlook_2013" do
214
+ assert_equal "One from Outlook 2013?", visible_text(:email_2_5)
215
+ end
216
+
217
+ it "test_parse_out_just_top_for_hotmail_reply" do
218
+ assert_equal "Reply from the hottest mail.", visible_text(:email_2_6)
219
+ end
220
+
221
+ it "test_parse_original_message" do
222
+ assert_equal "Foo", visible_text(:email_2_7)
223
+ end
224
+
225
+ it "test_parse_original_message_german" do
226
+ assert_equal "Foo", visible_text(:email_2_7_de)
227
+ end
228
+
229
+ it "test_parse_reply_message" do
230
+ assert_equal "Foo", visible_text(:email_2_7_1)
231
+ end
232
+
233
+ it "test_parse_weird_signature" do
234
+ assert_equal "Hello", visible_text(:email_2_8)
235
+ end
236
+
237
+ it "test_parse_weird_signature_by_name" do
238
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_2_9.txt").to_s
239
+ expected_body = "Hello"
240
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Rick Olson <rick.olson@example.com>")
241
+ end
242
+
243
+ it "test_parse_out_sent_from_iPhone" do
244
+ assert_equal "Here is another email", visible_text(:email_iPhone)
245
+ end
246
+
247
+ it "test_parse_out_sent_from_iPhone_de" do
248
+ assert_equal "Here is another email", visible_text(:email_iPhone_de)
249
+ end
250
+
251
+ it "test_parse_out_sent_from_iPhone_de_2" do
252
+ assert_equal "Here is another email", visible_text(:email_iPhone_de_2)
253
+ end
254
+
255
+ it "test_parse_out_sent_from_BlackBerry" do
256
+ assert_equal "Here is another email", visible_text(:email_BlackBerry)
257
+ end
258
+
259
+ it "test_parse_out_send_from_multiword_mobile_device" do
260
+ assert_equal "Here is another email", visible_text(:email_multi_word_sent_from_my_mobile_device)
261
+ end
262
+
263
+ it "test_do_not_parse_out_send_from_in_regular_sentence" do
264
+ expected = "Here is another email\n\nSent from my desk, is much easier then my mobile phone."
265
+ assert_equal expected, visible_text(:email_sent_from_my_not_signature)
266
+ end
267
+
268
+ it "test_retains_bullets" do
269
+ expected = "test 2 this should list second\n\nand have spaces\n\nand retain this formatting\n\n\n - how about bullets\n - and another"
270
+ assert_equal expected, visible_text(:email_bullets)
271
+ end
272
+
273
+ it "test_parse_reply" do
274
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_1_2.txt").to_s
275
+ assert_equal EmailReplyParser.read(body).visible_text, EmailReplyParser.parse_reply(body)
276
+ end
277
+
278
+ it "test_parse_out_signature_using_from_name" do
279
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_no_signature_deliminator.txt").to_s
280
+ expected_body = "I don't like putting any delimiator in my signature because I think that is cool.\n\nReally it is."
281
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Jim Smith <john.smith@gmail.com>")
282
+ end
283
+
284
+ it "test_parse_out_signature_using_from_name_different_case" do
285
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_no_signature_deliminator.txt").to_s
286
+ expected_body = "I don't like putting any delimiator in my signature because I think that is cool.\n\nReally it is."
287
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "jim smith <john.smith@gmail.com>")
288
+ end
289
+
290
+
291
+ it "test_parse_out_signature_using_from_name_last_then_first" do
292
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_no_signature_deliminator.txt").to_s
293
+ expected_body = "I don't like putting any delimiator in my signature because I think that is cool.\n\nReally it is."
294
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, '"Smith, Jim" <john.smith@gmail.com>')
295
+ end
296
+
297
+ it "test_parse_out_signature_using_from_name_when_middle_initial_is_in_signature" do
298
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_no_signature_deliminator_adds_a_middle_initial.txt").to_s
299
+ expected_body = "I don't like putting any delimiator in my signature because I think that is cool.\n\nReally it is."
300
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Jim Smith <john.smith@gmail.com>")
301
+ end
302
+
303
+ it "test_that_a_sentence_with_my_name_in_it_does_not_become_a_signature" do
304
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_mentions_own_name.txt").to_s
305
+ expected_body = "Hi,\n\nMy name is Jim Smith and I had a question.\n\nWhat do you do?"
306
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Jim Smith <john.smith@gmail.com>")
307
+ end
308
+
309
+ it "test_simple_email_with_reply" do
310
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_was_showing_as_nothing_visible.txt").to_s
311
+ expected_body = "On Friday, one achievement I had was learning a new technology that allows us
312
+ to keep UI elements and events separated from the software on the
313
+ server side, which should allow for more flexible UI code and
314
+ decreased chances of code becoming a swarm of angry hornets. I've
315
+ been transparent about the initial increased development time while
316
+ learning the technology."
317
+
318
+ assert_equal expected_body, EmailReplyParser.parse_reply(body)
319
+ end
320
+
321
+ it "test_2nd_paragraph_starts_with_on" do
322
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_2nd_paragraph_starting_with_on.txt").to_s
323
+ expected_body = "This emails tests that multiline header fix isn't catching things it shouldn't.
324
+
325
+ On friday when I tried it didn't work as expect.
326
+
327
+ This line would have been considered part of the header line."
328
+ assert_equal expected_body, EmailReplyParser.parse_reply(body)
329
+ end
330
+
331
+ it "test_from_email_in_quote_header" do
332
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_from_address_in_quote_header.txt").to_s
333
+ expected_body = "I have gained valuable experience from working with students from other cultures. They bring a significantly different perspective to the work we do. I have also had the opportunity to practice making myself very clear in discussion, so that everyone understands. I've also seen how different our culture is to them, in their reactions to what I think is a normal approach to assignments, and to life in general."
334
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "shelly@example.com")
335
+ end
336
+
337
+ it "test_do_not_make_any_line_with_from_address_quote_heading" do
338
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_mentions_own_email_address.txt").to_s
339
+ expected_body = "Hi,\n\nMy email is john.smith@gmail.com and I had a question.\n\nWhat do you do?"
340
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Jim Smith <john.smith@gmail.com>")
341
+ end
342
+
343
+ it "test_from_name_in_quote_header" do
344
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_from_name_in_quote_header.txt").to_s
345
+ expected_body = "I have gained valuable experience from working with students from other cultures. They bring a significantly different perspective to the work we do. I have also had the opportunity to practice making myself very clear in discussion, so that everyone understands. I've also seen how different our culture is to them, in their reactions to what I think is a normal approach to assignments, and to life in general."
346
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Smith, Shelly <shelly@example.com>")
347
+ end
348
+
349
+ it "test_multiline_quote_header_from_first" do
350
+ body = IO.read EMAIL_FIXTURE_PATH.join("email_multiline_quote_header_from_first.txt").to_s
351
+ expected_body = "I have gained valuable experience from working with students from other cultures. They bring a significantly different perspective to the work we do. I have also had the opportunity to practice making myself very clear in discussion, so that everyone understands. I've also seen how different our culture is to them, in their reactions to what I think is a normal approach to assignments, and to life in general."
352
+ assert_equal expected_body, EmailReplyParser.parse_reply(body, "Smith, Shelly <shelly@example.com>")
353
+ end
354
+
355
+ it "test_multiline_quote_header_none" do
356
+ text = visible_text(:email_multiline_quote_header_none)
357
+ assert_match /Foo/, text
358
+ assert_match /THE END!/, text
359
+ end
360
+
361
+ it "test_multiline_quote_header_from_to_date_subject" do
362
+ assert_equal "Foo!", visible_text(:email_multiline_quote_header_from_to_date_subject)
363
+ end
364
+
365
+ it "test_multiline_quote_header_from_replyto_date_to_subject" do
366
+ assert_equal "Foo!", visible_text(:email_multiline_quote_header_from_replyto_date_to_subject)
367
+ end
368
+
369
+ it "test_multiline_quote_header_pt_br" do
370
+ assert_equal "Foo-pt-br", visible_text(:email_multiline_quote_header_pt_br)
371
+ end
372
+
373
+ it "test_multiline_quote_header_es_mx" do
374
+ assert_equal "Foo!", visible_text(:email_multiline_quote_header_es_mx)
375
+ end
376
+
377
+ it "test_multiline_quote_header_de_mx" do
378
+ assert_equal "Foo!", visible_text(:email_multiline_quote_header_de_mx)
379
+ end
380
+
381
+ it "test_multiline_quote_header_fr" do
382
+ assert_equal "Foo!", visible_text(:email_multiline_quote_header_fr)
383
+ end
384
+
385
+ it "test_multiline_quote_header_with_cc" do
386
+ assert_equal "Foo", visible_text(:email_multiline_quote_header_with_cc)
387
+ end
388
+
389
+ it "test_multiline_quote_header_with_multiline_headers" do
390
+ assert_equal "Foo", visible_text(:email_multiline_quote_header_with_multiline_headers)
391
+ end
392
+
393
+ it "test_multiline_quote_header_with_asterisks" do
394
+ assert_equal "Outlook with a reply", visible_text(:email_multiline_quote_header_with_asterisks)
395
+ end
396
+
397
+ it "test_parsing_name_from_address" do
398
+ address = "Bob Jones <bob@gmail.com>"
399
+ email = EmailReplyParser::Email.new
400
+ assert_equal "Bob Jones", email.send(:parse_name_from_address, address)
401
+ end
402
+
403
+ it "test_parsing_name_from_address_with_double_quotes" do
404
+ address = "\"Bob Jones\" <bob@gmail.com>"
405
+ email = EmailReplyParser::Email.new
406
+ assert_equal "Bob Jones", email.send(:parse_name_from_address, address)
407
+ end
408
+
409
+ it "test_parsing_name_from_address_with_single_quotes" do
410
+ address = "'Bob Jones' <bob@gmail.com>"
411
+ email = EmailReplyParser::Email.new
412
+ assert_equal "Bob Jones", email.send(:parse_name_from_address, address)
413
+ end
414
+
415
+ it "test_parsing_name_from_address_with_no_name" do
416
+ address = "bob@gmail.com"
417
+ email = EmailReplyParser::Email.new
418
+ assert_equal "", email.send(:parse_name_from_address, address)
419
+ end
420
+
421
+ it "test_parsing_email_from_address_with_name" do
422
+ address = "\"Bob Jones\" <bob@gmail.com>"
423
+ email = EmailReplyParser::Email.new
424
+ assert_equal "bob@gmail.com", email.send(:parse_email_from_address, address)
425
+ end
426
+
427
+ it "test_parsing_email_from_address_without_name" do
428
+ address = "bob@gmail.com"
429
+ email = EmailReplyParser::Email.new
430
+ assert_equal "bob@gmail.com", email.send(:parse_email_from_address, address)
431
+ end
432
+
433
+ it "test_one_is_not_on" do
434
+ reply = email("email_one_is_not_on")
435
+ assert_match /One outstanding question/, reply.fragments[0].to_s
436
+ assert_match /^On Oct 1, 2012/, reply.fragments[1].to_s
437
+ end
438
+
439
+ it "test_new_content" do
440
+ body = read("email_1_2")
441
+ correct = read(File.join("new_content", "email_1_2"))
442
+ assert_equal correct, EmailReplyParser.read(body).new_content
443
+ end
444
+
445
+ it "test_normalize_name_first_last" do
446
+ email = EmailReplyParser::Email.new
447
+ name = "John Smith"
448
+ assert_equal name, email.send(:normalize_name, name)
449
+ end
450
+
451
+ it "test_normalize_name_last_first" do
452
+ email = EmailReplyParser::Email.new
453
+ name = "Smith, John"
454
+ assert_equal "John Smith", email.send(:normalize_name, name)
455
+ end
456
+
457
+ it "test_normalize_name_first_last_and_qualification" do
458
+ email = EmailReplyParser::Email.new
459
+ name = "John Smith, MD"
460
+ assert_equal "John Smith", email.send(:normalize_name, name)
461
+ end
462
+
463
+ it "test_parse_nil_body" do
464
+ body = nil
465
+ assert_equal "", EmailReplyParser.parse_reply(body)
466
+ end
467
+
468
+ it "test_parse_empty_body" do
469
+ body = ""
470
+ assert_equal "", EmailReplyParser.parse_reply(body)
471
+ end
472
+
473
+ private
474
+
475
+ def email(name)
476
+ body = IO.read EMAIL_FIXTURE_PATH.join("#{name}.txt").to_s
477
+ EmailReplyParser.read(body)
478
+ end
479
+
480
+ def visible_text(name)
481
+ email(name).visible_text
482
+ end
483
+
484
+ def read(name)
485
+ IO.read EMAIL_FIXTURE_PATH.join("#{name}.txt").to_s
486
+ end
487
+
488
+ end
@@ -0,0 +1,4 @@
1
+ this is an email with a correct -- signature.
2
+
3
+ --
4
+ rick
@@ -0,0 +1,13 @@
1
+ Hi folks
2
+
3
+ What is the best way to clear a Riak bucket of all key, values after
4
+ running a test?
5
+ I am currently using the Java HTTP API.
6
+
7
+ -Abhishek Kona
8
+
9
+
10
+ _______________________________________________
11
+ riak-users mailing list
12
+ riak-users@lists.basho.com
13
+ http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com