]> git.cworth.org Git - sup/commitdiff
Merge branch 'better-buffer-list'
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 14:31:55 +0000 (07:31 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 14:31:55 +0000 (07:31 -0700)
22 files changed:
bin/sup
bin/sup-sync
bugs/issue-aae5ae6378afa9bd2a8e1b15d28ba7ccef867791.yaml
contrib/completion/_sup.zsh [new file with mode: 0644]
lib/sup.rb
lib/sup/account.rb
lib/sup/buffer.rb
lib/sup/contact.rb
lib/sup/index.rb
lib/sup/label.rb
lib/sup/message-chunks.rb
lib/sup/message.rb
lib/sup/modes/edit-message-mode.rb
lib/sup/modes/label-list-mode.rb
lib/sup/modes/reply-mode.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/modes/thread-view-mode.rb
lib/sup/person.rb
lib/sup/poll.rb
lib/sup/util.rb
sup-files.rb
test/test_message.rb

diff --git a/bin/sup b/bin/sup
index 77a5da3ab11abd26c3d16193d6f8f6b857234074..0af3d11ecfea671bc299342f6ca410d6cb83bf12 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -81,6 +81,36 @@ global_keymap = Keymap.new do |k|
   k.add :recall_draft, "Edit most recent draft message", 'R'
 end
 
+## the following magic enables wide characters when used with a ruby
+## ncurses.so that's been compiled against libncursesw. (note the w.) why
+## this works, i have no idea. much like pretty much every aspect of
+## dealing with curses.  cargo cult programming at its best.
+##
+## BSD users: if libc.so.6 is not found, try installing compat6x.
+require 'dl/import'
+module LibC
+  extend DL::Importable
+  setlocale_lib = case Config::CONFIG['arch']
+    when /darwin/; "libc.dylib"
+    when /cygwin/; "cygwin1.dll"
+    else; "libc.so.6"
+  end
+
+  Redwood::log "dynamically loading setlocale() from #{setlocale_lib}"
+  begin
+    dlload setlocale_lib
+    extern "void setlocale(int, const char *)"
+    Redwood::log "setting locale..."
+    LibC.setlocale(6, "")  # LC_ALL == 6
+  rescue RuntimeError => e
+    Redwood::log "cannot dlload setlocale(); ncurses wide character support probably broken."
+    Redwood::log "dlload error was #{e.class}: #{e.message}"
+    if Config::CONFIG['arch'] =~ /bsd/
+      Redwood::log "BSD variant detected. You may have to install a compat6x package to acquire libc."
+    end
+  end
+end
+
 def start_cursing
   Ncurses.initscr
   Ncurses.noecho
@@ -241,7 +271,7 @@ begin
     when :search_unread
       SearchResultsMode.spawn_from_query "is:unread"
     when :list_labels
-      labels = LabelManager.listable_labels.map { |l| LabelManager.string_for l }
+      labels = LabelManager.all_labels.map { |l| LabelManager.string_for l }
       user_label = bm.ask_with_completions :label, "Show threads with label (enter for listing): ", labels
       unless user_label.nil?
         if user_label.empty?
index ac5caf6c6b724e2df48db24afb46994e8cfaa683..91710d47495ab263a69e03ec709657d1ee8b66ae 100644 (file)
@@ -143,12 +143,7 @@ begin
       next if target == :changed && entry && entry[:source_id].to_i == source.id && entry[:source_info].to_i == offset
 
       ## get the state currently in the index
-      index_state =
-        if entry
-          entry[:label].split(/\s+/).map { |x| x.intern }
-        else
-          nil
-        end
+      index_state = entry[:label].split(/\s+/).map { |x| x.intern } if entry
 
       ## skip if we're operating on restored messages, and this one
       ## ain't.
@@ -163,7 +158,7 @@ begin
       ## assign message labels based on the operation we're performing
       case op
       when :asis
-        m.labels = index_state if index_state
+        m.labels = ((m.labels - [:unread, :inbox]) + index_state).uniq if index_state
       when :restore
         ## if the entry exists on disk
         if restored_state[m.id]
index cd3820da3e481d82c284661f3561f81fff8603f0..83cc00a4a4d1d1560b858c8809c5cc22ea5f32c4 100644 (file)
@@ -5,8 +5,8 @@ type: :bugfix
 component: sup
 release: 
 reporter: William Morgan <wmorgan-sup@masanjin.net>
-status: :unstarted
-disposition: 
+status: :closed
+disposition: :fixed
 creation_time: 2008-05-19 23:42:25.910550 Z
 references: []
 
@@ -20,4 +20,8 @@ log_events:
   - William Morgan <wmorgan-sup@masanjin.net>
   - unassigned from release 0.6
   - ""
+- - 2008-11-22 16:31:27.450146 Z
+  - Nicolas Pouillard <nicolas.pouillard@gmail.com>
+  - closed with disposition fixed
+  - This mapping and the PersonManager are now removed.
 git_branch: 
diff --git a/contrib/completion/_sup.zsh b/contrib/completion/_sup.zsh
new file mode 100644 (file)
index 0000000..76870ca
--- /dev/null
@@ -0,0 +1,114 @@
+#compdef sup sup-add sup-config sup-dump sup-sync sup-sync-back sup-tweak-labels sup-recover-sources
+# vim: set et sw=2 sts=2 ts=2 ft=zsh :
+
+# TODO: sources completion: maildir://some/dir, mbox://some/file, ...
+#       for sup-add, sup-sync, sup-sync-back, sup-tweak-labels
+
+(( ${+functions[_sup_cmd]} )) ||
+_sup_cmd()
+{
+  _arguments -s : \
+    "(--list-hooks -l)"{--list-hooks,-l}"[list all hooks and descriptions, and quit]" \
+    "(--no-threads -n)"{--no-threads,-n}"[turn off threading]" \
+    "(--no-initial-poll -o)"{--no-initial-poll,-o}"[Don't poll for new messages when starting]" \
+    "(--search -s)"{--search,-s}"[search for this query upon startup]:Query: " \
+    "(--compose -c)"{--compose,-c}"[compose message to this recipient upon startup]:Email: " \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_add_cmd]} )) ||
+_sup_add_cmd()
+{
+  _arguments -s : \
+    "(--archive -a)"{--archive,-a}"[automatically archive all new messages from this source]" \
+    "(--unusual -u)"{--unusual,-u}"[do not automatically poll for new messages from this source]" \
+    "(--labels -l)"{--labels,-l}"[set of labels to apply to all messages from this source]:Labels: " \
+    "(--force-new -f)"{--force-new,-f}"[create a new account for this source, even if one already exists]" \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_config_cmd]} )) ||
+_sup_config_cmd()
+{
+  _arguments -s : \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_dump_cmd]} )) ||
+_sup_dump_cmd()
+{
+  _arguments -s : \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_recover_sources_cmd]} )) ||
+_sup_recover_sources_cmd()
+{
+  _arguments -s : \
+    "--archive[automatically archive all new messages from this source]" \
+    "--scan-num[number of messages to scan per source]:" \
+    "--unusual[do not automatically poll for new messages from this source]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_sync_cmd]} )) ||
+_sup_sync_cmd()
+{
+  # XXX Add only when --restore is given: (--restored -r)
+  #     Add only when --changed or--all are given: (--start-at -s)
+  _arguments -s : \
+    "--new[operate on new messages only]" \
+    "(--changed -c)"{--changed,-c}"[scan over the entire source for messages that have been deleted, altered, or moved from another source]" \
+    "(--restored -r)"{--restored,-r}"[operate only on those messages included in a dump file as specified by --restore which have changed state]" \
+    "(--all -a)"{--all,-a}"[operate on all messages in the source, regardless of newness or changedness]" \
+    "(--start-at -s)"{--start-at,-s}"[start at a particular offset]:Offset: " \
+    "--asis[if the message is already in the index, preserve its state, otherwise, use default source state]" \
+    "--restore[restore message state from a dump file created with sup-dump]:File:_file" \
+    "--discard[discard any message state in the index and use the default source state]" \
+    "(--archive -x)"{--archive,-x}"[mark messages as archived when using the default source state]" \
+    "(--read -e)"{--read,-e}"[mark messages as read when using the default source state]" \
+    "--extra-labels[apply these labels when using the default source state]:Labels: " \
+    "(--verbose -v)"{--verbose,-v}"[print message ids as they're processed]" \
+    "(--optimize -o)"{--optimize,-o}"[as the final operation, optimize the index]" \
+    "--all-sources[scan over all sources]" \
+    "(--dry-run -n)"{--dry-run,-n}"[don't actually modify the index]" \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_sync_back_cmd]} )) ||
+_sup_sync_back_cmd()
+{
+  _arguments -s : \
+    "(--drop-deleted -d)"{--drop-deleted,-d}"[drop deleted messages]" \
+    "--move-deleted[move deleted messages to a local mbox file]:File:_file" \
+    "(--drop-spam -s)"{--drop-spam,-s}"[drop spam messages]" \
+    "--move-spam[move spam messages to a local mbox file]:File:_file" \
+    "--with-dotlockfile[specific dotlockfile location (mbox files only)]:File:_file" \
+    "--dont-use-dotlockfile[don't use dotlockfile to lock mbox files]" \
+    "(--verbose -v)"{--verbose,-v}"[print message ids as they're processed]" \
+    "(--dry-run -n)"{--dry-run,-n}"[don't actually modify the index]" \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+(( ${+functions[_sup_tweak_labels_cmd]} )) ||
+_sup_tweak_labels_cmd()
+{
+  _arguments -s : \
+    "(--add -a)"{--add,-a}"[which labels to add to every message from the specified sources]:Labels: " \
+    "(--remove -r)"{--remove,-r}"[which labels to remove from every message from the specified sources]:Labels: " \
+    "--all-sources[scan over all sources]" \
+    "(--verbose -v)"{--verbose,-v}"[print message ids as they're processed]" \
+    "(--dry-run -n)"{--dry-run,-n}"[don't actually modify the index]" \
+    "--version[show version information]" \
+    "(--help -h)"{--help,-h}"[show help]"
+}
+
+_call_function ret _${words[1]//-/_}_cmd
+return ret
+
index 92ace7d8f0c3072dbb2a98393fe7fd8484945b4d..88eae7fc5037da797616b0301d8005d36eb1b6b4 100644 (file)
@@ -6,19 +6,6 @@ require 'fileutils'
 require 'gettext'
 require 'curses'
 
-## the following magic enables wide characters when used with a ruby
-## ncurses.so that's been compiled against libncursesw. (note the w.) why
-## this works, i have no idea. much like pretty much every aspect of
-## dealing with curses.  cargo cult programming at its best.
-
-require 'dl/import'
-module LibC
-  extend DL::Importable
-  dlload Config::CONFIG['arch'] =~ /darwin/ ? "libc.dylib" : "libc.so.6"
-  extern "void setlocale(int, const char *)"
-end
-LibC.setlocale(6, "")  # LC_ALL == 6
-
 class Object
   ## this is for debugging purposes because i keep calling #id on the
   ## wrong object and i want it to throw an exception
@@ -53,7 +40,6 @@ module Redwood
   COLOR_FN   = File.join(BASE_DIR, "colors.yaml")
   SOURCE_FN  = File.join(BASE_DIR, "sources.yaml")
   LABEL_FN   = File.join(BASE_DIR, "labels.txt")
-  PERSON_FN  = File.join(BASE_DIR, "people.txt")
   CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
   DRAFT_DIR  = File.join(BASE_DIR, "drafts")
   SENT_FN    = File.join(BASE_DIR, "sent.mbox")
@@ -115,7 +101,6 @@ module Redwood
   end
 
   def start
-    Redwood::PersonManager.new Redwood::PERSON_FN
     Redwood::SentManager.new Redwood::SENT_FN
     Redwood::ContactManager.new Redwood::CONTACT_FN
     Redwood::LabelManager.new Redwood::LABEL_FN
@@ -130,7 +115,6 @@ module Redwood
   def finish
     Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
     Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
-    Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
     Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
   end
 
index f8ac0fcaf672ace7e2b72e4e666e2b56d7c6fc19..6f86129ca5d8997b0572f38512ba84a691ee4a7c 100644 (file)
@@ -5,8 +5,8 @@ class Account < Person
 
   def initialize h
     raise ArgumentError, "no name for account" unless h[:name]
-    raise ArgumentError, "no name for email" unless h[:name]
-    super h[:name], h[:email], 0, true
+    raise ArgumentError, "no email for account" unless h[:email]
+    super h[:name], h[:email]
     @sendmail = h[:sendmail]
     @signature = h[:signature]
   end
@@ -42,7 +42,6 @@ class AccountManager
     hash[:alternates] ||= []
 
     a = Account.new hash
-    PersonManager.register a
     @accounts[a] = true
 
     if default
index 59915345b14528f6f059efcb22fa82182b31dab2..cb61e12ffd19df6a2ccc0a2df7c54ec80066938e 100644 (file)
@@ -481,7 +481,9 @@ EOS
     default = default_labels.join(" ")
     default += " " unless default.empty?
 
-    applyable_labels = (LabelManager.applyable_labels - forbidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase }
+    # here I would prefer to give more control and allow all_labels instead of
+    # user_defined_labels only
+    applyable_labels = (LabelManager.user_defined_labels - forbidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase }
 
     answer = ask_many_with_completions domain, question, applyable_labels, default
 
@@ -509,7 +511,7 @@ EOS
     answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
 
     if answer
-      answer.split_on_commas.map { |x| ContactManager.contact_for(x) || PersonManager.person_for(x) }
+      answer.split_on_commas.map { |x| ContactManager.contact_for(x) || Person.from_address(x) }
     end
   end
 
index b0c272e8ece056b825ede520312f49d35de7d23c..51fd0e978c902f17485c8fcd81f20cc766b74157 100644 (file)
@@ -17,7 +17,7 @@ class ContactManager
       IO.foreach(fn) do |l|
         l =~ /^([^:]*): (.*)$/ or raise "can't parse #{fn} line #{l.inspect}"
         aalias, addr = $1, $2
-        p = PersonManager.person_for addr, :definitive => true
+        p = Person.from_address addr
         @p2a[p] = aalias
         @a2p[aalias] = p unless aalias.nil? || aalias.empty?
       end
index 8af4edd89e9a3c04799ac3d7a6774097d52d1630..838d601347f1f86ffba21ac72e37c3e191ac95ba 100644 (file)
@@ -246,8 +246,17 @@ EOS
       :snippet => snippet, # always override
       :label => labels.uniq.join(" "),
       :attachments => (entry[:attachments] || m.attachments.uniq.join(" ")),
-      :from => (entry[:from] || (m.from ? m.from.indexable_content : "")),
-      :to => (entry[:to] || (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" ")),
+
+      ## always override :from and :to.
+      ## older versions of Sup would often store the wrong thing in the index
+      ## (because they were canonicalizing email addresses, resulting in the
+      ## wrong name associated with each.) the correct address is read from
+      ## the original header when these messages are opened in thread-view-mode,
+      ## so this allows people to forcibly update the address in the index by
+      ## marking those threads for saving.
+      :from => (m.from ? m.from.indexable_content : ""),
+      :to => (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" "),
+
       :subject => (entry[:subject] || wrap_subj(Message.normalize_subj(m.subj))),
       :refs => (entry[:refs] || (m.refs + m.replytos).uniq.join(" ")),
     }
@@ -449,9 +458,9 @@ EOS
         t = @index[docid][:to]
 
         if AccountManager.is_account_email? f
-          t.split(" ").each { |e| contacts[PersonManager.person_for(e)] = true }
+          t.split(" ").each { |e| contacts[Person.from_address(e)] = true }
         else
-          contacts[PersonManager.person_for(f)] = true
+          contacts[Person.from_address(f)] = true
         end
       end
     end
index 70a26ead5409e2b63a0edef48cb2a9bb4ef4cc6a..8902dda5757584c4c9dee553ae4146e415544545 100644 (file)
@@ -7,9 +7,6 @@ class LabelManager
   ## add/remove these via normal label mechanisms.
   RESERVED_LABELS = [ :starred, :spam, :draft, :unread, :killed, :sent, :deleted, :inbox, :attachment ]
 
-  ## labels which it nonetheless makes sense to search for by
-  LISTABLE_RESERVED_LABELS = [ :starred, :spam, :draft, :sent, :killed, :deleted, :inbox, :attachment ]
-
   ## labels that will typically be hidden from the user
   HIDDEN_RESERVED_LABELS = [ :starred, :unread, :attachment ]
 
@@ -28,25 +25,25 @@ class LabelManager
     self.class.i_am_the_instance self
   end
 
-  ## all listable (just user-defined at the moment) labels, ordered
+  ## all labels user-defined and system, ordered
   ## nicely and converted to pretty strings. use #label_for to recover
   ## the original label.
-  def listable_labels
+  def all_labels
     ## uniq's only necessary here because of certain upgrade issues
-    (LISTABLE_RESERVED_LABELS + @labels.keys).uniq
+    (RESERVED_LABELS + @labels.keys).uniq
   end
 
-  ## all apply-able (user-defined and system listable) labels, ordered
+  ## all user-defined labels, ordered
   ## nicely and converted to pretty strings. use #label_for to recover
   ## the original label.
-  def applyable_labels
+  def user_defined_labels
     @labels.keys
   end
 
   ## reverse the label->string mapping, for convenience!
   def string_for l
     if RESERVED_LABELS.include? l
-      l.to_s.ucfirst
+      l.to_s.capitalize
     else
       l.to_s
     end
index b3726923a85e31fdc7993c7efa5287035751a8d4..1bf779612f4c135d00b8343efb4ee8971efe32d6 100644 (file)
@@ -45,7 +45,10 @@ module Chunk
 
   class Attachment
     HookManager.register "mime-decode", <<EOS
-Executes when decoding a MIME attachment.
+Decodes a MIME attachment into text form. The text will be displayed
+directly in Sup. For attachments that you wish to use a separate program
+to view (e.g. images), you should use the mime-view hook instead.
+
 Variables:
    content_type: the content-type of the message
        filename: the filename of the attachment as saved to disk
@@ -57,13 +60,22 @@ Return value:
 EOS
 
     HookManager.register "mime-view", <<EOS
-Executes when viewing a MIME attachment, i.e., launching a separate
-viewer program.
+Views a non-text MIME attachment. This hook allows you to run
+third-party programs for attachments that require such a thing (e.g.
+images). To instead display a text version of the attachment directly in
+Sup, use the mime-decode hook instead.
+
+Note that by default (at least on systems that have a run-mailcap command),
+Sup uses the default mailcap handler for the attachment's MIME type. If
+you want a particular behavior to be global, you may wish to change your
+mailcap instead.
+
 Variables:
    content_type: the content-type of the attachment
        filename: the filename of the attachment as saved to disk
 Return value:
-  True if the viewing was successful, false otherwise.
+  True if the viewing was successful, false otherwise. If false, calling
+  /usr/bin/run-mailcap will be tried.
 EOS
 #' stupid ruby-mode
 
@@ -108,7 +120,7 @@ EOS
       if expandable?
         "Attachment: #{filename} (#{lines.length} lines)"
       else
-        "Attachment: #{filename} (#{content_type})"
+        "Attachment: #{filename} (#{content_type}; #{@raw_content.size.to_human_size})"
       end
     end
 
index 33d801c3a81a30b5c51e5e15457f7b401873ce35..b3c001e5cc64db42b49a6c070f7b270492d897b1 100644 (file)
@@ -78,10 +78,10 @@ class Message
     
     @from =
       if header["from"]
-        PersonManager.person_for header["from"]
+        Person.from_address header["from"]
       else
         fakename = "Sup Auto-generated Fake Sender <sup@fake.sender.example.com>"
-        PersonManager.person_for fakename
+        Person.from_address fakename
       end
 
     Redwood::log "faking message-id for message from #@from: #{id}" if fakeid
@@ -105,9 +105,9 @@ class Message
       end
 
     @subj = header.member?("subject") ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
-    @to = PersonManager.people_for header["to"]
-    @cc = PersonManager.people_for header["cc"]
-    @bcc = PersonManager.people_for header["bcc"]
+    @to = Person.from_address_list header["to"]
+    @cc = Person.from_address_list header["cc"]
+    @bcc = Person.from_address_list header["bcc"]
 
     ## before loading our full header from the source, we can actually
     ## have some extra refs set by the UI. (this happens when the user
@@ -117,10 +117,10 @@ class Message
     @refs = (@refs + refs).uniq
     @replytos = (header["in-reply-to"] || "").scan(/<(.+?)>/).map { |x| sanitize_message_id x.first }
 
-    @replyto = PersonManager.person_for header["reply-to"]
+    @replyto = Person.from_address header["reply-to"]
     @list_address =
       if header["list-post"]
-        @list_address = PersonManager.person_for header["list-post"].gsub(/^<mailto:|>$/, "")
+        @list_address = Person.from_address header["list-post"].gsub(/^<mailto:|>$/, "")
       else
         nil
       end
@@ -391,7 +391,7 @@ private
     elsif m.header.content_type == "message/rfc822"
       payload = RMail::Parser.read(m.body)
       from = payload.header.from.first
-      from_person = from ? PersonManager.person_for(from.format) : nil
+      from_person = from ? Person.from_address(from.format) : nil
       [Chunk::EnclosedMessage.new(from_person, payload.to_s)] +
         message_to_chunks(payload, encrypted)
     else
@@ -423,7 +423,8 @@ private
         # Lowercase the filename because searches are easier that way 
         @attachments.push filename.downcase unless filename =~ /^sup-attachment-/
         add_label :attachment unless filename =~ /^sup-attachment-/
-        [Chunk::Attachment.new(m.header.content_type, filename, m, sibling_types)]
+        content_type = m.header.content_type || "application/unknown" # sometimes RubyMail gives us nil
+        [Chunk::Attachment.new(content_type, filename, m, sibling_types)]
 
       ## otherwise, it's body text
       else
index 407b23cb102b4d2dd77845cc77db342f696058e1..353e76ac137644d9a1389705d997630501a2a6ab 100644 (file)
@@ -323,8 +323,8 @@ protected
 
     ## do whatever crypto transformation is necessary
     if @crypto_selector && @crypto_selector.val != :none
-      from_email = PersonManager.person_for(@header["From"]).email
-      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| PersonManager.person_for(p).email }
+      from_email = Person.from_address(@header["From"]).email
+      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| Person.from_address(p).email }
 
       m = CryptoManager.send @crypto_selector.val, from_email, to_email, m
     end
