sup 1.4 → 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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTORS +2 -2
  3. data/History.txt +21 -0
  4. data/Manifest.txt +10 -0
  5. data/README.md +1 -1
  6. data/bin/sup-sync +1 -2
  7. data/contrib/nix/.gitignore +1 -0
  8. data/contrib/nix/Gemfile.lock +17 -17
  9. data/contrib/nix/gem-install-shell.nix +1 -1
  10. data/contrib/nix/gemset.nix +28 -28
  11. data/contrib/nix/ruby2.4-Gemfile.lock +1 -1
  12. data/contrib/nix/ruby2.4-gemset.nix +2 -2
  13. data/contrib/nix/ruby2.5-Gemfile.lock +1 -1
  14. data/contrib/nix/ruby2.5-gemset.nix +2 -2
  15. data/contrib/nix/ruby2.6-Gemfile.lock +1 -1
  16. data/contrib/nix/ruby2.6-gemset.nix +2 -2
  17. data/contrib/nix/ruby2.7-Gemfile.lock +1 -1
  18. data/contrib/nix/ruby2.7-gemset.nix +2 -2
  19. data/contrib/nix/ruby3.0-Gemfile.lock +1 -1
  20. data/contrib/nix/ruby3.0-gemset.nix +2 -2
  21. data/contrib/nix/ruby3.1-Gemfile.lock +1 -1
  22. data/contrib/nix/ruby3.1-gemset.nix +2 -2
  23. data/contrib/nix/ruby3.2-Gemfile.lock +1 -1
  24. data/contrib/nix/ruby3.2-gemset.nix +2 -2
  25. data/contrib/nix/ruby3.3-shell.nix +1 -1
  26. data/contrib/nix/ruby3.4-shell.nix +1 -1
  27. data/contrib/nix/ruby4.0-shell.nix +2 -1
  28. data/contrib/nix/test-all-rubies.sh +2 -1
  29. data/contrib/screenshot-generator/.gitignore +1 -0
  30. data/contrib/screenshot-generator/default.nix +253 -0
  31. data/contrib/screenshot-generator/scenes.yaml +51 -0
  32. data/contrib/screenshot-generator/shoot.rb +127 -0
  33. data/contrib/screenshot-generator/sup-is-plain-text-applied.msg +83 -0
  34. data/contrib/screenshot-generator/sup-is-plain-text.msg +78 -0
  35. data/lib/sup/buffer.rb +13 -3
  36. data/lib/sup/draft.rb +0 -4
  37. data/lib/sup/index.rb +7 -1
  38. data/lib/sup/maildir.rb +21 -16
  39. data/lib/sup/mbox.rb +0 -10
  40. data/lib/sup/message.rb +5 -19
  41. data/lib/sup/message_chunks.rb +1 -1
  42. data/lib/sup/modes/edit_message_mode.rb +52 -4
  43. data/lib/sup/modes/thread_index_mode.rb +28 -27
  44. data/lib/sup/person.rb +0 -6
  45. data/lib/sup/poll.rb +1 -4
  46. data/lib/sup/sent.rb +5 -4
  47. data/lib/sup/source.rb +0 -47
  48. data/lib/sup/util.rb +2 -2
  49. data/lib/sup/version.rb +1 -1
  50. data/test/dummy_source.rb +0 -4
  51. data/test/fixtures/folded-from-header.eml +8 -0
  52. data/test/fixtures/rfc2047-header-encoding.eml +1 -0
  53. data/test/fixtures/text-attachments-with-charset.eml +7 -0
  54. data/test/integration/test_index.rb +62 -0
  55. data/test/test_header_parsing.rb +9 -9
  56. data/test/test_message.rb +21 -3
  57. data/test/unit/test_index.rb +27 -3
  58. data/test/unit/test_line_cursor_mode.rb +6 -0
  59. data/test/unit/test_maildir.rb +21 -0
  60. metadata +15 -4
  61. data/man/sup-psych-ify-config-files.1 +0 -76
