🔍 Code Extractor

function print_banner

Maturity: 42

Prints a formatted ASCII banner displaying the Email Forwarder application's configuration settings including version, SMTP settings, message size limits, and debug status.

File:
/tf/active/vicechatdev/email-forwarder/src/main.py
Lines:
20 - 33
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v58 59.2% similar

    Performs a comprehensive status check of an email forwarder service, verifying process status, port availability, SMTP communication, and configuration settings.

    From: /tf/active/vicechatdev/email-forwarder/service_status.py
  • function main_v9 57.6% similar

    Asynchronous main entry point function that initializes and runs an email forwarding SMTP server with logging, configuration validation, and graceful shutdown handling.

    From: /tf/active/vicechatdev/email-forwarder/src/main.py
  • function main_v54 57.0% similar

    Entry point function that validates the working directory and starts an email forwarding service.

    From: /tf/active/vicechatdev/email-forwarder/run_service.py
  • function main_v70 56.0% similar

    Command-line interface function that parses arguments and sends a test email through an SMTP forwarder service, displaying connection details and returning an exit code based on success.

    From: /tf/active/vicechatdev/email-forwarder/send_test_email.py
  • function send_test_email 54.0% similar

    Sends a test email via SMTP to verify email forwarding service functionality, creating a MIME multipart message with customizable sender, recipient, subject, and body content.

    From: /tf/active/vicechatdev/email-forwarder/send_test_email.py
← Back to Browse