Revision 29da2972
Added by Marc Dequènes almost 14 years ago
- ID 29da2972f07c8f6087cd862929332fcf13626c85
lib/cyborghood/base/lang_additions.rb | ||
---|---|---|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
#++
|
||
|
||
# add Rails load path for Debian, until rails framework is split properly
|
||
DEB_RAILS_PATH = "/usr/share/rails" unless Object.constants.include?("DEB_RAILS_PATH")
|
||
Dir.new(DEB_RAILS_PATH).each do |file|
|
||
next if file =~ /^\./
|
||
path = File.join(DEB_RAILS_PATH, file, "lib")
|
||
$: << path if File.directory?(path)
|
||
end
|
||
|
||
require 'ostruct'
|
||
|
||
class Hash
|
||
... | ... | |
|
||
# WARNING: the TMail send_to() method is _unsuable_, even with the following fixes
|
||
require 'tmail'
|
||
require 'action_mailer/quoting'
|
||
require 'action_mailer/utils'
|
||
module TMail
|
||
class Mail
|
||
extend ActionMailer::Quoting
|
||
include ActionMailer::Utils
|
||
|
||
# fix method using obsoleted from_address() method
|
||
def do_send_to( smtp )
|
||
from = from_addrs or raise ArgumentError, 'no from address'
|
||
... | ... | |
end
|
||
end
|
||
|
||
# extra methods
|
||
|
||
def quoted_printable_body=(txt)
|
||
self.transfer_encoding = "quoted-printable"
|
||
self.body = [normalize_new_lines(txt)].pack("M")
|
||
end
|
||
|
||
def self.header_value_pretty(v)
|
||
Unquoter.unquote_and_convert_to(v.to_s, "UTF-8")
|
||
end
|
||
|
||
def self.header_value_smtp(v)
|
||
quote_address_if_necessary(v, "UTF-8")
|
||
end
|
||
|
||
["from", "to", "cc", "bcc", "reply_to"].each do |h|
|
||
class_eval <<-EOF
|
||
def #{h}_addrs_pretty
|
||
return nil if self.#{h}_addrs.nil?
|
||
self.#{h}_addrs.collect do |a|
|
||
self.class.header_value_pretty(a)
|
||
end
|
||
end
|
||
|
||
def #{h}_pretty
|
||
(self.#{h}_addrs_pretty || []).join(", ")
|
||
end
|
||
EOF
|
||
end
|
||
|
||
def subject_pretty
|
||
self.class.header_value_pretty(self.subject)
|
||
end
|
||
end
|
||
|
||
private
|
||
|
||
# reuse current boundary if already exist, not to break signed parts
|
||
... | ... | |
strategy.write epilogue()
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] reorganize TMail extra methods