Class: InboxSync::Sync
- Inherits:
-
Object
- Object
- InboxSync::Sync
- Defined in:
- lib/inbox-sync/sync.rb,
lib/inbox-sync/sync/mail_item_group.rb
Defined Under Namespace
Classes: MailItemGroup
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
-
#mail_item_groups ⇒ Object
this splits the mail_items list into ‘@config.num_workers` lists this spreads mail evenly across the groups with earlier items appearing earliest in each list.
- #name ⇒ Object
- #notify(notice) ⇒ Object
- #run(mail_item) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #uid ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/inbox-sync/sync.rb', line 13 def config @config end |
#notify_smtp ⇒ Object (readonly)
Returns the value of attribute notify_smtp.
13 14 15 |
# File 'lib/inbox-sync/sync.rb', line 13 def notify_smtp @notify_smtp end |
#source_imap ⇒ Object (readonly)
Returns the value of attribute source_imap.
13 14 15 |
# File 'lib/inbox-sync/sync.rb', line 13 def source_imap @source_imap end |
Instance Method Details
#configure(&config_block) ⇒ Object
38 39 40 41 |
# File 'lib/inbox-sync/sync.rb', line 38 def configure(&config_block) @config.instance_eval(&config_block) if config_block self end |
#logged_in? ⇒ Boolean
34 35 36 |
# File 'lib/inbox-sync/sync.rb', line 34 def logged_in? !!@logged_in end |
#logger ⇒ Object
22 23 24 |
# File 'lib/inbox-sync/sync.rb', line 22 def logger @config.logger end |
#mail_item_groups ⇒ Object
this splits the mail_items list into ‘@config.num_workers` lists this spreads mail evenly across the groups with earlier items appearing earliest in each list
61 62 63 64 65 66 67 68 69 |
# File 'lib/inbox-sync/sync.rb', line 61 def mail_item_groups num_groups = @config.num_workers groups = [] num_groups.times { groups << MailItemGroup.new(self) } get_mail_items.each_with_index do |item, i| groups[i % num_groups].add(item) end groups end |
#name ⇒ Object
30 31 32 |
# File 'lib/inbox-sync/sync.rb', line 30 def name "#{@config.source.login.user} (#{@config.source.host})" end |
#notify(notice) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/inbox-sync/sync.rb', line 90 def notify(notice) logger.info "** sending '#{notice.subject}' to #{notice.to.inspect}" begin notice.send rescue Exception => err log_error(err) end end |
#run(mail_item) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/inbox-sync/sync.rb', line 71 def run(mail_item) begin logger.debug "** #{mail_item.inspect}" response = send_to_dest(mail_item) dest_uid = parse_append_response_uid(response) apply_dest_filters(dest_uid) 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 |
#setup ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/inbox-sync/sync.rb', line 43 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
51 52 53 54 55 |
# File 'lib/inbox-sync/sync.rb', line 51 def teardown logout if logged_in? @source_imap = @notify_smtp = nil logger.info "=== #{config_log_detail(@config.source)} sync finished. ===" end |
#uid ⇒ Object
26 27 28 |
# File 'lib/inbox-sync/sync.rb', line 26 def uid "#{@config.source.login.user}:#{@config.source.host}" end |