+ # Remove *domain* from the Postfixadmin database. This should remove
+ # the domain from _every_ table in which it is referenced. It should
+ # also remove every user that belongs to the doomed domain
+ # Postfixadmin has some experimental support for triggers, but they
+ # don't do a very good job of cleaning up. Therefore we remove all
+ # users in the domain manually before removing the domain itself.
+ #
+ # Log entries (from the "log" table) are not removed since they may
+ # still contain valuable information (although they won't mention
+ # this removal).
+ #
+ # @param domain [Domain] the domain to remove.
+ #
+ def remove_domain(domain)
+ raise NonexistentDomainError.new(domain.to_s()) if not domain_exists(domain)
+
+ # First remove all users belonging to the domain. This will handle
+ # alias updates and all the sensitive crap we need to do when
+ # removing a user.
+ users = list_domains_users([domain])
+ users.each { |u| remove_user(u) }
+
+ # The domain_admins table contains one record per domain
+ # (repeating the user as necessary), so this really is sufficient.