require 'pathname'
require 'rmail'
+# 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
@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
if CryptoManager.have_crypto?
HorizontalSelector.new "Crypto:", [:none] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.keys, ["None"] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.values
end
- add_selector @crypto_selector if @crypto_selector
+ if @crypto_selector
+ if !$config[:crypto_default].nil?
+ @crypto_selector.set_to $config[:crypto_default]
+ end
+ add_selector @crypto_selector
+ end
HookManager.run "before-edit", :header => @header, :body => @body
protected
+ def mime_encode string
+ string = [string].pack('M') # basic quoted-printable
+ string.gsub!(/=\n/,'') # .. remove trailing newline
+ string.gsub!(/_/,'=96') # .. encode underscores
+ string.gsub!(/\?/,'=3F') # .. encode question marks
+ string.gsub!(/ /,'_') # .. translate space to underscores
+ "=?utf-8?q?#{string}?="
+ end
+
+ def mime_encode_subject string
+ 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(RE_UTF8)
+ string.sub(RE_ADDRESS) { |match| mime_encode($1) + $2 }
+ end
+
def move_cursor_left
if curpos < @selectors.length
@selectors[curpos].roll_left
if i == 0
header + " " + name
else
- (" " * (header.length + 1)) + name
+ (" " * (header.display_length + 1)) + name
end + (i == things.length - 1 ? "" : ",")
end
end
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
m.header[k] =
case v
when String
- v
+ k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)
when Array
- v.join ", "
+ v.map { |v| mime_encode_address v }.join ", "
end
end
+
m.header["Date"] = date.rfc2822
m.header["Message-Id"] = @message_id
m.header["User-Agent"] = "Sup/#{Redwood::VERSION}"
+ m.header["Content-Transfer-Encoding"] = '8bit'
m
end