commit f7ade4e96d9a1a7198b0f84644f62ab58bd5536d
parent 1a8e63f3fe2549ad27684192a6fd80bc0dbdce24
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 5 Apr 2025 15:50:50 +1100
fix some frozen string literal warnings
Diffstat:
9 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -198,17 +198,17 @@ EOS
end
encrypted_payload = RMail::Message.new
- encrypted_payload.header["Content-Type"] = "application/octet-stream"
- encrypted_payload.header["Content-Disposition"] = 'inline; filename="msg.asc"'
+ encrypted_payload.header["Content-Type"] = +"application/octet-stream"
+ encrypted_payload.header["Content-Disposition"] = +'inline; filename="msg.asc"'
encrypted_payload.body = cipher
control = RMail::Message.new
- control.header["Content-Type"] = "application/pgp-encrypted"
- control.header["Content-Disposition"] = "attachment"
+ control.header["Content-Type"] = +"application/pgp-encrypted"
+ control.header["Content-Disposition"] = +"attachment"
control.body = "Version: 1\n"
envelope = RMail::Message.new
- envelope.header["Content-Type"] = 'multipart/encrypted; protocol=application/pgp-encrypted'
+ envelope.header["Content-Type"] = +"multipart/encrypted; protocol=application/pgp-encrypted"
envelope.add_part control
envelope.add_part encrypted_payload
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -86,7 +86,7 @@ class MBox < Source
begin
## don't use RMail::Mailbox::MBoxReader because it doesn't properly ignore
## "From" at the start of a message body line.
- string = ""
+ string = +""
until @f.eof? || MBox::is_break_line?(l = @f.gets)
string << l
end
@@ -98,7 +98,7 @@ class MBox < Source
end
def raw_header offset
- ret = ""
+ ret = +""
@mutex.synchronize do
ensure_open
@f.seek offset
@@ -110,9 +110,7 @@ class MBox < Source
end
def raw_message offset
- ret = ""
- each_raw_message_line(offset) { |l| ret << l }
- ret
+ enum_for(:each_raw_message_line, offset).reduce(:+)
end
def store_message date, from_email, &block
diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb
@@ -563,7 +563,7 @@ protected
## there are attachments, so wrap body in an attachment of its own
unless @attachments.empty?
body_m = m
- body_m.header["Content-Disposition"] = "inline"
+ body_m.header["Content-Disposition"] = +"inline"
m = RMail::Message.new
m.add_part body_m
@@ -601,8 +601,8 @@ protected
m.header["Date"] = date.rfc2822
m.header["Message-Id"] = @message_id
m.header["User-Agent"] = "Sup/#{Redwood::VERSION}"
- m.header["Content-Transfer-Encoding"] ||= '8bit'
- m.header["MIME-Version"] = "1.0" if m.multipart?
+ m.header["Content-Transfer-Encoding"] ||= +"8bit"
+ m.header["MIME-Version"] = +"1.0" if m.multipart?
m
end
@@ -716,10 +716,10 @@ private
## encode to quoted-printable for all text/* MIME types,
## use base64 otherwise
if msg_part.header["Content-Type"] =~ /text\/.*/
- msg_part.header.set "Content-Transfer-Encoding", "quoted-printable"
+ msg_part.header.set "Content-Transfer-Encoding", +"quoted-printable"
msg_part.body = [msg_part.body].pack('M')
else
- msg_part.header.set "Content-Transfer-Encoding", "base64"
+ msg_part.header.set "Content-Transfer-Encoding", +"base64"
msg_part.body = [msg_part.body].pack('m')
end
msg_part
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -213,7 +213,7 @@ class String
end
def slice_by_display_length len
- each_char.each_with_object "" do |c, buffer|
+ each_char.each_with_object (+"") do |c, buffer|
len -= Unicode::DisplayWidth.of(c)
return buffer if len < 0
buffer << c
diff --git a/test/test_crypto.rb b/test/test_crypto.rb
@@ -38,7 +38,7 @@ class TestCryptoManager < Minitest::Test
@path = Dir.mktmpdir
Redwood::HookManager.init File.join(@path, 'hooks')
- am = {:default=> {name: "test", email: @from_email, alternates: [@from_email_ecc]}}
+ am = {:default=> {name: +"test", email: @from_email.dup, alternates: [@from_email_ecc.dup]}}
Redwood::AccountManager.init am
Redwood::CryptoManager.init
@@ -69,10 +69,10 @@ class TestCryptoManager < Minitest::Test
skip CryptoManager.not_working_reason if not CryptoManager.have_crypto?
body = RMail::Message.new
- body.header["Content-Disposition"] = "inline"
+ body.header["Content-Disposition"] = +"inline"
body.body = "ABCDEFG"
payload = RMail::Message.new
- payload.header["MIME-Version"] = "1.0"
+ payload.header["MIME-Version"] = +"1.0"
payload.add_part body
payload.add_part RMail::Message.make_attachment "attachment", "text/plain", nil, "attachment.txt"
signed = CryptoManager.sign @from_email, @to_email, payload
diff --git a/test/unit/test_contact.rb b/test/unit/test_contact.rb
@@ -6,7 +6,7 @@ module Redwood
class TestContact < Minitest::Test
def setup
@contact = ContactManager.init(File.expand_path("../../fixtures/contacts.txt", __FILE__))
- @person = Person.new "Terrible Name", "terrible@name.com"
+ @person = Person.new (+"Terrible Name"), (+"terrible@name.com")
end
def teardown
diff --git a/test/unit/test_edit_message_mode.rb b/test/unit/test_edit_message_mode.rb
@@ -13,7 +13,7 @@ class DummyCryptoManager
def have_crypto?; true; end
def sign from, to, payload
envelope = RMail::Message.new
- envelope.header["Content-Type"] = "multipart/signed; protocol=testdummy"
+ envelope.header["Content-Type"] = +"multipart/signed; protocol=testdummy"
envelope.add_part payload
envelope
end
@@ -24,7 +24,7 @@ class TestEditMessageMode < Minitest::Test
$config = {}
@path = Dir.mktmpdir
Redwood::HookManager.init File.join(@path, "hooks")
- Redwood::AccountManager.init :default => {name: "test", email: "sender@example.invalid"}
+ Redwood::AccountManager.init :default => {name: +"test", email: +"sender@example.invalid"}
Redwood::CryptoManager.instance_variable_set :@instance, DummyCryptoManager.new
end
@@ -48,8 +48,8 @@ class TestEditMessageMode < Minitest::Test
opts = {
:header => {
- "From" => "sender@example.invalid",
- "To" => "recip@example.invalid",
+ "From" => +"sender@example.invalid",
+ "To" => +"recip@example.invalid",
},
:attachments => {
"dummy.csv" => RMail::Message.make_file_attachment(attachment_filename),
@@ -71,8 +71,8 @@ class TestEditMessageMode < Minitest::Test
opts = {
:header => {
- "From" => "sender@example.invalid",
- "To" => "recip@example.invalid",
+ "From" => +"sender@example.invalid",
+ "To" => +"recip@example.invalid",
},
:attachments => {
"dummy.csv" => RMail::Message.make_file_attachment(attachment_filename),
diff --git a/test/unit/test_person.rb b/test/unit/test_person.rb
@@ -5,12 +5,12 @@ module Redwood
class TestPerson < Minitest::Test
def setup
- @person = Person.new("Thomassen, Bob", "bob@thomassen.com")
- @no_name = Person.new(nil, "alice@alice.com")
+ @person = Person.new(+"Thomassen, Bob", +"bob@thomassen.com")
+ @no_name = Person.new(nil, +"alice@alice.com")
end
def test_email_must_be_supplied
- assert_raises (ArgumentError) { Person.new("Alice", nil) }
+ assert_raises (ArgumentError) { Person.new(+"Alice", nil) }
end
def test_to_string
diff --git a/test/unit/util/test_string.rb b/test/unit/util/test_string.rb
@@ -18,7 +18,7 @@ describe "Sup's String extension" do
it "calculates display length of a string" do
data.each do |(str, length)|
- assert_equal length, str.display_length
+ assert_equal length, str.dup.display_length
end
end
end
@@ -36,7 +36,7 @@ describe "Sup's String extension" do
it "slices string by display length" do
data.each do |(str, length, sliced)|
- assert_equal sliced, str.slice_by_display_length(length)
+ assert_equal sliced, str.dup.slice_by_display_length(length)
end
end
end
@@ -56,7 +56,7 @@ describe "Sup's String extension" do
it "wraps string by display length" do
data.each do |(str, length, wrapped)|
- assert_equal wrapped, str.wrap(length)
+ assert_equal wrapped, str.dup.wrap(length)
end
end
end