Class: CheetahMail::Messenger

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Messenger

Returns a new instance of Messenger.



8
9
10
11
# File 'lib/cheetah_mail/messenger/messenger.rb', line 8

def initialize(options)
  @options  = options
  @cookie   = nil
end

Instance Method Details

#do_request(message) ⇒ Object

handles sending the request and processing any exceptions



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cheetah_mail/messenger/messenger.rb', line 27

def do_request(message)
  begin
     unless @cookie
    initheader = {'Cookie' => @cookie || ''}
    message.params['aid'] = @options[:aid]
    resp = do_post(message.path, message.params, initheader)
  rescue CheetahMailAuthorizationException => e
    # it may be that the cookie is stale. clear it and immediately retry. 
    # if it hits another authorization exception in the login function then it will come back as a permanent exception
    @cookie = nil
    retry
  end
end

#send_message(message) ⇒ Object

determines if and how to send based on options returns true if the message was sent false if it was suppressed



16
17
18
19
20
21
22
23
24
# File 'lib/cheetah_mail/messenger/messenger.rb', line 16

def send_message(message)
  if !@options[:whitelist_filter] or message.params['email'] =~ @options[:whitelist_filter]
    message.params['test'] = "1" unless @options[:enable_tracking]
    do_send(message) # implemented by the subclass
    true
  else
    false
  end
end