File: dummy_source.rb

package info (click to toggle)
sup-mail 0.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,168 kB
  • sloc: ruby: 12,583; sh: 115; makefile: 9
file content (61 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/ruby

require 'sup'
require 'stringio'
require 'rmail'
require 'uri'

module Redwood

class DummySource < Source

  attr_accessor :messages

  def initialize uri, last_date=nil, usual=true, archived=false, id=nil, labels=[]
    super uri, usual, archived, id
    @messages = nil
  end

  def start_offset
    0
  end

  def end_offset
    # should contain the number of test messages -1
    return @messages ? @messages.length - 1 : 0
  end

  def load_header offset
    Source.parse_raw_email_header StringIO.new(raw_header(offset))
  end

  def load_message offset
    RMail::Parser.read raw_message(offset)
  end

  def raw_header offset
    ret = ""
    f = StringIO.new(@messages[offset])
    until f.eof? || (l = f.gets) =~ /^$/
      ret += l
    end
    ret
  end

  def raw_message offset
    @messages[offset]
  end

  def each_raw_message_line offset
    ret = ""
    f = StringIO.new(@messages[offset])
    until f.eof?
      yield f.gets
    end
  end
end

end

# vim:noai:ts=2:sw=2: