vmail 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +5 -0
- data/lib/vmail/imap_client.rb +25 -13
- data/lib/vmail/version.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/vmail/imap_client.rb
CHANGED
@@ -41,26 +41,33 @@ module Vmail
|
|
41
41
|
@imap.disconnect
|
42
42
|
end
|
43
43
|
|
44
|
-
def select_mailbox(mailbox)
|
44
|
+
def select_mailbox(mailbox, force=false)
|
45
45
|
if MailboxAliases[mailbox]
|
46
46
|
mailbox = MailboxAliases[mailbox]
|
47
47
|
end
|
48
|
-
if mailbox == @mailbox
|
48
|
+
if mailbox == @mailbox && !force
|
49
49
|
return
|
50
50
|
end
|
51
51
|
log "selecting mailbox #{mailbox.inspect}"
|
52
52
|
reconnect_if_necessary do
|
53
53
|
log @imap.select(mailbox)
|
54
54
|
end
|
55
|
-
@
|
56
|
-
|
55
|
+
@mailbox = mailbox
|
56
|
+
get_mailbox_status
|
57
|
+
get_highest_message_id
|
58
|
+
return "OK"
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_highest_message_id
|
57
62
|
# get highest message ID
|
58
63
|
res = @imap.fetch([1,"*"], ["ENVELOPE"])
|
59
64
|
@num_messages = res[-1].seqno
|
60
65
|
log "HIGHEST ID: #@num_messages"
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_mailbox_status
|
69
|
+
@status = @imap.status(@mailbox, ["MESSAGES", "RECENT", "UNSEEN"])
|
70
|
+
log "mailbox status: #{@status.inspect}"
|
64
71
|
end
|
65
72
|
|
66
73
|
def revive_connection
|
@@ -107,7 +114,6 @@ module Vmail
|
|
107
114
|
id_set = id_set.split(',')
|
108
115
|
end
|
109
116
|
max_id = id_set.to_a[-1]
|
110
|
-
log "fetch envelopes for #{id_set.inspect}"
|
111
117
|
if id_set.to_a.empty?
|
112
118
|
log "empty set"
|
113
119
|
return ""
|
@@ -220,10 +226,10 @@ module Vmail
|
|
220
226
|
@all_search = false
|
221
227
|
end
|
222
228
|
log "@all_search #{@all_search}"
|
223
|
-
@query = query
|
224
|
-
log "search query: #@query"
|
229
|
+
@query = query
|
230
|
+
log "search query: #@query.inspect"
|
225
231
|
@ids = reconnect_if_necessary do
|
226
|
-
@imap.search(@query)
|
232
|
+
@imap.search(@query.join(' '))
|
227
233
|
end
|
228
234
|
# save ids in @ids, because filtered search relies on it
|
229
235
|
fetch_ids = if @all_search
|
@@ -239,9 +245,15 @@ module Vmail
|
|
239
245
|
|
240
246
|
def update
|
241
247
|
prime_connection
|
248
|
+
old_num_messages = @num_messages
|
249
|
+
# we need to re-select the mailbox to get the new highest id
|
250
|
+
select_mailbox(@mailbox, true)
|
251
|
+
update_query = @query
|
252
|
+
# set a new range filter
|
253
|
+
update_query[0] = "#{old_num_messages}:#{@num_messages}"
|
242
254
|
ids = reconnect_if_necessary {
|
243
|
-
log "search
|
244
|
-
@imap.search(
|
255
|
+
log "search #update_query"
|
256
|
+
@imap.search(update_query.join(' '))
|
245
257
|
}
|
246
258
|
# TODO change this. will throw error now
|
247
259
|
new_ids = ids.select {|x| x > @ids.max}
|
data/lib/vmail/version.rb
CHANGED