summaryrefslogtreecommitdiff
path: root/lib/net/imap.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net/imap.rb')
-rw-r--r--lib/net/imap.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 8b7529d79d..3a8145e03c 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -270,6 +270,16 @@ module Net
return @@debug = val
end
+ # Returns the max number of flags interned to symbols.
+ def self.max_flag_count
+ return @@max_flag_count
+ end
+
+ # Sets the max number of flags interned to symbols.
+ def self.max_flag_count=(count)
+ @@max_flag_count = count
+ end
+
# Adds an authenticator for Net::IMAP#authenticate. +auth_type+
# is the type of authentication this authenticator supports
# (for instance, "LOGIN"). The +authenticator+ is an object
@@ -929,6 +939,7 @@ module Net
@@debug = false
@@authenticators = {}
+ @@max_flag_count = 10000
# call-seq:
# Net::IMAP.new(host, options = {})
@@ -1929,6 +1940,14 @@ module Net
end
class ResponseParser # :nodoc:
+ def initialize
+ @str = nil
+ @pos = nil
+ @lex_state = nil
+ @token = nil
+ @flag_symbols = {}
+ end
+
def parse(str)
@str = str
@pos = 0
@@ -2939,7 +2958,16 @@ module Net
if @str.index(/\(([^)]*)\)/ni, @pos)
@pos = $~.end(0)
return $1.scan(FLAG_REGEXP).collect { |flag, atom|
- atom || flag.capitalize.intern
+ if atom
+ atom
+ else
+ symbol = flag.capitalize.untaint.intern
+ @flag_symbols[symbol] = true
+ if @flag_symbols.length > IMAP.max_flag_count
+ raise FlagCountError, "number of flag symbols exceeded"
+ end
+ symbol
+ end
}
else
parse_error("invalid flag list")
@@ -3410,6 +3438,10 @@ module Net
# out due to inactivity.
class ByeResponseError < ResponseError
end
+
+ # Error raised when too many flags are interned to symbols.
+ class FlagCountError < Error
+ end
end
end