Skip to content

Commit

Permalink
Merge #120
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Aug 11, 2013
2 parents bfb9045 + 9b36d1c commit b424243
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bin/sup
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
Expand Down Expand Up @@ -416,7 +418,7 @@ unless Redwood::exceptions.empty?
We are very sorry. It seems that an error occurred in Sup. Please
accept our sincere apologies. Please submit the contents of
#{BASE_DIR}/exception-log.txt and a brief report of the
circumstances to https://github.com/sup-heliotrope/sup/issues so that
circumstances to https://github.com/sup-heliotrope/sup/issues so that
we might address this problem. Thank you!

Sincerely,
Expand Down
2 changes: 2 additions & 0 deletions lib/sup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'rubygems'
require 'yaml'
YAML::ENGINE.yamler = 'psych'
Expand Down
9 changes: 6 additions & 3 deletions lib/sup/buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'etc'
require 'thread'

Expand Down Expand Up @@ -466,7 +468,7 @@ def ask_many_with_completions domain, question, completions, default=nil

prefix.fix_encoding
target.fix_encoding
completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
completions.select { |x| x =~ /^#{Regexp::escape target}/iu }.map { |x| [prefix + x, x] }
end
end

Expand All @@ -479,7 +481,7 @@ def ask_many_emails_with_completions domain, question, completions, default=nil
prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
prefix.fix_encoding

completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
completions.select { |x| x =~ /^#{Regexp::escape target}/iu }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
end
end

Expand All @@ -492,7 +494,7 @@ def ask_for_filename domain, question, default=nil, allow_directory=false
if dir
[[s.sub(full, dir), "~#{name}"]]
else
users.select { |u| u =~ /^#{Regexp::escape name}/ }.map do |u|
users.select { |u| u =~ /^#{Regexp::escape name}/u }.map do |u|
[s.sub("~#{name}", "~#{u}"), "~#{u}"]
end
end
Expand Down Expand Up @@ -551,6 +553,7 @@ def ask_for_contacts domain, question, default_contacts=[]

completions = (recent + contacts).flatten.uniq
completions += HookManager.run("extra-contact-addresses") || []

answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default

if answer
Expand Down
4 changes: 3 additions & 1 deletion lib/sup/contact.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

module Redwood

class ContactManager
Expand Down Expand Up @@ -54,7 +56,7 @@ def person_for email; @e2p[email] end
def is_aliased_contact? person; !@p2a[person].nil? end

def save
File.open(@fn, "w") do |f|
File.open(@fn, "w:UTF-8") do |f|
@p2a.sort_by { |(p, a)| [p.full_address, a] }.each do |(p, a)|
f.puts "#{a || ''}: #{p.full_address}"
end
Expand Down
4 changes: 3 additions & 1 deletion lib/sup/label.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

module Redwood

class LabelManager
Expand Down Expand Up @@ -77,7 +79,7 @@ def delete t

def save
return unless @modified
File.open(@fn, "w") { |f| f.puts @labels.keys.sort_by { |l| l.to_s } }
File.open(@fn, "w:UTF-8") { |f| f.puts @labels.keys.sort_by { |l| l.to_s } }
@new_labels = {}
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sup/modes/compose_mode.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

module Redwood

class ComposeMode < EditMessageMode
Expand Down
9 changes: 9 additions & 0 deletions lib/sup/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ def wrap len
#
# Not Ruby 1.8 compatible
def fix_encoding
# first try to set the string to utf-8 and check if it is valid
# in case ruby just thinks it is something else
orig_encoding = encoding
force_encoding 'UTF-8'
return self if valid_encoding?

# that didn't work, go back to original and try to convert
force_encoding orig_encoding

encode!('UTF-8', :invalid => :replace, :undef => :replace)

# do this anyway in case string is set to be UTF-8, encoding to
Expand Down

0 comments on commit b424243

Please sign in to comment.