data/lib/sup/maildir.rb CHANGED
@@ -84,10 +84,6 @@ class Maildir < Source
84
84
  end
85
85
  end
86
86
 
87
- def load_header id
88
- with_file_for(id) { |f| parse_raw_email_header f }
89
- end
90
-
91
87
  def load_message id
92
88
  with_file_for(id) { |f| RMail::Parser.read f }
93
89
  end
@@ -189,20 +185,29 @@ class Maildir < Source
189
185
  end
190
186
 
191
187
  def maildir_labels id
192
- (seen?(id) ? [] : [:unread]) +
193
- (trashed?(id) ? [:deleted] : []) +
194
- (flagged?(id) ? [:starred] : []) +
195
- (passed?(id) ? [:forwarded] : []) +
196
- (replied?(id) ? [:replied] : []) +
197
- (draft?(id) ? [:draft] : [])
188
+ flags = maildir_flags id
189
+ labels = []
190
+ labels << :unread unless flags.member? :seen
191
+ labels << :deleted if flags.member? :trashed
192
+ labels << :starred if flags.member? :flagged
193
+ labels << :forwarded if flags.member? :passed
194
+ labels << :replied if flags.member? :replied
195
+ labels << :draft if flags.member? :draft
196
+ labels
198
197
  end
199
198
 
200
- def draft? id; maildir_data(id)[2].include? "D"; end
201
- def flagged? id; maildir_data(id)[2].include? "F"; end
202
- def passed? id; maildir_data(id)[2].include? "P"; end
203
- def replied? id; maildir_data(id)[2].include? "R"; end
204
- def seen? id; maildir_data(id)[2].include? "S"; end
205
- def trashed? id; maildir_data(id)[2].include? "T"; end
199
+ def maildir_flags id
200
+ maildir_data(id)[2].each_char.map do |c|
201
+ case c
202
+ when 'D' then :draft
203
+ when 'F' then :flagged
204
+ when 'P' then :passed
205
+ when 'R' then :replied
206
+ when 'S' then :seen
207
+ when 'T' then :trashed
208
+ end
209
+ end
210
+ end
206
211
 
207
212
  def valid? id
208
213
  File.exist? File.join(@dir, id)
data/lib/sup/mbox.rb CHANGED
@@ -69,16 +69,6 @@ class MBox < Source
69
69
  end
70
70
  end
71
71
 
72
- def load_header offset
73
- header = nil
74
- @mutex.synchronize do
75
- ensure_open
76
- @f.seek offset
77
- header = parse_raw_email_header @f
78
- end
79
- header
80
- end
81
-
82
72
  def load_message offset
83
73
  @mutex.synchronize do
84
74
  ensure_open
data/lib/sup/message.rb CHANGED
@@ -48,8 +48,6 @@ class Message
48
48
 
49
49
  attr_accessor :locations
50
50
 
51
- ## if you specify a :header, will use values from that. otherwise,
52
- ## will try and load the header from the source.
53
51
  def initialize opts
54
52
  @locations = opts[:locations] or raise ArgumentError, "locations can't be nil"
55
53
  @snippet = opts[:snippet]
@@ -64,17 +62,18 @@ class Message
64
62
  ## we need to initialize this. see comments in parse_header as to
65
63
  ## why.
66
64
  @refs = []
67
-
68
- #parse_header(opts[:header] || @source.load_header(@source_info))
69
65
  end
70
66
 
71
67
  def decode_header_field v
72
68
  return unless v
73
69
  return v unless v.is_a? String
74
70
  return unless v.size < MAX_HEADER_VALUE_SIZE # avoid regex blowup on spam
71
+ ## Unfold per RFC 5322 2.2.3: remove each CRLF immediately followed
72
+ ## by WSP, leaving the WSP in place.
73
+ v = v.gsub(/\r?\n(?=[ \t])/, "")
75
74
  ## Header values should be either 7-bit with RFC2047-encoded words
76
75
  ## or UTF-8 as per RFC6532. Replace any invalid high bytes with U+FFFD.
