lib/mournmail/summary_mode.rb in mournmail-0.1.0 vs lib/mournmail/summary_mode.rb in mournmail-0.1.1

- old
+ new

@@ -25,15 +25,15 @@ SUMMARY_MODE_MAP.define_key("q", :mournmail_quit) SUMMARY_MODE_MAP.define_key("k", :previous_line) SUMMARY_MODE_MAP.define_key("j", :next_line) SUMMARY_MODE_MAP.define_key("m", :mournmail_visit_mailbox) - define_syntax :seen, /^\d+ .*/ - define_syntax :unseen, /^\d+ u.*/ - define_syntax :flagged, /^\d+ \$.*/ - define_syntax :deleted, /^\d+ d.*/ - define_syntax :answered, /^\d+ a.*/ + define_syntax :seen, /^ *\d+ .*/ + define_syntax :unseen, /^ *\d+ u.*/ + define_syntax :flagged, /^ *\d+ \$.*/ + define_syntax :deleted, /^ *\d+ d.*/ + define_syntax :answered, /^ *\d+ a.*/ def initialize(buffer) super(buffer) buffer.keymap = SUMMARY_MODE_MAP end @@ -41,11 +41,12 @@ define_local_command(:summary_read, doc: "Read a mail.") do uid = scroll_up_or_next_uid return if uid.nil? Mournmail.background do mailbox = Mournmail.current_mailbox - mail = Mail.new(Mournmail.read_mail(mailbox, uid)) + s, fetched = Mournmail.read_mail(mailbox, uid) + mail = Mail.new(s) message = mail.render next_tick do message_buffer = Buffer.find_or_new("*message*", undo_limit: 0, read_only: true) message_buffer.apply_mode(Mournmail::MessageMode) @@ -54,11 +55,11 @@ message_buffer.insert(message) message_buffer.beginning_of_buffer end window = Mournmail.message_window window.buffer = message_buffer - mark_as_seen(uid) + mark_as_seen(uid, !fetched) Mournmail.current_uid = uid Mournmail.current_mail = mail end end end @@ -97,11 +98,11 @@ doc: "Reply to the current message.") do |reply_all = current_prefix_arg| uid = selected_uid Mournmail.background do mailbox = Mournmail.current_mailbox - mail = Mail.new(Mournmail.read_mail(mailbox, uid)) + mail = Mail.new(Mournmail.read_mail(mailbox, uid)[0]) body = mail.render_body next_tick do Window.current = Mournmail.message_window Commands.mail(run_hooks: false) if reply_all @@ -197,11 +198,11 @@ define_local_command(:summary_view_source, doc: "View source of a mail.") do uid = selected_uid Mournmail.background do mailbox = Mournmail.current_mailbox - source = Mournmail.read_mail(mailbox, uid) + source, = Mournmail.read_mail(mailbox, uid) next_tick do source_buffer = Buffer.find_or_new("*message-source*", file_encoding: "ascii-8bit", undo_limit: 0, read_only: true) source_buffer.read_only_edit do @@ -219,16 +220,16 @@ private def selected_uid uid = @buffer.save_excursion { @buffer.beginning_of_line - if !@buffer.looking_at?(/\d+/) + if !@buffer.looking_at?(/ *\d+/) Mournmail.current_mail = nil Mournmail.current_uid = nil raise EditorError, "No message found" end - match_string(0).to_i + @buffer.match_string(0).to_i } end def scroll_up_or_next_uid begin @@ -251,14 +252,14 @@ next_message retry end end - def mark_as_seen(uid) + def mark_as_seen(uid, update_server) summary_item = Mournmail.current_summary[uid] if summary_item && !summary_item.flags.include?(:Seen) - summary_item.set_flag(:Seen, update_server: false) + summary_item.set_flag(:Seen, update_server: update_server) Mournmail.current_summary.save update_flags(summary_item) end end @@ -279,12 +280,12 @@ @buffer.read_only_edit do @buffer.save_excursion do @buffer.beginning_of_buffer uid = summary_item.uid flags_char = summary_item.flags_char - if @buffer.re_search_forward(/^#{uid} ./) - @buffer.replace_match("#{uid} #{flags_char}") + if @buffer.re_search_forward(/^( *#{uid}) ./) + @buffer.replace_match(@buffer.match_string(1) + " " + flags_char) end end end end @@ -292,10 +293,10 @@ @buffer.end_of_line if @buffer.end_of_buffer? raise EditorError, "No more mail" end begin - @buffer.re_search_forward(/^\d+ u/) + @buffer.re_search_forward(/^ *\d+ u/) rescue SearchError @buffer.forward_line end end end