import sys 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())) 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")