@@ -414,7 +414,7 @@ private
   end
 
   def sig_lines
-    p = PersonManager.person_for(@header["From"])
+    p = Person.from_address(@header["From"])
     from_email = p && p.email
 
     ## first run the hook
index 132b654066a8f107e2e52d7d2622c722e1e65ea6..a35d110df8d0607589b9c412682818674c181c9c 100644 (file)
@@ -48,12 +48,12 @@ protected
 
   def regen_text
     @text = []
-    labels = LabelManager.listable_labels
+    labels = LabelManager.all_labels
 
     counts = labels.map do |label|
       string = LabelManager.string_for label
       total = Index.num_results_for :label => label
-      unread = Index.num_results_for :labels => [label, :unread]
+      unread = (label == :unread)? total : Index.num_results_for(:labels => [label, :unread])
       [label, string, total, unread]
     end.sort_by { |l, s, t, u| s.downcase }
 
index 4e08e8e9158bead401d437d4933d1a3ed0c42b81..6b9f55933a6ef967fc221f8b31a6f209e48bbe84 100644 (file)
@@ -53,22 +53,33 @@ EOS
     hook_reply_from = HookManager.run "reply-from", :message => @m
 
     ## sanity check that selection is a Person (or we'll fail below)
-    ## don't check that it's an Account, though; assume they know what they're doing.
+    ## don't check that it's an Account, though; assume they know what they're
+    ## doing.
     if hook_reply_from && !(hook_reply_from.is_a? Person)
