Class: InboxSync::MailItem

Inherits:
Object
  • Object
show all
Defined in:
lib/inbox-sync/mail_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#imapObject (readonly)

Returns the value of attribute imap.



13
14
15
# File 'lib/inbox-sync/mail_item.rb', line 13

def imap
  @imap
end

#uidObject (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

#inspectObject



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.message.from.inspect}, subject=#{self.message.subject.inspect}, 'INTERNALDATE'=#{self.internal_date.inspect}>"
end

#internal_dateObject



39
40
41
# File 'lib/inbox-sync/mail_item.rb', line 39

def internal_date
  @internal_date ||= self.meta.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

#messageObject



47
48
49
# File 'lib/inbox-sync/mail_item.rb', line 47

def message
  @message ||= ::Mail.new(self.rfc822)
end

#message=(value) ⇒ Object



51
52
53
# File 'lib/inbox-sync/mail_item.rb', line 51

def message=(value)
  @message = value
end

#metaObject



27
28
29
# File 'lib/inbox-sync/mail_item.rb', line 27

def meta
  @meta ||= @imap.uid_fetch(self.uid, ['RFC822', 'INTERNALDATE']).first
end

#nameObject



23
24
25
# File 'lib/inbox-sync/mail_item.rb', line 23

def name
  @name ||= "[#{self.uid}] #{self.message.from}: #{self.message.subject.inspect} (#{time_s(self.message.date)})"
end

#rfc822Object



31
32
33
# File 'lib/inbox-sync/mail_item.rb', line 31

def rfc822
  @rfc822 ||= self.meta.attr['RFC822']
end

#rfc822=(value) ⇒ Object



35
36
37
# File 'lib/inbox-sync/mail_item.rb', line 35

def rfc822=(value)
  @rfc822 = value
end

#strippedObject

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