Class: Mbox::Mail::Content
- Inherits:
-
Array
- Object
- Array
- Mbox::Mail::Content
- Defined in:
- lib/mbox/mail/content.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(headers, content = [], attachments = []) ⇒ Content
constructor
A new instance of Content.
- #parse(text, headers = {}) ⇒ Object
Constructor Details
#initialize(headers, content = [], attachments = []) ⇒ Content
Returns a new instance of Content.
27 28 29 30 31 32 |
# File 'lib/mbox/mail/content.rb', line 27 def initialize (headers, content = [], = []) @headers = headers @attachments = push *content end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
25 26 27 |
# File 'lib/mbox/mail/content.rb', line 25 def @attachments end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
25 26 27 |
# File 'lib/mbox/mail/content.rb', line 25 def headers @headers end |
Instance Method Details
#parse(text, headers = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mbox/mail/content.rb', line 34 def parse (text, headers = {}) headers = @headers.merge(headers) type = headers[:content_type] if type && type.mime && type.boundary && matches = type.mime.match(%r{multipart/(\w+)}) text.sub(/^.*?--#{type.boundary}\n/m, '').sub(/--#{type.boundary}--$/m, '').split("--#{type.boundary}\n").each {|part| stream = StringIO.new(part) headers = '' until stream.eof? || (line = stream.readline).chomp.empty? headers << line end headers = Headers.parse(headers) content = !stream.eof? ? stream.readline : '' until stream.eof? || line = stream.readline content << line end content.chomp! file = File.new(headers, content) if (headers[:content_disposition] || '').match(/^attachment/) << file else self << file end } else self << File.new(headers, text) end self end |