-        Redwood::log "reply-from returned non-Person, using default from."
-        hook_reply_from = nil
+      Redwood::log "reply-from returned non-Person, using default from."
+      hook_reply_from = nil
     end
 
-    from =
-      if hook_reply_from
-        hook_reply_from
-      elsif @m.recipient_email && AccountManager.is_account_email?(@m.recipient_email)
-        PersonManager.person_for(@m.recipient_email)
-      elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p })
-        b
-      else
-        AccountManager.default_account
-      end
+    ## determine the from address of a reply.
+    ## if we have a value from a hook, use it.
+    from = if hook_reply_from
+      hook_reply_from
+    ## otherwise, if the original email had an envelope-to header, try and use
+    ## it, and look up the corresponding name form the list of accounts.
+    ##
+    ## this is for the case where mail is received from a mailing lists (so the
+    ## To: is the list id itself). if the user subscribes via a particular
+    ## alias, we want to use that alias in the reply.
+    elsif @m.recipient_email && (a = AccountManager.account_for(@m.recipient_email))
+      Person.new a.name, @m.recipient_email
+    ## otherwise, try and find an account somewhere in the list of to's
+    ## and cc's.
+    elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p })
+      b
+    ## if all else fails, use the default
+    else
+      AccountManager.default_account
+    end
 
     ## now, determine to: and cc: addressess. we ignore reply-to for list
     ## messages because it's typically set to the list address, which we
