Class: RIMS::RFC822::Message
- Inherits:
-
Object
- Object
- RIMS::RFC822::Message
- Defined in:
- lib/rims/rfc822.rb
Instance Attribute Summary collapse
-
#raw_source ⇒ Object
readonly
Returns the value of attribute raw_source.
Instance Method Summary collapse
- #bcc ⇒ Object
- #body ⇒ Object
- #boundary ⇒ Object
- #cc ⇒ Object
- #charset ⇒ Object
- #content_disposition ⇒ Object
- #content_disposition_parameter(name) ⇒ Object
- #content_disposition_parameter_list ⇒ Object (also: #content_disposition_parameters)
- #content_disposition_upcase ⇒ Object
- #content_language ⇒ Object
- #content_language_upcase ⇒ Object
- #content_type ⇒ Object
- #content_type_parameter(name) ⇒ Object
- #content_type_parameter_list ⇒ Object (also: #content_type_parameters)
- #content_type_upcase ⇒ Object
- #date ⇒ Object
- #from ⇒ Object
- #header ⇒ Object
-
#initialize(msg_txt, charset_aliases: DEFAULT_CHARSET_ALIASES) ⇒ Message
constructor
A new instance of Message.
- #media_main_type ⇒ Object
- #media_main_type_upcase ⇒ Object
- #media_sub_type ⇒ Object (also: #media_subtype)
- #media_sub_type_upcase ⇒ Object (also: #media_subtype_upcase)
- #message ⇒ Object
- #message? ⇒ Boolean
- #mime_binary_body_string ⇒ Object
- #mime_charset_body_text(charset = nil) ⇒ Object
- #mime_decoded_header(name, decode_charset = nil, charset_convert_options: {}) ⇒ Object
- #mime_decoded_header_field_value_list(name, decode_charset = nil, charset_convert_options: {}) ⇒ Object
- #mime_decoded_header_text(decode_charset = nil, charset_convert_options: {}) ⇒ Object
- #multipart? ⇒ Boolean
- #parts ⇒ Object
- #reply_to ⇒ Object
- #sender ⇒ Object
- #setup_content_disposition ⇒ Object
- #text? ⇒ Boolean
- #to ⇒ Object
Constructor Details
#initialize(msg_txt, charset_aliases: DEFAULT_CHARSET_ALIASES) ⇒ Message
Returns a new instance of Message.
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/rims/rfc822.rb', line 583 def initialize(msg_txt, charset_aliases: DEFAULT_CHARSET_ALIASES) @raw_source = msg_txt.dup.freeze @charset_aliases = charset_aliases @header = nil @body = nil @content_type = nil @content_disposition = nil @content_language = nil @parts = nil @message = nil @date = nil @from = nil @sender = nil @reply_to = nil @to = nil @cc = nil @bcc = nil @mime_decoded_header_cache = nil @mime_decoded_header_field_value_list_cache = nil @mime_decoded_header_text_cache = nil @mime_charset_body_text_cache = nil end |
Instance Attribute Details
#raw_source ⇒ Object (readonly)
Returns the value of attribute raw_source.
606 607 608 |
# File 'lib/rims/rfc822.rb', line 606 def raw_source @raw_source end |
Instance Method Details
#bcc ⇒ Object
837 838 839 |
# File 'lib/rims/rfc822.rb', line 837 def bcc mail_address_header_field('bcc') end |
#body ⇒ Object
624 625 626 627 |
# File 'lib/rims/rfc822.rb', line 624 def body @body end |
#boundary ⇒ Object
686 687 688 |
# File 'lib/rims/rfc822.rb', line 686 def boundary content_type_parameter('boundary') end |
#cc ⇒ Object
833 834 835 |
# File 'lib/rims/rfc822.rb', line 833 def cc mail_address_header_field('cc') end |
#charset ⇒ Object
682 683 684 |
# File 'lib/rims/rfc822.rb', line 682 def charset content_type_parameter('charset') end |
#content_disposition ⇒ Object
701 702 703 704 |
# File 'lib/rims/rfc822.rb', line 701 def content_disposition setup_content_disposition @content_disposition && @content_disposition[0] end |
#content_disposition_parameter(name) ⇒ Object
710 711 712 713 714 715 716 717 |
# File 'lib/rims/rfc822.rb', line 710 def content_disposition_parameter(name) setup_content_disposition if (@content_disposition) then if (name_value_pair = @content_disposition[1][name.downcase]) then name_value_pair[1] end end end |
#content_disposition_parameter_list ⇒ Object Also known as: content_disposition_parameters
719 720 721 722 |
# File 'lib/rims/rfc822.rb', line 719 def content_disposition_parameter_list setup_content_type @content_disposition && @content_disposition[1].values end |
#content_disposition_upcase ⇒ Object
706 707 708 |
# File 'lib/rims/rfc822.rb', line 706 def content_disposition_upcase content_disposition&.upcase end |
#content_language ⇒ Object
739 740 741 742 |
# File 'lib/rims/rfc822.rb', line 739 def content_language setup_content_language @content_language end |
#content_language_upcase ⇒ Object
744 745 746 |
# File 'lib/rims/rfc822.rb', line 744 def content_language_upcase content_language&.map{|tag| tag.upcase } end |
#content_type ⇒ Object
647 648 649 |
# File 'lib/rims/rfc822.rb', line 647 def content_type "#{media_main_type}/#{media_sub_type}" end |
#content_type_parameter(name) ⇒ Object
668 669 670 671 672 673 |
# File 'lib/rims/rfc822.rb', line 668 def content_type_parameter(name) setup_content_type if (name_value_pair = @content_type[2][name.downcase]) then name_value_pair[1] end end |
#content_type_parameter_list ⇒ Object Also known as: content_type_parameters
675 676 677 678 |
# File 'lib/rims/rfc822.rb', line 675 def content_type_parameter_list setup_content_type @content_type[2].values end |
#content_type_upcase ⇒ Object
663 664 665 666 |
# File 'lib/rims/rfc822.rb', line 663 def content_type_upcase # not return `nil' content_type.upcase end |
#date ⇒ Object
786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/rims/rfc822.rb', line 786 def date if (@date.nil?) then if (header.key? 'Date') then begin @date = Time.parse(header['Date']) rescue ArgumentError @date = Time.at(0) end @date.freeze end end @date end |
#from ⇒ Object
817 818 819 |
# File 'lib/rims/rfc822.rb', line 817 def from mail_address_header_field('from') end |
#header ⇒ Object
619 620 621 622 |
# File 'lib/rims/rfc822.rb', line 619 def header @header end |
#media_main_type ⇒ Object
635 636 637 638 |
# File 'lib/rims/rfc822.rb', line 635 def media_main_type setup_content_type @content_type[0] end |
#media_main_type_upcase ⇒ Object
651 652 653 654 |
# File 'lib/rims/rfc822.rb', line 651 def media_main_type_upcase # not return `nil' media_main_type.upcase end |
#media_sub_type ⇒ Object Also known as: media_subtype
640 641 642 643 |
# File 'lib/rims/rfc822.rb', line 640 def media_sub_type setup_content_type @content_type[1] end |
#media_sub_type_upcase ⇒ Object Also known as: media_subtype_upcase
656 657 658 659 |
# File 'lib/rims/rfc822.rb', line 656 def media_sub_type_upcase # not return `nil' media_sub_type.upcase end |
#message ⇒ Object
776 777 778 779 780 781 782 783 784 |
# File 'lib/rims/rfc822.rb', line 776 def if (@message.nil?) then if () then @message = Message.new(body.raw_source) end end @message end |
#message? ⇒ Boolean
772 773 774 |
# File 'lib/rims/rfc822.rb', line 772 def media_main_type_upcase == 'MESSAGE' end |
#mime_binary_body_string ⇒ Object
905 906 907 |
# File 'lib/rims/rfc822.rb', line 905 def mime_binary_body_string mime_charset_body_text(Encoding::ASCII_8BIT) end |
#mime_charset_body_text(charset = nil) ⇒ Object
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/rims/rfc822.rb', line 885 def mime_charset_body_text(charset=nil) @mime_charset_body_text_cache ||= {} unless (charset) then unless (@mime_charset_body_text_cache.key? :default) then charset = (text?) ? self.charset : Encoding::ASCII_8BIT @mime_charset_body_text_cache[:default] = CharsetText.get_mime_charset_text(body.raw_source, charset, header['Content-Transfer-Encoding'], charset_aliases: @charset_aliases) end @mime_charset_body_text_cache[:default] else cache_key = make_charset_key(charset) @mime_charset_body_text_cache[cache_key] ||= CharsetText.get_mime_charset_text(body.raw_source, charset, header['Content-Transfer-Encoding'], charset_aliases: @charset_aliases) end end |
#mime_decoded_header(name, decode_charset = nil, charset_convert_options: {}) ⇒ Object
850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/rims/rfc822.rb', line 850 def mime_decoded_header(name, decode_charset=nil, charset_convert_options: {}) cache_key = [ name.downcase.freeze, (decode_charset) ? make_charset_key(decode_charset) : :default ].freeze @mime_decoded_header_cache ||= {} @mime_decoded_header_cache[cache_key] ||= CharsetText.decode_mime_encoded_words(header[name], decode_charset, charset_aliases: @charset_aliases, charset_convert_options: ) end |
#mime_decoded_header_field_value_list(name, decode_charset = nil, charset_convert_options: {}) ⇒ Object
862 863 864 865 866 867 868 869 870 871 872 873 874 |
# File 'lib/rims/rfc822.rb', line 862 def mime_decoded_header_field_value_list(name, decode_charset=nil, charset_convert_options: {}) cache_key = [ name.downcase.freeze, (decode_charset) ? make_charset_key(decode_charset) : :default ].freeze @mime_decoded_header_field_value_list_cache ||= {} @mime_decoded_header_field_value_list_cache[cache_key] ||= header.field_value_list(name).map{|field_value| CharsetText.decode_mime_encoded_words(field_value, decode_charset, charset_aliases: @charset_aliases, charset_convert_options: ) }.freeze end |
#mime_decoded_header_text(decode_charset = nil, charset_convert_options: {}) ⇒ Object
876 877 878 879 880 881 882 883 |
# File 'lib/rims/rfc822.rb', line 876 def mime_decoded_header_text(decode_charset=nil, charset_convert_options: {}) cache_key = (decode_charset) ? make_charset_key(decode_charset) : :default @mime_decoded_header_text_cache ||= {} @mime_decoded_header_text_cache[cache_key] ||= CharsetText.decode_mime_encoded_words(header.raw_source, decode_charset, charset_aliases: @charset_aliases, charset_convert_options: ) end |
#multipart? ⇒ Boolean
752 753 754 |
# File 'lib/rims/rfc822.rb', line 752 def multipart? media_main_type_upcase == 'MULTIPART' end |
#parts ⇒ Object
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/rims/rfc822.rb', line 756 def parts if (@parts.nil?) then if (multipart?) then if (boundary = self.boundary) then part_list = Parse.parse_multipart_body(boundary, body.raw_source) @parts = part_list.map{|msg_txt| Message.new(msg_txt) } else @parts = [] end @parts.freeze end end @parts end |
#reply_to ⇒ Object
825 826 827 |
# File 'lib/rims/rfc822.rb', line 825 def reply_to mail_address_header_field('reply-to') end |
#sender ⇒ Object
821 822 823 |
# File 'lib/rims/rfc822.rb', line 821 def sender mail_address_header_field('sender') end |
#setup_content_disposition ⇒ Object
690 691 692 693 694 695 696 697 698 |
# File 'lib/rims/rfc822.rb', line 690 def setup_content_disposition if (@content_disposition.nil?) then if (header.key? 'Content-Disposition') then @content_disposition = Parse.parse_content_disposition(header['Content-Disposition']) end end nil end |
#text? ⇒ Boolean
748 749 750 |
# File 'lib/rims/rfc822.rb', line 748 def text? media_main_type_upcase == 'TEXT' end |
#to ⇒ Object
829 830 831 |
# File 'lib/rims/rfc822.rb', line 829 def to mail_address_header_field('to') end |