Skip to content

Commit

Permalink
Fix warning: assigned but unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Jan 19, 2012
1 parent 26bb22a commit 8d6bdf0
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 50 deletions.
4 changes: 2 additions & 2 deletions lib/mail/encodings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def Encodings.value_decode(str)

# Takes an encoded string of the format =?<encoding>?[QB]?<string>?=
def Encodings.unquote_and_convert_to(str, to_encoding)
original_encoding, string = split_encoding_from_string( str )
original_encoding = split_encoding_from_string( str )

output = value_decode( str ).to_s

Expand Down Expand Up @@ -253,7 +253,7 @@ def Encodings.q_value_decode(str)
def Encodings.split_encoding_from_string( str )
match = str.match(/\=\?([^?]+)?\?[QB]\?(.+)?\?\=/mi)
if match
[match[1], match[2]]
match[1]
else
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/fields/resent_sender_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def addresses
end

def address
result = tree.addresses.first
tree.addresses.first
end

def encoded
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/fields/sender_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def addresses
end

def address
result = tree.addresses.first
tree.addresses.first
end

def encoded
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/multibyte/chars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def translate_offset(byte_offset) #:nodoc:

begin
@wrapped_string[0...byte_offset].unpack('U*').length
rescue ArgumentError => e
rescue ArgumentError
byte_offset -= 1
retry
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mail/network/retriever_methods/pop3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def validate_options(options)
def start(config = Configuration.instance, &block)
raise ArgumentError.new("Mail::Retrievable#pop3_start takes a block") unless block_given?

pop3 = Net::POP3.new(settings[:address], settings[:port], isapop = false)
pop3.enable_ssl(verify = OpenSSL::SSL::VERIFY_NONE) if settings[:enable_ssl]
pop3 = Net::POP3.new(settings[:address], settings[:port], false)
pop3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if settings[:enable_ssl]
pop3.start(settings[:user_name], settings[:password])

yield pop3
Expand Down
26 changes: 11 additions & 15 deletions spec/mail/attachments_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,52 @@ def check_decoded(actual, expected)

describe "from direct content" do
it "should work" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'].filename.should eq 'test.png'
check_decoded(@mail.attachments[0].decoded, file_data)
end

it "should work out magically the mime_type" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = File.read(fixture('attachments', 'test.png'))
@mail.attachments[0].mime_type.should eq 'image/png'
end

it "should assign the filename" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = file_data
@mail.attachments['test.png'] = File.read(fixture('attachments', 'test.png'))
@mail.attachments[0].filename.should eq 'test.png'
end

it "should assign mime-encoded multibyte filename" do
file_data = File.read(filename = fixture('attachments', 'てすと.txt'))
@mail.attachments['てすと.txt'] = file_data
@mail.attachments['てすと.txt'] = File.read(fixture('attachments', 'てすと.txt'))
@mail.attachments.should_not be_blank
Mail::Encodings.decode_encode(@mail.attachments[0].filename, :decode).should eq 'てすと.txt'
end
end

describe "from a supplied Hash" do
it "should work" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data }
@mail.attachments[0].filename.should eq 'test.png'
check_decoded(@mail.attachments[0].decoded, file_data)
end

it "should allow you to override the content_type" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data,
:content_type => "application/x-gzip" }
@mail.attachments[0].content_type.should eq 'application/x-gzip'
end

it "should allow you to override the mime_type" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data,
:mime_type => "application/x-gzip" }
@mail.attachments[0].mime_type.should eq 'application/x-gzip'
end

it "should allow you to override the mime_type" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
@mail.attachments['invoice.jpg'] = { :data => "you smiling",
:mime_type => "image/x-jpg",
:transfer_encoding => "base64" }
Expand All @@ -83,36 +79,36 @@ def check_decoded(actual, expected)
describe "decoding and encoding" do

it "should set it's content_transfer_encoding" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data }
@mail.ready_to_send!
@mail.attachments[0].content_transfer_encoding.should eq 'base64'
end

it "should encode it's body to base64" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data }
@mail.ready_to_send!
@mail.attachments[0].encoded.should include(encode_base64(file_data))
end

it "should allow you to pass in an encoded attachment with an encoding" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
encoded_data = encode_base64(file_data)
@mail.attachments['test.png'] = { :content => encoded_data,
:encoding => 'base64' }
check_decoded(@mail.attachments[0].decoded, file_data)
end

it "should not allow you to pass in an encoded attachment with an unknown encoding" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
base64_encoded_data = encode_base64(file_data)
doing {@mail.attachments['test.png'] = { :content => base64_encoded_data,
:encoding => 'weird_encoding' }}.should raise_error
end

it "should be able to call read on the attachment to return the decoded data" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
file_data = File.read(fixture('attachments', 'test.png'))
@mail.attachments['test.png'] = { :content => file_data }
if RUBY_VERSION >= '1.9'
expected = @mail.attachments[0].read.force_encoding(file_data.encoding)
Expand Down
4 changes: 2 additions & 2 deletions spec/mail/elements/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
it "should give it's address back on :to_s if there is no display name" do
parse_text = 'test@lindsaar.net'
result = 'test@lindsaar.net'
Mail::Address.new(parse_text).to_s.should eq 'test@lindsaar.net'
Mail::Address.new(parse_text).to_s.should eq result
end

it "should give it's format back on :to_s if there is a display name" do
parse_text = 'Mikel Lindsaar <test@lindsaar.net>'
result = 'Mikel Lindsaar <test@lindsaar.net>'
Mail::Address.new(parse_text).to_s.should eq 'Mikel Lindsaar <test@lindsaar.net>'
Mail::Address.new(parse_text).to_s.should eq result
end

it "should give back the display name" do
Expand Down
7 changes: 1 addition & 6 deletions spec/mail/encodings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
doing {Mail::Encodings.b_value_encode(string)}.should_not raise_error
else
string = "This is あ string"
encoding = 'UTF-8'
doing {Mail::Encodings.b_value_encode(string, nil)}.should raise_error("Must supply an encoding")
end
end
Expand Down Expand Up @@ -201,7 +200,6 @@
doing {Mail::Encodings.q_value_encode(string)}.should_not raise_error
else
string = "This is あ string"
encoding = 'UTF-8'
doing {Mail::Encodings.q_value_encode(string)}.should raise_error("Must supply an encoding")
end
end
Expand Down Expand Up @@ -273,9 +271,8 @@

it "should round trip another complex string (koi-8)" do
original = "Слово 9999 и число"
orginial = original.encode('koi8-r') if RUBY_VERSION >= "1.9"
mail = Mail.new
mail.subject = original
mail.subject = (RUBY_VERSION >= "1.9" ? original.encode('koi8-r') : original)
mail[:subject].charset = 'koi8-r'
wrapped = mail[:subject].wrapped_value
unwrapped = Mail::Encodings.value_decode(wrapped)
Expand Down Expand Up @@ -623,13 +620,11 @@
describe "quoted printable encoding and decoding" do
it "should handle underscores in the text" do
expected = 'something_with_underscores'
encoded = [expected].pack('M')
Mail::Encodings.get_encoding(:quoted_printable).encode(expected).unpack("M").first.should eq expected
end

it "should handle underscores in the text" do
expected = 'something with_underscores'
encoded = [expected].pack('M')
Mail::Encodings.get_encoding(:quoted_printable).encode(expected).unpack("M").first.should eq expected
end

Expand Down
1 change: 0 additions & 1 deletion spec/mail/fields/content_type_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@
string.force_encoding('SJIS')
result = %Q{Content-Type: application/octet-stream;\r\n\sfilename*=shift_jis'jp'01%20Quien%20Te%20Dij%91%61t.%20Pitbull.mp3\r\n}
else
storedkcode = $KCODE
$KCODE = 'SJIS'
result = %Q{Content-Type: application/octet-stream;\r\n\sfilename*=sjis'jp'01%20Quien%20Te%20Dij%91at.%20Pitbull.mp3\r\n}
end
Expand Down
6 changes: 3 additions & 3 deletions spec/mail/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ def basic_email
it "should give the header class the header to parse" do
header = Mail::Header.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
Mail::Header.should_receive(:new).with("To: mikel\r\nFrom: bob\r\nSubject: Hello!", 'UTF-8').and_return(header)
mail = Mail::Message.new(basic_email)
Mail::Message.new(basic_email)
end

it "should give the header class the header to parse even if there is no body" do
header = Mail::Header.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
Mail::Header.should_receive(:new).with("To: mikel\r\nFrom: bob\r\nSubject: Hello!", 'UTF-8').and_return(header)
mail = Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
end

it "should give the body class the body to parse" do
Expand All @@ -259,7 +259,7 @@ def basic_email
it "should still ask the body for a new instance even though these is nothing to parse, yet" do
body = Mail::Body.new('')
Mail::Body.should_receive(:new).and_return(body)
mail = Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
end

