sup 1.3 → 1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/checks.yml +10 -9
  3. data/.rubocop.yml +1 -1
  4. data/CONTRIBUTORS +2 -2
  5. data/History.txt +38 -0
  6. data/Manifest.txt +19 -1
  7. data/README.md +5 -3
  8. data/Rakefile +1 -1
  9. data/bin/sup +5 -3
  10. data/bin/sup-sync +1 -2
  11. data/contrib/nix/.gitignore +1 -0
  12. data/contrib/nix/Gemfile.lock +41 -34
  13. data/contrib/nix/gem-install-shell.nix +1 -1
  14. data/contrib/nix/gemset.nix +80 -58
  15. data/contrib/nix/ruby2.4-Gemfile.lock +1 -1
  16. data/contrib/nix/ruby2.4-gemset.nix +2 -2
  17. data/contrib/nix/ruby2.5-Gemfile.lock +1 -1
  18. data/contrib/nix/ruby2.5-gemset.nix +2 -2
  19. data/contrib/nix/ruby2.6-Gemfile.lock +1 -1
  20. data/contrib/nix/ruby2.6-gemset.nix +2 -2
  21. data/contrib/nix/ruby2.7-Gemfile.lock +1 -1
  22. data/contrib/nix/ruby2.7-gemset.nix +2 -2
  23. data/contrib/nix/ruby3.0-Gemfile.lock +1 -1
  24. data/contrib/nix/ruby3.0-gemset.nix +2 -2
  25. data/contrib/nix/ruby3.1-Gemfile.lock +101 -0
  26. data/contrib/nix/ruby3.1-gemset.nix +391 -0
  27. data/contrib/nix/ruby3.1-shell.nix +2 -13
  28. data/contrib/nix/ruby3.2-Gemfile.lock +101 -0
  29. data/contrib/nix/ruby3.2-gemset.nix +391 -0
  30. data/contrib/nix/ruby3.2-shell.nix +2 -13
  31. data/contrib/nix/ruby3.3-shell.nix +1 -12
  32. data/contrib/nix/ruby3.4-shell.nix +1 -10
  33. data/contrib/nix/ruby4.0-shell.nix +41 -0
  34. data/contrib/nix/test-all-rubies.sh +2 -1
  35. data/contrib/screenshot-generator/.gitignore +1 -0
  36. data/contrib/screenshot-generator/default.nix +253 -0
  37. data/contrib/screenshot-generator/scenes.yaml +51 -0
  38. data/contrib/screenshot-generator/shoot.rb +127 -0
  39. data/contrib/screenshot-generator/sup-is-plain-text-applied.msg +83 -0
  40. data/contrib/screenshot-generator/sup-is-plain-text.msg +78 -0
  41. data/lib/sup/account.rb +2 -0
  42. data/lib/sup/buffer.rb +14 -3
  43. data/lib/sup/contact.rb +3 -4
  44. data/lib/sup/draft.rb +15 -15
  45. data/lib/sup/index.rb +15 -5
  46. data/lib/sup/maildir.rb +21 -16
  47. data/lib/sup/mbox.rb +0 -10
  48. data/lib/sup/message.rb +5 -19
  49. data/lib/sup/message_chunks.rb +1 -25
  50. data/lib/sup/mode.rb +1 -0
  51. data/lib/sup/modes/contact_list_mode.rb +0 -1
  52. data/lib/sup/modes/edit_message_mode.rb +53 -5
  53. data/lib/sup/modes/label_search_results_mode.rb +1 -2
  54. data/lib/sup/modes/line_cursor_mode.rb +22 -20
  55. data/lib/sup/modes/search_results_mode.rb +0 -1
  56. data/lib/sup/modes/thread_index_mode.rb +28 -27
  57. data/lib/sup/modes/thread_view_mode.rb +1 -2
  58. data/lib/sup/person.rb +0 -6
  59. data/lib/sup/poll.rb +1 -4
  60. data/lib/sup/rfc2047.rb +5 -2
  61. data/lib/sup/sent.rb +5 -4
  62. data/lib/sup/source.rb +2 -47
  63. data/lib/sup/util.rb +2 -2
  64. data/lib/sup/version.rb +1 -1
  65. data/lib/sup.rb +1 -1
  66. data/man/sup-add.1 +6 -6
  67. data/man/sup-config.1 +6 -6
  68. data/man/sup-dump.1 +5 -5
  69. data/man/sup-import-dump.1 +7 -7
  70. data/man/sup-recover-sources.1 +5 -5
  71. data/man/sup-sync-back-maildir.1 +9 -9
  72. data/man/sup-sync.1 +11 -11
  73. data/man/sup-tweak-labels.1 +10 -10
  74. data/man/sup.1 +11 -11
  75. data/sup.gemspec +1 -1
  76. data/test/dummy_buffer.rb +34 -0
  77. data/test/dummy_source.rb +0 -4
  78. data/test/fixtures/contacts.txt +2 -1
  79. data/test/fixtures/folded-from-header.eml +8 -0
  80. data/test/fixtures/rfc2047-header-encoding.eml +2 -1
  81. data/test/fixtures/text-attachments-with-charset.eml +7 -0
  82. data/test/integration/test_draft.rb +128 -0
  83. data/test/integration/test_index.rb +62 -0
  84. data/test/integration/test_maildir.rb +2 -0
  85. data/test/integration/test_mbox.rb +2 -0
  86. data/test/integration/test_sup-add.rb +4 -0
  87. data/test/test_crypto.rb +7 -2
  88. data/test/test_header_parsing.rb +9 -9
  89. data/test/test_message.rb +22 -3
  90. data/test/unit/test_contact.rb +15 -3
  91. data/test/unit/test_edit_message_mode.rb +6 -1
  92. data/test/unit/test_index.rb +89 -0
  93. data/test/unit/test_line_cursor_mode.rb +214 -0
  94. data/test/unit/test_maildir.rb +21 -0
  95. metadata +30 -9
  96. data/man/sup-psych-ify-config-files.1 +0 -76
  97. data/shell.nix +0 -1
