Revision 2fd36b40
Added by Marc Dequènes over 14 years ago
- ID 2fd36b409515560b0d0b84b02f065750db8a935d
bin/postman | ||
---|---|---|
logger.log_to_file(@config.log.file) unless @config.log.file.nil?
|
||
end
|
||
|
||
@current_thread = Thread.current
|
||
@stop_asap = false
|
||
@imap = IMAP.new(@config.imap, @config.imap.min_check_interval)
|
||
|
||
logger.info "Bot '#{self.human_name}' loaded"
|
||
end
|
||
|
||
def run
|
||
logger.info "Bot starting"
|
||
imap = IMAP.new(@config.imap, @config.imap.min_check_interval)
|
||
imap.check_mails do |msg|
|
||
@imap.check_mails do |msg|
|
||
process_message(msg)
|
||
end
|
||
logger.info "Bot terminating"
|
||
end
|
||
|
||
def ask_to_stop
|
||
@stop_asap = true
|
||
# wakeup sleeps
|
||
Process.kill("ALRM", $$)
|
||
logger.info "Bot was asked to stop..."
|
||
@imap.stop_mail_check
|
||
end
|
||
|
||
private
|
||
|
||
def process_message(msg)
|
||
if @stop_asap
|
||
logger.info "Bot was asked to stop..."
|
||
return false
|
||
end
|
||
|
||
mail = Mail.new(msg.content)
|
||
logger.info "Received mail with ID '#{mail.message_id}': #{mail.from_pretty} -> #{mail.to_pretty} (#{mail.subject_pretty})"
|
||
|
Also available in: Unified diff
[fix] repaired bot stop action