Class: EyeMap::Driver

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

Overview

EyeMap::Driver - Top level calls for IMAP connections.

<documentation about implementing a driver goes here>

Direct Known Subclasses

Courier, Dovecot

Defined Under Namespace

Classes: Courier, Dovecot

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Driver

Create a new driver object. This really shouldn’t be called by itself, but as a super() method, as it just fills in defaults intended to be overridden.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/eyemap/eyemap.rb', line 58

def initialize(args)
    args = args[0]

    if ! args.include? :user or 
        ! args.include? :password or
        ! args.include? :host

        raise EyeMap::Exception::BadCall.new("User, Password and Host must be provided to connect")

    end
    @capabilities        = EyeMap::Capabilities.new
    self[:driver_class]  = args[:driver_class]
    self[:driver]        = args[:driver]
    self[:message_class] = EyeMap::Message
    self[:folder_class]  = EyeMap::Folder
    self[:delimiter]     = '/'
    self[:user]          = args[:user]
    self[:password]      = args[:password]
    self[:host]          = args[:host]
    self[:auth_mech]     = 'LOGIN' # for now
    self[:ssl]           = !!args[:ssl]
    self[:verify_ssl]    = args[:ssl] ? !!args[:verify_ssl] : false
    self[:cert]          = args[:cert]

    if ! args[:port]
        args[:port] = args[:ssl] ? 993 : 143
    end

    self[:port] = args[:port] 

end

Instance Method Details

#[](key) ⇒ Object

Fetch a capability. Capabilities are a struct, but are presented in hash form. See EyeMap::Capabilities for more information.



95
96
97
# File 'lib/eyemap/eyemap.rb', line 95

def [](key)
    return @capabilities[key]
end

#connObject

Get the underlying Net::IMAP connection.



124
125
126
# File 'lib/eyemap/eyemap.rb', line 124

def conn
    @conn
end

#connectObject

Initiates a connection (or reconnection) to the server.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/eyemap/eyemap.rb', line 140

def connect
    if @conn and connected?
        begin
            @conn.authenticate("LOGIN", self[:user], self[:password]) unless
            @conn.(self[:user], self[:password]) 
        rescue Exception => e
        end

    else
        @conn = Net::IMAP.new(self[:host], self[:port], 
                              self[:ssl], self[:cert], 
                              self[:verify_ssl])
        connect() # recurse
    end
end

#connected?Boolean

Returns true if the connection is still alive.

Returns:

  • (Boolean)


132
133
134
# File 'lib/eyemap/eyemap.rb', line 132

def connected?
    ! @conn.disconnected?
end

#create(folder_name) ⇒ Object

Creates a new folder with the name specified.



103
104
105
106
# File 'lib/eyemap/eyemap.rb', line 103

def create(folder_name)
    self.conn.create(folder_name)
    self[:folder_class].new(folder_name, self, self[:delimiter])
end

#disconnectObject

Disconnect from the server



160
161
162
# File 'lib/eyemap/eyemap.rb', line 160

def disconnect
    @conn.disconnect
end

#folder(folder_name = nil) ⇒ Object

Get an EyeMap::Folder (or derivative) object for the name of the folder in question. Requires the full folder name.



113
114
115
116
117
118
# File 'lib/eyemap/eyemap.rb', line 113

def folder(folder_name=nil)
    return self[:folder_class].
        new(folder_name,
            self,
            self[:delimiter])
end