Skip to content

Headers are treated case sensitively #162

@GUI

Description

@GUI

If MailHog receives messages where the headers aren't in the expected case, then MailHog's interface doesn't display the message properly. For example, if the headers are all lower case (so 'subject' instead of 'Subject'), then the to/from, subject, and HTML message parsing doesn't work as expected.

  • Here's a quick example using mhsendmail:

    (
    echo "from: me@xyz.com"
    echo "to: them@xyz.com"
    echo "mime-version: 1.0"
    echo "content-type: multipart/alternative; "
    echo ' boundary="some.unique.value.ABC123/server.xyz.com"'
    echo "subject: Test HTML e-mail."
    echo ""
    echo "This is a MIME-encapsulated message"
    echo ""
    echo "--some.unique.value.ABC123/server.xyz.com"
    echo "content-type: text/html"
    echo ""
    echo "<html>
    <head>
    <title>HTML E-mail</title>
    </head>
    <body>
    <a href='http://www.google.com'>Click Here</a>
    </body>
    </html>"
    echo "--some.unique.value.ABC123/server.xyz.com--"
    ) | mhsendmail test@mailhog.local
    

    In the inbox this message shows up as being from {{ getSender(message) }}, and contains a blank subject. The actual message shows up like this:

    lower-case-headers
  • If I use the more standard title-case for the headers, then this same test works as expected:

    (
    echo "From: me@xyz.com"
    echo "To: them@xyz.com"
    echo "MIME-Version: 1.0"
    echo "Content-Type: multipart/alternative; "
    echo ' boundary="some.unique.value.ABC123/server.xyz.com"'
    echo "Subject: Test HTML e-mail."
    echo ""
    echo "This is a MIME-encapsulated message"
    echo ""
    echo "--some.unique.value.ABC123/server.xyz.com"
    echo "Content-Type: text/html"
    echo ""
    echo "<html>
    <head>
    <title>HTML E-mail</title>
    </head>
    <body>
    <a href='http://www.google.com'>Click Here</a>
    </body>
    </html>"
    echo "--some.unique.value.ABC123/server.xyz.com--"
    ) | mhsendmail test@mailhog.local
    

    Which shows up as:

    title-case-headers

I saw a few explicit headers are being treated in a case insensitive fashion, but this doesn't extend to all headers, like "From," "To," "Subject," and "Content-Type." I poked around a bit to see about submitting a pull request, but I wasn't sure the preferred way to go about it. I saw various things in the UI are expecting title-cased headers, so maybe it would be simplest to have the server normalize all the values to title-case to minimize the UI changes needed?

I'm not sure how common this is, but headers should be case insensitive according to the spec. I encountered this since LuaSocket's SMTP client actually does lowercase all the headers before sending.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions