123456789_123456789_123456789_123456789_123456789_

Class: Net::IMAP::ValidNonLiteralData

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, CommandData, Data
Instance Chain:
self, CommandData, Data
Inherits: Net::IMAP::CommandData
Defined in: lib/net/imap/command_data.rb

Overview

Represents IMAP text or quoted data, which share the same validations of decoded #data, and differ only in how they are formatted.

data may contain any 7-bit ASCII character except NULL, CR, or LF. Any multibyte UTF-8 character is also allowed when the connection supports UTF8: either UTF8=ACCEPT or IMAP4rev2 have been enabled, or the server supports only IMAP4rev2 and not earlier ::Net::IMAP revisions, or the server advertises UTF8=ONLY.

NOTE: This does not verify whether the connection supports UTF-8, but that may change in future versions.

The string's bytes must be valid ASCII or valid UTF-8. The string's reported encoding is ignored, but the string is not transcoded.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(data:) ⇒ ValidNonLiteralData

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 187

def initialize(data:)
  data = String(data.to_str)
  unless data.encoding in Encoding::ASCII | Encoding::UTF_8
    data = data.dup.force_encoding(data.ascii_only? ? "ASCII" : "UTF-8")
  end
  data = -data
  super
  validate
end

Instance Attribute Details

#ascii_only?Boolean (readonly)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 209

def ascii_only? = data.ascii_only?

Instance Method Details

#send_data(imap, tag = nil)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 211

def send_data(imap, tag = nil) = imap.__send__(:put_string, formatted)

#validate

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 197

def validate
  if !(data.encoding in Encoding::ASCII | Encoding::UTF_8)
    raise DataFormatError, "must use ASCII or UTF-8 encoding"
  elsif !data.valid_encoding?
    raise DataFormatError, "invalid UTF-8 must be literal encoded"
  elsif data.include?("\0")
    raise DataFormatError, "NULL byte must be binary literal encoded"
  elsif /[\r\n]/.match?(data)
    raise DataFormatError, "CR and LF bytes must be literal encoded"
  end
end