Class: Net::IMAP::RawData

Inherits:
CommandData show all
Defined in:
lib/net/imap/command_data.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandData

validate

Constructor Details

#initialize(data:) ⇒ RawData

Returns a new instance of RawData.



225
226
227
228
229
230
231
232
233
234
# File 'lib/net/imap/command_data.rb', line 225

def initialize(data:)
  case data
  in String then data = self.class.split(data)
  in Array  if   data.all? { _1 in RawText | Literal }
  else
    raise TypeError, "expected String or Array[#{RawText} | #{Literal}]"
  end
  super
  validate
end

Class Method Details

.split(data) ⇒ Object

Splits an input string into an array of RawText and Literal/Literal8.

NOTE: unlike RawData#validate, this does not prevent the final RawText from ending with a literal prefix.



249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/net/imap/command_data.rb', line 249

def self.split(data)
  data = data.b # dups and ensures BINARY encoding
  parts = []
  while data.match(/(~)?\{(0|[1-9]\d*)(\+)?\}\r\n/n)
    text, binary, bytesize, non_sync, data = $`, !!$1, $2, !!$3, $'
    bytesize = NumValidator.coerce_number64 bytesize
    parts << RawText[text] unless text.empty?
    parts << extract_literal(data, binary:, bytesize:, non_sync:)
    data.bytesplice(0, bytesize, "")
  end
  parts << RawText[data] unless data.empty?
  parts
end

Instance Method Details

#send_data(imap, tag) ⇒ Object



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

def send_data(imap, tag) = data.each do _1.send_data(imap, tag) end

#validateObject



238
239
240
241
242
243
# File 'lib/net/imap/command_data.rb', line 238

def validate
  return unless data.last in RawText(data: text)
  if text.rindex(/\{\d+\+?\}\z/n)
    raise DataFormatError, "RawData cannot end with literal continuation"
  end
end