index a45175dda8f34781fbc0723868105268245db561..56dcdff2df5f139c0129c984b0f02696d6d2cd70 100644 (file)
@@ -68,6 +68,8 @@ EOS
 
     UpdateManager.register self
 
+    @save_thread_mutex = Mutex.new
+
     @last_load_more_size = nil
     to_load_more do |size|
       next if @last_load_more_size == 0
@@ -386,15 +388,25 @@ EOS
     BufferManager.flash "#{threads.size.pluralize 'Thread'} killed."
   end
 
-  def save
-    BufferManager.say("Saving contacts...") { ContactManager.instance.save }
-    dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } }
-    return if dirty_threads.empty?
+  def save background=true
+    if background
+      Redwood::reporting_thread("saving thread") { actually_save }
+    else
+      actually_save
+    end
+  end
+
+  def actually_save
+    @save_thread_mutex.synchronize do
+      BufferManager.say("Saving contacts...") { ContactManager.instance.save }
+      dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } }
+      next if dirty_threads.empty?
 
-    BufferManager.say("Saving threads...") do |say_id|
-      dirty_threads.each_with_index do |t, i|
-        BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id
-        t.save Index
+      BufferManager.say("Saving threads...") do |say_id|
+        dirty_threads.each_with_index do |t, i|
+          BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id
+          t.save Index
+        end
       end
     end
   end
