lib/sup/imap.rb in sup-0.2 vs lib/sup/imap.rb in sup-0.3
- old
+ new
@@ -85,32 +85,27 @@
x = @parsed_uri.path[1..-1]
(x.nil? || x.empty?) ? 'INBOX' : CGI.unescape(x)
end
def ssl?; @parsed_uri.scheme == 'imaps' end
- def check
- return unless start_offset
+ def check; end # do nothing because anything we do will be too slow,
+ # and we'll catch the errors later.
- 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
-
## is this necessary? TODO: remove maybe
def == o; o.is_a?(IMAP) && o.uri == self.uri && o.username == self.username; end
def load_header id
MBox::read_header StringIO.new(raw_header(id))
end
def load_message id
RMail::Parser.read raw_message(id)
end
+
+ def each_raw_message_line id
+ StringIO.new(raw_message(id)).each { |l| yield l }
+ end
def raw_header id
unsynchronized_scan_mailbox
header, flags = get_imap_fields id, 'RFC822.HEADER'
header.gsub(/\r\n/, "\n")
@@ -162,17 +157,18 @@
start.upto(ids.length - 1) do |i|
id = ids[i]
state = @mutex.synchronize { @imap_state[id] } or next
self.cur_offset = id
- labels = { :Seen => :unread,
- :Flagged => :starred,
+ labels = { :Flagged => :starred,
:Deleted => :deleted
}.inject(@labels) do |cur, (imap, sup)|
cur + (state[:flags].include?(imap) ? [sup] : [])
end
+ labels += [:unread] unless state[:flags].include?(:Seen)
+
yield id, labels
end
end
def start_offset
@@ -226,13 +222,15 @@
## although RFC1730 claims that "If an AUTHENTICATE command
## fails with a NO response, the client may try another", in
## practice it seems like they can also send a BAD response.
begin
+ raise Net::IMAP::NoResponseError unless @imap.capability().member? "AUTH=CRAM-MD5"
@imap.authenticate 'CRAM-MD5', @username, @password
rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
Redwood::log "CRAM-MD5 authentication failed: #{e.class}. Trying LOGIN auth..."
begin
+ raise Net::IMAP::NoResponseError unless @imap.capability().member? "AUTH=LOGIN"
@imap.authenticate 'LOGIN', @username, @password
rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
Redwood::log "LOGIN authentication failed: #{e.class}. Trying plain-text LOGIN..."
@imap.login @username, @password
end