Class: Redwood::DraftLoader
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Source
#==, #file_path, #go_idle, #is_source_for?, parse_raw_email_header, #read?, #usual, #valid?
Constructor Details
Returns a new instance of DraftLoader.
35
36
37
38
39
40
41
|
# File 'lib/sup/draft.rb', line 35
def initialize
dir = Redwood::DRAFT_DIR
Dir.mkdir dir unless File.exists? 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
92
93
94
95
96
|
# File 'lib/sup/draft.rb', line 92
def each_raw_message_line offset
File.open(fn_for_offset(offset)) do |f|
yield f.gets until f.eof?
end
end
|
#end_offset ⇒ Object
103
104
105
106
|
# File 'lib/sup/draft.rb', line 103
def end_offset
ids = get_ids
ids.empty? ? 0 : (ids.last + 1)
end
|
#fn_for_offset(o) ⇒ Object
68
|
# File 'lib/sup/draft.rb', line 68
def fn_for_offset o; File.join(@dir, o.to_s); end
|
#gen_offset ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/sup/draft.rb', line 60
def gen_offset
i = 0
while File.exists? fn_for_offset(i)
i += 1
end
i
end
|
70
71
72
|
# File 'lib/sup/draft.rb', line 70
def offset
File.open(fn_for_offset(offset)) { |f| f }
end
|
#load_message(offset) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/sup/draft.rb', line 74
def load_message 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
|
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/sup/draft.rb', line 47
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
|
82
83
84
85
86
87
88
89
90
|
# File 'lib/sup/draft.rb', line 82
def offset
ret = ""
File.open fn_for_offset(offset) do |f|
until f.eof? || (l = f.gets) =~ /^$/
ret += l
end
end
ret
end
|
#raw_message(offset) ⇒ Object
98
99
100
|
# File 'lib/sup/draft.rb', line 98
def raw_message offset
IO.read(fn_for_offset(offset))
end
|
#start_offset ⇒ Object
102
|
# File 'lib/sup/draft.rb', line 102
def start_offset; 0; end
|