X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup.rb;h=910b333841c28654d2abee3d95d0b83194ad7fbc;hb=9ee2844486c7e826117418b9f94da07aaa144da4;hp=60679ee882757c517eaa1223ae1bc824f1b70e80;hpb=f8989bae2cf6126690b2bcb978e1950021c3cb41;p=sup diff --git a/lib/sup.rb b/lib/sup.rb index 60679ee..910b333 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -3,6 +3,7 @@ require 'yaml' require 'zlib' require 'thread' require 'fileutils' +require 'gettext' require 'curses' class Object @@ -32,7 +33,7 @@ class Module end module Redwood - VERSION = "0.3" + VERSION = "0.5" BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup") CONFIG_FN = File.join(BASE_DIR, "config.yaml") @@ -49,16 +50,6 @@ module Redwood YAML_DOMAIN = "masanjin.net" YAML_DATE = "2006-10-01" -## determine encoding and character set -## probably a better way to do this - $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8" - $encoding = - if $ctype =~ /\.(.*)?/ - $1 - else - "utf-8" - end - ## record exceptions thrown in threads nicely def reporting_thread name if $opts[:no_threads] @@ -81,7 +72,7 @@ module Redwood def save_yaml_obj object, fn, safe=false if safe safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}" - mode = File.stat(fn) if File.exists? fn + mode = File.stat(fn).mode if File.exists? fn File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml } FileUtils.mv safe_fn, fn else @@ -178,7 +169,8 @@ if File.exists? Redwood::CONFIG_FN else require 'etc' require 'socket' - name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first + name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first rescue nil + name ||= ENV["USER"] email = ENV["USER"] + "@" + begin Socket.gethostbyname(Socket.gethostname).first @@ -204,6 +196,7 @@ else :ask_for_subject => true, :confirm_no_attachments => true, :confirm_top_posting => true, + :discard_snippets_from_encrypted_messages => false, } begin FileUtils.mkdir_p Redwood::BASE_DIR @@ -234,6 +227,15 @@ module Redwood module_function :log end +## determine encoding and character set + $encoding = Locale.current.charset + if $encoding + Redwood::log "using character set encoding #{$encoding.inspect}" + else + Redwood::log "warning: can't find character set by using locale, defaulting to utf-8" + $encoding = "utf-8" + end + ## now everything else (which can feel free to call Redwood::log at load time) require "sup/update" require "sup/suicide"