# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

module MimeStructureHelper
  def nested_multipart_mail(levels, subject: 'Nested')
    openings = Array.new(levels) { |level| "Content-Type: multipart/mixed; boundary=\"b#{level}\"\r\n\r\n--b#{level}\r\n" }
    closings = Array.new(levels) { |level| "\r\n--b#{level}--\r\n" }.reverse

    "From: foo@example.com\r\nTo: support@example.com\r\nSubject: #{subject}\r\n#{openings.join}Content-Type: text/plain\r\n\r\nLorem ipsum#{closings.join}"
  end

  def wide_multipart_mail(parts, subject: 'Wide')
    body = Array.new(parts) { |index| "--b\r\nContent-Type: text/plain\r\n\r\nPart #{index}\r\n" }.join

    "From: foo@example.com\r\nTo: support@example.com\r\nSubject: #{subject}\r\nContent-Type: multipart/mixed; boundary=\"b\"\r\n\r\n#{body}--b--\r\n"
  end
end

RSpec.configure do |config|
  config.include MimeStructureHelper
end
