File: imapidle.rb

package info (click to toggle)
imaprowl 1.2.1-1.1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 124 kB
  • ctags: 27
  • sloc: ruby: 524; xml: 172; makefile: 20
file content (46 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
#
# This code has been copied from Ruby-1.9.2's Net::IMAP.
#
# Copyright (C) 2000  Shugo Maeda <shugo@ruby-lang.org>
#
# This library is distributed under the terms of the Ruby license.
# You can freely distribute/modify this library.
#
#

class Net::IMAP
  def idle(&response_handler)
    raise LocalJumpError, "no block given" unless response_handler

    response = nil

    synchronize do
      tag = Thread.current[:net_imap_tag] = generate_tag
      put_string "#{tag} IDLE#{CRLF}"

      begin
        add_response_handler response_handler

        @idle_done_cond = new_cond
        @idle_done_cond.wait
        @idle_done_cond = nil
      ensure
        remove_response_handler response_handler
        put_string "DONE#{CRLF}"
        response = get_tagged_response( tag, "IDLE")
      end
    end

    response
  end

  def idle_done
    synchronize do
      if @idle_done_cond.nil? 
         raise Net::IMAP::Error, 'not during IDLE'
      end
      @idle_done_cond.signal
    end
  end
end