Set up mail client DNS aliases for managed domains

This commit is contained in:
parkel committed 2026-11-24 13:41:06 +01:00
1 parent c0dd02e7a6
commit d81e716ff5
13 files changed
+185 -7

No files matched your search

+4 -2
View File
@@ -626,14 +626,16 @@ class Installer:
options["COULOBRE_LOCAL_MAILBOX_PROVISIONING"] = "1" options["COULOBRE_LOCAL_MAILBOX_PROVISIONING"] = "1"
if self.plan.mail.mode in {"local", "remote-install"}: if self.plan.mail.mode in {"local", "remote-install"}:
options["COULOBRE_MAIL_NODE_DKIM"] = "1" options["COULOBRE_MAIL_NODE_DKIM"] = "1"
options["COULOBRE_MAIL_IMAP_HOST"] = self.plan.mail.mail_hostname
options["COULOBRE_MAIL_SUBMISSION_HOST"] = (
self.plan.mail.mail_hostname
)
if self.plan.mail.mode == "local": if self.plan.mail.mode == "local":
options.update( options.update(
COULOBRE_SMTP_HOST="127.0.0.1", COULOBRE_SMTP_HOST="127.0.0.1",
COULOBRE_SMTP_PORT="25", COULOBRE_SMTP_PORT="25",
COULOBRE_SMTP_STARTTLS="0", COULOBRE_SMTP_STARTTLS="0",
COULOBRE_EMAIL_FROM=f"panel@{self.plan.mail.host}", COULOBRE_EMAIL_FROM=f"panel@{self.plan.mail.host}",
COULOBRE_MAIL_IMAP_HOST=self.plan.mail.host,
COULOBRE_MAIL_SUBMISSION_HOST=self.plan.mail.host,
) )
hosting = self.plan.hosting hosting = self.plan.hosting
if hosting.public_addresses: if hosting.public_addresses:
+8
View File
@@ -2277,6 +2277,14 @@ policy ID. Checking the HTTPS policy is a separate step. The DKIM check
compares the managed selector with the public key received from the mail compares the managed selector with the public key received from the mail
node. node.
When IMAP and SMTP submission share a hostname, Coulobre adds a CNAME
for `mail.<domain>` when creating or refreshing managed mail DNS. It
keeps existing records at that name. For external DNS, copy the suggested
CNAME from **Check mail DNS**. Use the configured service hostname until
public DNS resolves and the mail service presents a certificate valid for
the alias. Welcome emails list the configured IMAP and submission hostnames
as the defaults.
### Set up signing on a Coulobre mail node ### Set up signing on a Coulobre mail node
Install the distribution's `rspamd` package on the mail node, including Install the distribution's `rspamd` package on the mail node, including
+18 -2
View File
@@ -12,7 +12,7 @@ from .dns_defaults import zone_defaults
from .dns_forms import normalize_record_rows from .dns_forms import normalize_record_rows
from .dns_publication import queue_zone_snapshot from .dns_publication import queue_zone_snapshot
from .installation_features import panel_feature_allowed from .installation_features import panel_feature_allowed
from .mail_dns_setup import mail_dns_proposal from .mail_dns_setup import available_mail_client_alias, mail_dns_proposal
from .models import ( from .models import (
HostingDnsZone, HostingDnsZone,
HostingMailDomain, HostingMailDomain,
@@ -110,6 +110,7 @@ def default_dns_zone(account, *, www=None, wildcard=None, managed_mail=False):
domain, domain,
) )
mx = txt = () mx = txt = ()
extra_records = extra["extra_records"]
if managed_mail: if managed_mail:
public_key = ( public_key = (
account.mail_domains.filter(domain=domain) account.mail_domains.filter(domain=domain)
@@ -124,6 +125,21 @@ def default_dns_zone(account, *, www=None, wildcard=None, managed_mail=False):
for record in mail_addresses for record in mail_addresses
if record.name == domain or record.name.endswith(f".{domain}") if record.name == domain or record.name.endswith(f".{domain}")
) )
alias = available_mail_client_alias(
domain,
defaults.nameservers,
(
*addresses,
*extra["addresses"],
*mx,
*extra["mx_records"],
*txt,
*extra["txt_records"],
*extra_records,
),
)
if alias is not None:
extra_records += (alias,)
return HostingDnsZone( return HostingDnsZone(
account=account, account=account,
domain=domain, domain=domain,
@@ -141,7 +157,7 @@ def default_dns_zone(account, *, www=None, wildcard=None, managed_mail=False):
asdict(record) asdict(record)
for record in dict.fromkeys((*txt, *extra["txt_records"])) for record in dict.fromkeys((*txt, *extra["txt_records"]))
], ],
extra_records=[asdict(record) for record in extra["extra_records"]], extra_records=[asdict(record) for record in extra_records],
manage_mail_dns=bool(managed_mail), manage_mail_dns=bool(managed_mail),
) )
+7
View File
@@ -32,6 +32,7 @@ from kombu.exceptions import OperationalError
from .access import customer_for_user, is_tenant, reseller_for_user from .access import customer_for_user, is_tenant, reseller_for_user
from .account_setup import website_records from .account_setup import website_records
from .mail_dns_setup import mail_client_alias
from .models import ( from .models import (
Customer, Customer,
HostingAccount, HostingAccount,
@@ -280,6 +281,11 @@ def welcome_message_context(
nameservers, nameservers,
mail_configured, mail_configured,
): ):
alias = (
mail_client_alias(account.primary_domain)
if account and mail_configured
else None
)
return { return {
"username": username, "username": username,
"welcome_message": welcome_message, "welcome_message": welcome_message,
@@ -298,6 +304,7 @@ def welcome_message_context(
), ),
"imap_host": settings.MAIL_IMAP_HOST, "imap_host": settings.MAIL_IMAP_HOST,
"submission_host": settings.MAIL_SUBMISSION_HOST, "submission_host": settings.MAIL_SUBMISSION_HOST,
"mail_alias": alias.name if alias else "",
"mail_configured": mail_configured, "mail_configured": mail_configured,
} }
+53 -2
View File
@@ -7,8 +7,10 @@ from django.db import transaction
from coulobre.dns_node import ( from coulobre.dns_node import (
MAX_SOA_SERIAL, MAX_SOA_SERIAL,
AddressRecord, AddressRecord,
ExtraRecord,
MxRecord, MxRecord,
TxtRecord, TxtRecord,
dns_name,
) )
from coulobre.mail_dns import MANAGED_DKIM_SELECTOR, matches_version from coulobre.mail_dns import MANAGED_DKIM_SELECTOR, matches_version
@@ -57,6 +59,42 @@ def mail_dns_proposal(domain, public_key):
return addresses, mx, tuple(records) return addresses, mx, tuple(records)
def mail_client_alias(domain):
"""Return an alias for a shared IMAP and submission hostname."""
name = f"mail.{domain}"
if len(name) > 253:
return None
try:
imap = dns_name(settings.MAIL_IMAP_HOST)
submission = dns_name(settings.MAIL_SUBMISSION_HOST)
except ValueError:
return None
if imap != submission or name == imap or name == settings.MAIL_MX_HOST:
return None
return ExtraRecord(name, "CNAME", imap)
def available_mail_client_alias(domain, nameservers, records):
alias = mail_client_alias(domain)
if alias is None or alias.name in nameservers:
return None
aliases = {}
for record in records:
if record.name == alias.name or (
isinstance(record, MxRecord) and record.exchange == alias.name
):
return None
if isinstance(record, ExtraRecord) and record.record_type == "CNAME":
aliases[record.name] = record.value.removesuffix(".")
visited = {alias.name}
target = alias.value.removesuffix(".")
while target in aliases and target not in visited:
visited.add(target)
target = aliases[target]
return alias if target not in visited else None
@transaction.atomic @transaction.atomic
def sync_mail_dns(mail_domain, *, public_key=None): def sync_mail_dns(mail_domain, *, public_key=None):
account = lock_hosting_account(mail_domain.account_id, customer_id=None) account = lock_hosting_account(mail_domain.account_id, customer_id=None)
@@ -164,7 +202,12 @@ def publish_mail_records(zone, domain, public_key):
raise ValueError( raise ValueError(
"Publish the saved zone revision before updating mail DNS." "Publish the saved zone revision before updating mail DNS."
) )
changed = bool(additions or not current_mx or new_txt) alias = available_mail_client_alias(
domain,
spec.nameservers,
(*spec.addresses, *spec.mx_records, *existing, *spec.extra_records),
)
changed = bool(additions or not current_mx or new_txt or alias)
if publication and publication.finished_at is None: if publication and publication.finished_at is None:
if changed: if changed:
raise MailDnsPublicationPendingError raise MailDnsPublicationPendingError
@@ -177,14 +220,22 @@ def publish_mail_records(zone, domain, public_key):
addresses=spec.addresses + additions, addresses=spec.addresses + additions,
mx_records=spec.mx_records + (mx if not current_mx else ()), mx_records=spec.mx_records + (mx if not current_mx else ()),
txt_records=spec.txt_records + tuple(new_txt), txt_records=spec.txt_records + tuple(new_txt),
extra_records=spec.extra_records + ((alias,) if alias else ()),
) )
manifest = spec.manifest() manifest = spec.manifest()
zone.serial = spec.serial zone.serial = spec.serial
zone.addresses = manifest["addresses"] zone.addresses = manifest["addresses"]
zone.mx_records = manifest["mx_records"] zone.mx_records = manifest["mx_records"]
zone.txt_records = manifest["txt_records"] zone.txt_records = manifest["txt_records"]
zone.extra_records = manifest.get("extra_records", [])
zone.save( zone.save(
update_fields=["serial", "addresses", "mx_records", "txt_records"] update_fields=[
"serial",
"addresses",
"mx_records",
"txt_records",
"extra_records",
]
) )
if changed or publication is None or publication.problem: if changed or publication is None or publication.problem:
queue_zone_snapshot(zone) queue_zone_snapshot(zone)
+13
View File
@@ -25,6 +25,7 @@ from .access import OperatorOnlyMixin, TenantScopeMixin, is_tenant
from .installation_features import panel_feature_allowed from .installation_features import panel_feature_allowed
from .mail_dns_setup import ( from .mail_dns_setup import (
closest_zone, closest_zone,
mail_client_alias,
mail_dns_proposal, mail_dns_proposal,
queue_mail_dns_setup, queue_mail_dns_setup,
) )
@@ -119,6 +120,7 @@ class MailDnsCheckView(
self.zone_txt = () self.zone_txt = ()
self.zone_mx = () self.zone_mx = ()
self.zone_addresses = () self.zone_addresses = ()
self.zone_extra = ()
if is_tenant(self.request.user) or self.request.user.has_perm( if is_tenant(self.request.user) or self.request.user.has_perm(
VIEW_DNS_ZONES VIEW_DNS_ZONES
): ):
@@ -130,6 +132,7 @@ class MailDnsCheckView(
self.zone_txt = spec.txt_records self.zone_txt = spec.txt_records
self.zone_mx = spec.mx_records self.zone_mx = spec.mx_records
self.zone_addresses = spec.addresses self.zone_addresses = spec.addresses
self.zone_extra = spec.extra_records
def get_initial(self): def get_initial(self):
initial = super().get_initial() initial = super().get_initial()
@@ -174,6 +177,9 @@ class MailDnsCheckView(
== {host + "." for host in self.zone.nameservers} == {host + "." for host in self.zone.nameservers}
), ),
entries=entries, entries=entries,
has_mail_client_alias=any(
entry.kind == "CNAME" for entry in entries
),
sending_ips=settings.MAIL_SENDING_IPS, sending_ips=settings.MAIL_SENDING_IPS,
explicit_resolver=bool(settings.MAIL_DNS_RESOLVERS), explicit_resolver=bool(settings.MAIL_DNS_RESOLVERS),
dmarc_example=not any( dmarc_example=not any(
@@ -224,6 +230,13 @@ class MailDnsCheckView(
for record in dict.fromkeys(self.zone_addresses + addresses) for record in dict.fromkeys(self.zone_addresses + addresses)
if record.name in targets if record.name in targets
) )
alias = mail_client_alias(self.domain)
if alias is not None and (
self.zone is None or alias in self.zone_extra
):
entries.append(
DnsEntry(alias.name, alias.record_type, alias.value)
)
txt_owners = { txt_owners = {
self.domain: "v=spf1", self.domain: "v=spf1",
f"_dmarc.{self.domain}": "v=DMARC1", f"_dmarc.{self.domain}": "v=DMARC1",
@@ -95,6 +95,7 @@
<p>Enter the full record name below, or remove the zone suffix if the editor appends it automatically. Use <code>@</code> only at that zone’s apex. Enter TXT values without extra quotes.</p> <p>Enter the full record name below, or remove the zone suffix if the editor appends it automatically. Use <code>@</code> only at that zone’s apex. Enter TXT values without extra quotes.</p>
<ul> <ul>
<li><strong>MX and addresses.</strong> Use the mail service’s inbound hostname and priority. Publish A and AAAA for the IPv4 and IPv6 addresses it serves. Use a DNS-only host for mail.</li> <li><strong>MX and addresses.</strong> Use the mail service’s inbound hostname and priority. Publish A and AAAA for the IPv4 and IPv6 addresses it serves. Use a DNS-only host for mail.</li>
{% if has_mail_client_alias %}<li><strong>Mail client alias.</strong> Publish the CNAME below for the shared IMAP and SMTP service. Use the configured server name until DNS resolves and the TLS certificate covers the alias.</li>{% endif %}
<li><strong>SPF.</strong> Publish one TXT policy at <code>{{ domain }}.</code>. Include every authorized sender using the IPs or include mechanism supplied by its mail service. Merge senders into an existing SPF record.</li> <li><strong>SPF.</strong> Publish one TXT policy at <code>{{ domain }}.</code>. Include every authorized sender using the IPs or include mechanism supplied by its mail service. Merge senders into an existing SPF record.</li>
<li><strong>DKIM.</strong> Copy the provider’s TXT or CNAME at <code>selector._domainkey.{{ domain }}.</code>. Use the exact selector and public value supplied by the signer. Keep the signing key private.</li> <li><strong>DKIM.</strong> Copy the provider’s TXT or CNAME at <code>selector._domainkey.{{ domain }}.</code>. Use the exact selector and public value supplied by the signer. Keep the signing key private.</li>
<li><strong>DMARC.</strong> Use a TXT at <code>_dmarc.{{ domain }}.</code>. If no policy applies, start with monitoring and set up aggregate reports before choosing an enforcement policy.</li> <li><strong>DMARC.</strong> Use a TXT at <code>_dmarc.{{ domain }}.</code>. If no policy applies, start with monitoring and set up aggregate reports before choosing an enforcement policy.</li>
@@ -28,6 +28,8 @@ If your DNS is hosted elsewhere, add these website records at your DNS provider:
Use the full mailbox email address as your mail client username.{% if imap_host %} Use the full mailbox email address as your mail client username.{% if imap_host %}
Incoming mail (IMAP over TLS): {{ imap_host }}, port 993{% endif %}{% if submission_host %} Incoming mail (IMAP over TLS): {{ imap_host }}, port 993{% endif %}{% if submission_host %}
Outgoing mail (SMTP with STARTTLS): {{ submission_host }}, port 587{% endif %} Outgoing mail (SMTP with STARTTLS): {{ submission_host }}, port 587{% endif %}
{% if mail_alias %}Use the server names above by default. You can also use {{ mail_alias }} once DNS points to your mail service and its TLS certificate covers that name.
{% endif %}
{% endif %}{% endif %} {% endif %}{% endif %}
After signing in, open the hosting account for website status, DNS settings, After signing in, open the hosting account for website status, DNS settings,
@@ -52,6 +52,7 @@
{% if message.imap_host %}<li>Incoming mail (IMAP over TLS) · {{ message.imap_host }}, port 993</li>{% endif %} {% if message.imap_host %}<li>Incoming mail (IMAP over TLS) · {{ message.imap_host }}, port 993</li>{% endif %}
{% if message.submission_host %}<li>Outgoing mail (SMTP with STARTTLS) · {{ message.submission_host }}, port 587</li>{% endif %} {% if message.submission_host %}<li>Outgoing mail (SMTP with STARTTLS) · {{ message.submission_host }}, port 587</li>{% endif %}
</ul> </ul>
{% if message.mail_alias %}<p>Use the server names above by default. You can also use <strong>{{ message.mail_alias }}</strong> once DNS points to your mail service and its TLS certificate covers that name.</p>{% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -15,6 +15,8 @@ from .models import Customer, HostingAccount, PanelInvitation, WebsiteAlias
HOSTING_PUBLIC_ADDRESSES=("192.0.2.21", "2001:db8::21"), HOSTING_PUBLIC_ADDRESSES=("192.0.2.21", "2001:db8::21"),
HOSTING_NAMESERVERS=("ns1.example.test", "ns2.example.test"), HOSTING_NAMESERVERS=("ns1.example.test", "ns2.example.test"),
MAIL_MX_HOST="mx.example.test", MAIL_MX_HOST="mx.example.test",
MAIL_IMAP_HOST="mail.service.example",
MAIL_SUBMISSION_HOST="mail.service.example",
MAIL_SENDING_IPS=("192.0.2.21",), MAIL_SENDING_IPS=("192.0.2.21",),
) )
class HostingAccountSetupTests(TestCase): class HostingAccountSetupTests(TestCase):
@@ -54,6 +56,10 @@ class HostingAccountSetupTests(TestCase):
{"new.example.test", "www.new.example.test", "*.new.example.test"}, {"new.example.test", "www.new.example.test", "*.new.example.test"},
) )
self.assertEqual(zone.spec.mx_records[0].exchange, "mx.example.test") self.assertEqual(zone.spec.mx_records[0].exchange, "mx.example.test")
alias = zone.spec.extra_records[0]
self.assertEqual(alias.name, "mail.new.example.test")
self.assertEqual(alias.record_type, "CNAME")
self.assertEqual(alias.value, "mail.service.example.")
self.assertTrue( self.assertTrue(
any("v=spf1" in record.text for record in zone.spec.txt_records) any("v=spf1" in record.text for record in zone.spec.txt_records)
) )
+24
View File
@@ -36,6 +36,7 @@ from .tasks import dispatch_dns_publications, provision_mailbox
DOMAIN = "example.net" DOMAIN = "example.net"
MX = "mx.example.net" MX = "mx.example.net"
CLIENT_HOST = "mail.service.example"
IP = "93.184.215.14" IP = "93.184.215.14"
DKIM = "v=DKIM1; k=ed25519; p=" + base64.b64encode(bytes(range(32))).decode() DKIM = "v=DKIM1; k=ed25519; p=" + base64.b64encode(bytes(range(32))).decode()
@@ -125,6 +126,8 @@ class MailDnsRecordsTests(SimpleTestCase):
LOCAL_MAILBOX_PROVISIONING=True, LOCAL_MAILBOX_PROVISIONING=True,
MANAGE_MAIL_DNS=True, MANAGE_MAIL_DNS=True,
MAIL_MX_HOST=MX, MAIL_MX_HOST=MX,
MAIL_IMAP_HOST=CLIENT_HOST,
MAIL_SUBMISSION_HOST=CLIENT_HOST,
MAIL_MX_IPS=(IP,), MAIL_MX_IPS=(IP,),
MAIL_SENDING_IPS=(IP,), MAIL_SENDING_IPS=(IP,),
) )
@@ -177,6 +180,8 @@ class MailDnsPanelTests(TestCase):
page = self.client.get(url) page = self.client.get(url)
self.assertContains(page, "registrar") self.assertContains(page, "registrar")
self.assertContains(page, 'value="mx.example.net."') self.assertContains(page, 'value="mx.example.net."')
self.assertContains(page, 'value="mail.example.net."')
self.assertContains(page, f'value="{CLIENT_HOST}."')
self.assertContains(page, 'value="v=spf1 ip4:93.184.215.14 ~all"') self.assertContains(page, 'value="v=spf1 ip4:93.184.215.14 ~all"')
self.assertContains(page, 'data-copy-field="dns-name-1"') self.assertContains(page, 'data-copy-field="dns-name-1"')
self.assertContains( self.assertContains(
@@ -226,6 +231,16 @@ class MailDnsPanelTests(TestCase):
zone.mx_records, [{"name": DOMAIN, "priority": 10, "exchange": MX}] zone.mx_records, [{"name": DOMAIN, "priority": 10, "exchange": MX}]
) )
self.assertEqual(zone.addresses, [{"name": MX, "address": IP}]) self.assertEqual(zone.addresses, [{"name": MX, "address": IP}])
self.assertEqual(
zone.extra_records,
[
{
"name": f"mail.{DOMAIN}",
"record_type": "CNAME",
"value": f"{CLIENT_HOST}.",
}
],
)
self.assertEqual( self.assertEqual(
{item["name"]: item["text"] for item in zone.txt_records}, {item["name"]: item["text"] for item in zone.txt_records},
{ {
@@ -240,6 +255,15 @@ class MailDnsPanelTests(TestCase):
zone.refresh_from_db() zone.refresh_from_db()
self.assertEqual(zone.serial, 6) self.assertEqual(zone.serial, 6)
def test_dns_sync_keeps_an_existing_mail_client_host_record(self):
address = {"name": f"mail.{DOMAIN}", "address": "192.0.2.43"}
zone = self.zone(manage_mail_dns=True, addresses=[address])
sync_mail_dns(self.domain, public_key=DKIM)
zone.refresh_from_db()
self.assertIn(address, zone.addresses)
self.assertEqual(zone.extra_records, [])
self.assertTrue(zone.mx_records)
def test_dns_sync_waits_for_inflight_publication(self): def test_dns_sync_waits_for_inflight_publication(self):
zone = self.zone(manage_mail_dns=True) zone = self.zone(manage_mail_dns=True)
publication = DnsPublication.objects.create( publication = DnsPublication.objects.create(
@@ -14,10 +14,17 @@ from django_otp.oath import TOTP, totp
from django_otp.plugins.otp_email.models import EmailDevice from django_otp.plugins.otp_email.models import EmailDevice
from django_otp.plugins.otp_totp.models import TOTPDevice from django_otp.plugins.otp_totp.models import TOTPDevice
from .invitations import deliver_invitation, invitation_token, queue_invitation from .invitations import (
deliver_invitation,
invitation_email,
invitation_message_context,
invitation_token,
queue_invitation,
)
from .models import ( from .models import (
Customer, Customer,
HostingAccount, HostingAccount,
HostingMailDomain,
PanelInvitation, PanelInvitation,
PanelRecoveryCode, PanelRecoveryCode,
Reseller, Reseller,
@@ -255,6 +262,29 @@ class PanelAuthenticationTests(TestCase):
403, 403,
) )
@override_settings(
MAIL_IMAP_HOST="srv.example.test",
MAIL_SUBMISSION_HOST="srv.example.test",
)
def test_welcome_email_keeps_fallback_hosts_and_explains_alias(self):
HostingMailDomain.objects.create(
account=self.account, domain=self.account.primary_domain
)
context = invitation_message_context(self.customer)
invitation = invitation_email(self.customer.email, context)
html = invitation.alternatives[0].content
for message in (invitation.body, html):
self.assertIn("srv.example.test", message)
self.assertIn(f"mail.{self.account.primary_domain}", message)
self.assertIn("its TLS certificate covers that name", message)
with self.settings(MAIL_SUBMISSION_HOST="submission.example.test"):
context = invitation_message_context(self.customer)
self.assertEqual(context["mail_alias"], "")
self.assertEqual(context["imap_host"], "srv.example.test")
self.assertEqual(
context["submission_host"], "submission.example.test"
)
def invitation_path(self, body): def invitation_path(self, body):
return urlsplit( return urlsplit(
next(line for line in body.splitlines() if "/welcome/" in line) next(line for line in body.splitlines() if "/welcome/" in line)
+17
View File
@@ -266,6 +266,23 @@ class InstallerParametersTests(unittest.TestCase):
) )
self.assertIn("192.0.2.41", plan.description()) self.assertIn("192.0.2.41", plan.description())
self.assertNotIn("/root/node-install-key", plan.description()) self.assertNotIn("/root/node-install-key", plan.description())
with patch(
"deploy.panel_installer.engine.platform_settings",
return_value=(None, True),
):
installer = Installer(plan, "test-only", Mock())
installer.state = dict.fromkeys(
("secret_key", "database_password", "broker_password"),
"test-only",
)
env = dict(
line.split("=", 1)
for line in installer.environment().splitlines()
)
self.assertEqual(env["COULOBRE_MAIL_IMAP_HOST"], "mx.example.net")
self.assertEqual(
env["COULOBRE_MAIL_SUBMISSION_HOST"], "mx.example.net"
)
def test_password_file_must_be_private_and_regular(self): def test_password_file_must_be_private_and_regular(self):
with tempfile.TemporaryDirectory() as folder: with tempfile.TemporaryDirectory() as folder: