2009-11-19 13:56:23 +00:00
|
|
|
require "net/imap"
|
|
|
|
require "test/unit"
|
|
|
|
|
|
|
|
class IMAPResponseParserTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@do_not_reverse_lookup = Socket.do_not_reverse_lookup
|
|
|
|
Socket.do_not_reverse_lookup = true
|
2010-02-06 14:09:13 +00:00
|
|
|
if Net::IMAP.respond_to?(:max_flag_count)
|
|
|
|
@max_flag_count = Net::IMAP.max_flag_count
|
|
|
|
Net::IMAP.max_flag_count = 3
|
|
|
|
end
|
2009-11-19 13:56:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Socket.do_not_reverse_lookup = @do_not_reverse_lookup
|
2010-02-06 14:09:13 +00:00
|
|
|
if Net::IMAP.respond_to?(:max_flag_count)
|
|
|
|
Net::IMAP.max_flag_count = @max_flag_count
|
|
|
|
end
|
2009-11-19 13:56:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_flag_list_safe
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = lambda {
|
|
|
|
$SAFE = 1
|
|
|
|
parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* LIST (\\HasChildren) "." "INBOX"
|
|
|
|
EOF
|
|
|
|
}.call
|
|
|
|
assert_equal [:Haschildren], response.data.attr
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_flag_list_too_many_flags
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
assert_nothing_raised do
|
|
|
|
3.times do |i|
|
|
|
|
parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* LIST (\\Foo#{i}) "." "INBOX"
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_raise(Net::IMAP::FlagCountError) do
|
|
|
|
parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* LIST (\\Foo3) "." "INBOX"
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_flag_list_many_same_flags
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
assert_nothing_raised do
|
|
|
|
100.times do
|
|
|
|
parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* LIST (\\Foo) "." "INBOX"
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-06 14:09:13 +00:00
|
|
|
|
2010-12-07 08:07:12 +00:00
|
|
|
def test_flag_xlist_inbox
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* XLIST (\\Inbox) "." "INBOX"
|
|
|
|
EOF
|
2010-12-07 13:12:10 +00:00
|
|
|
assert_equal [:Inbox], response.data.attr
|
2010-12-07 08:07:12 +00:00
|
|
|
end
|
|
|
|
|
2010-02-06 14:09:13 +00:00
|
|
|
def test_resp_text_code
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* OK [CLOSED] Previous mailbox closed.
|
|
|
|
EOF
|
2010-02-06 14:11:21 +00:00
|
|
|
assert_equal "CLOSED", response.data.code.name
|
2010-02-06 14:09:13 +00:00
|
|
|
end
|
2011-06-16 02:41:03 +00:00
|
|
|
|
|
|
|
def test_search_response
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* SEARCH
|
|
|
|
EOF
|
|
|
|
assert_equal [], response.data
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* SEARCH 1
|
|
|
|
EOF
|
|
|
|
assert_equal [1], response.data
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* SEARCH 1 2 3
|
|
|
|
EOF
|
|
|
|
assert_equal [1, 2, 3], response.data
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_response_of_yahoo
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* SEARCH 1
|
|
|
|
EOF
|
|
|
|
assert_equal [1], response.data
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* SEARCH 1 2 3
|
|
|
|
EOF
|
|
|
|
assert_equal [1, 2, 3], response.data
|
|
|
|
end
|
2011-08-19 02:32:59 +00:00
|
|
|
|
|
|
|
def test_msg_att_extra_space
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 1 FETCH (UID 92285)
|
|
|
|
EOF
|
|
|
|
assert_equal 92285, response.data.attr["UID"]
|
|
|
|
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 1 FETCH (UID 92285 )
|
|
|
|
EOF
|
|
|
|
assert_equal 92285, response.data.attr["UID"]
|
|
|
|
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 1 FETCH (UID 92285 )
|
|
|
|
EOF
|
|
|
|
end
|
2011-12-11 03:21:43 +00:00
|
|
|
|
|
|
|
def test_msg_att_parse_error
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
e = assert_raise(Net::IMAP::ResponseParseError) {
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 123 FETCH (UNKNOWN 92285)
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
assert_match(/ for \{123\}/, e.message)
|
|
|
|
end
|
2012-03-16 04:56:18 +00:00
|
|
|
|
|
|
|
def test_msg_att_rfc822_text
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 123 FETCH (RFC822 {5}
|
|
|
|
foo
|
|
|
|
)
|
|
|
|
EOF
|
|
|
|
assert_equal("foo\r\n", response.data.attr["RFC822"])
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 123 FETCH (RFC822[] {5}
|
|
|
|
foo
|
|
|
|
)
|
|
|
|
EOF
|
|
|
|
assert_equal("foo\r\n", response.data.attr["RFC822"])
|
|
|
|
end
|
2012-05-07 04:05:44 +00:00
|
|
|
|
|
|
|
# [Bug #6397] [ruby-core:44849]
|
|
|
|
def test_body_type_attachment
|
|
|
|
parser = Net::IMAP::ResponseParser.new
|
|
|
|
response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
|
|
|
|
* 980 FETCH (UID 2862 BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "7BIT" 416 21 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "iso-8859-1") NIL NIL "7BIT" 1493 32 NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "Boundary_(ID_IaecgfnXwG5bn3x8lIeGIQ)") NIL NIL)("MESSAGE" "RFC822" ("NAME" "Fw_ ____ _____ ____.eml") NIL NIL "7BIT" 1980088 NIL ("ATTACHMENT" ("FILENAME" "Fw_ ____ _____ ____.eml")) NIL) "MIXED" ("BOUNDARY" "Boundary_(ID_eDdLc/j0mBIzIlR191pHjA)") NIL NIL))
|
|
|
|
EOF
|
|
|
|
assert_equal("Fw_ ____ _____ ____.eml",
|
|
|
|
response.data.attr["BODYSTRUCTURE"].parts[1].body.param["FILENAME"])
|
|
|
|
end
|
2009-11-19 13:56:23 +00:00
|
|
|
end
|