Class: Mail::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/jpmobile/mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_type_with_jpmobileObject

Returns the value of attribute content_type_with_jpmobile


299
300
301
# File 'lib/jpmobile/mail.rb', line 299

def content_type_with_jpmobile
  @content_type_with_jpmobile
end

#mobileObject

Returns the value of attribute mobile


299
300
301
# File 'lib/jpmobile/mail.rb', line 299

def mobile
  @mobile
end

Instance Method Details

#crlf_boundary_with_jpmobileObject Also known as: crlf_boundary


373
374
375
376
377
378
379
# File 'lib/jpmobile/mail.rb', line 373

def crlf_boundary_with_jpmobile
  if @mobile
    Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @mobile.mail_charset(@charset))
  else
    crlf_boundary_without_jpmobile
  end
end

#decode_transfer_encodingObject


351
352
353
354
355
# File 'lib/jpmobile/mail.rb', line 351

def decode_transfer_encoding
  _raw_source = Jpmobile::Util.decode(@raw_source, self.encoding, @charset)
  @raw_source = @mobile.decode_transfer_encoding(_raw_source, @charset)
  self.encoding = 'text'
end

#decoded_with_jpmobileObject Also known as: decoded


326
327
328
# File 'lib/jpmobile/mail.rb', line 326

def decoded_with_jpmobile
  decoded_without_jpmobile
end

#encoded_with_jpmobile(transfer_encoding = '8bit') ⇒ Object Also known as: encoded

convert encoding


306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/jpmobile/mail.rb', line 306

def encoded_with_jpmobile(transfer_encoding = '8bit')
  if @mobile and !multipart?
    case transfer_encoding
    when /base64/
      _raw_source = if transfer_encoding == encoding
                      @raw_source.dup
                    else
                      get_best_encoding(transfer_encoding).encode(@raw_source)
                    end
      Jpmobile::Util.set_encoding(_raw_source, @mobile.mail_charset(@charset))
    when /quoted-printable/
      Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack("M").gsub(/\n/, "\r\n"), @mobile.mail_charset(@charset))
    else
      @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, nil, Jpmobile::Util::UTF8))
    end
  else
    encoded_without_jpmobile(transfer_encoding)
  end
end

#end_boundary_with_jpmobileObject Also known as: end_boundary


381
382
383
384
385
386
387
# File 'lib/jpmobile/mail.rb', line 381

def end_boundary_with_jpmobile
  if @mobile
    Jpmobile::Util.encode(end_boundary_without_jpmobile, @mobile.mail_charset(@charset))
  else
    end_boundary_without_jpmobile
  end
end

#epilogue_with_jpmobileObject Also known as: epilogue


365
366
367
368
369
370
371
# File 'lib/jpmobile/mail.rb', line 365

def epilogue_with_jpmobile
  if @mobile
    Jpmobile::Util.encode(@epilogue, @mobile.mail_charset(@charset))
  else
    epilogue_without_jpmobile
  end
end

#preamble_with_jpmobileObject Also known as: preamble


357
358
359
360
361
362
363
# File 'lib/jpmobile/mail.rb', line 357

def preamble_with_jpmobile
  if @mobile
    Jpmobile::Util.encode(@preamble, @mobile.mail_charset(@charset))
  else
    preamble_without_jpmobile
  end
end

#raw_source_with_jpmobileObject Also known as: raw_source


301
302
303
# File 'lib/jpmobile/mail.rb', line 301

def raw_source_with_jpmobile
  raw_source_without_jpmobile.to_crlf
end

#set_charset_with_jpmobileObject Also known as: set_charset

fix charset


331
332
333
# File 'lib/jpmobile/mail.rb', line 331

def set_charset_with_jpmobile
  @charset ||= only_us_ascii? ? 'US-ASCII' : nil
end

#split!(boundary) ⇒ Object


413
414
415
416
417
418
419
420
421
422
# File 'lib/jpmobile/mail.rb', line 413

def split!(boundary)
  self.boundary = boundary
  parts = raw_source.split(/(?:\A|\r\n)--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
  # Make the preamble equal to the preamble (if any)
  self.preamble = parts[0].to_s.strip
  # Make the epilogue equal to the epilogue (if any)
  self.epilogue = parts[-1].to_s.sub('--', '').strip
  parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(:body_raw => part, :mobile => @mobile) }
  self
end