@@ -0,0 +1,128 @@
1
+ require "sup"
2
+ require "test_helper"
3
+
4
+ class TestDraft < Minitest::Test
5
+ include Redwood
6
+
7
+ def setup
8
+ @path = Dir.mktmpdir
9
+ start
10
+ Logger.remove_sink $stderr
11
+ @draft_dir = File.join @path, "drafts"
12
+ @test_message_1 = <<EOS
13
+ From: Some Person <someone@example.invalid>
14
+ To:
15
+ Cc:
16
+ Bcc:
17
+ Subject: draft
18
+ Date: Fri, 11 Apr 2025 22:34:05 +1000
19
+ Message-ID: <123@example.invalid>
20
+
21
+ My incomplete message
22
+ EOS
23
+ DraftManager.instance.instance_eval "@dir = '#{@draft_dir}'"
24
+ Index.init @path
25
+ Index.load
26
+ SourceManager.instance.instance_eval "@sources = {}"
27
+ @draft_source = DraftManager.new_source
28
+ SourceManager.add_source @draft_source
29
+ end
30
+
31
+ def teardown
32
+ Index.save_index
33
+ ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
34
+ klass.deinstantiate! unless klass == Redwood::Logger
35
+ end
36
+ FileUtils.rm_r @path
37
+ end
38
+
39
+ def test_write_draft
40
+ DraftManager.write_draft { |f| f.write @test_message_1 }
41
+
42
+ draft_filename = File.join @draft_dir, "0"
43
+ assert File.exist? draft_filename
44
+ assert_equal @test_message_1, (File.read draft_filename)
45
+
46
+ ## Check that it is loaded back into the index successfully too.
47
+ messages_in_index = Index.instance.enum_for(:each_message).to_a
48
+ assert_equal @test_message_1, messages_in_index.first.raw_message
49
+ assert_equal [:draft, :inbox].to_set, messages_in_index.first.labels
50
+ end
51
+
52
+ def test_discard_draft
53
+ DraftManager.write_draft { |f| f.write @test_message_1 }
54
+ draft_filename = File.join @draft_dir, "0"
55
+ assert File.exist? draft_filename
56
+ message_in_index = Index.instance.enum_for(:each_message).to_a.first
57
+
58
+ DraftManager.discard message_in_index
59
+ refute File.exist? draft_filename
60
+ end
61
+
62
+ def test_discard_already_deleted_from_disk
63
+ DraftManager.write_draft { |f| f.write @test_message_1 }
64
+ draft_filename = File.join @draft_dir, "0"
65
+ assert File.exist? draft_filename
66
+ message_in_index = Index.instance.enum_for(:each_message).to_a.first
67
+
68
+ File.delete draft_filename
69
+
70
+ DraftManager.discard message_in_index
71
+ refute File.exist? draft_filename
72
+ end
73
+
74
+ def test_load_malformed_draft
75
+ ## Sup always writes drafts by serialising a Message, meaning the draft is
76
+ ## guaranteed to have certain headers like Date. But it's always possible
77
+ ## for the user to edit the draft directly on the filesystem and leave it
78
+ ## in some kind of malformed state. Sup should handle it without crashing.
79
+ draft_filename = File.join @draft_dir, "0"
80
+ fallback_date = Time.new 2025, 5, 3, 15, 47, 41
81
+ File.write draft_filename, <<EOS
82
+ Some-Header: Value
83
+
84
+ body
85
+ EOS
86
+ File.utime fallback_date, fallback_date, draft_filename
87
+ PollManager.poll_from @draft_source
88
+ messages_in_index = Index.instance.enum_for(:each_message).to_a
89
+ assert_equal "", messages_in_index[0].subj
90
+ assert_equal fallback_date, messages_in_index[0].date
91
+
92
+ File.write (File.join @draft_dir, "1"), <<EOS
93
+ missing a header!
94
+ EOS
95
+ PollManager.poll_from @draft_source
96
+ messages_in_index = Index.instance.enum_for(:each_message).to_a
97
+ assert_equal "", messages_in_index[0].subj
98
+
99
+ File.write (File.join @draft_dir, "2"), ""
100
+ PollManager.poll_from @draft_source
101
+ messages_in_index = Index.instance.enum_for(:each_message).to_a
102
+ assert_equal "", messages_in_index[0].subj
103
+ end
104
+
105
+ def test_draft_with_non_ascii_chars
106
+ message = <<EOS
107
+ From: Some Person <someone@example.invalid>
108
+ To:
109
+ Cc:
110
+ Bcc:
111
+ Subject: UTF-8 draft 🤐
112
+ Date: Fri, 11 Apr 2025 22:34:05 +1000
113
+ Message-ID: <123@example.invalid>
114
+
115
+ ¡Buen día! Доброго ранку! おはよう!
116
+ EOS
117
+ DraftManager.write_draft { |f| f.write message }
118
+ draft_filename = File.join @draft_dir, "0"
119
+ assert_equal message, (File.read draft_filename)
120
+
121
+ PollManager.poll_from @draft_source
122
+ messages_in_index = Index.instance.enum_for(:each_message).to_a
123
+ assert_equal "UTF-8 draft 🤐", messages_in_index[0].subj
124
+ assert_equal message, messages_in_index.first.raw_message
125
+ assert_equal "¡Buen día! Доброго ранку! おはよう!", \
126
+ messages_in_index[0].chunks[0].lines[0]
127
+ end
128
+ end
@@ -0,0 +1,62 @@
1
+ require "sup"
2
+ require "test_helper"
3
+
4
+ class TestIndexIntegration < Minitest::Test
5
+ include Redwood
6
+
7
+ def setup
8
+ @path = Dir.mktmpdir
9
+ end
10
+
11
+ def teardown
12
+ ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
13
+ klass.deinstantiate! unless klass == Redwood::Logger
14
+ end
15
+ FileUtils.rm_r @path
16
+ end
17
+
18
+ def create_large_mbox n_messages
19
+ mbox = File.join @path, "big.mbox"
20
+ File.open(mbox, "w") do |f|
21
+ n_messages.times do |i|
22
+ ## spread the dates out so that the assigned docids are not
23
+ ## contiguous, as in a real index
24
+ date = Time.utc(2011) + i * 3600
25
+ f.write <<EOS
26
+ From bob@example.com Sat Jan 1 00:00:00 2011
27
+ From: Bob <bob@example.com>
28
+ To: Joe <joe@example.com>
29
+ Subject: message number #{i}
30
+ Date: #{date.strftime "%a, %d %b %Y %H:%M:%S +0000"}
31
+ Message-ID: <message-#{i}@example.com>
32
+
33
+ Hi Bob, this is test message #{i}. From Joe.
34
+
35
+ EOS
36
+ end
37
+ end
38
+ mbox
39
+ end
40
+
41
+ def start_sup_and_add_source source
42
+ start
43
+ Logger.remove_sink $stderr
44
+ Index.init @path
45
+ Index.load
46
+ SourceManager.instance.instance_eval '@sources = {}'
47
+ SourceManager.instance.add_source source
48
+ PollManager.poll_from source
49
+ Index.save_index
50
+ end
51
+
52
+ def test_all_mail_query
53
+ n_messages = 1200
54
+ mbox = create_large_mbox n_messages
55
+ start_sup_and_add_source MBox.new "mbox:#{mbox}"
56
+
57
+ ## the empty query is the "all mail" listing
58
+ ids = []
59
+ Index.each_id({}) { |id| ids << id }
60
+ assert_equal n_messages, ids.size
61
+ end
62
+ end
@@ -41,11 +41,13 @@ EOS
41
41
 
