]> git.cworth.org Git - sup/blobdiff - lib/sup/imap.rb
add #pipe-to-process to text-mode
[sup] / lib / sup / imap.rb
index 290ae2a76036652e3b54de28c056b50ae0c1ba4a..057027b0ba233b79cf1b217d1a0ab534b858dff9 100644 (file)
@@ -72,11 +72,7 @@ class IMAP < Source
   end
 
   def self.suggest_labels_for path
-    if path =~ /inbox/i
-      [path.intern]
-    else
-      []
-    end
+    path =~ /([^\/]*inbox[^\/]*)/i ? [$1.downcase.intern] : []
   end
 
   def host; @parsed_uri.host; end
@@ -87,17 +83,8 @@ class IMAP < Source
   end
   def ssl?; @parsed_uri.scheme == 'imaps' end
 
-  def check
-    return unless start_offset
-
-    ids = 
-      @mutex.synchronize do
-        unsynchronized_scan_mailbox
-        @ids
-      end
-
-    start = ids.index(cur_offset || start_offset) or raise OutOfSyncSourceError, "Unknown message id #{cur_offset || start_offset}."
-  end
+  def check; end # do nothing because anything we do will be too slow,
+                 # and we'll catch the errors later.
 
   ## is this necessary? TODO: remove maybe
   def == o; o.is_a?(IMAP) && o.uri == self.uri && o.username == self.username; end
@@ -150,6 +137,7 @@ class IMAP < Source
       @ids << id
       @imap_state[id] = { :id => v.seqno, :flags => v.attr["FLAGS"] }
     end
+    Redwood::log "done fetching IMAP headers"
   end
   synchronized :scan_mailbox
 
@@ -253,8 +241,6 @@ private
       end
     end.join
 
-
-
     raise exception if exception
   end
 
@@ -284,7 +270,22 @@ private
     imap_id = @imap_state[id][:id]
     result = fetch(imap_id, (fields + ['RFC822.SIZE', 'INTERNALDATE']).uniq).first
     got_id = make_id result
-    raise OutOfSyncSourceError, "IMAP message mismatch: requested #{id}, got #{got_id}." unless got_id == id
+
+    ## I've turned off the following sanity check because Microsoft Exchange fails it.
+    ## Exchange actually reports two different INTERNALDATEs for the exact same message
+    ## when queried at different points in time.
+    ##
+    ##
+    ## RFC2060 defines the semantics of INTERNALDATE for messages that arrive
+    ## via SMTP for via various IMAP commands, but states that "All other
+    ## cases are implementation defined.". Great, thanks guys, yet another
+    ## useless field.
+    ## 
+    ## Of course no OTHER imap server I've encountered returns DIFFERENT values for
+    ## the SAME message. But it's Microsoft; what do you expect? If their programmers
+    ## were any good they'd be working at Google.
+
+    # raise OutOfSyncSourceError, "IMAP message mismatch: requested #{id}, got #{got_id}." unless got_id == id
 
     fields.map { |f| result.attr[f] or raise FatalSourceError, "empty response from IMAP server: #{f}" }
   end