Commit graph

27 commits

Author SHA1 Message Date
c39abe0509 Add license section to README
Include license information in README.md for clarity and compliance.

Changes:
- Add ## License section with GPLv3 reference
2026-01-04 21:09:29 +09:00
4bd1c39eab Add GPLv3 license
License the email forwarder under GNU General Public License v3 to
ensure free software distribution and modification rights.

Changes:
- Add LICENSE file with full GPLv3 text
2026-01-04 21:08:58 +09:00
a1e6d84733 Re-add WorkingDirectory to systemd service
WorkingDirectory is required to set the cwd to the project dir for
relative paths like ./state. It was accidentally removed in a previous
edit.

Changes:
- Add WorkingDirectory= to [Service] section
2026-01-04 20:15:22 +09:00
6d8a5002e7 Move OnFailure to [Unit] section
OnFailure directive must be in [Unit], not [Service], for systemd
user services to recognize it.

Changes:
- Move OnFailure from [Service] to [Unit] in email_forwarder.service
2026-01-04 20:13:24 +09:00
05f2e6c870 Fail script on all server errors
Remove local exception handling for IMAP operations to ensure script
exits on any server failure (e.g., auth, connection, search errors).
This allows systemd OnFailure to notify on fixable issues.

Changes:
- Remove try-except in check_duplicate, sync_folder, sync_all_folders
- Let IMAP exceptions propagate to main() for exit(1)
2026-01-04 20:10:33 +09:00
69ec294a56 Fix duplicate detection by ensuring folder selection
Call ensure_folder_exists before check_duplicate to select the dest
folder, allowing IMAP SEARCH to work in SELECTED state.

Changes:
- Move dest.ensure_folder_exists(folder) before check_duplicate in process_email
- Add logging to check_duplicate for debugging
2026-01-04 20:03:49 +09:00
a0f40a1327 Add WorkingDirectory to systemd service
Ensure ./state resolves to project_dir/state by setting WorkingDirectory
to the absolute PROJECT_DIR path.

Changes:
- Add WorkingDirectory= to email_forwarder.service
2026-01-04 19:55:27 +09:00
a32f79980e Implement configurable STATE_DIR for state files
Move processed_message_ids.txt and last_run.txt to STATE_DIR,
configurable via .env. Install script creates ./state by default.

Changes:
- Add STATE_DIR to .env.example and config loading
- Update EmailForwarder to use os.path.join for file paths
- Add os.makedirs for state dir creation
- Update README with STATE_DIR option
2026-01-04 19:45:48 +09:00
4adce1079f Remove temp files 2026-01-04 19:25:28 +09:00
d9cbf829bb Fix calls to private connect/disconnect methods
Change remaining .connect() and .disconnect() calls to private
._connect() and ._disconnect() after removing public methods.

Changes:
- Update EmailForwarder.sync_all_folders to use _connect/_disconnect
2026-01-04 19:19:38 +09:00
daef4cbc9f Fix systemd variable expansion with shell wrapper
Wrap ExecStartPost in /bin/sh -c to enable variable expansion for
UPTIME_SUCCESS_URL. Add EnvironmentFile to load vars from .env.

Changes:
- Update ExecStartPost to use shell for  expansion
- Add EnvironmentFile=/.env to service
- Update fail service ExecStart similarly
2026-01-04 18:53:06 +09:00
701c8545a0 Remove drop-in config and use absolute paths in service file
Eliminate drop-in dependency by having install.sh replace
with absolute paths in the service file. EnvironmentFile loads vars from
.env directly.

Changes:
- Remove email_forwarder.service.d/ directory
- Update install.sh to sed service file for absolute paths
- Simplify README to rely on install.sh
2026-01-04 18:30:49 +09:00
c96bd8ed71 Restructure as runnable Python module
Convert email_forwarder.py to a package with __main__.py for module execution.
Update systemd service to use -m email_forwarder.
Configure pyproject.toml to exclude state/ from packaging.

Changes:
- Create email_forwarder/ package with __init__.py and __main__.py
- Move main script to email_forwarder/email_forwarder.py
- Update ExecStart to python -m email_forwarder
- Add setuptools config to exclude state/ directory
2026-01-04 18:22:42 +09:00
02f6461cbc Rename main.py to email_forwarder.py and fix systemd variable expansion
- Rename main.py to email_forwarder.py for better readability
- Update systemd service to use  in ExecStart and EnvironmentFile,
  remove WorkingDirectory to fix expansion issues
- Update install.sh and README references
- Drop-in sets PROJECT_DIR for runtime expansion

