lib/sup/modes/edit-message-mode.rb in sup-0.8.1 vs lib/sup/modes/edit-message-mode.rb in sup-0.9
- old
+ new
@@ -1,11 +1,14 @@
require 'tempfile'
require 'socket' # just for gethostname!
require 'pathname'
require 'rmail'
-require 'jcode' # for RE_UTF8
+# from jcode.rb, not included in ruby 1.9
+PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
+RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')
+
module Redwood
class SendmailCommandFailed < StandardError; end
class EditMessageMode < LineCursorMode
@@ -68,11 +71,18 @@
else
@attachments = []
@attachment_names = []
end
- @message_id = "<#{Time.now.to_i}-sup-#{rand 10000}@#{Socket.gethostname}>"
+ begin
+ hostname = File.open("/etc/mailname", "r").gets.chomp
+ rescue
+ nil
+ end
+ hostname = Socket.gethostname if hostname.nil? or hostname.empty?
+
+ @message_id = "<#{Time.now.to_i}-sup-#{rand 10000}@#{hostname}>"
@edited = false
@selectors = []
@selector_label_width = 0
@crypto_selector =
@@ -179,20 +189,20 @@
string.gsub!(/ /,'_') # .. translate space to underscores
"=?utf-8?q?#{string}?="
end
def mime_encode_subject string
- return string unless string.match(String::RE_UTF8)
+ return string unless string.match(RE_UTF8)
mime_encode string
end
RE_ADDRESS = /(.+)( <.*@.*>)/
# Encode "bælammet mitt <user@example.com>" into
# "=?utf-8?q?b=C3=A6lammet_mitt?= <user@example.com>
def mime_encode_address string
- return string unless string.match(String::RE_UTF8)
+ return string unless string.match(RE_UTF8)
string.sub(RE_ADDRESS) { |match| mime_encode($1) + $2 }
end
def move_cursor_left
if curpos < @selectors.length
@@ -313,10 +323,10 @@
SentManager.write_sent_message(date, from_email) { |f| f.puts sanitize_body(m.to_s) }
BufferManager.kill_buffer buffer
BufferManager.flash "Message sent!"
true
rescue SystemCallError, SendmailCommandFailed, CryptoManager::Error => e
- Redwood::log "Problem sending mail: #{e.message}"
+ warn "Problem sending mail: #{e.message}"
BufferManager.flash "Problem sending mail: #{e.message}"
false
end
end