Class: Message

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/mail2wiki-helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imap, message_id) ⇒ Message

Returns a new instance of Message.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/helpers/mail2wiki-helper.rb', line 14

def initialize( imap, message_id )
	@imap, @message_id = imap, message_id
	envelope = @imap.fetch( @message_id, 'ENVELOPE' ).first.attr['ENVELOPE']
	@subject = envelope['subject'].gsub(/^(Fw|Re):?/i,'').strip
	@sender_name = envelope['from'].first['name']
	@date = envelope['date']
	@sender_email = envelope['from'].first['mailbox'] + ' at ' + envelope['from'].first['host']
	@sender_name = @sender_email unless @sender_name && @sender_name.size > 1
	@sender_name.gsub!(/@/,' at ')
	@text = plain_text_content_from_message( message_id )
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def date
  @date
end

#message_idObject (readonly)

Returns the value of attribute message_id.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def message_id
  @message_id
end

#sender_emailObject (readonly)

Returns the value of attribute sender_email.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def sender_email
  @sender_email
end

#sender_nameObject (readonly)

Returns the value of attribute sender_name.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def sender_name
  @sender_name
end

#subjectObject (readonly)

Returns the value of attribute subject.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def subject
  @subject
end

#textObject (readonly)

Returns the value of attribute text.



12
13
14
# File 'lib/helpers/mail2wiki-helper.rb', line 12

def text
  @text
end

Instance Method Details

#plain_text_content_from_message(id) ⇒ Object



26
27
28
# File 'lib/helpers/mail2wiki-helper.rb', line 26

def plain_text_content_from_message( id )
	@imap.fetch( id, 'BODY[1]' ).first.attr['BODY[1]'].from_quoted_printable
end