77
- Rfc2047.decode_to $encoding, v.dup.force_encoding(Encoding::UTF_8).scrub
76
+ Rfc2047.decode_to $encoding, v.force_encoding(Encoding::UTF_8).scrub
78
77
  end
79
78
 
80
79
  def parse_header encoded_header
@@ -333,21 +332,8 @@ EOS
333
332
  end
334
333
  end
335
334
 
336
- ## returns all the content from a message that will be indexed
337
- def indexable_content
338
- load_from_source!
339
- [
340
- from && from.indexable_content,
341
- to.map { |p| p.indexable_content },
342
- cc.map { |p| p.indexable_content },
343
- bcc.map { |p| p.indexable_content },
344
- indexable_chunks.map { |c| c.lines.map { |l| l.fix_encoding! } },
345
- indexable_subject,
346
- ].flatten.compact.join " "
347
- end
348
-
349
335
  def indexable_body
350
- indexable_chunks.map { |c| c.lines }.flatten.compact.map { |l| l.fix_encoding! }.join " "
336
+ indexable_chunks.map { |c| c.lines }.flatten.compact.join " "
351
337
  end
352
338
 
353
339
  def indexable_chunks
@@ -105,7 +105,7 @@ EOS
105
105
  text = case @content_type
106
106
  when /^text\/plain\b/
107
107
  if /^UTF-7$/i =~ encoded_content.charset
108
- @raw_content.decode_utf7
108
+ @raw_content.decode_utf7 :invalid => :replace, :undef => :replace
109
109
  else
110
110
  begin
111
111
  charset = Encoding.find(encoded_content.charset || 'US-ASCII')
@@ -80,6 +80,16 @@ Return value:
80
80
  True if mail has been sent successfully, false otherwise.
81
81
  EOS
82
82
 
