Class: EmailReplyParser::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_email_reply_parser/email_reply_parser/email.rb

Instance Method Summary collapse

Instance Method Details

#except_in_visible_block_quotesObject



44
45
46
47
48
# File 'lib/extended_email_reply_parser/email_reply_parser/email.rb', line 44

def except_in_visible_block_quotes
  @except_in_visible_block_quotes = true
  yield
  @except_in_visible_block_quotes = false
end

#hide_everything_after(expressions) ⇒ Object



3
4
5
6
# File 'lib/extended_email_reply_parser/email_reply_parser/email.rb', line 3

def hide_everything_after(expressions)
  split_regex = /(#{expressions.join(".*?")}.*?\n)/m
  split_fragments_at split_regex
end

#remove_empty_lines_between_block_quote_linesObject



8
9
10
11
12
13
14
15
# File 'lib/extended_email_reply_parser/email_reply_parser/email.rb', line 8

def remove_empty_lines_between_block_quote_lines
  @fragments = @fragments.collect do |fragment|
    if fragment.quoted?
      fragment.content = fragment.content.gsub /\n *?\n>/m, "\n>"
    end
    fragment
  end
end

#split_fragments_at(regex) ⇒ Object



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
# File 'lib/extended_email_reply_parser/email_reply_parser/email.rb', line 17

def split_fragments_at(regex)
  @fragments = @fragments.collect do |fragment|
    if fragment.to_s
      first_text, *rest = fragment.to_s.split(regex)

      first_fragment = Fragment.new(false, first_text)
      first_fragment.quoted = fragment.quoted
      first_fragment.hidden = fragment.hidden
      first_fragment.signature = fragment.signature
      first_fragment.content = first_text

      hidden_fragment = Fragment.new(true, rest.join("\n"))
      hidden_fragment.content = rest.join("\n")

      hidden_fragment.quoted = true
      if @except_in_visible_block_quotes
        hidden_fragment.hidden = true unless fragment.quoted? and not fragment.hidden?
      else
        hidden_fragment.hidden = true
      end

      [first_fragment, hidden_fragment]
    end
  end.flatten - [nil]
  @fragments = @fragments.select { |fragment| fragment.to_s && fragment.to_s != "" }
end