@@ -408,7 +420,7 @@ EOS
       sleep 0.1 # TODO: necessary?
       BufferManager.erase_flash
     end
-    save
+    save false
     super
   end
 
@@ -454,13 +466,22 @@ EOS
   end
 
   def multi_edit_labels threads
-    user_labels = BufferManager.ask_for_labels :add_labels, "Add labels: ", [], @hidden_labels
+    user_labels = BufferManager.ask_for_labels :labels, "Add/remove labels (use -label to remove): ", [], @hidden_labels
     return unless user_labels
-    
-    hl = user_labels.select { |l| @hidden_labels.member? l }
+
+    user_labels.map! { |l| (l.to_s =~ /^-/)? [l.to_s.gsub(/^-?/, '').to_sym, true] : [l, false] }
+    hl = user_labels.select { |(l,_)| @hidden_labels.member? l }
     if hl.empty?
-      threads.each { |t| user_labels.each { |l| t.apply_label l } }
-      user_labels.each { |l| LabelManager << l }
+      threads.each do |t|
+        user_labels.each do |(l, to_remove)|
+          if to_remove
+            t.remove_label l
+          else
+            t.apply_label l
+          end
+        end
+      end
+      user_labels.each { |(l,_)| LabelManager << l }
     else
       BufferManager.flash "'#{hl}' is a reserved label!"
     end
