Skip to content

Commit 33e4af2

Browse files
authored
Merge pull request #231 from stdevPavelmc/t_228-cron
Cron and preparedness for AI, closes #228
2 parents 4e15675 + 749039e commit 33e4af2

6 files changed

Lines changed: 89 additions & 3 deletions

File tree

.github/copilot-instructions.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# MailAD Codebase Guide for AI Agents
2+
3+
## Project Overview
4+
MailAD is a bash-based mail server provisioning tool that links to Active Directory (Samba/Windows) for user management. It automates multi-service mail infrastructure deployment on Debian/Ubuntu systems. The project targets Cuba's specific regulatory requirements but is usable anywhere.
5+
6+
**Key services provisioned:** Postfix (SMTP), Dovecot (IMAP/POP3), Amavis (AV filtering), SpamAssassin, optional Roundcube/SnappyMail webmail, Nginx frontend.
7+
8+
## Architecture Pattern: Template-Based Provisioning
9+
10+
The core workflow uses **template files + variable substitution**:
11+
1. **Template files** in `var/` directories (e.g., `var/postfix/main.cf`, `var/dovecot-2.2/dovecot.conf`) contain placeholders like `_DOMAIN_`, `_ADMINMAIL_`, `_MESSAGESIZE_`
12+
2. **Configuration** comes from two sources:
13+
- `common.conf`: system-wide defaults (OS support matrix, package lists, service names, version detection)
14+
- `mailad.conf`: user-facing deployment config (domain, hostname, LDAP credentials, feature toggles)
15+
3. **Provisioning** (see [scripts/provision.sh](scripts/provision.sh#L85-L96)): `sed` replaces placeholders with values, then copies templated configs to `/etc/`
16+
4. **Version handling**: Dovecot configs differ by version (2.2/2.3/2.4 in `var/dovecot-*/`)—detection happens in provision.sh
17+
18+
## Critical Developer Workflows
19+
20+
### Building/Deploying
21+
```bash
22+
make conf # Interactive config setup
23+
make deps # Install build dependencies
24+
make conf-check # Validate AD connectivity + config
25+
make install # Install packages (no configuration)
26+
make provision # Apply configurations to /etc/ + start services
27+
make all # Full sequence: deps → conf-check → install → provision
28+
```
29+
30+
### Testing
31+
- **Manual tests:** [tests/test.sh](tests/test.sh) runs SMTP/auth validation against a live server
32+
- **Test dependencies:** `.mailadmin.auth` file required (credentials for admin + national/local test users)
33+
- **Key test scenarios:** receive emails, auth for users, reject open relay, size limits, restriction levels
34+
35+
### Configuration Upgrade Pattern
36+
- `scripts/confupgrade.sh` runs before provision to detect and apply config migrations
37+
- Backward compatibility is maintained by detecting old config keys and transforming them
38+
39+
## Project Conventions & Patterns
40+
41+
### Variable Naming in Configs
42+
- **User-facing** (in `mailad.conf`): `DOMAIN`, `HOSTNAME`, `ADMINMAIL`, `MESSAGESIZE`, feature flags like `DOVECOT_SPAM_FILTER_ENABLED`
43+
- **System** (in `common.conf`): `SERVICENAMES` (array of systemd services), `OS_SUPPORTED`/`OS_LEGACY`/`OS_DISCONTINUED` (OS matrices), `VARS` (dynamically extracted from `mailad.conf`)
44+
- **Escaped versions**: `ESCDOMAIN`, `ESCNATIONAL` for sed patterns (backslash escaping dots/special chars)
45+
46+
### Postfix Rules & LDAP Integration
47+
- **LDAP bind:** Configured in [var/postfix/ldap/](var/postfix/ldap/) with separate files for lookup tables (domains, users, groups)
48+
- **Mail restrictions:** Domain-local vs. national/international users controlled via `ESCNATIONAL` regex in `filter_loc` and `filter_nat` files
49+
- **Alias management:** [scripts/groups.sh](scripts/groups.sh) runs daily (cron) to sync AD groups as email aliases
50+
51+
### Dovecot LDAP & Sieve
52+
- **LDAP auth:** Dovecot config points to AD via [var/dovecot-*/dovecot-ldap.conf.ext](var/dovecot-2.2/dovecot-ldap.conf.ext)
53+
- **Mailbox quotas:** Per-user sizes from AD `wWWHomePage` field, defaults to `DEFAULT_MAILBOX_SIZE`
54+
- **Sieve filtering:** Auto-creates spam filter if `DOVECOT_SPAM_FILTER_ENABLED` is set
55+
56+
### Amavis/AV Integration
57+
- **Config location:** [var/amavis/conf.d/](var/amavis/conf.d/) with modular structure (e.g., `50-user` for customization)
58+
- **Feature toggles:** `ANTIVIRUS`, `SPAMD_PROXY` enable ClamAV and SpamAssassin via sed substitution (comment/uncomment pattern)
59+
- **Spam bypass:** [scripts/provision.sh](scripts/provision.sh#L350-L394) conditionally enables `@bypass_spam_checks_maps`
60+
61+
### Backup/Restore
62+
- [scripts/backup.sh](scripts/backup.sh), [scripts/restore.sh](scripts/restore.sh), [scripts/custom_restore.sh](scripts/custom_restore.sh) preserve `/etc/` configurations
63+
- No user mailbox data included—focus is config portability
64+
65+
## Git & Issue Workflow
66+
- **Branch naming:** `{username}_t{issue#}_{short_description}` (e.g., `stdevPavelmc_t228_fix_cron`)
67+
- **Commits:** Start with `Refs #{issue#}` to auto-link to GitHub issues
68+
- **Pull requests:** Mention @stdevPavelmc when ready to merge; CI/CD (GitHub Actions) validates against test suite
69+
70+
## Key Integration Points
71+
- **Active Directory:** All user management via LDAP bind DN (configurable, typically Domain Admin)
72+
- **DNS:** Checked by [scripts/check_dns_records.sh](scripts/check_dns_records.sh) for MX/SPF/DKIM readiness
73+
- **Mail storage:** `/home/vmail/` (uid:gid 5000:5000)—can be NFS mount
74+
- **Webmail:** Roundcube or SnappyMail with SQLite/MySQL backend, installed via [scripts/webmails.sh](scripts/webmails.sh)
75+
76+
## When Adding Features
77+
1. Add toggle in `mailad.conf` (e.g., `NEW_FEATURE_ENABLED`)
78+
2. Add corresponding template files or sed edits in `scripts/provision.sh`
79+
3. Version-gate if affecting Postfix/Dovecot (query `common.conf` OS/version arrays)
80+
4. Update [tests/test.sh](tests/test.sh) to validate new feature
81+
5. Document in [README.md](README.md) and [Features.md](Features.md)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ install
1010
webmail
1111
*.log
1212
*.eml
13+
*.code-workspace
1314

1415
# local storage to work on develop
1516
.localdata

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ This is a note for developers about the recommended tags to keep track of the ch
2020
Dates must be YEAR-MONTH-DAY
2121
-->
2222

23+
## [v1.2.6] - 2026-02-05
24+
25+
- Added: Cron as a forced base dependency as some slim/basic os versions has no cron an then the programmed tasks fails, not to mention the provision process
26+
2327
## [v1.2.5] - 2025-12-15
2428

2529
- Added: Section on the README about the users of MailAD, as a request of the users [included a mosaic of logos and some notices]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MailAD v1.2.5
1+
# MailAD v1.2.6
22

33
[![Chat on Telegram](https://img.shields.io/badge/Chat%20on-Telegram-brightgreen?style=flat-square)](https://t.me/MailAD_dev) [![GitHub Issues](https://img.shields.io/github/issues/stdevPavelmc/mailad?style=flat-square)](https://github.com/stdevPavelmc/mailad/issues) [![GitHub Issues Closed](https://img.shields.io/github/issues-closed/stdevPavelmc/mailad?style=flat-square)](https://github.com/stdevPavelmc/mailad/issues?q=is%3Aissue+is%3Aclosed) [![GitHub repo size](https://img.shields.io/github/repo-size/stdevPavelmc/mailad?style=flat-square)](https://github.com/stdevPavelmc/mailad/archive/master.zip) [![GitHub last commit](https://img.shields.io/github/last-commit/stdevPavelmc/mailad?style=flat-square)](https://github.com/stdevPavelmc/mailad/commits/master) [![GitHub commit rate](https://img.shields.io/github/commit-activity/m/stdevPavelmc/mailad?style=flat-square)](https://github.com/stdevPavelmc/mailad/commits/master) [![Financial contributors](https://opencollective.com/mailad/tiers/badge.svg?style=flat-square)](https://opencollective.com/mailad) [![Develop Testing Status](https://img.shields.io/github/actions/workflow/status/stdevPavelmc/mailad/mailad-tests.yml?branch=develop&label=Develop+Testing+Status&style=flat-square)](https://github.com/stdevPavelmc/mailad/actions/workflows/mailad-tests.yml) [![Production Testing Status](https://img.shields.io/github/actions/workflow/status/stdevPavelmc/mailad/mailad-tests.yml?branch=master&label=Production+Testing+Status&style=flat-square)](https://github.com/stdevPavelmc/mailad/actions/workflows/mailad-tests.yml)
44

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.2.5
1+
v1.2.6

common.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OS_WORKING_D=("${OS_DISCONTINUED_D[@]}" "${OS_LEGACY_D[@]}" "${OS_SUPPORTED_D[@]
2626
OS_WORKING=("${OS_WORKING_U[@]}" "${OS_WORKING_D[@]}")
2727

2828
# Common deps packages
29-
COMMON_DEPS_PKGS="ldap-utils libldap-common dnsutils netcat-traditional openssl ca-certificates wget"
29+
COMMON_DEPS_PKGS="ldap-utils libldap-common dnsutils netcat-traditional openssl ca-certificates wget cron"
3030

3131
#### Pkgs to install for Debian Buster & Bullseye (10/11)
3232
DEBIAN_BASE_PKGS="postfix postfix-pcre postfix-ldap dovecot-core dovecot-pop3d dovecot-imapd dovecot-ldap dovecot-sieve dovecot-managesieved libnet-ldap-perl rsync dnsutils pflogsumm mailutils amavisd-new p7zip-full unrar-free cabextract cron"

0 commit comments

Comments
 (0)