lib/sup/modes/thread_view_mode.rb in sup-0.20.0 vs lib/sup/modes/thread_view_mode.rb in sup-0.21.0

- old
+ new

@@ -87,10 +87,11 @@ k.add :delete_and_next, "Delete this thread, kill buffer, and view next", 'd' k.add :kill_and_next, "Kill this thread, kill buffer, and view next", '&' k.add :toggle_wrap, "Toggle wrapping of text", 'w' k.add :goto_uri, "Goto uri under cursor", 'g' + k.add :fetch_and_verify, "Fetch the PGP key on poolserver and re-verify message", "v" k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk| kk.add :archive_and_kill, "Archive this thread and kill buffer", 'a' kk.add :delete_and_kill, "Delete this thread and kill buffer", 'd' kk.add :kill_and_kill, "Kill this thread and kill buffer", '&' @@ -222,14 +223,28 @@ end end def unsubscribe_from_list m = @message_lines[curpos] or return - if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)(\?subject=(.*?))?>/ + BufferManager.flash "Can't find List-Unsubscribe header for this message." unless m.list_unsubscribe + + if m.list_unsubscribe =~ /<mailto:(.*?)(\?subject=(.*?))?>/ ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => ($3 || "unsubscribe") - else - BufferManager.flash "Can't find List-Unsubscribe header for this message." + elsif m.list_unsubscribe =~ /<(http.*)?>/ + unless HookManager.enabled? "goto" + BufferManager.flash "You must add a goto.rb hook before you can goto an unsubscribe URI." + return + end + + begin + u = URI.parse($1) + rescue URI::InvalidURIError => e + BufferManager.flash("Invalid unsubscribe link") + return + end + + HookManager.run "goto", :uri => Shellwords.escape(u.to_s) end end def forward if(chunk = @chunk_lines[curpos]) && chunk.is_a?(Chunk::Attachment) @@ -372,11 +387,11 @@ chunk = @chunk_lines[curpos] or return case chunk when Chunk::Attachment default_dir = $config[:default_attachment_save_dir] default_dir = ENV["HOME"] if default_dir.nil? || default_dir.empty? - default_fn = File.expand_path File.join(default_dir, chunk.filename) + default_fn = File.expand_path File.join(default_dir, chunk.safe_filename) fn = BufferManager.ask_for_filename :filename, "Save attachment to file or directory: ", default_fn, true # if user selects directory use file name from message if fn and File.directory? fn fn = File.join(fn, chunk.filename) @@ -401,11 +416,11 @@ num = 0 num_errors = 0 m.chunks.each do |chunk| next unless chunk.is_a?(Chunk::Attachment) - fn = File.join(folder, chunk.filename) + fn = File.join(folder, chunk.safe_filename) num_errors += 1 unless save_to_file(fn, false) { |f| f.print chunk.raw_content } num += 1 end if num == 0 @@ -706,18 +721,23 @@ return unless chunk || message command = BufferManager.ask(:shell, "pipe command: ") return if command.nil? || command.empty? - output = pipe_to_process(command) do |stream| + output, success = pipe_to_process(command) do |stream| if chunk stream.print chunk.raw_content else message.each_raw_message_line { |l| stream.print l } end end + unless success + BufferManager.flash "Invalid command: '#{command}' is not an executable" + return + end + if output BufferManager.spawn "Output of '#{command}'", TextMode.new(output.ascii) else BufferManager.flash "'#{command}' done!" end @@ -770,9 +790,30 @@ debug "not a uri: #{e}" # Do nothing, this is an ok flow end end BufferManager.flash "No URI found." unless found + end + + def fetch_and_verify + message = @message_lines[curpos] + crypto_chunk = message.chunks.select {|chunk| chunk.is_a?(Chunk::CryptoNotice)}.first + return unless crypto_chunk + return unless crypto_chunk.unknown_fingerprint + + BufferManager.flash "Retrieving key #{crypto_chunk.unknown_fingerprint} ..." + + error = CryptoManager.retrieve crypto_chunk.unknown_fingerprint + + if error + BufferManager.flash "Couldn't retrieve key: #{error.to_s}" + else + BufferManager.flash "Key #{crypto_chunk.unknown_fingerprint} successfully retrieved !" + end + + # Re-trigger gpg verification + message.reload_from_source! + update end private def initial_state_for m