Class: InboxSync::Sync
- Inherits:
-
Object
- Object
- InboxSync::Sync
- Defined in:
- lib/inbox-sync/sync.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#notify_smtp ⇒ Object
readonly
Returns the value of attribute notify_smtp.
-
#source_imap ⇒ Object
readonly
Returns the value of attribute source_imap.
Instance Method Summary collapse
- #configure(&config_block) ⇒ Object
-
#initialize(configs = {}) ⇒ Sync
constructor
A new instance of Sync.
- #logged_in? ⇒ Boolean
- #logger ⇒ Object
- #name ⇒ Object
- #notify(notice) ⇒ Object
- #run(runner = nil) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #uid ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/inbox-sync/sync.rb', line 11 def config @config end |
#notify_smtp ⇒ Object (readonly)
Returns the value of attribute notify_smtp.
11 12 13 |
# File 'lib/inbox-sync/sync.rb', line 11 def notify_smtp @notify_smtp end |
#source_imap ⇒ Object (readonly)
Returns the value of attribute source_imap.
11 12 13 |
# File 'lib/inbox-sync/sync.rb', line 11 def source_imap @source_imap end |
Instance Method Details
#configure(&config_block) ⇒ Object
36 37 38 39 |
# File 'lib/inbox-sync/sync.rb', line 36 def configure(&config_block) @config.instance_eval(&config_block) if config_block self end |
#logged_in? ⇒ Boolean
32 33 34 |
# File 'lib/inbox-sync/sync.rb', line 32 def logged_in? !!@logged_in end |
#logger ⇒ Object
20 21 22 |
# File 'lib/inbox-sync/sync.rb', line 20 def logger @config.logger end |
#name ⇒ Object
28 29 30 |
# File 'lib/inbox-sync/sync.rb', line 28 def name "#{@config.source.login.user} (#{@config.source.host})" end |
#notify(notice) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/inbox-sync/sync.rb', line 76 def notify(notice) logger.info "** sending '#{notice.subject}' to #{notice.to.inspect}" begin notice.send rescue Exception => err log_error(err) end end |
#run(runner = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/inbox-sync/sync.rb', line 55 def run(runner=nil) return if runner && runner.shutdown? each_source_mail_item(runner) do |mail_item| begin response = send_to_dest(mail_item) dest_uid = parse_append_response_uid(response) logger.debug "** dest uid: #{dest_uid.inspect}" rescue Exception => err log_error(err) notify(Notice::SyncMailItemError.new(@notify_smtp, @config.notify, { :error => err, :mail_item => mail_item, :sync => self })) ensure archive_on_source(mail_item) mail_item = nil end end end |
#setup ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/inbox-sync/sync.rb', line 41 def setup logger.info "=== #{config_log_detail(@config.source)} sync started. ===" @notify_smtp ||= setup_smtp(:notify, @config.notify) @config.validate! login if !logged_in? end |
#teardown ⇒ Object
49 50 51 52 53 |
# File 'lib/inbox-sync/sync.rb', line 49 def teardown logout if logged_in? @source_imap = @notify_smtp = nil logger.info "=== #{config_log_detail(@config.source)} sync finished. ===" end |
#uid ⇒ Object
24 25 26 |
# File 'lib/inbox-sync/sync.rb', line 24 def uid "#{@config.source.login.user}:#{@config.source.host}" end |