Class: InboxSync::MailItem
- Inherits:
-
Object
- Object
- InboxSync::MailItem
- Defined in:
- lib/inbox-sync/mail_item.rb
Instance Attribute Summary collapse
-
#imap ⇒ Object
readonly
Returns the value of attribute imap.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(imap, uid, attrs = {}) ⇒ MailItem
constructor
A new instance of MailItem.
- #inspect ⇒ Object
- #internal_date ⇒ Object
- #internal_date=(value) ⇒ Object
- #message ⇒ Object
- #message=(value) ⇒ Object
- #meta ⇒ Object
- #name ⇒ Object
- #rfc822 ⇒ Object
- #rfc822=(value) ⇒ Object
-
#stripped ⇒ Object
Returns a stripped down version of the mail item The stripped down versions is just the ‘text/plain’ part of multipart mail items.
Constructor Details
#initialize(imap, uid, attrs = {}) ⇒ MailItem
Returns a new instance of MailItem.
15 16 17 18 19 20 21 |
# File 'lib/inbox-sync/mail_item.rb', line 15 def initialize(imap, uid, attrs={}) @imap = imap @uid = uid @rfc822 = attrs[:rfc822] @internal_date = attrs[:internal_date] @message = attrs[:message] end |
Instance Attribute Details
#imap ⇒ Object (readonly)
Returns the value of attribute imap.
13 14 15 |
# File 'lib/inbox-sync/mail_item.rb', line 13 def imap @imap end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
13 14 15 |
# File 'lib/inbox-sync/mail_item.rb', line 13 def uid @uid end |
Class Method Details
.find(imap) ⇒ Object
7 8 9 10 11 |
# File 'lib/inbox-sync/mail_item.rb', line 7 def self.find(imap) imap.uid_search(['ALL']).map do |uid| self.new(imap, uid) end end |
Instance Method Details
#inspect ⇒ Object
71 72 73 |
# File 'lib/inbox-sync/mail_item.rb', line 71 def inspect "#<#{self.class}:#{'0x%x' % (self.object_id << 1)}: @uid=#{self.uid.inspect}, from=#{self..from.inspect}, subject=#{self..subject.inspect}, 'INTERNALDATE'=#{self.internal_date.inspect}>" end |
#internal_date ⇒ Object
45 46 47 |
# File 'lib/inbox-sync/mail_item.rb', line 45 def internal_date @internal_date ||= self..attr['INTERNALDATE'] end |
#internal_date=(value) ⇒ Object
49 50 51 |
# File 'lib/inbox-sync/mail_item.rb', line 49 def internal_date=(value) @internal_date = value end |
#message ⇒ Object
53 54 55 |
# File 'lib/inbox-sync/mail_item.rb', line 53 def @message ||= ::Mail.new(self.rfc822) end |
#message=(value) ⇒ Object
57 58 59 |
# File 'lib/inbox-sync/mail_item.rb', line 57 def (value) @message = value end |
#meta ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/inbox-sync/mail_item.rb', line 27 def @meta ||= begin fetch_data = @imap.uid_fetch(self.uid, ['RFC822', 'INTERNALDATE']) if fetch_data.nil? || fetch_data.empty? raise "error fetching data for uid '#{self.uid}'" end fetch_data.first end end |
#name ⇒ Object
23 24 25 |
# File 'lib/inbox-sync/mail_item.rb', line 23 def name @name ||= "[#{self.uid}] #{self..from}: #{self..subject.inspect} (#{time_s(self..date)})" end |
#rfc822 ⇒ Object
37 38 39 |
# File 'lib/inbox-sync/mail_item.rb', line 37 def rfc822 @rfc822 ||= self..attr['RFC822'] end |
#rfc822=(value) ⇒ Object
41 42 43 |
# File 'lib/inbox-sync/mail_item.rb', line 41 def rfc822=(value) @rfc822 = value end |
#stripped ⇒ Object
Returns a stripped down version of the mail item The stripped down versions is just the ‘text/plain’ part of multipart mail items. If the original mail item was not multipart, then the stripped down version is the same as the original. This implies that stripped down mail items have no attachments.
67 68 69 |
# File 'lib/inbox-sync/mail_item.rb', line 67 def stripped @stripped ||= strip_down(copy_mail_item(self)) end |