Class: Mail::Part

Inherits:
Message show all
Defined in:
lib/mail/part.rb

Constant Summary

Constant Summary

Constants included from Constants

Constants::ASTERISK, Constants::ATOM_UNSAFE, Constants::B_VALUES, Constants::CAPITAL_M, Constants::COLON, Constants::CONTROL_CHAR, Constants::CR, Constants::CRLF, Constants::CR_ENCODED, Constants::EMPTY, Constants::ENCODED_VALUE, Constants::EQUAL_LF, Constants::FIELD_BODY, Constants::FIELD_LINE, Constants::FIELD_NAME, Constants::FIELD_PREFIX, Constants::FIELD_SPLIT, Constants::FWS, Constants::HEADER_LINE, Constants::HEADER_SPLIT, Constants::HYPHEN, Constants::LF, Constants::LF_ENCODED, Constants::NULL_SENDER, Constants::PHRASE_UNSAFE, Constants::QP_SAFE, Constants::QP_UNSAFE, Constants::Q_VALUES, Constants::SPACE, Constants::TEXT, Constants::TOKEN_UNSAFE, Constants::UNDERSCORE, Constants::WSP

Instance Attribute Summary

Attributes inherited from Message

#delivery_handler, #perform_deliveries, #raise_delivery_errors

Instance Method Summary collapse

Methods inherited from Message

#<=>, #==, #[], #[]=, #add_charset, #add_content_transfer_encoding, #add_content_type, #add_date, #add_file, #add_message_id, #add_mime_version, #add_part, #add_transfer_encoding, #all_parts, #attachment, #attachment?, #attachments, #bcc, #bcc=, #bcc_addrs, #body, #body=, #body_encoding, #body_encoding=, #boundary, #cc, #cc=, #cc_addrs, #charset, #charset=, #comments, #comments=, #content_description, #content_description=, #content_disposition, #content_disposition=, #content_id, #content_id=, #content_location, #content_location=, #content_transfer_encoding, #content_transfer_encoding=, #content_type, #content_type=, #content_type_parameters, #convert_to_multipart, #date, #date=, #decode_body, #decoded, #default, default_charset, default_charset=, #deliver, #deliver!, #delivery_method, #delivery_status_part, #delivery_status_report?, #destinations, #encode!, #encoded, #envelope_date, #envelope_from, #errors, #filename, #find_first_mime_type, #from, #from=, #from_addrs, from_hash, from_yaml, #has_attachments?, #has_charset?, #has_content_transfer_encoding?, #has_content_type?, #has_date?, #has_message_id?, #has_mime_version?, #has_transfer_encoding?, #header, #header=, #header_fields, #headers, #html_part, #html_part=, #in_reply_to, #in_reply_to=, #inform_interceptors, #inform_observers, #initialize, #initialize_copy, #inspect, #is_marked_for_delete?, #keywords, #keywords=, #main_type, #mark_for_delete=, #message_content_type, #message_id, #message_id=, #method_missing, #mime_parameters, #mime_type, #mime_version, #mime_version=, #multipart?, #multipart_report?, #part, #parts, #raw_envelope, #raw_source, #read, #ready_to_send!, #received, #received=, #references, #references=, #register_for_delivery_notification, #reply, #reply_to, #reply_to=, #resent_bcc, #resent_bcc=, #resent_cc, #resent_cc=, #resent_date, #resent_date=, #resent_from, #resent_from=, #resent_message_id, #resent_message_id=, #resent_sender, #resent_sender=, #resent_to, #resent_to=, #return_path, #return_path=, #sender, #sender=, #set_envelope, #skip_deletion, #smtp_envelope_from, #smtp_envelope_from=, #smtp_envelope_to, #smtp_envelope_to=, #sub_type, #subject, #subject=, #text?, #text_part, #text_part=, #to, #to=, #to_addrs, #to_s, #to_yaml, #transfer_encoding, #transport_encoding, #transport_encoding=, #without_attachments!

Methods included from Utilities

#atom_safe?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, #token_safe?, #unbracket, #underscoreize, #unparen, #unquote, #uri_escape, #uri_parser, #uri_unescape

Constructor Details

This class inherits a constructor from Mail::Message

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mail::Message

Instance Method Details

#actionObject

Either returns the action if the message has just a single report, or an array of all the actions, one for each report



68
69
70
# File 'lib/mail/part.rb', line 68

def action
  get_return_values('action')
end

#add_content_id(content_id_val = '') ⇒ Object

Creates a new empty Content-ID field and inserts it in the correct order into the Header. The ContentIdField object will automatically generate a unique content ID if you try and encode it or output it to_s without specifying a content id.

It will preserve the content ID you specify if you do.



11
12
13
# File 'lib/mail/part.rb', line 11

def add_content_id(content_id_val = '')
  header['content-id'] = content_id_val
end

#add_required_fieldsObject



40
41
42
43
# File 'lib/mail/part.rb', line 40

def add_required_fields
  super
  add_content_id if !has_content_id? && inline?
end

#add_required_message_fieldsObject



45
46
47
# File 'lib/mail/part.rb', line 45

def add_required_message_fields
  # Override so we don't add Date, MIME-Version, or Message-ID.
end

#bounced?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'lib/mail/part.rb', line 57

def bounced?
  if action.is_a?(Array)
    !!(action.first =~ /failed/i)
  else
    !!(action =~ /failed/i)
  end
end

#cidObject



27
28
29
30
# File 'lib/mail/part.rb', line 27

def cid
  add_content_id unless has_content_id?
  uri_escape(unbracket(content_id))
end

#delivery_status_dataObject



53
54
55
# File 'lib/mail/part.rb', line 53

def delivery_status_data
  delivery_status_report_part? ? parse_delivery_status_report : {}
end

#delivery_status_report_part?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/mail/part.rb', line 49

def delivery_status_report_part?
  (main_type =~ /message/i && sub_type =~ /delivery-status/i) && body =~ /Status:/
end

#diagnostic_codeObject



80
81
82
# File 'lib/mail/part.rb', line 80

def diagnostic_code
  get_return_values('diagnostic-code')
end

#error_statusObject



76
77
78
# File 'lib/mail/part.rb', line 76

def error_status
  get_return_values('status')
end

#final_recipientObject



72
73
74
# File 'lib/mail/part.rb', line 72

def final_recipient
  get_return_values('final-recipient')
end

#has_content_id?Boolean

Returns true if the part has a content ID field, the field may or may not have a value, but the field exists or not.

Returns:

  • (Boolean)


17
18
19
# File 'lib/mail/part.rb', line 17

def has_content_id?
  header.has_content_id?
end

#inline?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/mail/part.rb', line 36

def inline?
  header[:content_disposition].disposition_type == 'inline' if header[:content_disposition]
end

#inline_content_idObject



21
22
23
24
25
# File 'lib/mail/part.rb', line 21

def inline_content_id
  # TODO: Deprecated in 2.2.2 - Remove in 2.3
  STDERR.puts("Part#inline_content_id is deprecated, please call Part#cid instead")
  cid
end

#remote_mtaObject



84
85
86
# File 'lib/mail/part.rb', line 84

def remote_mta
  get_return_values('remote-mta')
end

#retryable?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/mail/part.rb', line 88

def retryable?
  !(error_status =~ /^5/)
end

#urlObject



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

def url
  "cid:#{cid}"
end