Module: Vmail::ShowingHeaders
- Included in:
- ImapClient
- Defined in:
- lib/vmail/showing_headers.rb
Constant Summary collapse
- FLAGMAP =
{'Flagged' => '*', 'Seen' => 'Seen'}
Instance Method Summary collapse
- #extract_address(address_struct) ⇒ Object
- #fetch_and_cache_headers(id_set) ⇒ Object
- #format_flags(flags) ⇒ Object
- #format_header_for_list(message) ⇒ Object
- #get_message_headers(message_ids) ⇒ Object
- #with_more_message_line(res) ⇒ Object
Instance Method Details
#extract_address(address_struct) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vmail/showing_headers.rb', line 55 def extract_address(address_struct) address = if address_struct.nil? "Unknown" else email = [ (address_struct.mailbox ? Mail::Encodings.unquote_and_convert_to(address_struct.mailbox, 'UTF-8') : ""), (address_struct.host ? Mail::Encodings.unquote_and_convert_to(address_struct.host, 'UTF-8'): "") ].join('@') if address_struct.name "#{Mail::Encodings.unquote_and_convert_to((address_struct.name || ''), 'UTF-8')} <#{email}>" else email end end end |
#fetch_and_cache_headers(id_set) ⇒ 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 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vmail/showing_headers.rb', line 17 def fetch_and_cache_headers(id_set) log "Fetching headers for #{id_set.size} messages" results = reconnect_if_necessary do @imap.fetch(id_set, ["FLAGS", "ENVELOPE", "RFC822.SIZE", "UID"]) end results.reverse.map do |x| envelope = x.attr["ENVELOPE"] = envelope. subject = Mail::Encodings.unquote_and_convert_to((envelope.subject || ''), 'UTF-8') recipients = ((envelope.to || []) + (envelope.cc || [])).map {|a| extract_address(a)}.join(', ') sender = extract_address envelope.from.first uid = x.attr["UID"] = Message[] unless = Message.new . = .save end params = { subject: (subject || ''), flags: x.attr['FLAGS'].join(','), date: Time.parse(envelope.date).localtime.to_s, size: x.attr['RFC822.SIZE'], sender: sender, recipients: recipients } # We really just need to update the flags, buy let's update everything .update params unless Vmail::Labeling[message_id: , label_id: @label.label_id] params = {message_id: ., uid: uid, label_id: @label.label_id} Labeling.create params end end end |
#format_flags(flags) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/vmail/showing_headers.rb', line 97 def format_flags(flags) flags = flags.split(',').map {|flag| FLAGMAP[flag]}.compact if flags.delete('Seen').nil? flags << '+' # unread end flags.join('') end |
#format_header_for_list(message) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vmail/showing_headers.rb', line 71 def format_header_for_list() date = DateTime.parse(.date) formatted_date = if date.year != Time.now.year date.strftime "%b %d %Y" else date.strftime "%b %d %I:%M%P" end address = if @mailbox == mailbox_aliases['sent'] .recipients else .sender end mid_width = @width - 38 address_col_width = (mid_width * 0.3).ceil subject_col_width = (mid_width * 0.7).floor row_text = [ format_flags(.flags).col(2), (formatted_date || '').col(14), address.col(address_col_width), .subject.col(subject_col_width), number_to_human_size(.size).rcol(7), . ].join(' | ') end |
#get_message_headers(message_ids) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vmail/showing_headers.rb', line 5 def () = .map {|| m = Message[] if m.nil? raise "Message #{} not found" end m } res = .map {|m| format_header_for_list(m)}.join("\n") res end |
#with_more_message_line(res) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/vmail/showing_headers.rb', line 105 def (res) remaining = @start_index if remaining <= 1 return res end res + "\n> Load #{[100, remaining].min} more messages. #{remaining} remaining." end |