Module: Vmail::ShowingMessage
- Included in:
- ImapClient
- Defined in:
- lib/vmail/showing_message.rb
Instance Method Summary collapse
- #cached_full_message?(message_id) ⇒ Boolean
- #current_mail ⇒ Object
- #current_message ⇒ Object
- #fetch_and_cache(message_id) ⇒ Object
- #format_parts_info(parts) ⇒ Object
- #show_message(message_id, raw = false) ⇒ Object
Instance Method Details
#cached_full_message?(message_id) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/vmail/showing_message.rb', line 13 def () m = Message[] log "- found message #{}" log "- message has plaintext? #{!m.plaintext.nil?}" m && !m.plaintext.nil? && m end |
#current_mail ⇒ Object
9 10 11 |
# File 'lib/vmail/showing_message.rb', line 9 def current_mail (c = ) && Mail.new(c.rfc822) end |
#current_message ⇒ Object
4 5 6 7 |
# File 'lib/vmail/showing_message.rb', line 4 def return unless @cur_message_id Message[@cur_message_id] end |
#fetch_and_cache(message_id) ⇒ Object
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vmail/showing_message.rb', line 30 def fetch_and_cache() if = () log "- full message cache hit" return .plaintext end log "- full message cache miss" labeling = Labeling[message_id: , label_id: @label.label_id] uid = labeling.uid log "- fetching message uid #{uid}" fetch_data = reconnect_if_necessary do res = retry_if_needed do @imap.uid_fetch(uid, ["FLAGS", "RFC822", "RFC822.SIZE"]) end res[0] end seqno = fetch_data.seqno rfc822 = Mail.new(fetch_data.attr['RFC822']) formatter = Vmail::MessageFormatter.new rfc822 = Message[] = <<-EOF #{} #{number_to_human_size .size} #{.flags} #{format_parts_info(formatter.list_parts)} #{divider '-'} #{format_headers(formatter.extract_headers)} #{formatter.plaintext_part} EOF # 2 calls so we can see more fine grained exceptions .update(:rfc822 => rfc822) if !.valid_encoding? ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') = ic.iconv() end begin .update(:plaintext => ) rescue log .encoding #log message_text raise end rescue msg = "Error encountered in fetch_and_cache(), message_id #{} [#{@mailbox}]:\n#{$!}\n#{$!.backtrace.join("\n")}" log msg msg end |
#format_parts_info(parts) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/vmail/showing_message.rb', line 79 def format_parts_info(parts) lines = parts.select {|part| part !~ %r{text/plain}} if lines.size > 0 "\n#{lines.join("\n")}" end end |
#show_message(message_id, raw = false) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/vmail/showing_message.rb', line 20 def (, raw=false) = .strip.gsub('\\', '') log "Show message: #{.inspect}" return .rfc822 if raw res = retry_if_needed { fetch_and_cache() } log "Showing message message_id: #{}" @cur_message_id = res end |