🔍 Code Extractor

function parse_email_address

Maturity: 42

Parses email address strings by handling multiple addresses separated by semicolons and converting them to comma-separated format.

File:
/tf/active/vicechatdev/msg_to_eml.py
Lines:
32 - 41
Complexity:
simple

Purpose

This function normalizes email address strings for consistent formatting. It handles cases where multiple email addresses are separated by semicolons (common in some email clients like Outlook) and converts them to a comma-separated format. Empty or None inputs are safely handled by returning an empty string.

Source Code

def parse_email_address(address_string):
    """Parse email address strings into proper format"""
    if not address_string:
        return ''
        
    # Handle multiple addresses separated by semicolons
    if ';' in address_string:
        addresses = address_string.split(';')
        return ', '.join(addr.strip() for addr in addresses if addr.strip())
    return address_string

Parameters

Name Type Default Kind
address_string - - positional_or_keyword

Parameter Details

address_string: A string containing one or more email addresses. Can be a single email address, multiple addresses separated by semicolons, or None/empty string. Expected format examples: 'user@example.com', 'user1@example.com; user2@example.com', or None.

Return Value

Returns a string containing the formatted email address(es). If input contains semicolon-separated addresses, returns them as comma-separated with whitespace trimmed. Returns empty string if input is None, empty, or contains only whitespace. Return type is always str.

Usage Example

# Example 1: Single email address
result = parse_email_address('user@example.com')
print(result)  # Output: 'user@example.com'

# Example 2: Multiple semicolon-separated addresses
result = parse_email_address('user1@example.com; user2@example.com; user3@example.com')
print(result)  # Output: 'user1@example.com, user2@example.com, user3@example.com'

# Example 3: Empty or None input
result = parse_email_address(None)
print(result)  # Output: ''

# Example 4: Addresses with extra whitespace
result = parse_email_address('user1@example.com ;  user2@example.com  ')
print(result)  # Output: 'user1@example.com, user2@example.com'

Best Practices

  • This function does not validate email address format - it only reformats the separator characters
  • The function assumes semicolons are the only alternative separator to commas
  • Empty addresses in the semicolon-separated list are filtered out automatically
  • The function is safe to use with None or empty string inputs
  • Consider adding email validation logic if you need to ensure addresses are properly formatted
  • This function does not handle email addresses with display names (e.g., 'John Doe <john@example.com>') - it treats them as plain strings

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function msg_to_eml 43.7% similar

    Converts Microsoft Outlook .msg files to standard .eml format, preserving email headers, body content (plain text and HTML), and attachments.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function convert_european_decimals 43.4% similar

    Detects and converts numeric data with European decimal format (comma as decimal separator) to standard format (dot as decimal separator) in a pandas DataFrame, handling mixed formats and missing data patterns.

    From: /tf/active/vicechatdev/vice_ai/smartstat_service.py
  • function smart_read_csv 43.2% similar

    Automatically detects CSV file delimiters (comma, semicolon, tab) and handles regional decimal formats (European comma vs US/UK point) to reliably parse CSV files from different locales.

    From: /tf/active/vicechatdev/vice_ai/smartstat_service.py
  • function msg_to_eml_alternative 42.7% similar

    Converts Microsoft Outlook .msg files to .eml (email) format using the extract_msg library, preserving email headers, body content (plain text and HTML), and attachments.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function main_v67 42.5% 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
← Back to Browse