index f4d4232073e0126eef807e87170611c6840f344d..f27f00d81ec28bb7563dac53e2ccfd406ae93e2f 100644 (file)
@@ -149,7 +149,7 @@ EOS
   def subscribe_to_list
     m = @message_lines[curpos] or return
     if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
-      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
     else
       BufferManager.flash "Can't find List-Subscribe header for this message."
     end
@@ -158,7 +158,7 @@ EOS
   def unsubscribe_from_list
     m = @message_lines[curpos] or return
     if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
-      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
     else
       BufferManager.flash "Can't find List-Unsubscribe header for this message."
     end
index fb58f23889d53503bce539407b2583767b40a49c..c4f40a523e77907590d6eb1e546a37905fef6576 100644 (file)
@@ -1,62 +1,9 @@
 module Redwood
 
-class PersonManager
-  include Singleton
-
-  def initialize fn
-    @fn = fn
-    @@people = {}
-
-    ## read in stored people
-    IO.readlines(fn).map do |l|
-      l =~ /^(.*)?:\s+(\d+)\s+(.*)$/ or next
-      email, time, name = $1, $2, $3
-      @@people[email] = Person.new name, email, time, false
-    end if File.exists? fn
-
-    self.class.i_am_the_instance self
-  end
-
-  def save
-    File.open(@fn, "w") do |f|
-      @@people.each do |email, p|
-        next if p.email == p.name
-        next if p.name =~ /=/ # drop rfc2047-encoded, and lots of other useless emails. definitely a heuristic.
-        f.puts "#{p.email}: #{p.timestamp} #{p.name}"
-      end
-    end
-  end
-
-  def self.people_for s, opts={}
-    return [] if s.nil?
-    s.split_on_commas.map { |ss| self.person_for ss, opts }
-  end
-
-  def self.person_for s, opts={}
-    p = Person.from_address(s) or return nil
-    p.definitive = true if opts[:definitive]
-    register p
-  end
-  
-  def self.register p
-    oldp = @@people[p.email]
-
-    if oldp.nil? || p.better_than?(oldp)
-      @@people[p.email] = p
-    end
-
-    @@people[p.email].touch!
-    @@people[p.email]
-  end
-end
-
-## don't create these by hand. rather, go through personmanager, to
-## ensure uniqueness and overriding.
 class Person 
