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
65 66 67 |
# File 'lib/inbox-sync/mail_item.rb', line 65 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
39 40 41 |
# File 'lib/inbox-sync/mail_item.rb', line 39 def internal_date @internal_date ||= self..attr['INTERNALDATE'] end |
#internal_date=(value) ⇒ Object
43 44 45 |
# File 'lib/inbox-sync/mail_item.rb', line 43 def internal_date=(value) @internal_date = value end |
#message ⇒ Object
47 48 49 |
# File 'lib/inbox-sync/mail_item.rb', line 47 def @message ||= ::Mail.new(self.rfc822) end |
#message=(value) ⇒ Object
51 52 53 |
# File 'lib/inbox-sync/mail_item.rb', line 51 def (value) @message = value end |
#meta ⇒ Object
27 28 29 |
# File 'lib/inbox-sync/mail_item.rb', line 27 def @meta ||= @imap.uid_fetch(self.uid, ['RFC822', 'INTERNALDATE']).first 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
31 32 33 |
# File 'lib/inbox-sync/mail_item.rb', line 31 def rfc822 @rfc822 ||= self..attr['RFC822'] end |
#rfc822=(value) ⇒ Object
35 36 37 |
# File 'lib/inbox-sync/mail_item.rb', line 35 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.
61 62 63 |
# File 'lib/inbox-sync/mail_item.rb', line 61 def stripped @stripped ||= strip_down(copy_mail_item(self)) end |