function print_banner
Prints a formatted ASCII banner displaying the Email Forwarder application's configuration settings including version, SMTP settings, message size limits, and debug status.
/tf/active/vicechatdev/email-forwarder/src/main.py
20 - 33
simple
Purpose
This function displays a visually formatted startup banner for the Email Forwarder application. It provides operators with immediate visibility of key configuration parameters when the application starts, including SMTP listen address/port, maximum message size, MS365 sender email, and debug mode status. This is typically called during application initialization to confirm settings before the service begins processing emails.
Source Code
def print_banner():
"""Print application banner."""
banner = f"""
╔══════════════════════════════════════════════════════════════╗
║ Email Forwarder ║
║ Version {settings.VERSION} ║
╠══════════════════════════════════════════════════════════════╣
║ SMTP Listen Address: {settings.SMTP_LISTEN_HOST}:{settings.SMTP_LISTEN_PORT:<4} ║
║ Max Message Size: {settings.MAX_MESSAGE_SIZE // (1024*1024)}MB ║
║ MS365 Sender: {settings.MS365_SENDER_EMAIL:<30} ║
║ Debug Mode: {'Enabled' if settings.DEBUG else 'Disabled':<30} ║
╚══════════════════════════════════════════════════════════════╝
"""
print(banner)
Return Value
This function returns None. It performs a side effect of printing the banner to stdout.
Required Imports
from config import settings
Usage Example
from config import settings
# Ensure settings object has required attributes
class Settings:
VERSION = '1.0.0'
SMTP_LISTEN_HOST = '0.0.0.0'
SMTP_LISTEN_PORT = 25
MAX_MESSAGE_SIZE = 10485760 # 10MB in bytes
MS365_SENDER_EMAIL = 'noreply@example.com'
DEBUG = False
settings = Settings()
def print_banner():
"""Print application banner."""
banner = f"""
╔══════════════════════════════════════════════════════════════╗
║ Email Forwarder ║
║ Version {settings.VERSION} ║
╠══════════════════════════════════════════════════════════════╣
║ SMTP Listen Address: {settings.SMTP_LISTEN_HOST}:{settings.SMTP_LISTEN_PORT:<4} ║
║ Max Message Size: {settings.MAX_MESSAGE_SIZE // (1024*1024)}MB ║
║ MS365 Sender: {settings.MS365_SENDER_EMAIL:<30} ║
║ Debug Mode: {'Enabled' if settings.DEBUG else 'Disabled':<30} ║
╚══════════════════════════════════════════════════════════════╝
"""
print(banner)
# Call the function
print_banner()
Best Practices
- Call this function once during application startup, typically in the main() function or entry point
- Ensure all required settings attributes exist before calling to avoid AttributeError
- The MS365_SENDER_EMAIL should be 30 characters or less for proper banner alignment
- MAX_MESSAGE_SIZE should be divisible by (1024*1024) for clean MB display, or adjust formatting if fractional MB values are expected
- Consider redirecting output if running as a daemon/service where stdout may not be visible
- The banner uses Unicode box-drawing characters (╔═╗║╠╣╚╝) which require UTF-8 encoding support in the terminal
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v58 59.2% similar
-
function main_v9 57.6% similar
-
function main_v54 57.0% similar
-
function main_v70 56.0% similar
-
function send_test_email 54.0% similar