Project

General

Profile

« Previous | Next » 

Revision 29da2972

Added by Marc Dequènes over 14 years ago

  • ID 29da2972f07c8f6087cd862929332fcf13626c85

[evol] reorganize TMail extra methods

View differences:

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
lib/cyborghood/mail.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 'delegate'
require 'tmail'
require 'tmail_gpg'
require 'action_mailer/quoting'
require 'action_mailer/utils'
require 'net/smtp'
require 'fileutils'
require 'digest/md5'
......
end
class Mail < Delegator
include ActionMailer::Quoting
include ActionMailer::Utils
include I18nTranslation
DEFAULT_MAX_DRIFT_TIME = 3600
......
elsif msg.is_a? TMail::Mail
@mail = msg
else
# unquote headers and transform into TMail object
@mail = TMail::Mail.parse(msg)
end
end
......
@mail
end
def self.header_value_pretty(v)
TMail::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"].each do |h|
class_eval <<-EOF
def #{h}_addrs_pretty
@mail.#{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
def process
if is_marked?
return MailReport.new(:error => _("Replay detected."))
......
def create_reply
tmail_reply = @mail.create_reply
tmail_reply.from_addrs = TMail::Address.parse(@config.mail.from_address || self.to.first)
tmail_reply.to_addrs = (@mail.reply_to_addrs || @mail.from_addrs).collect do |a|
address = TMail::Unquoter.unquote_and_convert_to(a.to_s, "UTF-8")
quoted_address = quote_address_if_necessary(address, "UTF-8")
TMail::Address.parse(quoted_address)
tmail_reply.to_addrs = (@mail.reply_to_addrs_pretty || @mail.from_addrs_pretty).collect do |a|
TMail::Address.parse(@mail.class.header_value_smtp(a))
end
p tmail_reply.to_addrs
reply = self.class.new(tmail_reply.to_s)
reply.set_custom_headers
reply.user = self.user
......
def check_headers
@mail.header.keys.each do |h|
@mail[h] = quote_address_if_necessary(@mail[h].to_s, "utf-8")
@mail[h] = @mail.class.quote_address_if_necessary(@mail[h].to_s, "utf-8")
end
end
......
crypt(fingerprint)
end
def quoted_printable_body=(txt)
@mail.transfer_encoding = "quoted-printable"
@mail.body = [normalize_new_lines(txt)].pack("M")
end
private
def process_signed

Also available in: Unified diff