Module: Vmail

Extended by:
Vmail
Included in:
Vmail
Defined in:
lib/vmail.rb,
lib/vmail/query.rb,
lib/vmail/sender.rb,
lib/vmail/helpers.rb,
lib/vmail/options.rb,
lib/vmail/version.rb,
lib/vmail/database.rb,
lib/vmail/searching.rb,
lib/vmail/imap_client.rb,
lib/vmail/send_options.rb,
lib/vmail/address_quoter.rb,
lib/vmail/showing_headers.rb,
lib/vmail/showing_message.rb,
lib/vmail/reply_templating.rb,
lib/vmail/message_formatter.rb,
lib/vmail/contacts_extractor.rb,
lib/vmail/flagging_and_moving.rb

Defined Under Namespace

Modules: AddressQuoter, FlaggingAndMoving, Helpers, ReplyTemplating, Searching, Sender, ShowingHeaders, ShowingMessage Classes: ContactsExtractor, ImapClient, Label, Labeling, Message, MessageFormatter, Options, Query, SendOptions

Constant Summary collapse

DIVIDER_WIDTH =
46
UNITS =
[:b, :k, :M, :G].freeze
INSTRUCTIONS =
<<-EOF
Please visit http://danielchoi.com/software/vmail.html for instructions
on how to configure and run vmail.

EOF
VERSION =
'2.2.5'

Instance Method Summary collapse

Instance Method Details

#startObject



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
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vmail.rb', line 11

def start
  puts "Starting vmail #{Vmail::VERSION}"
  if  "1.9.0" > RUBY_VERSION
    puts "This version of vmail requires Ruby version 1.9.0 or higher (1.9.2 is recommended)"
    exit
  end

  vim = ENV['VMAIL_VIM'] || 'vim'
  ENV['VMAIL_BROWSER'] ||= if RUBY_PLATFORM.downcase.include?('linux') 
                             tools = ['gnome-open', 'kfmclient-exec', 'konqueror']
                             tool = tools.detect { |tool|
                               `which #{tool}`.size > 0
                             }
                             if tool.nil?
                               puts "Can't find a VMAIL_BROWSER tool on your system. Please report this issue."
                             else
                               tool
                             end
                           else
                             'open'
                           end

  puts "Setting VMAIL_BROWSER to '#{ENV['VMAIL_BROWSER']}'"
  check_lynx

  opts = Vmail::Options.new(ARGV)
  opts.config
  config = opts.config

  contacts_file = opts.contacts_file

  logfile = (vim == 'mvim' || vim == 'gvim') ? 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}" 
  STDERR.puts "Query String: #{String.shellescape(query_string)}"
  
  buffer_file = "vmailbuffer"
  # invoke vim
  vimscript = File.expand_path("../vmail.vim", __FILE__)
  vim_command = "DRB_URI=#{drb_uri} VMAIL_CONTACTS_FILE=#{contacts_file} VMAIL_MAILBOX=#{String.shellescape(mailbox)} VMAIL_QUERY=\"#{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 "\n\nVmail #{Vmail::VERSION}\n\n"
    file.puts "Please wait while I fetch your messages.\n\n\n"
  end

  system(vim_command)

  if vim == 'mvim' || vim == 'gvim'
    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