    # File lib/vmail/imap_client.rb, line 704
        def new_mail_from_input(text)
          require 'mail'
          mail = Mail.new
          raw_headers, raw_body = *text.split(/\n\s*\n/, 2)
          headers = {}
          raw_headers.split("\n").each do |line|
            key, value = *line.split(/:\s*/, 2)
            log [key, value].join(':')
            if %w(from to cc bcc).include?(key)
              value = quote_addresses(value)
            end
            headers[key] = value
          end
          log "Delivering message with headers: #{headers.to_yaml}"
          mail.from = headers['from'] || @username
          mail.to = headers['to'] #.split(/,\s+/)
          mail.cc = headers['cc'] #&& headers['cc'].split(/,\s+/)
          mail.bcc = headers['bcc'] #&& headers['cc'].split(/,\s+/)
          mail.subject = headers['subject']
          mail.from ||= @username
          # attachments are added as a snippet of YAML after a blank line
          # after the headers, and followed by a blank line
          if (attachments = raw_body.split(/\n\s*\n/, 2)[0]) =~ /^attach(ment|ments)*:/
            files = YAML::load(attachments).values.flatten
            log "Attach: #{files}"
            files.each do |file|
              if File.directory?(file)
                Dir.glob("#{file}/*").each {|f| mail.add_file(f) if File.size?(f)}
              else
                mail.add_file(file) if File.size?(file)
              end
            end
            mail.text_part do
              body raw_body.split(/\n\s*\n/, 2)[1]
            end

          else
            mail.text_part do
              body raw_body
            end
          end
          mail
        end