-  attr_accessor :name, :email, :timestamp
-  bool_accessor :definitive
+  attr_accessor :name, :email
 
-  def initialize name, email, timestamp=0, definitive=false
+  def initialize name, email
     raise ArgumentError, "email can't be nil" unless email
     
     if name
@@ -67,26 +14,10 @@ class Person
     end
 
     @email = email.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ").downcase
-    @definitive = definitive
-    @timestamp = timestamp
-  end
-
-  ## heuristic: whether the name attached to this email is "real", i.e. 
-  ## we should bother to store it.
-  def generic?
-    @email =~ /no\-?reply/
-  end
-
-  def better_than? o
-    return false if o.definitive? || generic?
-    return true if definitive?
-    o.name.nil? || (name && name.length > o.name.length && name =~ /[a-z]/)
   end
 
   def to_s; "#@name <#@email>" end
 
-  def touch!; @timestamp = Time.now.to_i end
-
 #   def == o; o && o.email == email; end
 #   alias :eql? :==
 #   def hash; [name, email].hash; end
@@ -146,8 +77,20 @@ class Person
     return nil if s.nil?
 
     ## try and parse an email address and name
-    name, email =
-      case s
+    name, email = case s
+      when /(.+?) ((\S+?)@\S+) \3/
+        ## ok, this first match cause is insane, but bear with me.  email
+        ## addresses are stored in the to/from/etc fields of the index in a
+        ## weird format: "name address first-part-of-address", i.e.  spaces
+        ## separating those three bits, and no <>'s. this is the output of
+        ## #indexable_content. here, we reverse-engineer that format to extract
+        ## a valid address.
+        ##
+        ## we store things this way to allow searches on a to/from/etc field to
+        ## match any of those parts. a more robust solution would be to store a
+        ## separate, non-indexed field with the proper headers. but this way we
+        ## save precious bits, and it's backwards-compatible with older indexes.
+        [$1, $2]
       when /["'](.*?)["'] <(.*?)>/, /([^,]+) <(.*?)>/
         a, b = $1, $2
         [a.gsub('\"', '"'), b]
@@ -162,6 +105,12 @@ class Person
     Person.new name, email
   end
 
+  def self.from_address_list ss
+    return [] if ss.nil?
+    ss.split_on_commas.map { |s| self.from_address s }
+  end
+
+  ## see comments in self.from_address
   def indexable_content
     [name, email, email.split(/@/).first].join(" ")
   end
index 92305c9fde1b25a24e5160e24ffbd17c970b623a..d85abb5fe9557f993e8138b9a8068d66305b7bb2 100644 (file)
@@ -97,13 +97,13 @@ EOS
         numi = 0
         add_messages_from source do |m, offset, entry|
           ## always preserve the labels on disk.
-          m.labels = entry[:label].split(/\s+/).map { |x| x.intern } if entry
+          m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].split(/\s+/).map { |x| x.intern }).uniq if entry
           yield "Found message at #{offset} with labels {#{m.labels * ', '}}"
           unless entry
             num += 1
