class Mail::Message
def reply(*args, &block)
def reply(*args, &block) self.class.new.tap do |reply| if message_id bracketed_message_id = "<#{message_id}>" reply.in_reply_to = bracketed_message_id if !references.nil? refs = [references].flatten.map { |r| "<#{r}>" } refs << bracketed_message_id reply.references = refs.join(' ') elsif !in_reply_to.nil? && !in_reply_to.kind_of?(Array) reply.references = "<#{in_reply_to}> #{bracketed_message_id}" end reply.references ||= bracketed_message_id end if subject reply.subject = subject =~ /^Re:/i ? subject : "Re: #{subject}" end if reply_to || from reply.to = self[reply_to ? :reply_to : :from].to_s end if to reply.from = self[:to].formatted.first.to_s end unless args.empty? if args.flatten.first.respond_to?(:each_pair) reply.send(:init_with_hash, args.flatten.first) else reply.send(:init_with_string, args.flatten[0].to_s.strip) end end if block_given? reply.instance_eval(&block) end end end