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,46 @@
1
+ require_relative '../test_helper'
2
+
3
+ setup_database
4
+
5
+ describe Replyr::HandleReply do
6
+ describe '#reply_address_object_for_user' do
7
+ it 'returns reply address object' do
8
+ @user1 = User.create
9
+ @user2 = User.create
10
+ @comment = Comment.create(user: @user1)
11
+
12
+ address = @comment.reply_address_object_for_user(@user2)
13
+
14
+ assert_kind_of Replyr::ReplyAddress, address
15
+ assert_equal @comment, address.model
16
+ assert_equal @user2, address.user
17
+ end
18
+ end
19
+
20
+ describe '#reply_address_for_user' do
21
+ it 'returns reply address string' do
22
+ @user1 = User.create
23
+ @user2 = User.create
24
+ @comment = Comment.create(user: @user1)
25
+
26
+ address = @comment.reply_address_for_user(@user2)
27
+
28
+ assert_kind_of String, address
29
+ end
30
+ end
31
+
32
+ describe '#handle_reply' do
33
+ it 'receives the passed reply and calls block' do
34
+ user1 = User.create
35
+ user2 = User.create
36
+ comment = Comment.create(user: @user1)
37
+
38
+ old_count = Comment.count
39
+ comment.handle_reply(@user2, "Ein neuer Kommentar")
40
+ new_count = Comment.count
41
+
42
+ assert_equal new_count, old_count + 1
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../test_helper'
2
+
3
+ setup_database
4
+
5
+ describe Replyr::ReplyAddress do
6
+ describe '#new' do
7
+ it 'returns new address' do
8
+ @user = User.create
9
+ @comment = Comment.create
10
+
11
+ address = Replyr::ReplyAddress.new(@comment, @user)
12
+ assert_kind_of Replyr::ReplyAddress, address
13
+ assert_equal @comment, address.model
14
+ assert_equal @user, address.user
15
+ end
16
+
17
+ end
18
+
19
+ describe '#new_from_address' do
20
+ it 'returns new instance if address is valid' do
21
+ user = User.create
22
+ comment = Comment.create
23
+ correct_address = Replyr::ReplyAddress.new(comment, user).address
24
+ address = Replyr::ReplyAddress.new_from_address(correct_address)
25
+ assert_kind_of Replyr::ReplyAddress, address
26
+ assert_equal comment.id, address.model.id
27
+ assert_equal comment.class.name, address.model.class.name
28
+ assert_equal user.id, address.user.id
29
+ assert_equal user.class.name, address.user.class.name
30
+ end
31
+
32
+ it 'raises ArgumentError if email address is malformed (no reply email)' do
33
+ assert_raises ArgumentError do
34
+ Replyr::ReplyAddress.new_from_address("malformed@example.com")
35
+ end
36
+ end
37
+
38
+ it 'returns nil if addreess is invalid' do
39
+ address = Replyr::ReplyAddress.new_from_address("reply-comment-1-1-wrongtoken@example.com")
40
+ assert_equal nil, address
41
+ end
42
+ end
43
+
44
+ describe '#token' do
45
+ before do
46
+ @user1 = User.create
47
+ @user2 = User.create
48
+ @comment1 = Comment.create
49
+ @comment2 = Comment.create
50
+ end
51
+
52
+ it 'returns an auth token' do
53
+ address = Replyr::ReplyAddress.new(@comment1, @user1)
54
+ assert_kind_of String, address.token
55
+ end
56
+
57
+ it 'return the same auth token for same arguments' do
58
+ address1 = Replyr::ReplyAddress.new(@comment1, @user2)
59
+ address2 = Replyr::ReplyAddress.new(@comment1, @user2)
60
+ assert_equal address1.token, address2.token
61
+ end
62
+
63
+ it 'return a different auth token for different model' do
64
+ address1 = Replyr::ReplyAddress.new(@comment2, @user1)
65
+ address2 = Replyr::ReplyAddress.new(@comment1, @user1)
66
+ refute_equal address1.token, address2.token
67
+ end
68
+
69
+ it 'return a different auth token for different user' do
70
+ address1 = Replyr::ReplyAddress.new(@comment1, @user1)
71
+ address2 = Replyr::ReplyAddress.new(@comment1, @user2)
72
+ refute_equal address1.token, address2.token
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require_relative '../test_helper'
3
+ require 'mail'
4
+
5
+ describe Replyr::ReplyEmail do
6
+ it 'parses plain message object correctly' do
7
+ mail = Mail.read('test/support/emails/reply_plain.eml')
8
+ reply_email = Replyr::ReplyEmail.new(mail)
9
+ assert_equal "wursttheke@me.com", reply_email.from
10
+ assert_equal "Das ist wunderschön", reply_email.stripped_body
11
+ end
12
+
13
+ it 'parses multipart message object correctly' do
14
+ mail = Mail.read('test/support/emails/reply_plain.eml')
15
+ reply_email = Replyr::ReplyEmail.new(mail)
16
+ assert_equal "wursttheke@me.com", reply_email.from
17
+ assert_equal "Das ist wunderschön", reply_email.stripped_body
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ReplyrTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Replyr
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ Content-Type: multipart/alternative;
2
+ boundary="Apple-Mail=_3C4CAFE2-2D3A-4DD5-8122-E0F3B2B2392C";
3
+ charset=UTF-8
4
+ Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\))
5
+ Subject: Re: Aufgabe: Neues Todo
6
+ From: =?iso-8859-1?Q?Philipp_W=FCllner?= <wursttheke@me.com>
7
+ Date: Wed, 19 Mar 2014 07:49:15 +0100
8
+ Content-Transfer-Encoding: 7bit
9
+ Message-Id: <1EACD37B-1E55-482A-8EAA-E0F06E438B4C@me.com>
10
+ To: reply-t-1-b36712af6a5e7012-73-b2022a46a52075a9@example.com
11
+
12
+ --Apple-Mail=_3C4CAFE2-2D3A-4DD5-8122-E0F3B2B2392C
13
+ Date: Mon, 03 Sep 2012 10:53:09 +0000
14
+ Mime-Version: 1.0
15
+ Content-Type: text/plain;
16
+ charset=windows-1252
17
+ Content-Transfer-Encoding: quoted-printable
18
+ Content-ID: <50448c1523a5f_31e34d563f445258@machinex.mail>
19
+
20
+ Das ist wundersch=F6n=
21
+
22
+ --Apple-Mail=_3C4CAFE2-2D3A-4DD5-8122-E0F3B2B2392C
23
+ Date: Mon, 03 Sep 2012 10:53:09 +0000
24
+ Mime-Version: 1.0
25
+ Content-Type: text/html;
26
+ charset=windows-1252
27
+ Content-Transfer-Encoding: quoted-printable
28
+ Content-ID: <50448c152476a_31e34d563f4453f1@machinex.mail>
29
+
30
+ <html><head></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mod=
31
+ e: space; -webkit-line-break: after-white-space; ">Das ist wundersch=F6n<div=
32
+ ><br></body></html>=
33
+
34
+
35
+ --Apple-Mail=_3C4CAFE2-2D3A-4DD5-8122-E0F3B2B2392C--
@@ -0,0 +1,11 @@
1
+ Content-Type: text/plain;
2
+ charset=iso-8859-1
3
+ Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\))
4
+ Subject: Re: Aufgabe: Neues Todo
5
+ From: =?iso-8859-1?Q?Philipp_W=FCllner?= <wursttheke@me.com>
6
+ Date: Wed, 19 Mar 2014 07:49:15 +0100
7
+ Content-Transfer-Encoding: quoted-printable
8
+ Message-Id: <1EACD37B-1E55-482A-8EAA-E0F06E438B4C@me.com>
9
+ To: reply-t-1-b36712af6a5e7012-73-b2022a46a52075a9@example.com
10
+
11
+ Das ist wundersch=F6n=