🚀 Use at Your Own Risk! 🚀
This script is provided "as is" with no warranty, no guarantee, and absolutely no responsibility on my part if it crashes, burns, wipes your email archive, steals your lunch, or causes your cat to start plotting against you.
By using this script, you accept that anything that happens is 100% on you. If it works—awesome! 🎉 If it doesn't—well, you’ve been warned. 🔥
I will not be held liable for data loss, system malfunctions, email monsters, existential crises, or any other chaos that may ensue. Use at your own discretion. Modify it, break it, improve it, but don’t blame me if something goes sideways.
Email Archiver is a Python script that connects to an IMAP email server, retrieves emails, and stores them locally in a structured format. The script decodes email content, handles attachments, and ensures safe filenames for storage.
- Connects to an IMAP server
- Retrieves and processes emails
- Decodes text and HTML content
- Handles attachments
- Stores emails in a structured format
- Configurable via a YAML file
- Python 3.x
- Required dependencies (install via
pip install -r requirements.txt):PyYAMLbeautifulsoup4unidecode
git clone https://github.com/yourusername/email-archiver.git
cd email-archiverpython3 -m venv env
source env/bin/activate # On Windows use `env\Scripts\activate`pip install -r requirements.txt• Edit the config.yaml file with your IMAP server details and archive directory.
The script uses a config.yaml file to store configuration details:
imap_server: "imap.example.com"
username: "your-email@example.com"
password: "your-email-password"
output_folder: "/path/to/archive"Run the script using:
python Email_Archiver.pyTo run this script every hour on macOS, you can use launchd. Follow these steps:
• Open Terminal and create a new file in ~/Library/LaunchAgents/:
nano ~/Library/LaunchAgents/com.email.archiver.plist<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.email.archiver</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/your/virtualenv/bin/python</string>
<string>/path/to/email-archiver/Email_Archiver.py</string>
</array>
<key>StartInterval</key>
<integer>3600</integer> <!-- Runs every hour -->
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/email-archiver</string>
<key>StandardOutPath</key>
<string>/tmp/email_archiver.out</string>
<key>StandardErrorPath</key>
<string>/tmp/email_archiver.err</string>
</dict>
</plist>Note: • Replace /path/to/your/virtualenv/bin/python with the absolute path to the Python interpreter in your virtual environment. For example, /Users/yourusername/email-archiver/env/bin/python. • Replace /path/to/email-archiver/Email_Archiver.py with the absolute path to the Email_Archiver.py script. • Ensure all paths are absolute to prevent issues with launchd.
launchctl load ~/Library/LaunchAgents/com.email.archiver.plistTo unload the job:
launchctl unload ~/Library/LaunchAgents/com.email.archiver.plistImportant Considerations: • Absolute Paths: Ensure all paths in the .plist file are absolute. Relative paths can cause the job to fail. • Permissions: Ensure your script and the Python interpreter have the necessary execute permissions. You can set the appropriate permissions using the chmod command:
chmod +x /path/to/your/virtualenv/bin/python
chmod +x /path/to/email-archiver/Email_Archiver.py• Environment Variables: If your script relies on specific environment variables, you can define them within the .plist file using the EnvironmentVariables directive.
By following these steps, your Python script will run automatically every hour using launchd on macOS.
Ordner: =this.file.folder