class Redwood::DraftLoader
Attributes
dir[RW]
Public Class Methods
new(cur_offset=0)
click to toggle source
Calls superclass method
# File lib/sup/draft.rb, line 42 def initialize cur_offset=0 dir = Redwood::DRAFT_DIR Dir.mkdir dir unless File.exists? dir super DraftManager.source_name, cur_offset, true, false @dir = dir end
Public Instance Methods
each() { |id, [:draft, :inbox]| ... }
click to toggle source
# File lib/sup/draft.rb, line 53 def each ids = get_ids ids.each do |id| if id >= cur_offset self.cur_offset = id + 1 yield [id, [:draft, :inbox]] end end end
each_raw_message_line(offset) { |gets until eof?| ... }
click to toggle source
# File lib/sup/draft.rb, line 95 def each_raw_message_line offset File.open(fn_for_offset(offset)) do |f| yield f.gets until f.eof? end end
end_offset()
click to toggle source
# File lib/sup/draft.rb, line 106 def end_offset ids = get_ids ids.empty? ? 0 : (ids.last + 1) end
fn_for_offset(o;)
click to toggle source
# File lib/sup/draft.rb, line 71 def fn_for_offset o; File.join(@dir, o.to_s); end
gen_offset()
click to toggle source
# File lib/sup/draft.rb, line 63 def gen_offset i = cur_offset while File.exists? fn_for_offset(i) i += 1 end i end
id()
click to toggle source
# File lib/sup/draft.rb, line 49 def id; DraftManager.source_id; end
load_header(offset)
click to toggle source
# File lib/sup/draft.rb, line 73 def load_header offset File.open(fn_for_offset(offset)) { |f| parse_raw_email_header f } end
load_message(offset)
click to toggle source
# File lib/sup/draft.rb, line 77 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
raw_header(offset)
click to toggle source
# File lib/sup/draft.rb, line 85 def raw_header 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)
click to toggle source
# File lib/sup/draft.rb, line 101 def raw_message offset IO.read(fn_for_offset(offset)) end
start_offset()
click to toggle source
# File lib/sup/draft.rb, line 105 def start_offset; 0; end
to_s()
click to toggle source
# File lib/sup/draft.rb, line 50 def to_s; DraftManager.source_name; end
uri()
click to toggle source
# File lib/sup/draft.rb, line 51 def uri; DraftManager.source_name; end
Private Instance Methods
get_ids()
click to toggle source
# File lib/sup/draft.rb, line 113 def get_ids Dir.entries(@dir).select { |x| x =~ /^\d+$/ }.map { |x| x.to_i }.sort end