# File lib/sup/modes/edit-message-mode.rb, line 344
  def build_message date
    m = RMail::Message.new
    m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
    m.body = @body.join("\n")
    m.body += sig_lines.join("\n") unless $config[:edit_signature]
    ## body must end in a newline or GPG signatures will be WRONG!
    m.body += "\n" unless m.body =~ /\n\Z/

    ## there are attachments, so wrap body in an attachment of its own
    unless @attachments.empty?
      body_m = m
      body_m.header["Content-Disposition"] = "inline"
      m = RMail::Message.new
      
      m.add_part body_m
      @attachments.each { |a| m.add_part a }
    end

    ## do whatever crypto transformation is necessary
    if @crypto_selector && @crypto_selector.val != :none
      from_email = Person.from_address(@header["From"]).email
      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| Person.from_address(p).email }

      m = CryptoManager.send @crypto_selector.val, from_email, to_email, m
    end

    ## finally, set the top-level headers
    @header.each do |k, v|
      next if v.nil? || v.empty?
      m.header[k] = 
        case v
        when String
          k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)
        when Array
          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