Changes:
- File rename: main.py -> email_forwarder.py
- Service: ExecStart and EnvironmentFile now use
- Docs: Updated to reflect new script name
2026-01-04 18:16:37 +09:00
fad2727ae8 Update default FOLDERS to include Sent
Change default from INBOX to INBOX,Sent for better out-of-the-box
experience, as Sent is commonly forwarded alongside inbox.

Changes:
- Update FOLDERS in .env.example
- Update README to reflect new default
2026-01-04 17:55:19 +09:00
4a96c4a291 Remove unused ENV_FILE from install script
Since ENV_FILE is no longer replaced, remove the variable and its echo
to simplify the script.

Changes:
- Remove ENV_FILE definition
- Remove Env file echo in main
2026-01-04 17:47:30 +09:00
cc00650bc2 Fix install script and update .gitignore
Correct STATE_DIR to project dir, remove unnecessary pip3 check and ENV_FILE
replacement for cleaner, accurate installation.

Changes:
- Set STATE_DIR to ./state in install.sh
- Remove pip3 dependency check (included in venv)
- Remove redundant ENV_FILE sed replacement
- Update .gitignore to ignore state/ directory
2026-01-04 17:46:16 +09:00
8433e4a442 Simplify README by removing manual setup and dependencies
With the install script handling automation, remove redundant sections
to keep README concise.

Changes:
- Remove manual setup steps (covered by install.sh comments)
- Remove dependencies section (specified in pyproject.toml)
2026-01-04 17:32:30 +09:00
c06474dd0d Add AGENTS.md with project guidelines
Document GNOME commit style, code principles, testing, and security
practices for contributors.

Changes:
- Include commit guidelines
- Code style notes
- Testing and security reminders
2026-01-04 17:19:58 +09:00
9b7a6c5c07 Improve code style in load_state
Replace duplicate strip() calls with filter(None, generator) for
cleaner and more efficient processing of processed Message-IDs.

Changes:
- Use set(filter(None, (line.strip() for line in f))) to avoid calling
  strip() twice and filter empty lines
2026-01-04 16:54:13 +09:00
f2bc700939 Improve encapsulation in IMAP classes
Make all attributes private (_host, _imap, etc.) and remove redundant
public connect/disconnect methods. Connection management is now handled
internally by the orchestrator calling private _connect/_disconnect.

Changes:
- Privatize ImapClient attributes and methods
- Update EmailForwarder to call private connection methods
- Enhance encapsulation without changing functionality
2026-01-04 16:48:57 +09:00
f70f1853f0 Refactor main.py for readability and maintainability
Introduce class-based architecture with inheritance for IMAP clients:
- ImapClient base class with private low-level methods
- SourceImap and DestImap subclasses for specific operations
- EmailForwarder orchestrator class for coordination
- Global load_config and main functions

Improvements:
- Clear separation of concerns and encapsulation
- Private methods for internal IMAP calls
- Better error handling and logging
- Maintains all original functionality
2026-01-04 16:41:58 +09:00
485a5db8b9 Implement multi-folder synchronization
Add support for syncing multiple IMAP folders with auto-creation of missing
dest folders and configurable folder selection.

Changes:
- Update main.py to loop over folders, with auto-create for dest
- Add FOLDERS env var for all or specific folders
- Update .env.example and README for FOLDERS config
2026-01-04 16:27:54 +09:00
2ecdf33dc4 Add install script
Provide automated installation for Linux users to set up venv and systemd
services with proper path configuration.

Changes:
- Add install.sh with dependency checks, venv setup, and systemd configuration
- Update README to highlight automated install option
2026-01-04 16:20:46 +09:00
acec14553d Add sample drop-in config
Provide override.conf.sample as a template for customizing systemd
environment paths.

Changes:
- Rename override.conf to override.conf.sample with placeholders and comments
- Update README to instruct copying the sample
2026-01-04 16:15:04 +09:00
45b179ede3 Clean up unused code and config
Remove PROCESSED_FILE references and update .env.example with placeholder
Uptime URLs for privacy.

Changes:
- Remove unused processed_file variable and loading in main.py
- Update .env.example to use generic Uptime URLs
- Remove processed_uids.txt from .gitignore
2026-01-04 15:44:57 +09:00
686c4877d3 Implement email forwarder
Add core IMAP forwarding logic with time-based searches and Message-ID
deduplication to prevent duplicates in destination mailbox.

Changes:
- Implement SINCE-based email search using last_run.txt for incremental forwarding
- Add Message-ID extraction and IMAP checks for deduplication
- Configure systemd user services with drop-in overrides for portability
- Integrate Uptime Kuma pings for monitoring
- Set up virtual environment for dependency isolation
- Update documentation and configuration templates
2026-01-04 15:34:31 +09:00