Sha256: a48244a8e6efca01265b649157414e2535dd2967c19a0ab8351cf31bc300f12d

Contents?: true

Size: 780 Bytes

Versions: 4

Compression:

Stored size: 780 Bytes

Contents

# encoding: utf-8

module Imap::Backup::Account
  class Folder
    REQUESTED_ATTRIBUTES = ['RFC822', 'FLAGS', 'INTERNALDATE']

    def initialize(connection, folder)
      @connection, @folder = connection, folder
    end

    def uids
      @connection.imap.examine(@folder)
      @connection.imap.uid_search(['ALL']).sort
    rescue Net::IMAP::NoResponseError => e
      warn "Folder '#{@folder}' does not exist"
      []
    end

    def fetch(uid)
      @connection.imap.examine(@folder)
      message = @connection.imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES)[0][1]
      message['RFC822'].force_encoding('utf-8') if RUBY_VERSION > '1.9'
      message
    rescue Net::IMAP::NoResponseError => e
      warn "Folder '#{@folder}' does not exist"
      nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imap-backup-1.0.9 lib/imap/backup/account/folder.rb
imap-backup-1.0.8 lib/imap/backup/account/folder.rb
imap-backup-1.0.7 lib/imap/backup/account/folder.rb
imap-backup-1.0.6 lib/imap/backup/account/folder.rb