1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* lib/net/imap.rb: changed return value of Net::IMAP#fetch.
* lib/net/imap.rb: support HEADER.FIELDS.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2000-10-17 18:04:41 +00:00
parent 8353f303e3
commit d51bcd2007

View file

@ -157,6 +157,8 @@ Object
ex). ex).
p imap.search(["SUBJECT", "hello"]) p imap.search(["SUBJECT", "hello"])
#=> [1, 6, 7, 8] #=> [1, 6, 7, 8]
p imap.search('SUBJECT "hello"')
#=> [1, 6, 7, 8]
: fetch(set, attr) : fetch(set, attr)
: uid_fetch(set, attr) : uid_fetch(set, attr)
@ -166,8 +168,18 @@ Object
number (fetch) or a unique identifier (uid_fetch). number (fetch) or a unique identifier (uid_fetch).
ex). ex).
p imap.fetch(6..-1, "UID") p imap.fetch(6..8, "UID")
#=> [[6, {"UID"=>28}], [7, {"UID"=>29}], [8, {"UID"=>30}]] #=> [[6, ["UID", 98]], [7, ["UID", 99]], [8, ["UID", 100]]]
p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]")
#=> [[6, ["BODY[HEADER.FIELDS (\"SUBJECT\")]", "Subject: test\r\n\r\n"]]]
seqno, data = imap.uid_fetch(98, ["RFC822.SIZE", "INTERNALDATE"])[0]
attr = Hash[*data]
p attr["RFC822.SIZE"]
#=> 611
p attr["INTERNALDATE"]
#=> "12-Oct-2000 22:40:59 +0900"
p attr["UID"]
#=> 98
: store(set, attr, flags) : store(set, attr, flags)
: uid_store(set, attr, flags) : uid_store(set, attr, flags)
@ -177,8 +189,8 @@ Object
number (store) or a unique identifier (uid_store). number (store) or a unique identifier (uid_store).
ex). ex).
p imap.store(6..-1, "+FLAGS", [:Deleted]) p imap.store(6..8, "+FLAGS", [:Deleted])
#=> [[6, {"FLAGS"=>[:Deleted]}], [7, {"FLAGS"=>[:Seen, :Deleted]}], [8, {"FLAGS"=>[:Seen, :Deleted]}]] #=> [[6, ["FLAGS", [:Seen, :Deleted]]], [7, ["FLAGS", [:Seen, :Deleted]]], [8, ["FLAGS", [:Deleted]]]]
: copy(set, mailbox) : copy(set, mailbox)
: uid_copy(set, mailbox) : uid_copy(set, mailbox)
@ -536,7 +548,11 @@ module Net
end end
def search_internal(cmd, keys, charset) def search_internal(cmd, keys, charset)
normalize_searching_criteria(keys) if keys.instance_of?(String)
keys = [RawData.new(keys)]
else
normalize_searching_criteria(keys)
end
if charset if charset
send_command(cmd, "CHARSET", charset, *keys) send_command(cmd, "CHARSET", charset, *keys)
else else
@ -546,13 +562,19 @@ module Net
end end
def fetch_internal(cmd, set, attr) def fetch_internal(cmd, set, attr)
if attr.instance_of?(String)
attr = RawData.new(attr)
end
send_command(cmd, MessageSet.new(set), attr) send_command(cmd, MessageSet.new(set), attr)
return get_fetch_response return @responses.delete("FETCH")
end end
def store_internal(cmd, set, attr, flags) def store_internal(cmd, set, attr, flags)
if attr.instance_of?(String)
attr = RawData.new(attr)
end
send_command(cmd, MessageSet.new(set), attr, flags) send_command(cmd, MessageSet.new(set), attr, flags)
return get_fetch_response return @responses.delete("FETCH")
end end
def copy_internal(cmd, set, mailbox) def copy_internal(cmd, set, mailbox)
@ -560,6 +582,11 @@ module Net
end end
def sort_internal(cmd, sort_keys, search_keys, charset) def sort_internal(cmd, sort_keys, search_keys, charset)
if search_keys.instance_of?(String)
search_keys = [RawData.new(search_keys)]
else
normalize_searching_criteria(search_keys)
end
normalize_searching_criteria(search_keys) normalize_searching_criteria(search_keys)
send_command(cmd, sort_keys, charset, *search_keys) send_command(cmd, sort_keys, charset, *search_keys)
return @responses.delete("SORT")[-1] return @responses.delete("SORT")[-1]
@ -576,11 +603,16 @@ module Net
end end
end end
def get_fetch_response class RawData
return @responses.delete("FETCH").collect { |i| def format_data
i[1] = Hash[*i[1]] return @data
i end
}
private
def initialize(data)
@data = data
end
end end
class Atom class Atom
@ -712,6 +744,7 @@ module Net
T_NIL = :NIL T_NIL = :NIL
T_NUMBER = :NUMBER T_NUMBER = :NUMBER
T_ATTR = :ATTR
T_ATOM = :ATOM T_ATOM = :ATOM
T_QUOTED = :QUOTED T_QUOTED = :QUOTED
T_LITERAL = :LITERAL T_LITERAL = :LITERAL
@ -728,15 +761,16 @@ module Net
DATA_REGEXP = /\G *(?:\ DATA_REGEXP = /\G *(?:\
(?# 1: NIL )(NIL)|\ (?# 1: NIL )(NIL)|\
(?# 2: NUMBER )(\d+)|\ (?# 2: NUMBER )(\d+)|\
(?# 3: ATOM )([^(){ \x00-\x1f\x7f%*"\\]+)|\ (?# 3: ATTR )(BODY\[[^\]]*\](?:<\d+>)?)|\
(?# 4: QUOTED )"((?:[^"\\]|\\["\\])*)"|\ (?# 4: ATOM )([^(){ \x00-\x1f\x7f%*"\\]+)|\
(?# 5: LITERAL )\{(\d+)\}\r\n|\ (?# 5: QUOTED )"((?:[^"\\]|\\["\\])*)"|\
(?# 6: FLAG )(\\(?:[^(){ \x00-\x1f\x7f%*"\\]+|\*))|\ (?# 6: LITERAL )\{(\d+)\}\r\n|\
(?# 7: LPAREN )(\()|\ (?# 7: FLAG )(\\(?:[^(){ \x00-\x1f\x7f%*"\\]+|\*))|\
(?# 8: RPAREN )(\))|\ (?# 8: LPAREN )(\()|\
(?# 9: STAR )(\*)|\ (?# 9: RPAREN )(\))|\
(?# 10: CRLF )(\r\n)|\ (?# 10: STAR )(\*)|\
(?# 11: EOF )(\z))/ni (?# 11: CRLF )(\r\n)|\
(?# 12: EOF )(\z))/ni
CODE_REGEXP = /\G *(?:\ CODE_REGEXP = /\G *(?:\
(?# 1: NUMBER )(\d+)|\ (?# 1: NUMBER )(\d+)|\
@ -900,31 +934,34 @@ module Net
@token.symbol = T_NUMBER @token.symbol = T_NUMBER
elsif $3 elsif $3
@token.value = $+ @token.value = $+
@token.symbol = T_ATOM @token.symbol = T_ATTR
elsif $4 elsif $4
@token.value = $+
@token.symbol = T_ATOM
elsif $5
@token.value = $+.gsub(/\\(["\\])/n, "\\1") @token.value = $+.gsub(/\\(["\\])/n, "\\1")
@token.symbol = T_QUOTED @token.symbol = T_QUOTED
elsif $5 elsif $6
len = $+.to_i len = $+.to_i
@token.value = @str[@pos, len] @token.value = @str[@pos, len]
@pos += len @pos += len
@token.symbol = T_LITERAL @token.symbol = T_LITERAL
elsif $6 elsif $7
@token.value = $+[1..-1].intern @token.value = $+[1..-1].intern
@token.symbol = T_FLAG @token.symbol = T_FLAG
elsif $7
@token.value = nil
@token.symbol = T_LPAREN
elsif $8 elsif $8
@token.value = nil @token.value = nil
@token.symbol = T_RPAREN @token.symbol = T_LPAREN
elsif $9 elsif $9
@token.value = nil
@token.symbol = T_RPAREN
elsif $10
@token.value = $+ @token.value = $+
@token.symbol = T_STAR @token.symbol = T_STAR
elsif $10 elsif $11
@token.value = nil @token.value = nil
@token.symbol = T_CRLF @token.symbol = T_CRLF
elsif $11 elsif $12
@token.value = nil @token.value = nil
@token.symbol = T_EOF @token.symbol = T_EOF
else else