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



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

#internal_dateObject



45
46
47
# File 'lib/inbox-sync/mail_item.rb', line 45

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

#messageObject



53
54
55
# File 'lib/inbox-sync/mail_item.rb', line 53

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

#message=(value) ⇒ Object



57
58
59
# File 'lib/inbox-sync/mail_item.rb', line 57

def message=(value)
  @message = value
end

#metaObject



27
28
29
30
31
32
33
34
35
# File 'lib/inbox-sync/mail_item.rb', line 27

def meta
  @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

#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



37
38
39
# File 'lib/inbox-sync/mail_item.rb', line 37

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

#rfc822=(value) ⇒ Object



41
42
43
# File 'lib/inbox-sync/mail_item.rb', line 41

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.



67
68
69
# File 'lib/inbox-sync/mail_item.rb', line 67

def stripped
  @stripped ||= strip_down(copy_mail_item(self))
end