sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b498d85062616527e5ca2fafe5b82cd007550ddd
parent 75872267b06343b29e92ab6c3a5bc73c9e8c0c7f
Author: Eric Weikl <eric.weikl@gmx.net>
Date:   Sun,  8 Sep 2013 13:11:44 +0200

Merge branch 'sup-heliotrope/develop' into maildir-sync

Diffstat:
M CONTRIBUTORS | 14 +++++++-------
M History.txt | 5 +++++
M ReleaseNotes | 4 ++++
M doc/Hooks.txt | 3 ++-
M lib/sup.rb | 2 +-
M lib/sup/logger.rb | 5 ++++-
M lib/sup/message.rb | 2 +-
M lib/sup/modes/edit_message_mode.rb | 12 ++++++++----
M lib/sup/modes/search_list_mode.rb | 6 +++++-
M lib/sup/modes/search_results_mode.rb | 6 +++++-
M lib/sup/search.rb | 23 +++++++++++++++++++++--
M sup.gemspec | 9 +++++----
12 files changed, 68 insertions(+), 23 deletions(-)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
@@ -25,44 +25,44 @@ Richard Brown <rbrown at the exherbo dot orgs>
 Anthony Martinez <pi+sup at the pihost dot uss>
 Marc Hartstein <marc.hartstein at the alum.vassar dot edus>
 Israel Herraiz <israel.herraiz at the gmail dot coms>
+Matthieu Rakotojaona <matthieu.rakotojaona at the gmail dot coms>
 Bo Borgerson <gigabo at the gmail dot coms>
 Michael Hamann <michael at the content-space dot des>
 Jonathan Lassoff <jof at the thejof dot coms>
 William Erik Baxter <web at the superscript dot coms>
 Grant Hollingworth <grant at the antiflux dot orgs>
-Markus Klinik <markus.klinik at the gmx dot des>
 Ico Doornekamp <ico at the pruts dot nls>
+Markus Klinik <markus.klinik at the gmx dot des>
 Adeodato Simó <dato at the net.com.org dot ess>
 Daniel Schoepe <daniel.schoepe at the googlemail dot coms>
 Jason Petsod <jason at the petsod dot orgs>
 Edward Z. Yang <edwardzyang at the thewritingpot dot coms>
-Robin Burchell <viroteck at the viroteck dot nets>
 Steve Goldman <sgoldman at the tower-research dot coms>
+Robin Burchell <viroteck at the viroteck dot nets>
 Peter Harkins <ph at the malaprop dot orgs>
 Decklin Foster <decklin at the red-bean dot coms>
 Cameron Matheson <cam+sup at the cammunism dot orgs>
 Carl Worth <cworth at the cworth dot orgs>
 Alex Vandiver <alex at the chmrr dot nets>
-Andrew Pimlott <andrew at the pimlott dot nets>
 Jeff Balogh <its.jeff.balogh at the gmail dot coms>
+Andrew Pimlott <andrew at the pimlott dot nets>
 Matías Aguirre <matiasaguirre at the gmail dot coms>
 Kornilios Kourtis <kkourt at the cslab.ece.ntua dot grs>
 Kevin Riggle <kevinr at the free-dissociation dot coms>
 Giorgio Lando <patroclo7 at the gmail dot coms>
 Benoît PIERRE <benoit.pierre at the gmail dot coms>
-Matthieu Rakotojaona <matthieu.rakotojaona at the gmail dot coms>
 Alvaro Herrera <alvherre at the alvh.no-ip dot orgs>
 Steven Lawrance <stl at the koffein dot nets>
 Jonah <Jonah at the GoodCoffee dot cas>
 ian <itaylor at the uark dot edus>
-Todd Eisenberger <teisenbe at the andrew.cmu dot edus>
 Adam Lloyd <adam at the alloy-d dot nets>
+Todd Eisenberger <teisenbe at the andrew.cmu dot edus>
+Gregor Hoffleit <gregor at the sam.mediasupervision dot des>
 MichaelRevell <mikearevell at the gmail dot coms>
 Per Andersson <avtobiff at the gmail dot coms>
