]> git.cworth.org Git - sup/commitdiff
Merge branch 'attachments'
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 19 Jun 2008 18:11:12 +0000 (11:11 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 19 Jun 2008 18:11:12 +0000 (11:11 -0700)
lib/sup/index.rb
lib/sup/label.rb
lib/sup/message.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/modes/thread-view-mode.rb

index f1ede5538a2b7f3793b9ec5c946b3cb5df384e2b..12385d31a400aa61985267e508394835bf547e34 100644 (file)
@@ -147,6 +147,7 @@ EOS
       field_infos.add_field :date, :index => :untokenized
       field_infos.add_field :body
       field_infos.add_field :label
+      field_infos.add_field :attachments
       field_infos.add_field :subject
       field_infos.add_field :from
       field_infos.add_field :to
@@ -223,6 +224,7 @@ EOS
       :body => (entry[:body] || m.indexable_content),
       :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(" ")),
       :subject => (entry[:subject] || wrap_subj(Message.normalize_subj(m.subj))),
@@ -465,7 +467,7 @@ protected
     extraopts[:load_deleted] = true if subs =~ /\blabel:deleted\b/
 
     ## gmail style "is" operator
-    subs = subs.gsub(/\b(is):(\S+)\b/) do
+    subs = subs.gsub(/\b(is|has):(\S+)\b/) do
       field, label = $1, $2
       case label
       when "read"
@@ -481,6 +483,19 @@ protected
       end
     end
 
+    ## gmail style attachments "filename" and "filetype" searches
+    subs = subs.gsub(/\b(filename|filetype):(\((.+?)\)\B|(\S+)\b)/) do
+      field, name = $1, ($3 || $4)
+      case field
+      when "filename"
+        Redwood::log "filename - translated #{field}:#{name} to attachments:(#{name.downcase})"
+        "attachments:(#{name.downcase})"
+      when "filetype"
+        Redwood::log "filetype - translated #{field}:#{name} to attachments:(*.#{name.downcase})"
+        "attachments:(*.#{name.downcase})"
+      end
+    end
+
     if $have_chronic
       chronic_failure = false
       subs = subs.gsub(/\b(before|on|in|during|after):(\((.+?)\)\B|(\S+)\b)/) do
index 4afc0f9c31e7ab081939e5813e3a6a2a89f160cb..716ef98177eb38c74c7e1a905cc6371810e80d23 100644 (file)
@@ -5,13 +5,13 @@ class LabelManager
 
   ## labels that have special semantics. user will be unable to
   ## add/remove these via normal label mechanisms.
-  RESERVED_LABELS = [ :starred, :spam, :draft, :unread, :killed, :sent, :deleted, :inbox ]
+  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 ]
+  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 ]
+  HIDDEN_RESERVED_LABELS = [ :starred, :unread, :attachment ]
 
   def initialize fn
     @fn = fn
index 9b6063f48fb9f36e4a578aa4a9e8762dc9065fa3..2cf97c8ce482c69097d6b8f014d06ff0be6060c5 100644 (file)
@@ -37,7 +37,7 @@ class Message
   DEFAULT_SENDER = "(missing sender)"
 
   attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
-              :cc, :bcc, :labels, :list_address, :recipient_email, :replyto,
+              :cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto,
               :source_info, :list_subscribe, :list_unsubscribe
 
   bool_reader :dirty, :source_marked_read, :snippet_contains_encrypted_content
@@ -54,6 +54,7 @@ class Message
     @dirty = false
     @encrypted = false
     @chunks = nil
+    @attachments = []
 
     ## we need to initialize this. see comments in parse_header as to
     ## why.
@@ -416,6 +417,11 @@ private
 
       ## if there's a filename, we'll treat it as an attachment.
       if filename
+        # add this to the attachments list if its not a generated html
+        # attachment (should we allow images with generated names?).
+        # 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)]
 
       ## otherwise, it's body text
index d4aedbc4112d201d0993fea52f6bd865de2aca6a..4c01c938b85f24d242928cbc47873c387b0216ff 100644 (file)
@@ -712,7 +712,8 @@ protected
       from +
       [
       [subj_color, size_widget_text],
-      [:to_me_color, dp ? " >" : (p ? ' +' : "  ")],
+      [:to_me_color, t.labels.member?(:attachment) ? "@" : " "],
+      [:to_me_color, dp ? ">" : (p ? '+' : " ")],
       [subj_color, t.subj + (t.subj.empty? ? "" : " ")],
     ] +
       (t.labels - @hidden_labels).map { |label| [:label_color, "+#{label} "] } +
index b96576eee58512cef3a02c1ca68db3c52738f7f8..9d30a607d76d63e5fe7fe7e726d86432a8acfce9 100644 (file)
@@ -562,29 +562,29 @@ private
 
     open_widget = [color, (state == :closed ? "+ " : "- ")]
     new_widget = [color, (m.has_label?(:unread) ? "N" : " ")]
-    starred_widget = 
-      if m.has_label?(:starred)
-        [star_color, "* "]
+    starred_widget = if m.has_label?(:starred)
+        [star_color, "*"]
       else
-        [color, "  "]
+        [color, " "]
       end
+    attach_widget = [color, (m.has_label?(:attachment) ? "@" : " ")]
 
     case state
     when :open
       @person_lines[start] = m.from
-      [[prefix_widget, open_widget, new_widget, starred_widget,
+      [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget,
         [color, 
             "#{m.from ? m.from.mediumname : '?'} to #{m.recipients.map { |l| l.shortname }.join(', ')} #{m.date.to_nice_s} (#{m.date.to_nice_distance_s})"]]]
 
     when :closed
       @person_lines[start] = m.from
-      [[prefix_widget, open_widget, new_widget, starred_widget,
+      [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget,
         [color, 
         "#{m.from ? m.from.mediumname : '?'}, #{m.date.to_nice_s} (#{m.date.to_nice_distance_s})  #{m.snippet}"]]]
 
     when :detailed
       @person_lines[start] = m.from
-      from_line = [[prefix_widget, open_widget, new_widget, starred_widget,
+      from_line = [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget,
           [color, "From: #{m.from ? format_person(m.from) : '?'}"]]]
 
       addressee_lines = []