Class: GMail::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail/index.rb

Overview

Manages a database of message-ids from mail converted from gmvault into Maildir

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Index) initialize(path)

Create a new index if the file is not present or open the current one.

Parameters:

  • path (String)

    path to the mailbox in Maildir format



18
19
20
21
22
23
24
25
26
# File 'lib/gmail/index.rb', line 18

def initialize(path)
  if File.exists?("#{path}/cur") and File.exists?("#{path}/new")
    @path = path
  else
    raise ArgumentError, "#{path} is not a Maildir mailbox"
  end
  @db = Rufus::Tokyo::Cabinet.new("#{path}/index.tch")
  check_db()
end

Instance Attribute Details

- (Object) db (readonly)

Returns the value of attribute db



14
15
16
# File 'lib/gmail/index.rb', line 14

def db
  @db
end

- (Object) path (readonly)

Returns the value of attribute path



14
15
16
# File 'lib/gmail/index.rb', line 14

def path
  @path
end

Instance Method Details

- (TrueClass|FalseClass) [](gm_id)

Allow getting a value

Parameters:

  • gm_id

    GMail ID of the message

Returns:

  • (TrueClass|FalseClass)

    whether it has been stored



53
54
55
56
57
58
# File 'lib/gmail/index.rb', line 53

def [](gm_id)
  if gm_id.nil?
    return(gm_id)
  end
  @db[gm_id]
end

- (Object) []=(gm_id, value)

Allow inserting a new value

Parameters:

  • gm_id

    GMail ID of the message

  • value

    Value to assign



63
64
65
66
# File 'lib/gmail/index.rb', line 63

def []=(gm_id, value)
  return nil if gm_id.nil?
  @db[gm_id] = value
end

- (Object) check_db

Check db version and upgrade it if needed



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gmail/index.rb', line 29

def check_db
  if @db['db_version'].nil?
      @db['db_version'] = GMail::Utils::DB_VERSION
  end
  if @db['gmdb'].nil?
    puts('Warning: gmdb not found...')
  end
  if @db['db_version'] == '2'
    @db['last_sync'] = Time.now
    @db['db_version'] = '3'
  end
end

- (String) gmdb

Returns the path to the gmvault db

Returns:

  • (String)

    path to gmvault db



100
101
102
# File 'lib/gmail/index.rb', line 100

def gmdb
  @db['gmdb']
end

- (Object) gmdb=(value)

Set the gmvault db path in the index

Parameters:

  • value (String)

    path to the gmvault db



106
107
108
# File 'lib/gmail/index.rb', line 106

def gmdb=(value)
  @db['gmdb'] = value || ''
end

- (String) last_id

Return the last_id from the db

Returns:

  • (String)

    last_id'property from the db



70
71
72
# File 'lib/gmail/index.rb', line 70

def last_id
  @db['last_id']
end

- (Object) last_id=(value)

Set the last_id property in the db

Parameters:

  • value (Fixnum)

    set the last_id property to value



76
77
78
# File 'lib/gmail/index.rb', line 76

def last_id=(value)
  @db['last_id'] = value
end

- (Time) last_sync

Return the time of the last sync through the 'last_sync' property

Returns:

  • (Time)

    last_sync property from the db



82
83
84
# File 'lib/gmail/index.rb', line 82

def last_sync
  @db['last_sync']
end

- (Object) last_sync=(value)

Set the last_sync property in the db

Parameters:

  • value (Fixnum)

    set the last_id property to value



88
89
90
# File 'lib/gmail/index.rb', line 88

def last_sync=(value)
  @db['last_sync'] = value
end

- (TrueClass|FalseClass) present?(gm_id)

Check if a given gm_id is present

Parameters:

  • gm_id

    GMail ID of the message

Returns:

  • (TrueClass|FalseClass)

    true if present



45
46
47
48
# File 'lib/gmail/index.rb', line 45

def present?(gm_id)
  return false if gm_id.nil?
  return @db.keys.include?(gm_id)
end

- (Fixnum) size

Returns the size of the db

Returns:

  • (Fixnum)

    size of the db



94
95
96
# File 'lib/gmail/index.rb', line 94

def size
  @db.size
end

- (Fixnum) version

Returns the db version

Returns:

  • (Fixnum)

    version number



112
113
114
# File 'lib/gmail/index.rb', line 112

def version
  @db['db_version'].to_i || 0
end