diff --git a/lib/net/imap/sequence_set.rb b/lib/net/imap/sequence_set.rb index 1cb85112..b046b0eb 100644 --- a/lib/net/imap/sequence_set.rb +++ b/lib/net/imap/sequence_set.rb @@ -684,8 +684,9 @@ def append(object) modifying! tuple = input_to_tuple object entry = tuple_to_str tuple + string unless empty? # write @string before tuple_add tuple_add tuple - @string = -(string ? "#{@string},#{entry}" : entry) + @string = -(@string ? "#{@string},#{entry}" : entry) self end diff --git a/test/net/imap/test_sequence_set.rb b/test/net/imap/test_sequence_set.rb index 85204b24..94c096ba 100644 --- a/test/net/imap/test_sequence_set.rb +++ b/test/net/imap/test_sequence_set.rb @@ -344,6 +344,14 @@ def obj.to_sequence_set; 192_168.001_255 end assert_equal "1:6,4:9", SequenceSet.new("1:6").append("4:9").string assert_equal "1:4,5:*", SequenceSet.new("1:4").append(5..).string assert_equal "5:*,1:4", SequenceSet.new("5:*").append(1..4).string + # also works from empty + assert_equal "5,1", SequenceSet.new.append(5).append(1).string + # also works when *previously* input was non-strings + assert_equal "*,1", SequenceSet.new(:*).append(1).string + assert_equal "1,5", SequenceSet.new(1).append("5").string + assert_equal "1:6,4:9", SequenceSet.new(1..6).append(4..9).string + assert_equal "1:4,5:*", SequenceSet.new(1..4).append(5..).string + assert_equal "5:*,1:4", SequenceSet.new(5..).append(1..4).string end test "#merge" do