Class: Vmail::ImapClient
- Inherits:
-
Object
- Object
- Vmail::ImapClient
- Defined in:
- lib/vmail/imap_client.rb
Constant Summary collapse
- MailboxAliases =
{ 'sent' => '[Gmail]/Sent Mail', 'all' => '[Gmail]/All Mail', 'starred' => '[Gmail]/Starred', 'important' => '[Gmail]/Important', 'drafts' => '[Gmail]/Drafts', 'spam' => '[Gmail]/Spam', 'trash' => '[Gmail]/Trash' }
- UNITS =
[:b, :kb, :mb, :gb].freeze
- FLAGMAP =
{:Flagged => '[*]'}
Class Method Summary collapse
Instance Method Summary collapse
- #add_more_message_line(res, uids) ⇒ Object
- #address_to_string(x) ⇒ Object
- #append_to_file(file, uid_set) ⇒ Object
- #close ⇒ Object
- #copy_to(uid_set, mailbox) ⇒ Object
- #create_if_necessary(mailbox) ⇒ Object
- #deliver(text) ⇒ Object
- #fetch_headers(uid_set) ⇒ Object
-
#flag(uid_set, action, flg) ⇒ Object
uid_set is a string comming from the vim client action is -FLAGS or +FLAGS.
-
#format_flags(flags) ⇒ Object
flags is an array like [:Flagged, :Seen].
- #format_header(fetch_data, max_uid = nil) ⇒ Object
- #format_headers(hash) ⇒ Object
- #format_parts_info(parts) ⇒ Object
- #forward_template(uid) ⇒ Object
- #handle_error(error) ⇒ Object
-
#initialize(config) ⇒ ImapClient
constructor
A new instance of ImapClient.
- #list_mailboxes ⇒ Object
- #log(string) ⇒ Object
-
#mailboxes ⇒ Object
called internally, not by vim client.
-
#more_messages(uid, limit = 100) ⇒ Object
gets 100 messages prior to uid.
- #move_to(uid_set, mailbox) ⇒ Object
- #new_mail_from_input(text) ⇒ Object
- #new_message_template ⇒ Object
-
#number_to_human_size(number) ⇒ Object
borrowed from ActionView/Helpers.
- #open ⇒ Object
- #open_html_part(uid) ⇒ Object
- #reconnect_if_necessary(timeout = 60, &block) ⇒ Object
- #reply_template(uid, replyall = false) ⇒ Object
-
#resume_draft ⇒ Object
TODO.
- #revive_connection ⇒ Object
- #save_attachments(dir) ⇒ Object
- #save_draft(text) ⇒ Object
- #search(limit, *query) ⇒ Object
- #select_mailbox(mailbox) ⇒ Object
- #show_message(uid, raw = false, forwarded = false) ⇒ Object
- #signature ⇒ Object
- #smtp_settings ⇒ Object
- #update ⇒ Object
- #window_width=(width) ⇒ Object
Constructor Details
#initialize(config) ⇒ ImapClient
Returns a new instance of ImapClient.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vmail/imap_client.rb', line 22 def initialize(config) @username, @password = config['username'], config['password'] @name = config['name'] @signature = config['signature'] @mailbox = nil @logger = Logger.new(config['logfile'] || STDERR) @logger.level = Logger::DEBUG @current_mail = nil @current_uid = nil end |
Class Method Details
.daemon(config) ⇒ Object
582 583 584 585 586 587 588 |
# File 'lib/vmail/imap_client.rb', line 582 def self.daemon(config) $gmail = self.start(config) DRb.start_service(nil, $gmail) uri = DRb.uri puts "starting gmail service at #{uri}" uri end |
.start(config) ⇒ Object
576 577 578 579 580 |
# File 'lib/vmail/imap_client.rb', line 576 def self.start(config) imap_client = Vmail::ImapClient.new config imap_client.open imap_client end |
Instance Method Details
#add_more_message_line(res, uids) ⇒ Object
238 239 240 241 242 243 244 245 246 |
# File 'lib/vmail/imap_client.rb', line 238 def (res, uids) return res if uids.empty? start_index = @all_uids.index(uids[0]) if start_index > 0 remaining = start_index res = "> Load #{[100, remaining].min} more messages. #{remaining} remaining.\n" + res end res end |
#address_to_string(x) ⇒ Object
411 412 413 |
# File 'lib/vmail/imap_client.rb', line 411 def address_to_string(x) x.name ? "#{x.name} <#{x.mailbox}@#{x.host}>" : "#{x.mailbox}@#{x.host}" end |
#append_to_file(file, uid_set) ⇒ Object
353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/vmail/imap_client.rb', line 353 def append_to_file(file, uid_set) if uid_set.is_a?(String) uid_set = uid_set.split(",").map(&:to_i) end log "append messages to file: #{file}" uid_set.each do |uid| = (uid) divider = "#{'=' * 39}\n" File.open(file, 'a') {|f| f.puts(divider + + "\n\n")} log "appended uid #{uid}" end "printed #{uid_set.size} message#{uid_set.size == 1 ? '' : 's'} to #{file.strip}" end |
#close ⇒ Object
38 39 40 41 42 |
# File 'lib/vmail/imap_client.rb', line 38 def close log "closing connection" @imap.close rescue Net::IMAP::BadResponseError @imap.disconnect end |
#copy_to(uid_set, mailbox) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/vmail/imap_client.rb', line 331 def copy_to(uid_set, mailbox) if MailboxAliases[mailbox] mailbox = MailboxAliases[mailbox] end create_if_necessary mailbox log "copy #{uid_set.inspect} #{mailbox}" if uid_set.is_a?(String) uid_set = uid_set.split(",").map(&:to_i) end log @imap.uid_copy(uid_set, mailbox) end |
#create_if_necessary(mailbox) ⇒ Object
343 344 345 346 347 348 349 350 351 |
# File 'lib/vmail/imap_client.rb', line 343 def create_if_necessary(mailbox) current_mailboxes = mailboxes.map {|m| MailboxAliases[m] || m} if !current_mailboxes.include?(mailbox) log "current mailboxes: #{current_mailboxes.inspect}" log "creating mailbox #{mailbox}" log @imap.create(mailbox) mailboxes = nil # force reload next fime list_mailboxes() called end end |
#deliver(text) ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/vmail/imap_client.rb', line 427 def deliver(text) # parse the text. The headers are yaml. The rest is text body. require 'net/smtp' reconnect_if_necessary(4) do # this is just to prime the IMAP connection # It's necessary for some reason. log "priming connection for delivering" res = @imap.uid_fetch(@all_uids[-1], ["ENVELOPE"]) if res.nil? raise IOError, "IMAP connection seems broken" end end mail = new_mail_from_input(text) mail.delivery_method(*smtp_settings) log mail.deliver! "message '#{mail.subject}' sent" end |
#fetch_headers(uid_set) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vmail/imap_client.rb', line 86 def fetch_headers(uid_set) if uid_set.is_a?(String) uid_set = uid_set.split(",").map(&:to_i) elsif uid_set.is_a?(Integer) uid_set = [uid_set] end max_uid = uid_set.max log "fetch headers for #{uid_set.inspect}" if uid_set.empty? log "empty set" return "" end results = reconnect_if_necessary do @imap.uid_fetch(uid_set, ["FLAGS", "ENVELOPE", "RFC822.SIZE" ]) end log "extracting headers" lines = results. sort_by {|x| begin Time.parse(x.attr['ENVELOPE'].date) rescue ArgumentError Time.now end }. map {|x| format_header(x, max_uid)} log "returning result" return lines.join("\n") end |
#flag(uid_set, action, flg) ⇒ Object
uid_set is a string comming from the vim client action is -FLAGS or +FLAGS
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/vmail/imap_client.rb', line 288 def flag(uid_set, action, flg) if uid_set.is_a?(String) uid_set = uid_set.split(",").map(&:to_i) end # #<struct Net::IMAP::FetchData seqno=17423, attr={"FLAGS"=>[:Seen, "Flagged"], "UID"=>83113}> log "flag #{uid_set} #{flg} #{action}" if flg == 'Deleted' # for delete, do in a separate thread because deletions are slow Thread.new do unless @mailbox == '[Gmail]/Trash' @imap.uid_copy(uid_set, "[Gmail]/Trash") end res = @imap.uid_store(uid_set, action, [flg.to_sym]) end uid_set.each { |uid| @all_uids.delete(uid) } elsif flg == '[Gmail]/Spam' @imap.uid_copy(uid_set, "[Gmail]/Spam") res = @imap.uid_store(uid_set, action, [:Deleted]) "#{uid} deleted" else log "Flagging" res = @imap.uid_store(uid_set, action, [flg.to_sym]) # log res.inspect fetch_headers(uid_set) end end |
#format_flags(flags) ⇒ Object
flags is an array like [:Flagged, :Seen]
183 184 185 186 187 188 189 |
# File 'lib/vmail/imap_client.rb', line 183 def format_flags(flags) flags = flags.map {|flag| FLAGMAP[flag] || flag} if flags.delete(:Seen).nil? flags << '[+]' # unread end flags.join('') end |
#format_header(fetch_data, max_uid = nil) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vmail/imap_client.rb', line 115 def format_header(fetch_data, max_uid=nil) uid = fetch_data.attr["UID"] envelope = fetch_data.attr["ENVELOPE"] size = fetch_data.attr["RFC822.SIZE"] flags = fetch_data.attr["FLAGS"] address_struct = if @mailbox == '[Gmail]/Sent Mail' structs = envelope.to || envelope.cc structs.nil? ? nil : structs.first else envelope.from.first end address = if address_struct.nil? "unknown" elsif address_struct.name "#{Mail::Encodings.unquote_and_convert_to(address_struct.name, 'UTF-8')} <#{[address_struct.mailbox, address_struct.host].join('@')}>" else [Mail::Encodings.unquote_and_convert_to(address_struct.mailbox, 'UTF-8'), Mail::Encodings.unquote_and_convert_to(address_struct.host, 'UTF-8')].join('@') end if @mailbox == '[Gmail]/Sent Mail' && envelope.to && envelope.cc total_recips = (envelope.to + envelope.cc).size address += " + #{total_recips - 1}" end date = begin Time.parse(envelope.date).localtime rescue ArgumentError Time.now end date_formatted = if date.year != Time.now.year date.strftime "%b %d %Y" rescue envelope.date.to_s else date.strftime "%b %d %I:%M%P" rescue envelope.date.to_s end subject = envelope.subject || '' subject = Mail::Encodings.unquote_and_convert_to(subject, 'UTF-8') flags = format_flags(flags) first_col_width = max_uid.to_s.length mid_width = @width - (first_col_width + 33) address_col_width = (mid_width * 0.3).ceil subject_col_width = (mid_width * 0.7).floor [uid.to_s.col(first_col_width), (date_formatted || '').col(14), address.col(address_col_width), subject.col(subject_col_width), number_to_human_size(size).rcol(6), flags.rcol(7)].join(' ') rescue "#{uid.to_s} : error extracting this header" end |
#format_headers(hash) ⇒ Object
376 377 378 379 380 381 382 383 384 385 |
# File 'lib/vmail/imap_client.rb', line 376 def format_headers(hash) lines = [] hash.each_pair do |key, value| if value.is_a?(Array) value = value.join(", ") end lines << "#{key.gsub("_", '-')}: #{value}" end lines.join("\n") end |
#format_parts_info(parts) ⇒ Object
279 280 281 282 283 284 |
# File 'lib/vmail/imap_client.rb', line 279 def format_parts_info(parts) lines = parts.select {|part| part !~ %r{text/plain}} if lines.size > 0 "\n#{lines.join("\n")}" end end |
#forward_template(uid) ⇒ Object
420 421 422 423 424 425 |
# File 'lib/vmail/imap_client.rb', line 420 def forward_template(uid) original_body = (uid, false, true) + "\n---------- Forwarded message ----------\n" + original_body + signature end |
#handle_error(error) ⇒ Object
558 559 560 |
# File 'lib/vmail/imap_client.rb', line 558 def handle_error(error) log error end |
#list_mailboxes ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/vmail/imap_client.rb', line 68 def list_mailboxes @mailboxes ||= (@imap.list("[Gmail]/", "%") + @imap.list("", "%")). select {|struct| struct.attr.none? {|a| a == :Noselect} }. map {|struct| struct.name}. map {|name| MailboxAliases.invert[name] || name} @mailboxes.delete("INBOX") @mailboxes.unshift("INBOX") @mailboxes.join("\n") end |
#log(string) ⇒ Object
554 555 556 |
# File 'lib/vmail/imap_client.rb', line 554 def log(string) @logger.debug string end |
#mailboxes ⇒ Object
called internally, not by vim client
79 80 81 82 83 84 |
# File 'lib/vmail/imap_client.rb', line 79 def mailboxes if @mailboxes.nil? list_mailboxes end @mailboxes end |
#more_messages(uid, limit = 100) ⇒ Object
gets 100 messages prior to uid
229 230 231 232 233 234 235 236 |
# File 'lib/vmail/imap_client.rb', line 229 def (uid, limit=100) uid = uid.to_i x = [(@all_uids.index(uid) - limit), 0].max y = [@all_uids.index(uid) - 1, 0].max uids = @all_uids[x..y] res = fetch_headers(uids) (res, uids) end |
#move_to(uid_set, mailbox) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/vmail/imap_client.rb', line 315 def move_to(uid_set, mailbox) if mailbox == 'all' log "archiving messages" end if MailboxAliases[mailbox] mailbox = MailboxAliases[mailbox] end create_if_necessary mailbox if uid_set.is_a?(String) uid_set = uid_set.split(",").map(&:to_i) end log "move_to #{uid_set.inspect} #{mailbox}" log @imap.uid_copy(uid_set, mailbox) log @imap.uid_store(uid_set, '+FLAGS', [:Deleted]) end |
#new_mail_from_input(text) ⇒ Object
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/vmail/imap_client.rb', line 462 def new_mail_from_input(text) require 'mail' mail = Mail.new raw_headers, raw_body = *text.split(/\n\s*\n/, 2) headers = {} raw_headers.split("\n").each do |line| key, value = *line.split(/:\s*/, 2) headers[key] = value end log "headers: #{headers.inspect}" log "delivering: #{headers.inspect}" mail.from = headers['from'] || @username mail.to = headers['to'] #.split(/,\s+/) mail.cc = headers['cc'] #&& headers['cc'].split(/,\s+/) mail.bcc = headers['bcc'] #&& headers['cc'].split(/,\s+/) mail.subject = headers['subject'] mail.from ||= @username # attachments are added as a snippet of YAML after a blank line # after the headers, and followed by a blank line if ( = raw_body.split(/\n\s*\n/, 2)[0]) =~ /^attach(ment|ments)*:/ # TODO files = YAML::load().values.flatten log "attach: #{files}" files.each do |file| if File.directory?(file) Dir.glob("#{file}/*").each {|f| mail.add_file(f) if File.size?(f)} else mail.add_file(file) if File.size?(file) end end mail.text_part do body raw_body.split(/\n\s*\n/, 2)[1] end else mail.text_part do body raw_body end end mail end |
#new_message_template ⇒ Object
368 369 370 371 372 373 374 |
# File 'lib/vmail/imap_client.rb', line 368 def headers = {'from' => "#{@name} <#{@username}>", 'to' => nil, 'subject' => nil } format_headers(headers) + "\n\n" + signature end |
#number_to_human_size(number) ⇒ Object
borrowed from ActionView/Helpers
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/vmail/imap_client.rb', line 168 def number_to_human_size(number) if number.to_i < 1024 "#{number} b" else max_exp = UNITS.size - 1 exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024 exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit number /= 1024 ** exponent unit = UNITS[exponent] "#{number} #{unit}" end end |
#open ⇒ Object
33 34 35 36 |
# File 'lib/vmail/imap_client.rb', line 33 def open @imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false) @imap.login(@username, @password) end |
#open_html_part(uid) ⇒ Object
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/vmail/imap_client.rb', line 521 def open_html_part(uid) log "open_html_part #{uid}" log @current_mail.parts.inspect multipart = @current_mail.parts.detect {|part| part.multipart?} html_part = if multipart multipart.parts.detect {|part| part.header["Content-Type"].to_s =~ /text\/html/} elsif ! @current_mail.parts.empty? @current_mail.parts.detect {|part| part.header["Content-Type"].to_s =~ /text\/html/} else @current_mail.body end return if html_part.nil? outfile = 'vmail-htmlpart.html' File.open(outfile, 'w') {|f| f.puts(html_part.decoded)} # client should handle opening the html file return outfile end |
#reconnect_if_necessary(timeout = 60, &block) ⇒ Object
562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/vmail/imap_client.rb', line 562 def reconnect_if_necessary(timeout = 60, &block) # if this times out, we know the connection is stale while the user is # trying to update Timeout::timeout(timeout) do block.call end rescue IOError, Errno::EADDRNOTAVAIL, Timeout::Error log "error: #{$!}" log "attempting to reconnect" log(revive_connection) # try just once block.call end |
#reply_template(uid, replyall = false) ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/vmail/imap_client.rb', line 387 def reply_template(uid, replyall=false) log "sending reply template for #{uid}" fetch_data = @imap.uid_fetch(uid.to_i, ["FLAGS", "ENVELOPE", "RFC822"])[0] envelope = fetch_data.attr['ENVELOPE'] recipient = [envelope.reply_to, envelope.from].flatten.map {|x| address_to_string(x)}[0] cc = [envelope.to, envelope.cc] cc = cc.flatten.compact. select {|x| @username !~ /#{x.mailbox}@#{x.host}/}. map {|x| address_to_string(x)}.join(", ") mail = Mail.new fetch_data.attr['RFC822'] formatter = Vmail::MessageFormatter.new(mail) headers = formatter.extract_headers subject = headers['subject'] if subject !~ /Re: / subject = "Re: #{subject}" end cc = replyall ? cc : nil date = headers['date'].is_a?(String) ? Time.parse(headers['date']) : headers['date'] quote_header = "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{address_to_string(envelope.from[0])} wrote:\n\n" body = quote_header + formatter.process_body.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ") reply_headers = { 'from' => "#@name <#@username>", 'to' => recipient, 'cc' => cc, 'subject' => subject} format_headers(reply_headers) + "\n\n\n" + body + signature end |
#resume_draft ⇒ Object
TODO
455 456 457 458 459 460 |
# File 'lib/vmail/imap_client.rb', line 455 def resume_draft # chop off top three lines (this is hackey, fix later) # text = text.split("\n")[3..-1].join("\n") # delete date: field # text = text.sub("^date:\s*$", "") end |
#revive_connection ⇒ Object
61 62 63 64 65 66 |
# File 'lib/vmail/imap_client.rb', line 61 def revive_connection log "reviving connection" open log "reselecting mailbox #@mailbox" @imap.select(@mailbox) end |
#save_attachments(dir) ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/vmail/imap_client.rb', line 504 def (dir) log "save_attachments #{dir}" if !@current_mail log "missing a current message" end return unless dir && @current_mail = @current_mail. `mkdir -p #{dir}` saved = .map do |x| path = File.join(dir, x.filename) log "saving #{path}" File.open(path, 'wb') {|f| f.puts x.decoded} path end "saved:\n" + saved.map {|x| "- #{x}"}.join("\n") end |
#save_draft(text) ⇒ Object
445 446 447 448 449 450 451 452 |
# File 'lib/vmail/imap_client.rb', line 445 def save_draft(text) mail = new_mail_from_input(text) log "saving draft" reconnect_if_necessary do log "saving draft" log @imap.append("[Gmail]/Drafts", text.gsub(/\n/, "\r\n"), [:Seen], Time.now) end end |
#search(limit, *query) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/vmail/imap_client.rb', line 191 def search(limit, *query) log "uid_search limit: #{limit} query: #{@query.inspect}" limit = 25 if limit.to_s !~ /^\d+$/ query = ['ALL'] if query.empty? @query = query.join(' ') log "uid_search #@query #{limit}" @all_uids = reconnect_if_necessary do @imap.uid_search(@query) end uids = @all_uids[-([limit.to_i, @all_uids.size].min)..-1] || [] res = fetch_headers(uids) (res, uids) end |
#select_mailbox(mailbox) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vmail/imap_client.rb', line 44 def select_mailbox(mailbox) if MailboxAliases[mailbox] mailbox = MailboxAliases[mailbox] end if mailbox == @mailbox return end log "selecting mailbox #{mailbox.inspect}" reconnect_if_necessary do log @imap.select(mailbox) end @mailbox = mailbox @all_uids = [] @bad_uids = [] return "OK" end |
#show_message(uid, raw = false, forwarded = false) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/vmail/imap_client.rb', line 248 def (uid, raw=false, forwarded=false) uid = uid.to_i if forwarded return @current_message.split(/\n-{20,}\n/, 2)[1] end return @current_mail.to_s if raw return @current_message if uid == @current_uid log "fetching #{uid.inspect}" fetch_data = reconnect_if_necessary do @imap.uid_fetch(uid, ["FLAGS", "RFC822", "RFC822.SIZE"])[0] end res = fetch_data.attr["RFC822"] mail = Mail.new(res) @current_uid = uid @current_mail = mail # used later to show raw message or extract attachments if any log "saving current mail with parts: #{@current_mail.parts.inspect}" formatter = Vmail::MessageFormatter.new(mail) out = formatter.process_body size = fetch_data.attr["RFC822.SIZE"] @current_message = <<-EOF #{@mailbox} #{uid} #{number_to_human_size size} #{format_parts_info(formatter.list_parts)} --------------------------------------- #{format_headers(formatter.extract_headers)} #{out} EOF rescue log "parsing error" "Error encountered parsing this message:\n#{$!}" end |
#signature ⇒ Object
415 416 417 418 |
# File 'lib/vmail/imap_client.rb', line 415 def signature return '' unless @signature "\n\n#@signature" end |
#smtp_settings ⇒ Object
544 545 546 547 548 549 550 551 552 |
# File 'lib/vmail/imap_client.rb', line 544 def smtp_settings [:smtp, {:address => "smtp.gmail.com", :port => 587, :domain => 'gmail.com', :user_name => @username, :password => @password, :authentication => 'plain', :enable_starttls_auto => true}] end |
#update ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/vmail/imap_client.rb', line 205 def update reconnect_if_necessary(4) do # this is just to prime the IMAP connection # It's necessary for some reason. log "priming connection for update" res = @imap.uid_fetch(@all_uids[-1], ["ENVELOPE"]) if res.nil? raise IOError, "IMAP connection seems broken" end end uids = reconnect_if_necessary { log "uid_search #@query" @imap.uid_search(@query) } new_uids = uids - @all_uids log "UPDATE: NEW UIDS: #{new_uids.inspect}" if !new_uids.empty? res = fetch_headers(new_uids) @all_uids = uids res end end |
#window_width=(width) ⇒ Object
539 540 541 542 |
# File 'lib/vmail/imap_client.rb', line 539 def window_width=(width) log "setting window width to #{width}" @width = width.to_i end |