Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bits for UTF8=ACCEPT #114

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ module Net
#
# ==== RFC6855: <tt>UTF8=ACCEPT</tt>, <tt>UTF8=ONLY</tt>
#
# - See #enable for information about support foi UTF-8 string encoding.
# - See #enable for information about support for UTF-8 string encoding.
#
#--
# ==== RFC7888: <tt>LITERAL+</tt>, +LITERAL-+
Expand Down Expand Up @@ -1974,7 +1974,10 @@ def enable(*capabilities)
.join(' ')
synchronize do
send_command("ENABLE #{capabilities}")
return @responses.delete("ENABLED")[-1]
result = @responses.delete("ENABLED")[-1]
@utf8_strings ||= result.include? "SMTPUTF8"
arnt marked this conversation as resolved.
Show resolved Hide resolved
@utf8_strings ||= result.include? "IMAP4REV2"
result
end
end

Expand Down Expand Up @@ -2222,6 +2225,7 @@ def initialize(host, port_or_options = {},
@port = options[:port] || (options[:ssl] ? SSL_PORT : PORT)
@tag_prefix = "RUBY"
@tagno = 0
@utf8_strings = false
@open_timeout = options[:open_timeout] || 30
@idle_response_timeout = options[:idle_response_timeout] || 5
@parser = ResponseParser.new
Expand Down
19 changes: 13 additions & 6 deletions lib/net/imap/command_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ def send_data(data, tag = nil)
end

def send_string_data(str, tag = nil)
case str
when ""
if str.empty?
put_string('""')
when /[\x80-\xff\r\n]/n
# literal
elsif str.match?(/[\r\n]/n)
# literal, because multiline
send_literal(str, tag)
when /[(){ \x00-\x1f\x7f%*"\\]/n
elsif !str.ascii_only?
if @utf8_strings
# quoted string
send_quoted_string(str)
else
# literal, because of non-ASCII bytes
send_literal(str, tag)
end
elsif str.match?(/[(){ \x00-\x1f\x7f%*"\\]/n)
# quoted string
send_quoted_string(str)
else
Expand All @@ -67,7 +74,7 @@ def send_string_data(str, tag = nil)
end

def send_quoted_string(str)
put_string('"' + str.gsub(/["\\]/n, "\\\\\\&") + '"')
put_string('"' + str.gsub(/["\\]/, "\\\\\\&") + '"')
end

def send_literal(str, tag = nil)
Expand Down