42
42
  def start_sup_and_add_source(source)
43
43
  start
44
+ Logger.remove_sink $stderr
44
45
  Index.init @path
45
46
  Index.load
46
47
  SourceManager.instance.instance_eval '@sources = {}'
47
48
  SourceManager.instance.add_source source
48
49
  PollManager.poll_from source
50
+ Index.save_index
49
51
  end
50
52
 
51
53
  # and now, let the tests begin!
@@ -34,11 +34,13 @@ EOS
34
34
 
35
35
  def start_sup_and_add_source(source)
36
36
  start
37
+ Logger.remove_sink $stderr
37
38
  Index.init @path
38
39
  Index.load
39
40
  SourceManager.instance.instance_eval '@sources = {}'
40
41
  SourceManager.instance.add_source source
41
42
  PollManager.poll_from source
43
+ Index.save_index
42
44
  end
43
45
 
44
46
  # and now, let the tests begin!
@@ -26,6 +26,8 @@ class TestSupAdd < Minitest::Test
26
26
  EOS
27
27
  end
28
28
 
29
+ ## https://github.com/sup-heliotrope/sup/issues/577
30
+ ## https://github.com/sup-heliotrope/sup/issues/516
29
31
  def test_fixes_old_tag_uri_syntax
30
32
  File.write "#{@path}/sources.yaml", <<EOS