it "should give the header the part before the line without spaces and the body the part without" do
Expand Down
10 changes: 5 additions & 5 deletions spec/mail/mime_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@
body "This is Text"
end
mail.html_part = Mail::Part.new do
content_type = "text/html; charset=US-ASCII"
body = "<b>This is HTML</b>"
content_type "text/html; charset=US-ASCII"
body "<b>This is HTML</b>"
end
mail.parts.length.should eq 2
mail.parts.first.class.should eq Mail::Part
Expand All @@ -176,7 +176,7 @@
body "This is Text"
end
mail.html_part = Mail::Part.new do
content_type = "text/html; charset=US-ASCII"
content_type "text/html; charset=US-ASCII"
body "<b>This is HTML</b>"
end
mail.to_s.should =~ %r|Content-Type: multipart/alternative;\s+boundary="#{mail.boundary}"|
Expand All @@ -188,7 +188,7 @@
body "This is Text"
end
mail.html_part = Mail::Part.new do
content_type = "text/html; charset=US-ASCII"
content_type "text/html; charset=US-ASCII"
body "<b>This is HTML</b>"
end
mail.to_s.should =~ %r|#{mail.boundary}--|
Expand All @@ -200,7 +200,7 @@
body "This is Text"
end
mail.html_part = Mail::Part.new do
content_type = "text/html; charset=US-ASCII"
content_type "text/html; charset=US-ASCII"
body "<b>This is HTML</b>"
end
mail.to_s
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/network/delivery_methods/file_delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
delivery_method :file, :location => tmpdir
end

mail = Mail.deliver do
Mail.deliver do
from 'roger@moore.com'
to '"Long, stupid email address" <mikel@test.lindsaar.net>'
subject 'invalid RFC2822'
Expand Down
6 changes: 3 additions & 3 deletions spec/mail/network/delivery_methods/smtp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def redefine_verify_none(new_value)
describe "return path" do

it "should use the return path if specified" do
mail = Mail.deliver do
Mail.deliver do
to "to@someemail.com"
from "from@someemail.com"
sender "sender@test.lindsaar.net"
Expand All @@ -166,7 +166,7 @@ def redefine_verify_none(new_value)
end

it "should use the sender address is no return path is specified" do
mail = Mail.deliver do
Mail.deliver do
to "to@someemail.com"
from "from@someemail.com"
sender "sender@test.lindsaar.net"
Expand All @@ -178,7 +178,7 @@ def redefine_verify_none(new_value)
end

it "should use the from address is no return path or sender is specified" do
mail = Mail.deliver do
Mail.deliver do
to "to@someemail.com"
from "from@someemail.com"
subject "Can't set the return-path"
Expand Down
10 changes: 5 additions & 5 deletions spec/mail/network/retriever_methods/imap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
messages.map { |m| m.raw_source }.should eq MockIMAP.examples.map { |m| m.attr['RFC822'] }[-5..-1]
end
it "should handle the :mailbox option" do
messages = Mail.find(:mailbox => 'SOME-RANDOM-MAILBOX')
Mail.find(:mailbox => 'SOME-RANDOM-MAILBOX')

MockIMAP.mailbox.should eq 'SOME-RANDOM-MAILBOX'
end
Expand All @@ -86,7 +86,7 @@
messages.size.should eq 10
end
it "should search the mailbox 'INBOX' by default" do
messages = Mail.find
Mail.find

MockIMAP.mailbox.should eq 'INBOX'
end
Expand Down Expand Up @@ -148,7 +148,7 @@

describe "delete_all" do
it "should delete all messages" do
messages = Mail.all
Mail.all

Net::IMAP.should_receive(:encode_utf7).once
Mail.delete_all
Expand Down Expand Up @@ -238,15 +238,15 @@
Mail.defaults do
retriever_method :imap, {:user_name => 'foo', :password => 'secret'}
end
messages = Mail.find
Mail.find
end
it "should be changeable" do
@imap.should_receive(:authenticate).with('CRAM-MD5', 'foo', 'secret')
@imap.should_not_receive(:login)
Mail.defaults do
retriever_method :imap, {:authentication => 'CRAM-MD5', :user_name => 'foo', :password => 'secret'}
end
messages = Mail.find
Mail.find
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mail/network/retriever_methods/pop3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

describe "delete_all" do
it "should delete all mesages" do
messages = Mail.all
Mail.all
Mail.delete_all

MockPOP3.popmails.size.should eq 0
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/round_tripping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
body "This is Text"
end
mail.html_part = Mail::Part.new do
content_type = "text/html; charset=US-ASCII"
content_type "text/html; charset=US-ASCII"
body "<b>This is HTML</b>"
end
parsed_mail = Mail.new(mail.to_s)
Expand Down

0 comments on commit 8d6bdf0

Please sign in to comment.