Module: Vmail
- Extended by:
- Vmail
- Included in:
- Vmail
- Defined in:
- lib/vmail.rb,
lib/vmail/query.rb,
lib/vmail/sender.rb,
lib/vmail/options.rb,
lib/vmail/version.rb,
lib/vmail/imap_client.rb,
lib/vmail/send_options.rb,
lib/vmail/reply_template.rb,
lib/vmail/message_formatter.rb,
lib/vmail/contacts_extractor.rb
Defined Under Namespace
Modules: Sender Classes: ContactsExtractor, ImapClient, MessageFormatter, Options, Query, ReplyTemplate, SendOptions
Constant Summary collapse
- INSTRUCTIONS =
<<-EOF Please visit http://danielchoi.com/software/vmail.html for instructions on how to configure and run vmail. EOF
- VERSION =
"1.3.0"
Instance Method Summary collapse
-
#batch_run ⇒ Object
batch processing mode.
-
#noninteractive_list_messages ⇒ Object
non-interactive mode.
- #start ⇒ Object
Instance Method Details
#batch_run ⇒ Object
batch processing mode
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vmail.rb', line 98 def batch_run check_lynx opts = Vmail::Options.new(ARGV) opts.config config = opts.config.merge 'logfile' => 'vmail.log' # no search query args, but command args imap_client = Vmail::ImapClient.new config lines = STDIN.readlines# .reverse mailbox = lines.shift.chomp puts "mailbox: #{mailbox}" uid_set = lines.map do |line| line[/(\d+)\s*$/,1].to_i end commands = { 'rm' => ["flag", "+FLAGS", "Deleted"], 'spam' => ["flag", "+FLAGS", "spam"], 'mv' => ["move_to"], 'cp' => ["copy_to"], 'print' => ["append_to_file"] } args = commands[ARGV.first] if args.nil? abort "command '#{args.inspect}' not recognized" end command = args.shift imap_client.with_open do |vmail| puts "selecting mailbox: #{mailbox}" vmail.select_mailbox mailbox uid_set.each_slice(5) do |uid_set| params = [uid_set.join(',')] + args + ARGV[1..-1] puts "executing: #{command} #{params.join(' ')}" vmail.send command, *params end end end |
#noninteractive_list_messages ⇒ Object
non-interactive mode
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vmail.rb', line 83 def check_lynx opts = Vmail::Options.new(ARGV) opts.config config = opts.config.merge 'logfile' => 'vmail.log' mailbox, query = parse_query query_string = Vmail::Query.args2string query imap_client = Vmail::ImapClient.new config imap_client.with_open do |vmail| vmail.select_mailbox mailbox vmail.search query_string end end |
#start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vmail.rb', line 11 def start puts "starting vmail #{Vmail::VERSION}" vim = ENV['VMAIL_VIM'] || 'vim' ENV['VMAIL_BROWSER'] ||= 'open' check_lynx opts = Vmail::Options.new(ARGV) opts.config config = opts.config contacts_file = opts.contacts_file logfile = (vim == 'mvim') ? STDERR : 'vmail.log' config.merge! 'logfile' => logfile puts "starting vmail imap client for #{config['username']}" drb_uri = begin Vmail::ImapClient.daemon config rescue puts "Failure:", $! exit(1) end server = DRbObject.new_with_uri drb_uri mailbox, query = parse_query query_string = Vmail::Query.args2string query server.select_mailbox mailbox STDERR.puts "mailbox: #{mailbox}" STDERR.puts "query: #{query.inspect} => #{query_string}" buffer_file = "vmailbuffer" # invoke vim vimscript = File.("../vmail.vim", __FILE__) vim_command = "DRB_URI=#{drb_uri} VMAIL_CONTACTS_FILE=#{contacts_file} VMAIL_MAILBOX=#{String.shellescape(mailbox)} VMAIL_QUERY=#{String.shellescape(query_string)} #{vim} -S #{vimscript} #{buffer_file}" STDERR.puts vim_command STDERR.puts "using buffer file: #{buffer_file}" File.open(buffer_file, "w") do |file| file.puts "vmail starting with values:" file.puts "- drb uri: #{drb_uri}" file.puts "- mailbox: #{mailbox}" file.puts "- query: #{query_string}" file.puts file.puts "fetching messages. please wait..." end system(vim_command) if vim == 'mvim' DRb.thread.join end File.delete(buffer_file) STDERR.puts "closing imap connection" begin Timeout::timeout(10) do $gmail.close end rescue Timeout::Error puts "close connection attempt timed out" end puts "bye" exit end |