-Gregor Hoffleit <gregor at the sam.mediasupervision dot des>
 Steven Walter <swalter at the monarch.(none)>
-Jon M. Dugan <jdugan at the es dot nets>
 Matthias Vallentin <vallentin at the icir dot orgs>
+Jon M. Dugan <jdugan at the es dot nets>
 Stefan Lundström <lundst at the snabb.(none)>
 Horacio Sanson <horacio at the skillupjapan.co dot jps>
 Kirill Smelkov <kirr at the landau.phys.spbu dot rus>
diff --git a/History.txt b/History.txt
@@ -1,3 +1,8 @@
+== 0.14.1 / 2013-08-31
+
+* Various bugfixes.
+* Predefined 'All mail' search.
+
 == 0.14.0 / 2013-08-15
 
 * CJK compatability
diff --git a/ReleaseNotes b/ReleaseNotes
@@ -1,3 +1,7 @@
+Release 0.14.1:
+
+Service release to 0.14.0 plus a predefined 'All mail' search.
+
 Release 0.14.0:
 
 CJK-compatability, Psych usage, thread safety, GPGME 2.0 support. Sup is now
diff --git a/doc/Hooks.txt b/doc/Hooks.txt
@@ -50,10 +50,11 @@ before-poll:
 mime-decode:
   ## turn text/html attachments into plain text, unless they are part
   ## of a multipart/alternative pair
+  require 'shellwords'
   unless sibling_types.member? "text/plain"
     case content_type
     when "text/html"
-      `/usr/bin/w3m -dump -T #{content_type} '#{filename}'`
+      `/usr/bin/w3m -dump -T #{content_type} '#{Shellwords.escape filename}'`
     end
   end
 
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -317,7 +317,7 @@ EOM
         :accounts => {
           :default => {
             :name => name.dup.fix_encoding!,
-            :email => email.fix_encoding!,
+            :email => email.dup.fix_encoding!,
             :alternates => [],
             :sendmail => "/usr/sbin/sendmail -oem -ti",
             :signature => File.join(ENV["HOME"], ".signature"),
diff --git a/lib/sup/logger.rb b/lib/sup/logger.rb
@@ -60,7 +60,10 @@ private
   ## actually distribute the message
   def send_message m
     @mutex.synchronize do
-      @sinks.each { |sink| sink << m }
+      @sinks.each do |sink|
+        sink << m
+        sink.flush if sink.respond_to?(:flush) and level == "debug"
+      end
       @buf << m
     end
   end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -335,7 +335,7 @@ EOS
   end
 
   def indexable_chunks
-    chunks ? chunks.select { |c| c.is_a? Chunk::Text } : []
+    chunks.select { |c| c.is_a? Chunk::Text } || []
   end
 
   def indexable_subject
diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb
@@ -489,7 +489,7 @@ protected
               return false
         end
       else
-        IO.popen(acct.sendmail, "w") { |p| p.puts m }
+        IO.popen(acct.sendmail, "w:UTF-8") { |p| p.puts m }
         raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
       end
 
@@ -517,6 +517,7 @@ protected
     m.body += "\n" + sig_lines.join("\n") unless @sig_edited
     ## body must end in a newline or GPG signatures will be WRONG!
     m.body += "\n" unless m.body =~ /\n\Z/
+    m.body = m.body.fix_encoding!
 
     ## there are attachments, so wrap body in an attachment of its own
     unless @attachments.empty?
@@ -525,7 +526,10 @@ protected
       m = RMail::Message.new
 
       m.add_part body_m
-      @attachments.each { |a| m.add_part a }
+      @attachments.each do |a|
+        a.body = a.body.fix_encoding! if a.body.kind_of? String
+        m.add_part a
+      end
     end
 
     ## do whatever crypto transformation is necessary
@@ -547,9 +551,9 @@ protected
       m.header[k] =
         case v
         when String
-          k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)
+          (k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)).fix_encoding!
         when Array
-          v.map { |v| mime_encode_address v }.join ", "
+          (v.map { |v| mime_encode_address v }.join ", ").fix_encoding!
         end
     end
 
