bertjohnson/OpaqueMail

MailMessage class is not CLS compliant

Closed this issue · 1 comments

Let me start off by thanking you for making this library available, it's fantastic!

I'm currently using OpaqueMail as part of a PowerShell script, and ran into a problem when trying to view the contents of MailMessage objects:

The field or property: "pgpSigned" for type: "OpaqueMail.MailMessage" differs only in letter casing from the field or property: "PgpSigned". 
The type must be Common Language Specification (CLS) compliant.
At line:1 char:1
+ $messages[0].Subject
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : NotACLSComplaintField

In C#, having public properties/fields that only differ in character casing is perfectly valid, but this is illegal other languages like VB or PowerShell.

The offending line is highlighted here:

public bool pgpSigned = false;

I'm not opening a PR because the fix is trivial: just make pgpSigned private. pgpEncrypted also looks like it was meant to be private.

Lastly, a workaround for anyone else experiencing this issue:

Function Get-MailMessageProperty
{
    Param(
        [Parameter(Mandatory = $true)] [OpaqueMail.MailMessage] $MailMessage,
        [Parameter(Mandatory = $true)] [string] $Property
    )
    return [OpaqueMail.MailMessage].GetProperty($Property).GetValue($MailMessage)
}

To get the message subject for example, call the function like this:

Get-MailMessageProperty $mailMessageObject -Property Subject

Thanks easuter. Very small change and I'm glad you pointed it out. That's fixed in release 2.3.1, now on GitHub.