31
33
  ---
@@ -36,6 +38,7 @@ EOS
36
38
  sync_back: true
37
39
  id: 1
38
40
  labels: []
41
+ - !supmua.org,2006-10-01/Redwood/SentLoader {}
39
42
  EOS
40
43
  _out, _err = capture_subprocess_io do
41
44
  assert system({"SUP_BASE" => @path}, "bin/sup-add", "maildir:///other/path")
@@ -58,6 +61,7 @@ EOS
58
61
  sync_back: true
59
62
  id: 2
60
63
  labels: []
64
+ - !<tag:supmua.org,2006-10-01/Redwood/SentLoader> {}
61
65
  EOS
62
66
  end
63
67
 
data/test/test_crypto.rb CHANGED
@@ -38,8 +38,13 @@ class TestCryptoManager < Minitest::Test
38
38
  @path = Dir.mktmpdir
39
39
  Redwood::HookManager.init File.join(@path, 'hooks')
40
40
 
41
- am = {:default=> {name: +"test", email: @from_email.dup, alternates: [@from_email_ecc.dup]}}
42
- Redwood::AccountManager.init am
41
+ account = {
42
+ :name => +"test",
43
+ :email => @from_email.dup,
44
+ :alternates => [@from_email_ecc.dup],
45
+ :sendmail => "/bin/false",
46
+ }
47
+ Redwood::AccountManager.init :default => account
43
48
 
44
49
  Redwood::CryptoManager.init
45
50
  end
