Class: Redwood::DraftLoader
Instance Attribute Summary collapse
Attributes inherited from Source
#usual
Instance Method Summary
collapse
Methods inherited from Source
#==, #file_path, #go_idle, #is_source_for?, #labels?, parse_raw_email_header, #read?, #supported_labels?, #synchronize, #try_lock, #unlock, #valid?
Constructor Details
#initialize(dir = Redwood::DRAFT_DIR) ⇒ DraftLoader
Returns a new instance of DraftLoader.
35
36
37
38
39
40
|
# File 'lib/sup/draft.rb', line 35
def initialize dir=Redwood::DRAFT_DIR
Dir.mkdir dir unless File.exist? dir
super DraftManager.source_name, true, false
@dir = dir
@cur_offset = 0
end
|
Instance Attribute Details
Returns the value of attribute dir.
32
33
34
|
# File 'lib/sup/draft.rb', line 32
def dir
@dir
end
|
Instance Method Details
#each_raw_message_line(offset) ⇒ Object
96
97
98
99
100
|
# File 'lib/sup/draft.rb', line 96
def each_raw_message_line offset
File.open(fn_for_offset(offset), "r:UTF-8") do |f|
yield f.gets until f.eof?
end
end
|
#end_offset ⇒ Object
107
108
109
110
|
# File 'lib/sup/draft.rb', line 107
def end_offset
ids = get_ids
ids.empty? ? 0 : (ids.last + 1)
end
|
#fn_for_offset(o) ⇒ Object
71
|
# File 'lib/sup/draft.rb', line 71
def fn_for_offset o; File.join(@dir, o.to_s); end
|
#gen_offset ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/sup/draft.rb', line 63
def gen_offset
i = @cur_offset
while File.exist? fn_for_offset(i)
i += 1
end
i
end
|
73
74
75
|
# File 'lib/sup/draft.rb', line 73
def offset
File.open(fn_for_offset(offset)) { |f| f }
end
|
#load_message(offset) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/sup/draft.rb', line 77
def load_message offset
raise SourceError, "Draft not found" unless File.exist? fn_for_offset(offset)
File.open fn_for_offset(offset) do |f|
RMail::Mailbox::MBoxReader.new(f).each_message do |input|
return RMail::Parser.read(input)
end
end
end
|
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/sup/draft.rb', line 50
def poll
ids = get_ids
ids.each do |id|
if id >= @cur_offset
@cur_offset = id + 1
yield :add,
:info => id,
:labels => [:draft, :inbox],
:progress => 0.0
end
end
end
|
#properly_initialized? ⇒ Boolean
42
43
44
|
# File 'lib/sup/draft.rb', line 42
def properly_initialized?
!!(@dir && @cur_offset)
end
|
86
87
88
89
90
91
92
93
94
|
# File 'lib/sup/draft.rb', line 86
def offset
ret = ""
File.open(fn_for_offset(offset), "r:UTF-8") do |f|
until f.eof? || (l = f.gets) =~ /^$/
ret += l
end
end
ret
end
|
#raw_message(offset) ⇒ Object
102
103
104
|
# File 'lib/sup/draft.rb', line 102
def raw_message offset
IO.read(fn_for_offset(offset), :encoding => "UTF-8")
end
|
#start_offset ⇒ Object
106
|
# File 'lib/sup/draft.rb', line 106
def start_offset; 0; end
|