sup 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sup might be problematic. Click here for more details.

data/lib/sup/person.rb CHANGED
@@ -10,7 +10,7 @@ class PersonManager
10
10
  self.class.i_am_the_instance self
11
11
  end
12
12
 
13
- def name_for email; @names.member?(email) && @names[email][1]; end
13
+ def name_for email; @names.member?(email) ? @names[email][1] : nil; end
14
14
  def register email, name
15
15
  return unless name
16
16
 
data/lib/sup/poll.rb CHANGED
@@ -8,16 +8,14 @@ class PollManager
8
8
  DELAY = 300
9
9
 
10
10
  def initialize
11
- @polling = false
11
+ @mutex = Mutex.new
12
12
  @last_poll = nil
13
13
 
14
14
  self.class.i_am_the_instance self
15
15
  end
16
16
 
17
17
  def buffer
18
- BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) do
19
- PollMode.new
20
- end
18
+ BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) { PollMode.new }
21
19
  end
22
20
 
23
21
  def poll
@@ -40,55 +38,65 @@ class PollManager
40
38
  end
41
39
  end
42
40
 
41
+ ## TODO: merge this with sup-import
43
42
  def do_poll
44
- return [0, 0] if @polling
45
- @polling = true
46
- found = {}
47
- total_num = 0
48
- total_numi = 0
43
+ total_num = total_numi = 0
44
+ @mutex.synchronize do
45
+ found = {}
46
+ Index.usual_sources.each do |source|
47
+ next if source.broken? || source.done?
48
+
49
+ yield "Loading from #{source}... "
50
+ start_offset = nil
51
+ num = 0
52
+ num_inbox = 0
49
53
 
50
- Index.usual_sources.each do |source|
51
- next if source.done?
52
- yield "Loading from #{source}... "
54
+ source.each do |offset, labels|
55
+ break if source.broken?
56
+ start_offset ||= offset
57
+ yield "Found message at #{offset} with labels #{labels * ', '}"
53
58
 
54
- start_offset = nil
55
- num = 0
56
- num_inbox = 0
57
- source.each do |offset, labels|
58
- start_offset ||= offset
59
- yield "Found message at #{offset} with labels #{labels * ', '}"
60
- begin
61
- m = Redwood::Message.new :source => source, :source_info => offset,
62
- :labels => labels
63
- if found[m.id]
64
- yield "Skipping duplicate message #{m.id}"
65
- next
66
- else
59
+ begin
60
+ begin
61
+ m = Redwood::Message.new :source => source, :source_info => offset, :labels => labels
62
+ rescue MessageFormatError => e
63
+ yield "Non-fatal error loading message #{source}##{offset}: #{e.message}"
64
+ next
65
+ end
66
+
67
+ if found[m.id]
68
+ yield "Skipping duplicate message #{m.id}"
69
+ next
70
+ end
67
71
  found[m.id] = true
68
- end
69
72
 
70
- if Index.add_message m
71
- UpdateManager.relay :add, m
72
- num += 1
73
- total_num += 1
74
- total_numi += 1 if m.labels.include? :inbox
73
+ if Index.add_message m
74
+ UpdateManager.relay :add, m
75
+ num += 1
76
+ total_num += 1
77
+ total_numi += 1 if m.labels.include? :inbox
78
+ end
79
+
80
+ if num % 1000 == 0 && num > 0
81
+ elapsed = Time.now - start
82
+ pctdone = source.pct_done
83
+ remaining = (100.0 - pctdone) * (elapsed.to_f / pctdone)
84
+ yield "## #{num} (#{pctdone}% done) read; #{elapsed.to_time_s} elapsed; est. #{remaining.to_time_s} remaining"
85
+ end
86
+ rescue SourceError => e
87
+ msg = "Fatal error loading from #{source}: #{e.message}"
88
+ Redwood::log msg
89
+ yield msg
90
+ break
75
91
  end
76
- rescue SourceError, MessageFormatError => e
77
- yield "Ignoring erroneous message at #{source}##{offset}: #{e.message}"
78
- end
79
-
80
- if num % 1000 == 0 && num > 0
81
- elapsed = Time.now - start
82
- pctdone = (offset.to_f - start_offset) / (source.total.to_f - start_offset)
83
- remaining = (source.end_offset.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
84
- yield "## #{num} (#{(pctdone * 100.0)}% done) read; #{elapsed.to_time_s} elapsed; est. #{remaining.to_time_s} remaining"
85
92
  end
93
+ yield "Found #{num} messages" unless num == 0
86
94
  end
87
- yield "Found #{num} messages" unless num == 0
95
+
96
+ yield "Done polling; loaded #{total_num} new messages total"
97
+ @last_poll = Time.now
98
+ @polling = false
88
99
  end
89
- yield "Done polling; loaded #{total_num} new messages total"
90
- @last_poll = Time.now
91
- @polling = false
92
100
  [total_num, total_numi]
93
101
  end
94
102
  end
data/lib/sup/thread.rb CHANGED
@@ -7,7 +7,9 @@ class Thread
7
7
 
8
8
  attr_reader :containers
9
9
  def initialize
10
- raise "wrong thread, buddy!" if block_given?
10
+ ## ah, the joys of a multithreaded application with a class called
11
+ ## "Thread". i keep instantiating the wrong one...
12
+ raise "wrong Thread class, buddy!" if block_given?
11
13
  @containers = []
12
14
  end
13
15
 
@@ -28,7 +30,9 @@ class Thread
28
30
  puts "=== end thread ==="
29
31
  end
30
32
 
31
- ## yields each message and some stuff
33
+ ## yields each message, its depth, and its parent
34
+ ## note that the message can be a Message object, or :fake_root,
35
+ ## or nil.
32
36
  def each fake_root=false
33
37
  adj = 0
34
38
  root = @containers.find_all { |c| !Message.subj_is_reply?(c) }.argmin { |c| c.date }
@@ -78,6 +82,7 @@ class Thread
78
82
  def set_labels l; each { |m, *o| m && m.labels = l }; end
79
83
 
80
84
  def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
85
+ def dirty?; any? { |m, *o| m && m.dirty? }; end
81
86
  def save index; each { |m, *o| m && m.save(index) }; end
82
87
 
83
88
  def direct_participants
data/lib/sup/util.rb CHANGED
@@ -224,16 +224,16 @@ class Time
224
224
  ["minute", 60],
225
225
  ["hour", 24],
226
226
  ["day", 7],
227
- ["week", 4], # heh heh
227
+ ["week", 4.345], # heh heh
228
228
  ["month", 12],
229
229
  ["year", nil],
230
230
  ].argfind do |unit, size|
231
- if diff <= 1
231
+ if diff.round <= 1
232
232
  "one #{unit}"
233
- elsif size.nil? || diff < size
234
- "#{diff} #{unit}s"
233
+ elsif size.nil? || diff.round < size
234
+ "#{diff.round} #{unit}s"
235
235
  else
236
- diff = (diff / size.to_f).round
236
+ diff /= size.to_f
237
237
  false
238
238
  end
239
239
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: sup
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
7
- date: 2007-01-03 00:00:00 -08:00
6
+ version: 0.0.5
7
+ date: 2007-01-05 00:00:00 -08:00
8
8
  summary: A console-based email client with the best features of GMail, mutt, and emacs. Features full text search, labels, tagged operations, multiple buffers, recent contacts, and more.
9
9
  require_paths:
10
10
  - lib