@@ -24,7 +24,7 @@ class TestMBoxParsing < Minitest::Test
24
24
  end
25
25
 
26
26
  def test_normal_headers
27
- h = Source.parse_raw_email_header StringIO.new(<<EOS)
27
+ h = EditMessageMode.parse_raw_email_header StringIO.new(<<EOS)
28
28
  From: Bob <bob@bob.com>
29
29
  To: Sally <sally@sally.com>
30
30
  EOS
@@ -35,7 +35,7 @@ EOS
35
35
  end
36
36
 
37
37
  def test_multiline
38
- h = Source.parse_raw_email_header StringIO.new(<<EOS)
38
+ h = EditMessageMode.parse_raw_email_header StringIO.new(<<EOS)
39
39
  From: Bob <bob@bob.com>
40
40
  Subject: one two three
41
41
  four five six
@@ -57,7 +57,7 @@ EOS
57
57
  "Subject: one two three end \n",
58
58
  ]
59
59
  variants.each do |s|
60
- h = Source.parse_raw_email_header StringIO.new(s)
60
+ h = EditMessageMode.parse_raw_email_header StringIO.new(s)
61
61
  assert_equal "one two three end", h["subject"]
62
62
  end
63
63
  end
@@ -68,13 +68,13 @@ EOS
68
68
  "Message-Id:<one@bob.com> \n",
69
69
  ]
70
70
  variants.each do |s|
71
- h = Source.parse_raw_email_header StringIO.new(s)
71
+ h = EditMessageMode.parse_raw_email_header StringIO.new(s)
72
72
  assert_equal "<one@bob.com>", h["message-id"]
73
73
  end
74
74
  end
75
75
 
76
76
  def test_blank_lines
77
- h = Source.parse_raw_email_header StringIO.new("")
77
+ h = EditMessageMode.parse_raw_email_header StringIO.new("")
78
78
  assert_nil h["message-id"]
79
79
  end
80
80
 
@@ -84,13 +84,13 @@ EOS
84
84
  "Message-Id:\n",
85
85
  ]
86
86
  variants.each do |s|
87
- h = Source.parse_raw_email_header StringIO.new(s)
87
+ h = EditMessageMode.parse_raw_email_header StringIO.new(s)
88
88
  assert_equal "", h["message-id"]
89
89
  end
90
90
  end
91
91
 
92
92
  def test_detect_end_of_headers
93
- h = Source.parse_raw_email_header StringIO.new(<<EOS)
93
+ h = EditMessageMode.parse_raw_email_header StringIO.new(<<EOS)
94
94
  From: Bob <bob@bob.com>
95
95
 
96
96
  To: a dear friend
@@ -98,7 +98,7 @@ EOS
98
98
  assert_equal "Bob <bob@bob.com>", h["from"]
99
99
  assert_nil h["to"]
100
100
 
101
- h = Source.parse_raw_email_header StringIO.new(<<EOS)
101
+ h = EditMessageMode.parse_raw_email_header StringIO.new(<<EOS)
102
102
  From: Bob <bob@bob.com>
103
103
  \r
104
104
  To: a dear friend
@@ -106,7 +106,7 @@ EOS
106
106
  assert_equal "Bob <bob@bob.com>", h["from"]
107
107
  assert_nil h["to"]
108
108
 
109
- h = Source.parse_raw_email_header StringIO.new(<<EOS)
109
+ h = EditMessageMode.parse_raw_email_header StringIO.new(<<EOS)
110
110
  From: Bob <bob@bob.com>
111
111
  \r\n\r
112
112
  To: a dear friend
data/test/test_message.rb CHANGED
@@ -181,7 +181,7 @@ class TestMessage < Minitest::Test
181
181
  sup_message.load_from_source!
182
182
 
183
183
  chunks = sup_message.load_from_source!
184
- assert_equal(7, chunks.length)
184
+ assert_equal(8, chunks.length)
185
185
  assert(chunks[0].is_a? Redwood::Chunk::Text)
186
186
  ## The first attachment declares charset=us-ascii
187
187
  assert(chunks[1].is_a? Redwood::Chunk::Attachment)
