summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-10-26 08:19:04 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-10-26 08:19:04 +0000
commitcac38b30e56ee30cf73cb5a654fac1ece1900198 (patch)
treebeb17d922f50205aa30dbfc1c61715b35464b865 /lib/net
parent1488b9b4583fe141004be9805d5c7e53c02a1830 (diff)
shugo
* lib/net/imap.rb: hack for speed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/imap.rb54
1 files changed, 48 insertions, 6 deletions
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 9f9f134..be0a8a2 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -430,7 +430,7 @@ module Net
def get_all_responses(tag, cmd, &block)
while resp = get_response
if @@debug
- $stderr.puts(resp.inspect)
+ $stderr.printf("R: %s\n", resp.inspect)
end
case resp
when TaggedResponse
@@ -754,10 +754,11 @@ module Net
private
- EXPR_BEG = :BEG
- EXPR_TEXT = :TEXT
- EXPR_RTEXT = :RTEXT
- EXPR_CTEXT = :CTEXT
+ EXPR_BEG = :EXPR_BEG
+ EXPR_DATA = :EXPR_DATA
+ EXPR_TEXT = :EXPR_TEXT
+ EXPR_RTEXT = :EXPR_RTEXT
+ EXPR_CTEXT = :EXPR_CTEXT
T_SPACE = :SPACE
T_NIL = :NIL
@@ -795,6 +796,15 @@ module Net
(?# 15: CRLF )(\r\n)|\
(?# 16: EOF )(\z))/ni
+ DATA_REGEXP = /\G(?:\
+(?# 1: SPACE )( )|\
+(?# 2: NIL )(NIL)|\
+(?# 3: NUMBER )(\d+)|\
+(?# 4: QUOTED )"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)"|\
+(?# 5: LITERAL )\{(\d+)\}\r\n|\
+(?# 6: LPAR )(\()|\
+(?# 7: RPAR )(\)))/ni
+
TEXT_REGEXP = /\G(?:\
(?# 1: TEXT )([^\x00\x80-\xff\r\n]*))/ni
@@ -932,6 +942,7 @@ module Net
end
def envelope
+ @lex_state = EXPR_DATA
match(T_LPAR)
date = nstring
match(T_SPACE)
@@ -953,6 +964,7 @@ module Net
match(T_SPACE)
message_id = nstring
match(T_RPAR)
+ @lex_state = EXPR_BEG
return Envelope.new(date, subject, from, sender, reply_to,
to, cc, bcc, in_reply_to, message_id)
end
@@ -1006,6 +1018,7 @@ module Net
end
def body
+ @lex_state = EXPR_DATA
match(T_LPAR)
token = lookahead
if token.symbol == T_LPAR
@@ -1014,6 +1027,7 @@ module Net
result = body_type_1part
end
match(T_RPAR)
+ @lex_state = EXPR_BEG
return result
end
@@ -1639,7 +1653,7 @@ module Net
return Token.new(T_ATOM, $+)
elsif $5
return Token.new(T_QUOTED,
- $+.gsub(/\\(["\\])/n, "\\1"))
+ $+.gsub(/\\(["\\])/n, "\\1"))
elsif $6
return Token.new(T_LPAR, $+)
elsif $7
@@ -1672,6 +1686,34 @@ module Net
@str.index(/\S*/n, @pos)
parse_error("unknown token - %s", $&.dump)
end
+ when EXPR_DATA
+ if @str.index(DATA_REGEXP, @pos)
+ @pos = $~.end(0)
+ if $1
+ return Token.new(T_SPACE, $+)
+ elsif $2
+ return Token.new(T_NIL, $+)
+ elsif $3
+ return Token.new(T_NUMBER, $+)
+ elsif $4
+ return Token.new(T_QUOTED,
+ $+.gsub(/\\(["\\])/n, "\\1"))
+ elsif $5
+ len = $+.to_i
+ val = @str[@pos, len]
+ @pos += len
+ return Token.new(T_LITERAL, val)
+ elsif $6
+ return Token.new(T_LPAR, $+)
+ elsif $7
+ return Token.new(T_RPAR, $+)
+ else
+ parse_error("[Net::IMAP BUG] BEG_REGEXP is invalid")
+ end
+ else
+ @str.index(/\S*/n, @pos)
+ parse_error("unknown token - %s", $&.dump)
+ end
when EXPR_TEXT
if @str.index(TEXT_REGEXP, @pos)
@pos = $~.end(0)