Skip to content

Commit

Permalink
Add avatar preference tag
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Dec 29, 2024
1 parent 64315ab commit 23f68da
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions BusinessMonitor.MailTools.Test/BimiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public void TestParse()
Assert.That(record3, Is.Not.Null);
}

[Test]
public void TestAvatar()
{
var record = BimiCheck.ParseBimiRecord("v=BIMI1; l=https://example.com/logo.svg; s=personal");

Assert.That(record, Is.Not.Null);
Assert.That(record.AvatarPreference, Is.EqualTo(AvatarPreference.Personal));

var record2 = BimiCheck.ParseBimiRecord("v=BIMI1; l=https://example.com/logo.svg; s=bimi");

Assert.That(record2, Is.Not.Null);
Assert.That(record2.AvatarPreference, Is.EqualTo(AvatarPreference.Bimi));

var record3 = BimiCheck.ParseBimiRecord("v=BIMI1; l=https://example.com/logo.svg");

Assert.That(record3, Is.Not.Null);
Assert.That(record3.AvatarPreference, Is.EqualTo(AvatarPreference.Bimi));
}

[Test]
public void TestLookup()
{
Expand All @@ -48,6 +67,7 @@ public void TestLookup()
[TestCase("v=BIMI1; l=invalidlink")]
[TestCase("v=BIMI1; a=invalidlink l=https://businessmonitor.nl/logo.svg")]
[TestCase("v=BIMI1; l=http://nothttpstransport")]
[TestCase("v=BIMI1; l=https://example.com/logo.svg; s=invalid")]
public void TestInvalid(string value)
{
Assert.Throws<BimiInvalidException>(() =>
Expand Down
8 changes: 8 additions & 0 deletions BusinessMonitor.MailTools/Bimi/AvatarPreference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BusinessMonitor.MailTools.Bimi
{
public enum AvatarPreference
{
Personal,
Bimi
}
}
16 changes: 16 additions & 0 deletions BusinessMonitor.MailTools/Bimi/BimiCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public static BimiRecord ParseBimiRecord(string value)
ValidateUri(val, "location");
record.Location = val;

break;

// Avatar Preference
case "s":
record.AvatarPreference = GetAvatarPreference(val);

break;
}
}
Expand Down Expand Up @@ -148,5 +154,15 @@ private static void ValidateUri(string value, string type)
throw new BimiInvalidException($"BIMI record {type} is invalid, transport must be HTTPS");
}
}

private static AvatarPreference GetAvatarPreference(string value)
{
if (value != "personal" && value != "bimi")
{
throw new BimiInvalidException("Invalid avatar preference, must be personal or bimi");
}

return value == "personal" ? AvatarPreference.Personal : AvatarPreference.Bimi;
}
}
}
6 changes: 6 additions & 0 deletions BusinessMonitor.MailTools/Bimi/BimiRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal BimiRecord()
{
Evidence = "";
Location = null;
AvatarPreference = AvatarPreference.Bimi;
}

/// <summary>
Expand All @@ -20,5 +21,10 @@ internal BimiRecord()
/// Gets the location of the Brand Indicator file
/// </summary>
public string? Location { get; internal set; }

/// <summary>
/// Gets the avatar preference
/// </summary>
public AvatarPreference AvatarPreference { get; internal set; }
}
}

0 comments on commit 23f68da

Please sign in to comment.