Method: Redwood.load_config

Defined in:
lib/sup.rb

.load_config(filename) ⇒ Object

set up default configuration file



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/sup.rb', line 316

def load_config filename
  default_config = {
    :editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
    :thread_by_subject => false,
    :edit_signature => false,
    :ask_for_from => false,
    :ask_for_to => true,
    :ask_for_cc => true,
    :ask_for_bcc => false,
    :ask_for_subject => true,
    :account_selector => true,
    :confirm_no_attachments => true,
    :confirm_top_posting => true,
    :jump_to_open_message => true,
    :discard_snippets_from_encrypted_messages => false,
    :load_more_threads_when_scrolling => true,
    :default_attachment_save_dir => "",
    :sent_source => "sup://sent",
    :archive_sent => true,
    :poll_interval => 300,
    :wrap_width => 0,
    :slip_rows => 0,
    :indent_spaces => 2,
    :col_jump => 2,
    :stem_language => "english",
    :sync_back_to_maildir => false,
    :continuous_scroll => false,
    :always_edit_async => false,
  }
  if File.exist? filename
    config = Redwood::load_yaml_obj filename
    abort "#{filename} is not a valid configuration file (it's a #{config.class}, not a hash)" unless config.is_a?(Hash)
    default_config.merge config
  else
    require 'etc'
    require 'socket'
    name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first.force_encoding($encoding).fix_encoding! rescue nil
    name ||= ENV["USER"]
    email = ENV["USER"] + "@" +
      begin
        Addrinfo.getaddrinfo(Socket.gethostname, 'smtp').first.getnameinfo.first
      rescue SocketError
        Socket.gethostname
      end

    config = {
      :accounts => {
        :default => {
          :name => name.dup.fix_encoding!,
          :email => email.dup.fix_encoding!,
          :alternates => [],
          :sendmail => "/usr/sbin/sendmail -oem -ti",
          :signature => File.join(ENV["HOME"], ".signature"),
          :gpgkey => ""
        }
      },
    }
    config.merge! default_config
    begin
      Redwood::save_yaml_obj config, filename, false, true
    rescue StandardError => e
      $stderr.puts "warning: #{e.message}"
    end
    config
  end
end