83
+ HookManager.register "sent-save-to", <<EOS
84
+ Selects where to save sent mail to. If this hook doesn't exist, the
85
+ "sent_source" config will be used (possibly defaulting to sup://sent).
86
+ Variables:
87
+ message: RMail::Message instance of the mail which has been sent.
88
+ account: Account instance matching the From address.
89
+ Return value:
90
+ Source to save the sent mail to, or nil to use the default.
91
+ EOS
92
+
83
93
  attr_reader :status
84
94
  attr_accessor :body, :header
85
95
  bool_reader :edited
@@ -451,9 +461,46 @@ protected
451
461
  end
452
462
  end
453
463
 
464
+ ## utility method to read a raw email header from an IO stream and turn it
465
+ ## into a hash of key-value pairs. minor special semantics for certain headers.
466
+ def self.parse_raw_email_header f
467
+ header = {}
468
+ last = nil
469
+
470
+ while(line = f.gets)
471
+ case line
472
+ ## these three can occur multiple times, and we want the first one
473
+ when /^(Delivered-To|X-Original-To|Envelope-To):\s*(.*?)\s*$/i; header[last = $1.downcase] ||= $2
474
+ ## regular header: overwrite (not that we should see more than one)
475
+ ## TODO: figure out whether just using the first occurrence changes
476
+ ## anything (which would simplify the logic slightly)
477
+ when /^([^:\s]+):\s*(.*?)\s*$/i; header[last = $1.downcase] = $2
478
+ when /^\r*$/; break # blank line signifies end of header
479
+ else
480
+ if last
481
+ header[last] << " " unless header[last].empty?
482
+ header[last] << line.strip
483
+ end
484
+ end
485
+ end
486
+
487
+ %w(subject from to cc bcc).each do |k|
488
+ v = header[k] or next
489
+ next unless Rfc2047.is_encoded? v
490
+ header[k] = begin
491
+ Rfc2047.decode_to $encoding, v
492
+ rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence
493
+ v
494
+ end
495
+ end
496
+ header
497
+ end
498
+
499
+ def parse_raw_email_header f; self.class.parse_raw_email_header f end
500
+
454
501
  def parse_file fn
455
502
  File.open(fn) do |f|
456
- header = Source.parse_raw_email_header(f).inject({}) { |h, (k, v)| h[k.capitalize] = v; h } # lousy HACK
503
+ header = parse_raw_email_header(f).inject({}) { |h, (k, v)| h[k.capitalize] = v; h } # lousy HACK
457
504
  body = f.readlines.map { |l| l.chomp }
458
505
 
459
506
  header.delete_if { |k, v| NON_EDITABLE_HEADERS.member? k }
@@ -534,7 +581,8 @@ protected
534
581
  raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
535
582
  end
536
583
 
537
- SentManager.write_sent_message(date, from_email) { |f| f.puts sanitize_body(m.to_s) }
584
+ SentManager.write_sent_message(HookManager.run("sent-save-to", :message => m, :account => acct),
585
+ date, from_email) { |f| f.puts sanitize_body(m.to_s) }
538
586
  BufferManager.kill_buffer buffer
539
587
  BufferManager.flash "Message sent!"
540
588
  true
@@ -553,7 +601,6 @@ protected
553
601
 
554
602
  def build_message date
555
603
  m = RMail::Message.new
556
- m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
557
604
  m.body = @body.join("\n")
558
605
  m.body += "\n" + sig_lines.join("\n") unless @sig_edited
559
606
  ## body must end in a newline or GPG signatures will be WRONG!
@@ -601,8 +648,9 @@ protected
601
648
  m.header["Date"] = date.rfc2822
602
649
  m.header["Message-Id"] = @message_id
603
650
  m.header["User-Agent"] = "Sup/#{Redwood::VERSION}"
651
+ m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
604
652
  m.header["Content-Transfer-Encoding"] ||= +"8bit"
605
- m.header["MIME-Version"] = +"1.0" if m.multipart?
653
+ m.header["MIME-Version"] = +"1.0"
606
654
  m
607
655
  end
608
656
 
@@ -494,6 +494,29 @@ EOS
494
494
  threads.each { |t| Index.save_thread t }
495
495
  end
496
496
 
497
+ ## returns an undo lambda
498
+ def actually_toggle_killed t
499
+ if t.has_label? :killed
500
+ t.remove_label :killed
501
+ add_or_unhide t.first
502
+ UpdateManager.relay self, :labeled, t.first
503
+ lambda do
504
+ t.apply_label :killed
505
+ hide_thread t
506
+ UpdateManager.relay self, :labeled, t.first
507
+ end
508
+ else
509
+ t.apply_label :killed
510
+ hide_thread t
511
+ UpdateManager.relay self, :labeled, t.first
512
+ lambda do
513
+ t.remove_label :killed
514
+ add_or_unhide t.first
515
+ UpdateManager.relay self, :labeled, t.first
516
+ end
517
+ end
518
+ end
519
+
497
520
  def kill
498
521
  t = cursor_thread or return
499
522
  multi_kill [t]
@@ -507,35 +530,13 @@ EOS
507
530
 
508
531
  ## m-m-m-m-MULTI-KILL
509
532
  def multi_kill threads
510
- UndoManager.register "killing/unkilling #{threads.size.pluralize 'threads'}" do
511
- threads.each do |t|
512
- if t.toggle_label :killed
513
- add_or_unhide t.first
514
- else
515
- hide_thread t
516
- end
517
- end.each do |t|
518
- UpdateManager.relay self, :labeled, t.first
519
- Index.save_thread t
520
- end
521
- regen_text
522
- end
523
-
524
- threads.each do |t|
525
- if t.toggle_label :killed
526
- hide_thread t
527
- else
528
- add_or_unhide t.first
529
- end
530
- end.each do |t|
531
- # send 'labeled'... this might be more specific
532
- UpdateManager.relay self, :labeled, t.first
533
- Index.save_thread t
534
- end
535
-
533
+ undos = threads.map { |t| actually_toggle_killed t }
534
+ UndoManager.register "killing/unkilling #{threads.size.pluralize 'threads'}", undos,
535
+ lambda { regen_text }, lambda { threads.each { |t| Index.save_thread t } }
536
+ regen_text
537
+ threads.each { |t| Index.save_thread t }
536
538
  killed, unkilled = threads.partition { |t| t.has_label? :killed }.map(&:size)
537
539
  BufferManager.flash "#{killed.pluralize 'thread'} killed, #{unkilled} unkilled"
538
- regen_text
539
540
  end
540
541
 
541
542
  def cleanup
data/lib/sup/person.rb CHANGED
@@ -71,12 +71,6 @@ class Person
71
71
  def eql? o; email.eql? o.email end
72
72
  def hash; email.hash end
73
73
 
74
-
75
- ## see comments in self.from_address
76
- def indexable_content
77
- [name, email, email.split(/@/).first].join(" ")
78
- end
79
-
80
74
  class << self
81
75
 
82
76
  def full_address name, email
data/lib/sup/poll.rb CHANGED
@@ -219,12 +219,9 @@ EOS
219
219
  Index.sync_message m, true
220
220
  end
221
221
 
222
- ## We need to add or unhide the message when it either did not exist
223
- ## before at all or when it was updated. We do *not* add/unhide when
224
- ## the same message was found at a different location
225
222
  if old_m
226
223
  UpdateManager.relay self, :updated, m
227
- elsif !old_m or not old_m.locations.member? m.location
224
+ else
228
225
  UpdateManager.relay self, :added, m
229
226
  end
230
227
  when :delete
data/lib/sup/sent.rb CHANGED
@@ -24,13 +24,14 @@ class SentManager
24
24
  @source
25
25
  end
26
26
 
27
- def write_sent_message date, from_email, &block
27
+ def write_sent_message src, date, from_email, &block
28
28
  ::Thread.new do
29
29
  debug "store the sent message (locking sent source..)"
30
- @source.synchronize do
31
- @source.store_message date, from_email, &block
30
+ use_src = src || @source
31
+ use_src.synchronize do
32
+ use_src.store_message date, from_email, &block
32
33
  end
33
- PollManager.poll_from @source
34
+ PollManager.poll_from use_src
34
35
  end
35
36
  end
36
37
  end
data/lib/sup/source.rb CHANGED
@@ -33,7 +33,6 @@ class Source
33
33
  ## To write a new source, subclass this class, and implement:
34
34
  ##
35
35
  ## - initialize
36
- ## - load_header offset
37
36
  ## - load_message offset
38
37
  ## - raw_header offset
39
38
  ## - raw_message offset
@@ -122,52 +121,6 @@ class Source
122
121
  debug "lock released for: #{self}"
123
122
  end
124
123
 
125
- ## utility method to read a raw email header from an IO stream and turn it
126
- ## into a hash of key-value pairs. minor special semantics for certain headers.
127
- ##
128
- ## THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have a
129
- ## significant effect on Sup's processing speed of email from ALL sources.
130
- ## Little things like string interpolation, regexp interpolation, += vs <<,
131
- ## all have DRAMATIC effects. BE CAREFUL WHAT YOU DO!
132
- def self.parse_raw_email_header f
133
- header = {}
134
- last = nil
135
-
136
- while(line = f.gets)
137
- case line
138
- ## these three can occur multiple times, and we want the first one
139
- when /^(Delivered-To|X-Original-To|Envelope-To):\s*(.*?)\s*$/i; header[last = $1.downcase] ||= $2
140
- ## regular header: overwrite (not that we should see more than one)
141
- ## TODO: figure out whether just using the first occurrence changes
142
- ## anything (which would simplify the logic slightly)
143
- when /^([^:\s]+):\s*(.*?)\s*$/i; header[last = $1.downcase] = $2
144
- when /^\r*$/; break # blank line signifies end of header
145
- else
146
- if last
147
- header[last] << " " unless header[last].empty?
148
- header[last] << line.strip
149
- end
150
- end
151
- end
152
-
153
- %w(subject from to cc bcc).each do |k|
154
- v = header[k] or next
155
- next unless Rfc2047.is_encoded? v
156
- header[k] = begin
157
- Rfc2047.decode_to $encoding, v
158
- rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence
159
- #debug "warning: error decoding RFC 2047 header (#{e.class.name}): #{e.message}"
160
- v
161
- end
162
- end
163
- header
164
- end
165
-
166
- protected
167
-
168
- ## convenience function
169
- def parse_raw_email_header f; self.class.parse_raw_email_header f end
170
-
171
124
  def Source.expand_filesystem_uri uri
172
125
  uri.gsub "~", File.expand_path("~")
173
126
  end
data/lib/sup/util.rb CHANGED
@@ -364,10 +364,10 @@ class String
364
364
  ## Net::IMAP::decode_utf7 which only handles the IMAP "modified UTF-7"
365
365
  ## encoding. This implementation is inspired by that one but handles
366
366
  ## standard UTF-7 shift characters and not the IMAP-specific variation.
367
- def decode_utf7
367
+ def decode_utf7 **opts
368
368
  gsub(/\+([^-]+)?-/) {
369
369
  if $1
370
- ($1 + "===").unpack("m")[0].encode(Encoding::UTF_8, Encoding::UTF_16BE)
370
+ ($1 + "===").unpack("m")[0].encode(Encoding::UTF_8, Encoding::UTF_16BE, **opts)
371
371
  else
372
372
  "+"
373
373
  end
data/lib/sup/version.rb CHANGED
@@ -8,5 +8,5 @@ def git_suffix
8
8
  end
9
9
 
10
10
  module Redwood
11
- VERSION = "1.4"
11
+ VERSION = "1.5"
12
12
  end
data/test/dummy_source.rb CHANGED
@@ -32,10 +32,6 @@ class DummySource < Source
32
32
  File.open(fn, 'rb') { |f| yield f }
33
33
  end
34
34
 
35
- def load_header id
36
- with_file_for(id) { |f| parse_raw_email_header f }
37
- end
38
-
39
35
  def load_message id
40
36
  with_file_for(id) { |f| RMail::Parser.read f }
41
37
  end
@@ -0,0 +1,8 @@
1
+ From: "Kevin Frazier, Juliana Schroeder, Brian Frye, Nathanael Fast,
2
+ and Rob Greer" <user@rss2email.invalid>
3
+ To: someone@example.invalid
4
+ Subject: folded From header
5
+ Date: Fri, 16 Oct 2026 10:00:00 +0000
6
+ Message-Id: <folded-from-header@example.invalid>
7
+
8
+ body
@@ -8,6 +8,7 @@ Subject:
8
8
  =?UTF-7?b?LCBGcmlkYSBFbmcrQVBnLQ?=
9
9
  bad: =?UTF16?q?badcharsetname?= =?US-ASCII?b?/w?=
10
10
  =?UTF-7?Q?=41=6D=65=72=69=63=61=E2=80=99=73?=
11
+ =?UTF-7?b?K0FHRUEt?=
11
12
 
12
13
  The subject header contains various RFC2047 encoded words.
13
14
  For completeness we test both base64 and quoted-printable, and some
@@ -57,4 +57,11 @@ Content-Disposition: attachment; filename="ascii.txt"
57
57
 
58
58
  This is +Jyg-UTF-7+Jyg-
59
59
  --===============2385509127900810307==
60
+ Content-Type: text/plain; charset="utf-7"
61
+ Content-Transfer-Encoding: 7bit
62
+ MIME-Version: 1.0
63
+ Content-Disposition: attachment; filename="bad-utf7.txt"
64
+
65
+ Bad +AGEA- UTF-7
66
+ --===============2385509127900810307==
60
67
 
@@ -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
@@ -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,7 +268,8 @@ 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)
256
274
  assert_equal "=?utf-8?q?YouTube-tj=E4nst?=", sup_message.from.name
257
275
  end