Module: Mail::Jdec

Defined in:
lib/mail/jdec.rb,
lib/mail/jdec/config.rb,
lib/mail/jdec/decoder.rb,
lib/mail/jdec/version.rb,
lib/mail/jdec/detector.rb,
lib/mail/jdec/body_patch.rb,
lib/mail/jdec/message_patch.rb,
lib/mail/jdec/encodings_patch.rb,
lib/mail/jdec/utilities_patch.rb,
lib/mail/jdec/field_list_patch.rb,
lib/mail/jdec/fields/structured_field_patch.rb,
lib/mail/jdec/fields/common_date_field_patch.rb,
lib/mail/jdec/fields/unstructured_field_patch.rb,
lib/mail/jdec/fields/common_address_field_patch.rb,
lib/mail/jdec/elements/message_ids_element_patch.rb,
lib/mail/jdec/elements/content_type_element_patch.rb,
lib/mail/jdec/elements/content_disposition_element_patch.rb

Defined Under Namespace

Modules: BodyPatch, CommonAddressFieldPatch, CommonDateFieldPatch, ContentDispositionElementPatch, ContentTypeElementPatch, EncodingsPatch, Escaper, FieldListPatch, MessageIdsElementPatch, MessagePatch, StructuredFieldPatch, UnstructuredFieldPatch, UtilitiesPatch Classes: Config, Decoder, Detector, ValueDecoder

Constant Summary collapse

THREAD_KEY =
:_mail_jdec
VERSION =
'1.2.0'
@@config =
Config.new(
  enabled: true,
  autodetect_confidence: 50,
  autodetect_skip_charsets: %w(),
  mime_types_for_autodetect: [%r{^text/}, 'message/delivery-status', 'message/disposition-notification'],
  preferred_charsets: {
    'iso-2022-jp' => 'cp50221',
    'iso-2022-jp-1' => 'cp50221',
    'iso-2022-jp-2' => 'cp50221',
    'iso-2022-jp-3' => 'cp50221',
    'iso-2022-jp-2004' => 'cp50221',
    'shift_jis' => 'cp932',
    'shift-jis' => 'cp932',
    'x_sjis' => 'cp932',
    'x-sjis' => 'cp932'
  },
  keep_field_order: false
)

Class Method Summary collapse

Class Method Details

.configObject



38
39
40
# File 'lib/mail/jdec.rb', line 38

def config
  Thread.current[THREAD_KEY] || @@config
end

.configure {|@@config| ... } ⇒ Object

Yields:



32
33
34
# File 'lib/mail/jdec.rb', line 32

def configure
  yield @@config
end

.disable!Object



58
59
60
# File 'lib/mail/jdec.rb', line 58

def disable!
  config.enabled = false
end

.enable!Object



54
55
56
# File 'lib/mail/jdec.rb', line 54

def enable!
  config.enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/mail/jdec.rb', line 50

def enabled?
  config.enabled
end

.with_config(hash = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/mail/jdec.rb', line 42

def with_config(hash = {})
  old = Thread.current[THREAD_KEY]
  Thread.current[THREAD_KEY] = Config.new(config.attributes.merge(hash))
  yield
ensure
  Thread.current[THREAD_KEY] = old
end