🔍 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 _message_to_payload 44.7% similar

    Converts an email Message object to a payload format by replacing line feed characters with CRLF (carriage return + line feed) and removing the first two lines.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/internal/multipart_page_query.py
  • 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 msg_to_eml_alternative 43.4% similar

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

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function eml_to_pdf 41.6% similar

    Converts an .eml email file to PDF format, including the email body and all attachments merged into a single PDF document.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function generate_simple_html_from_eml 40.6% similar

    Converts an email.message.Message object into a clean, styled HTML representation with embedded inline images and attachment listings.

    From: /tf/active/vicechatdev/msg_to_eml.py
← Back to Browse