@@ -203,6 +203,10 @@ class TestMessage < Minitest::Test
203
203
  ## The sixth attachment is UTF-7 encoded
204
204
  assert(chunks[6].is_a? Redwood::Chunk::Attachment)
205
205
  assert_equal(["This is ✨UTF-7✨"], chunks[6].lines)
206
+ ## The seventh attachment is UTF-7 with an incomplete sequence,
207
+ ## which will be replaced with U+FFFD REPLACEMENT CHARACTER
208
+ assert(chunks[7].is_a? Redwood::Chunk::Attachment)
209
+ assert_equal(["Bad a� UTF-7"], chunks[7].lines)
206
210
  end
207
211
 
208
212
  def test_mailing_list_header
@@ -234,12 +238,25 @@ class TestMessage < Minitest::Test
234
238
 
235
239
  # Look at another header field whose first line was blank.
236
240
  list_unsubscribe = sup_message.list_unsubscribe
237
- assert_equal("<http://mailman2.widget.com/mailman/listinfo/monitor-list>,\n\t" +
241
+ assert_equal("<http://mailman2.widget.com/mailman/listinfo/monitor-list>,\t" +
238
242
  "<mailto:monitor-list-request@widget.com?subject=unsubscribe>",
239
243
  list_unsubscribe)
240
244
 
241
245
  end
242
246
 
247
+ def test_folded_from_header
248
+ source = DummySource.new("sup-test://test_folded_from_header")
249
+ source.messages = [ fixture_path("folded-from-header.eml") ]
250
+ source_info = 0
251
+
252
+ sup_message = Message.build_from_source(source, source_info)
253
+ sup_message.load_from_source!
254
+
255
+ assert_equal "Kevin Frazier, Juliana Schroeder, Brian Frye, " +
256
+ "Nathanael Fast, and Rob Greer", sup_message.from.name
257
+ assert_equal "user@rss2email.invalid", sup_message.from.email
258
+ end
259
+
243
260
  def test_rfc2047_header_encoding
244
261
  source = DummySource.new("sup-test://test_rfc2047_header_encoding")
245
262
  source.messages = [ fixture_path("rfc2047-header-encoding.eml") ]
@@ -251,8 +268,10 @@ class TestMessage < Minitest::Test
251
268
  assert_equal("Hans Martin Djupvik, Ingrid Bø, Ирина Сидорова, " +
252
269
  "Jesper Berg, Frida Engø " +
253
270
  "bad: =?UTF16?q?badcharsetname?==?US-ASCII?b?/w?=" +
254
- "=?UTF-7?Q?=41=6D=65=72=69=63=61=E2=80=99=73?=",
271
+ "=?UTF-7?Q?=41=6D=65=72=69=63=61=E2=80=99=73?=" +
272
+ "=?UTF-7?b?K0FHRUEt?=",
255
273
  sup_message.subj)
274
+ assert_equal "=?utf-8?q?YouTube-tj=E4nst?=", sup_message.from.name
256
275
  end
257
276
 
258
277
  def test_nonascii_header
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'sup'
2
3
  require 'sup/contact'
3
4
 
4
5
  module Redwood
@@ -16,9 +17,20 @@ class TestContact < Minitest::Test
16
17
 
17
18
  def test_contact_manager
18
19
  assert @contact
19
- ## 1 contact is imported from the fixture file.
20
- assert_equal 1, @contact.contacts.count
21
- assert_equal @contact.contact_for("RC").name, "Random Contact"
20
+
21
+ ## 2 contacts are imported from the fixture file.
22
+ assert_equal 2, @contact.contacts.count
23
+
24
+ rc = @contact.contact_for "RC"
25
+ assert_equal "Random Contact", rc.name
26
+ assert @contact.is_aliased_contact? rc
27
+ assert_equal "RC", @contact.alias_for(rc)
28
+
29
+ uc = @contact.person_for "unaliased@example.invalid"
30
+ refute @contact.is_aliased_contact? uc
31
+ assert_nil @contact.alias_for uc
32
+ assert_equal [rc, uc], @contact.contacts
33
+ assert_equal [rc], @contact.contacts_with_aliases
22
34
 
23
35
  assert_nil @contact.contact_for "TN"
24
36
  @contact.update_alias @person, "TN"
@@ -24,7 +24,12 @@ class TestEditMessageMode < Minitest::Test
24
24
  $config = {}
25
25
  @path = Dir.mktmpdir
26
26
  Redwood::HookManager.init File.join(@path, "hooks")
27
- Redwood::AccountManager.init :default => {name: +"test", email: +"sender@example.invalid"}
27
+ account = {
28
+ :name => +"test",
29
+ :email => +"sender@example.invalid",
30
+ :sendmail => "/bin/false",
31
+ }
32
+ Redwood::AccountManager.init :default => account
28
33
  Redwood::CryptoManager.instance_variable_set :@instance, DummyCryptoManager.new
29
34
  end
30
35
 
@@ -0,0 +1,89 @@
1
+ require "minitest/mock"
2
+ require "test_helper"
3
+
4
+ require "sup"
5
+
6
+ class TestIndex < Minitest::Test
7
+ def setup
8
+ @path = Dir.mktmpdir
9
+ Redwood::start
10
+ Redwood::Logger.remove_sink $stderr
11
+ Redwood::Index.init @path
12
+ Redwood::Index.load
13
+ end
14
+
15
+ def teardown
16
+ Redwood::Index.save_index
17
+ ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
18
+ klass.deinstantiate! unless klass == Redwood::Logger
19
+ end
20
+ FileUtils.rm_r @path
21
+ end
22
+
23
+ def with_fake_time &block
24
+ Time.stub :now, Time.utc(2000) do
25
+ ## Also stub Time.local to behave like Time.utc so that Chronic.parse
26
+ ## doesn't pick up the timezone of the test runner.
27
+ Time.stub :local, ->(*args) { Time.utc(*args) }, &block
28
+ end
29
+ end
30
+
31
+ def test_date_query_parsing
32
+ parsed = with_fake_time do
33
+ Redwood::Index.parse_query "after:yesterday"
34
+ end
35
+ expected_date_qobj = Xapian::Query.new(
36
+ Xapian::Query::OP_VALUE_RANGE,
37
+ Redwood::Index::DATE_VALUENO,
38
+ Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
39
+ Xapian.sortable_serialise(2**32),
40
+ )
41
+ expected_qobj = Xapian::Query.new(
42
+ 0.0,
43
+ Xapian::Query.new(
44
+ Xapian::Query::OP_AND,
45
+ expected_date_qobj,
46
+ Xapian::Query.new("Kmail"),
47
+ ),
48
+ )
49
+ assert_equal expected_qobj.description, parsed[:qobj].description
50
+
51
+ parsed = with_fake_time do
52
+ Redwood::Index.parse_query "before:yesterday"
53
+ end
54
+ expected_date_qobj = Xapian::Query.new(
55
+ Xapian::Query::OP_VALUE_RANGE,
56
+ Redwood::Index::DATE_VALUENO,
57
+ Xapian.sortable_serialise(0),
58
+ Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
59
+ )
60
+ expected_qobj = Xapian::Query.new(
61
+ 0.0,
62
+ Xapian::Query.new(
63
+ Xapian::Query::OP_AND,
64
+ expected_date_qobj,
65
+ Xapian::Query.new("Kmail"),
66
+ ),
67
+ )
68
+ assert_equal expected_qobj.description, parsed[:qobj].description
69
+
70
+ parsed = with_fake_time do
71
+ Redwood::Index.parse_query "during:yesterday"
72
+ end
73
+ expected_date_qobj = Xapian::Query.new(
74
+ Xapian::Query::OP_VALUE_RANGE,
75
+ Redwood::Index::DATE_VALUENO,
76
+ Xapian.sortable_serialise(Time.utc(1999, 12, 31).to_i),
77
+ Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
78
+ )
79
+ expected_qobj = Xapian::Query.new(
80
+ 0.0,
81
+ Xapian::Query.new(
82
+ Xapian::Query::OP_AND,
83
+ expected_date_qobj,
84
+ Xapian::Query.new("Kmail"),
85
+ ),
86
+ )
87
+ assert_equal expected_qobj.description, parsed[:qobj].description
88
+ end
89
+ end