74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
import sys
|
|
import os
|
|
import subprocess
|
|
from app import create_app, db
|
|
from app.models import Folder, User
|
|
from flask.cli import with_appcontext
|
|
import click
|
|
|
|
app = create_app()
|
|
|
|
@app.cli.command()
|
|
@with_appcontext
|
|
def shell():
|
|
"""Run a shell in the app context."""
|
|
import code
|
|
code.interact(local=dict(globals(), **locals()))
|
|
|
|
@app.cli.command("setup-dev")
|
|
def setup_dev():
|
|
"""Set up development environment with Docker Compose."""
|
|
# Create tmp directory for IMAP data if it doesn't exist
|
|
os.makedirs('tmp/imap-data', exist_ok=True)
|
|
|
|
# Start the services
|
|
try:
|
|
subprocess.run(['docker-compose', 'up', '-d'], check=True)
|
|
print("Services started successfully:")
|
|
print("- PostgreSQL: localhost:5432 (database: email_organizer_dev, user: postgres, password: password)")
|
|
print("- IMAP Server: localhost:1143")
|
|
print(" Users:")
|
|
print(" - user1@example.com / password1")
|
|
print(" - user2@example.com / password2")
|
|
print(" Folders: INBOX, Pending, Work, Personal, Receipts, Marketing, Archived")
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error starting services: {e}")
|
|
sys.exit(1)
|
|
except FileNotFoundError:
|
|
print("Docker Compose not found. Please install Docker and Docker Compose.")
|
|
sys.exit(1)
|
|
|
|
def mock_process_emails():
|
|
"""Simulate processing emails with defined rules."""
|
|
with app.app_context():
|
|
# Mock user ID
|
|
mock_user_id = '123e4567-e89b-12d3-a456-426614174000'
|
|
folders = Folder.query.filter_by(user_id=mock_user_id).all()
|
|
|
|
# Mock emails
|
|
emails = [
|
|
{'subject': 'Your Amazon Order', 'from': 'no-reply@amazon.com', 'body': 'Your order has shipped.'},
|
|
{'subject': 'Meeting Reminder', 'from': 'boss@company.com', 'body': 'Don\'t forget the meeting at 3 PM.'},
|
|
{'subject': 'Special Offer!', 'from': 'deals@shop.com', 'body': 'Exclusive discounts inside!'}
|
|
]
|
|
|
|
print("Starting mock email processing...")
|
|
for email in emails:
|
|
print(f"\nProcessing email: {email['subject']}")
|
|
matched = False
|
|
for folder in folders:
|
|
# Simple mock rule matching (in real app, this would be more complex)
|
|
if folder.rule_text.lower() in email['subject'].lower() or folder.rule_text.lower() in email['from'].lower():
|
|
print(f" -> Matched rule '{folder.rule_text}' -> Folder '{folder.name}'")
|
|
matched = True
|
|
break
|
|
if not matched:
|
|
print(" -> No matching rule found.")
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) > 1 and sys.argv[1] == 'mock-process':
|
|
mock_process_emails()
|
|
else:
|
|
print("Usage: python manage.py mock-process")
|
|
print(" flask setup-dev")
|