Class: Mail::SubjectField

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

Overview

for subject

Instance Attribute Summary

Attributes inherited from UnstructuredField

#mobile

Instance Method Summary collapse

Instance Method Details

#decode_b_value_for_mobile(str) ⇒ Object


473
474
475
476
477
478
479
480
481
482
# File 'lib/jpmobile/mail.rb', line 473

def decode_b_value_for_mobile(str)
  match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
  if match
    charset = match[1]
    str = Ruby19.decode_base64(match[2])
    @mobile.decode_transfer_encoding(str, charset)
  else
    str
  end
end

#decoded_with_jpmobileObject Also known as: decoded


450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/jpmobile/mail.rb', line 450

def decoded_with_jpmobile
  if @mobile
    return value unless value =~ /\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi
    Encodings.collapse_adjacent_encodings(value).each do |line|
      line.gsub!(/\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi) do |string|
        case $1
        when 'B','b' then decode_b_value_for_mobile(string)
        when 'Q','q' then Encodings.q_value_decode(string)
        else line
        end
      end
    end.join("")
  else
    decoded_without_jpmobile
  end
end

#encoded_with_jpmobileObject Also known as: encoded


437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/jpmobile/mail.rb', line 437

def encoded_with_jpmobile
  if @mobile
    if @mobile.to_mail_subject_encoded?(value)
      "#{name}: #{value}\r\n"
    else
      # convert encoding
      "#{name}: " + @mobile.to_mail_subject(value) + "\r\n"
    end
  else
    encoded_without_jpmobile
  end
end