0 votes
by (190 points)
edited

When I create a new mail message, or Mime Message, for each attachment or entity that I add the content-id looks like this: Content-ID: <57ff0553-3900-4503-9686-4419e2797d04>

While it should be like this: Content-ID: 57ff0553-3900-4503-9686-4419e2797d04

The system to which I send the message does not understand the "< >" delimiters in the ID How may I resolve this

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (148k points)
edited

Please note that RFC 2392 clearly states that Content-ID is supposed to be enclosed in angle brackets, which means that "Content-ID: <foo@bar.net>" is actually the correct form. It also says that the older RFC 2111 got the sample (with no angle brackets) wrong.

Fortunately, Rebex MIME is versatile enough to make it possible to create a message with bracket-less content IDs. All you need is the following routine:

public static void ForceBadContentIds(MimeEntity entity)
{
    if (entity.ContentId != null)
    {   
        entity.Headers["Content-ID"] =
            new MimeHeader("Content-ID", new Unparsed(entity.ContentId.Id));
    }

    foreach (MimeEntity part in entity.Parts)
    {
        ForceBadContentIds(part);
    }

    if (entity.ContentMessage != null)
        ForceBadContentIds(entity.ContentMessage);
}

Simple call this method on an instance of MimeMessage or MimeEntity to remove the angle brackets. For example:

    MimeMessage mime = new MimeMessage();
    mime.Load(fileNameIn);
    ForceBadContentIds(mime);
    mime.Save(fileNameOut);

If you would like to process an instance of MailMessage instead, convert it to MimeMessage first and then back:

    MailMessage mail = new MailMessage();
    mail.Load(fileNameIn);
    MimeMessage mime = mail.ToMimeMessage();
    ForceBadContentIds(mime);
    mail = new MailMessage(mime);
    mail.Save(fileNameOut);
...