-            from_and_subj << [m.from.longname, m.subj]
+            from_and_subj << [m.from && m.from.longname, m.subj]
             if m.has_label?(:inbox) && ([:spam, :deleted, :killed] & m.labels).empty?
-              from_and_subj_inbox << [m.from.longname, m.subj]
+              from_and_subj_inbox << [m.from && m.from.longname, m.subj]
               numi += 1 
             end
           end
index fc625328b2afb63310b4fa39ed196217d4eeae0b..8b92fd2e079761965d3684ab051aee1b72cf6840 100644 (file)
@@ -188,11 +188,6 @@ class String
     ret
   end
 
-  ## one of the few things i miss from perl
-  def ucfirst
-    self[0 .. 0].upcase + self[1 .. -1]
-  end
-
   ## a very complicated regex found on teh internets to split on
   ## commas, unless they occurr within double quotes.
   def split_on_commas
@@ -620,11 +615,12 @@ end
 
 class Iconv
   def self.easy_decode target, charset, text
-    return text if charset =~ /^(x-unknown|unknown[-_]?8bit|ascii[-_]?7[-_]?bit)$/i
+    return text if charset =~ /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i
     charset = case charset
-                when /UTF[-_]?8/i: "utf-8"
-                when /(iso[-_])?latin[-_]?1$/i: "ISO-8859-1"
-                when /unicode[-_]1[-_]1[-_]utf[-_]7/i: "utf-7"
+                when /UTF[-_ ]?8/i: "utf-8"
+                when /(iso[-_ ])?latin[-_ ]?1$/i: "ISO-8859-1"
+                when /iso[-_ ]?8859[-_ ]?15/i: 'ISO-8859-15'
+                when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i: "utf-7"
                 else charset
               end
 
index 71562f59b191a495e85d1a1bae51b24bf510f405..6acf7c0de6a001a2546161d9b8e0d9bec2396c36 100644 (file)
@@ -5,3 +5,7 @@ SUP_FILES =
   SUP_EXTRA_FILES +
   SUP_EXECUTABLES.map { |f| "bin/#{f}" } +
   SUP_LIB_DIRS.map { |d| Dir["#{d}/*.rb"] }.flatten
+
+if $0 == __FILE__ # if executed from commandline
+  puts SUP_FILES
+end
index 96562aa7f53a3780c37cf91c17eb2c217daa5f4c..e38ac5064ca999f8b95b6d70c93f9b05ed8796f4 100644 (file)
@@ -29,11 +29,6 @@ module Redwood
 class TestMessage < Test::Unit::TestCase
   
   def setup
-    person_file = StringIO.new("")
-    # this is a singleton
-    if not PersonManager.instantiated?
-      @person_manager = PersonManager.new(person_file)
-    end
   end
   
   def teardown