diff --git a/lib/sup/modes/search_list_mode.rb b/lib/sup/modes/search_list_mode.rb
@@ -86,7 +86,11 @@ protected
     counted = searches.map do |name|
       search_string = SearchManager.search_string_for name
       begin
-        query = Index.parse_query search_string
+        if SearchManager.predefined_queries.has_key? search_string
+          query = SearchManager.predefined_queries[search_string]
+        else
+          query = Index.parse_query search_string
+        end
         total = Index.num_results_for :qobj => query[:qobj]
         unread = Index.num_results_for :qobj => query[:qobj], :label => :unread
       rescue Index::ParseError => e
diff --git a/lib/sup/modes/search_results_mode.rb b/lib/sup/modes/search_results_mode.rb
@@ -40,7 +40,11 @@ class SearchResultsMode < ThreadIndexMode
 
   def self.spawn_from_query text
     begin
-      query = Index.parse_query(text)
+      if SearchManager.predefined_queries.has_key? text
+        query = SearchManager.predefined_queries[text]
+      else
+        query = Index.parse_query(text)
+      end
       return unless query
       short_text = text.length < 20 ? text : text[0 ... 20] + "..."
       mode = SearchResultsMode.new query
diff --git a/lib/sup/search.rb b/lib/sup/search.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
 module Redwood
 
 class SearchManager
@@ -15,10 +17,27 @@ class SearchManager
       end
     end
     @modified = false
+
+    @predefined_searches = { 'All mail' => 'Search all mail.' }
+    @predefined_queries  = { 'All mail'.to_sym => { :qobj => Xapian::Query.new('Kmail'),
+                                                    :load_spam => false,
+                                                    :load_deleted => false,
+                                                    :load_killed => false,
+                                                    :text => 'Search all mail.'}
+    }
+    @predefined_searches.each do |k,v|
+      @searches[k] = v
+    end
   end
 
+  def predefined_queries; return @predefined_queries; end
   def all_searches; return @searches.keys.sort; end
-  def search_string_for name; return @searches[name]; end
+  def search_string_for name;
+    if @predefined_searches.keys.member? name
+      return name.to_sym
+    end
+    return @searches[name];
+  end
   def valid_name? name; name =~ /^[\w-]+$/; end
   def name_format_hint; "letters, numbers, underscores and dashes only"; end
 
@@ -65,7 +84,7 @@ class SearchManager
 
   def save
     return unless @modified
-    File.open(@fn, "w") { |f| @searches.sort.each { |(n, s)| f.puts "#{n}: #{s}" } }
+    File.open(@fn, "w:UTF-8") { |f| (@searches - @predefined_searches.keys).sort.each { |(n, s)| f.puts "#{n}: #{s}" } }
     @modified = false
   end
 end
diff --git a/sup.gemspec b/sup.gemspec
@@ -36,10 +36,11 @@ DESC
     s.license = 'GPL-2'
     # TODO: might want to add index migrating script here, too
     s.post_install_message = <<-EOF
-SUP: Please run `sup-psych-ify-config-files` to migrate from 0.13 to 0.14.
+SUP: If you are upgrading Sup from before version 0.14.0: Please
+     run `sup-psych-ify-config-files` to migrate from 0.13 to 0.14.
 
-SUP: Check https://github.com/sup-heliotrope/sup/wiki/Migration-0.13-to-0.14
-     for more detailed up-to-date instructions.
+     Check https://github.com/sup-heliotrope/sup/wiki/Migration-0.13-to-0.14
+     for more detailed and up-to-date instructions.
     EOF
     s.files = SUP_FILES
     s.executables = SUP_EXECUTABLES
@@ -48,7 +49,7 @@ SUP: Check https://github.com/sup-heliotrope/sup/wiki/Migration-0.13-to-0.14
 
     s.add_runtime_dependency "xapian-ruby", "~> 1.2.15"
     s.add_runtime_dependency "ncursesw-sup", "~> 1.3.1"
-    s.add_runtime_dependency "rmail", ">= 0.17"
+    s.add_runtime_dependency "rmail-sup", "~> 1.0.1"
     s.add_runtime_dependency "highline"
     s.add_runtime_dependency "trollop", ">= 1.12"
     s.add_runtime_dependency "lockfile"