Skip to content

Commit ccfaadf

Browse files
committed
parse drafts as individual messages, not mboxes
As far as I can see they were always being written with one message per file and no From envelope (maildir style) so there is no reason to try iterating the draft as if it were an mbox. Fixes the pathological case of trying to load an empty file as a draft.
1 parent a0a496f commit ccfaadf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/sup/draft.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ def load_header offset
7676

7777
def load_message offset
7878
raise SourceError, "Draft not found" unless File.exist? fn_for_offset(offset)
79-
File.open fn_for_offset(offset) do |f|
80-
RMail::Mailbox::MBoxReader.new(f).each_message do |input|
81-
return RMail::Parser.read(input)
82-
end
83-
end
79+
File.open(fn_for_offset(offset)) { |f| RMail::Parser.read f }
8480
end
8581

8682
def fallback_date_for_message offset

test/integration/test_draft.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,10 @@ def test_load_malformed_draft
9393
PollManager.poll_from @draft_source
9494
messages_in_index = Index.instance.enum_for(:each_message).to_a
9595
assert_equal "", messages_in_index[0].subj
96+
97+
File.write (File.join @draft_dir, "2"), ""
98+
PollManager.poll_from @draft_source
99+
messages_in_index = Index.instance.enum_for(:each_message).to_a
100+
assert_equal "", messages_in_index[0].subj
96101
end
97102
end

0 commit comments

Comments
 (0)