vmail 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vmail/imap_client.rb +29 -22
- data/lib/vmail/version.rb +1 -1
- metadata +2 -2
data/lib/vmail/imap_client.rb
CHANGED
@@ -28,7 +28,6 @@ module Vmail
|
|
28
28
|
@current_mail = nil
|
29
29
|
@current_message_uid = nil
|
30
30
|
@width = 140
|
31
|
-
@prefix = "Gmail"
|
32
31
|
end
|
33
32
|
|
34
33
|
# holds mail objects keyed by [mailbox, uid]
|
@@ -140,28 +139,36 @@ module Vmail
|
|
140
139
|
|
141
140
|
def list_mailboxes
|
142
141
|
log 'loading mailboxes...'
|
143
|
-
@mailboxes ||= (
|
142
|
+
@mailboxes ||= (@imap.list("", "*") || []).
|
144
143
|
select {|struct| struct.attr.none? {|a| a == :Noselect} }.
|
145
|
-
map {|struct| struct.name}
|
144
|
+
map {|struct| struct.name}.uniq
|
146
145
|
@mailboxes.delete("INBOX")
|
147
146
|
@mailboxes.unshift("INBOX")
|
148
147
|
log "loaded mailboxes: #{@mailboxes.inspect}"
|
149
|
-
if @mailboxes.detect {|m| m =~ /^\[Google Mail\]/}
|
150
|
-
@prefix = "Google Mail"
|
151
|
-
end
|
152
148
|
@mailboxes = @mailboxes.map {|name| mailbox_aliases.invert[name] || name}
|
153
149
|
@mailboxes.join("\n")
|
154
150
|
end
|
155
151
|
|
152
|
+
# do this just once
|
156
153
|
def mailbox_aliases
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
154
|
+
return @mailbox_aliases if @mailbox_aliases
|
155
|
+
aliases = {"sent" => "Sent Mail",
|
156
|
+
"all" => "All Mail",
|
157
|
+
"starred" => "Starred",
|
158
|
+
"important" => "Important",
|
159
|
+
"drafts" => "Drafts",
|
160
|
+
"spam" => "Spam",
|
161
|
+
"trash" => "Trash"}
|
162
|
+
@mailbox_aliases = {}
|
163
|
+
aliases.each do |shortname, fullname|
|
164
|
+
[ "[Gmail]", "[Google Mail" ].each do |prefix|
|
165
|
+
if @mailboxes.include?( "#{prefix}/#{fullname}" )
|
166
|
+
@mailbox_aliases[shortname] = "#{prefix}/#{fullname}"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
log "setting aliases to #{@mailbox_aliases.inspect}"
|
171
|
+
@mailbox_aliases
|
165
172
|
end
|
166
173
|
|
167
174
|
# called internally, not by vim client
|
@@ -215,7 +222,7 @@ module Vmail
|
|
215
222
|
envelope = fetch_data.attr["ENVELOPE"]
|
216
223
|
size = fetch_data.attr["RFC822.SIZE"]
|
217
224
|
flags = fetch_data.attr["FLAGS"]
|
218
|
-
address_struct = if @mailbox ==
|
225
|
+
address_struct = if @mailbox == mailbox_aliases['sent']
|
219
226
|
structs = envelope.to || envelope.cc
|
220
227
|
structs.nil? ? nil : structs.first
|
221
228
|
else
|
@@ -228,7 +235,7 @@ module Vmail
|
|
228
235
|
else
|
229
236
|
[Mail::Encodings.unquote_and_convert_to(address_struct.mailbox, 'UTF-8'), Mail::Encodings.unquote_and_convert_to(address_struct.host, 'UTF-8')].join('@')
|
230
237
|
end
|
231
|
-
if @mailbox ==
|
238
|
+
if @mailbox == mailbox_aliases['sent'] && envelope.to && envelope.cc
|
232
239
|
total_recips = (envelope.to + envelope.cc).size
|
233
240
|
address += " + #{total_recips - 1}"
|
234
241
|
end
|
@@ -506,21 +513,21 @@ EOF
|
|
506
513
|
decrement_max_seqno(uid_set.size)
|
507
514
|
# for delete, do in a separate thread because deletions are slow
|
508
515
|
spawn_thread_if_tty do
|
509
|
-
unless @mailbox ==
|
510
|
-
log "@imap.uid_copy #{uid_set.inspect} to [
|
511
|
-
log @imap.uid_copy(uid_set,
|
516
|
+
unless @mailbox == mailbox_aliases['trash']
|
517
|
+
log "@imap.uid_copy #{uid_set.inspect} to #{mailbox_aliases['trash']}"
|
518
|
+
log @imap.uid_copy(uid_set, mailbox_aliases['trash'])
|
512
519
|
end
|
513
520
|
log "@imap.uid_store #{uid_set.inspect} #{action} [#{flg.to_sym}]"
|
514
521
|
log @imap.uid_store(uid_set, action, [flg.to_sym])
|
515
522
|
reload_mailbox
|
516
523
|
clear_cached_message
|
517
524
|
end
|
518
|
-
elsif flg == 'spam' || flg ==
|
525
|
+
elsif flg == 'spam' || flg == mailbox_aliases['spam']
|
519
526
|
log "Marking as spam uid_set: #{uid_set.inspect}"
|
520
527
|
decrement_max_seqno(uid_set.size)
|
521
528
|
spawn_thread_if_tty do
|
522
|
-
log "@imap.uid_copy #{uid_set.inspect} to [
|
523
|
-
log @imap.uid_copy(uid_set,
|
529
|
+
log "@imap.uid_copy #{uid_set.inspect} to #{mailbox_aliases['spam']}"
|
530
|
+
log @imap.uid_copy(uid_set, mailbox_aliases['spam'])
|
524
531
|
log "@imap.uid_store #{uid_set.inspect} #{action} [:Deleted]"
|
525
532
|
log @imap.uid_store(uid_set, action, [:Deleted])
|
526
533
|
reload_mailbox
|
data/lib/vmail/version.rb
CHANGED