]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/edit-message-mode.rb
Merge branch 'hook-local-vars'
[sup] / lib / sup / modes / edit-message-mode.rb
index d7bd41c692f55a7fe7f23f0ebb608e506f938f06..8da316fe00593f8085adb167e0200b5a6c650d07 100644 (file)
@@ -2,7 +2,10 @@ 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
 
@@ -70,7 +73,14 @@ EOS
       @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
@@ -181,7 +191,7 @@ protected
   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
 
@@ -190,7 +200,7 @@ protected
   # 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
 
@@ -315,7 +325,7 @@ protected
       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