Skip to content

Commit

Permalink
fix(API): #474 recipient properties should be array typed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rnwood committed Apr 13, 2024
1 parent 03da0a3 commit 26d5f06
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Rnwood.Smtp4dev.Tests/Controllers/MessagesControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public async Task GetMessage_ValidMime()
Assert.Equal(testMessage1.Id, result.Id);
Assert.InRange(result.ReceivedDate, startDate, DateTime.Now);
Assert.Equal("from@message.com", result.From);
Assert.Equal("to@message.com", result.To);
Assert.Equal("to@envelope.com", result.Bcc);
Assert.Equal("cc@message.com", result.Cc);
Assert.Equal(new[]{"to@message.com"}, result.To);
Assert.Equal(new[]{"to@envelope.com"}, result.Bcc);
Assert.Equal(new[]{"cc@message.com"}, result.Cc);
Assert.Equal("subject", result.Subject);

var allParts = result.Parts.Flatten(p => p.ChildParts).ToList();
Expand Down
21 changes: 11 additions & 10 deletions Rnwood.Smtp4dev/ApiModel/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public Message(DbModel.Message dbMessage)
Data = dbMessage.Data;
Id = dbMessage.Id;
From = dbMessage.From;
To = dbMessage.To;
Cc = "";
Bcc = "";
To = dbMessage.To.Split(',');
Cc = Array.Empty<string>();
Bcc = Array.Empty<string>();
ReceivedDate = dbMessage.ReceivedDate;
Subject = dbMessage.Subject;
SecureConnection = dbMessage.SecureConnection;
Expand Down Expand Up @@ -50,7 +50,7 @@ public Message(DbModel.Message dbMessage)

if (MimeMessage.To != null)
{
To = string.Join(", ", MimeMessage.To.Select(t => PunyCodeReplacer.DecodePunycode(t.ToString())));
To = MimeMessage.To.Select(t => PunyCodeReplacer.DecodePunycode(t.ToString())).ToArray();

foreach (var internetAddress in MimeMessage.To.Where(t => t is MailboxAddress))
{
Expand All @@ -61,7 +61,7 @@ public Message(DbModel.Message dbMessage)

if (MimeMessage.Cc != null)
{
Cc = string.Join(", ", MimeMessage.Cc.Select(t => PunyCodeReplacer.DecodePunycode(t.ToString())));
Cc = MimeMessage.Cc.Select(t => PunyCodeReplacer.DecodePunycode(t.ToString())).ToArray();

foreach (var internetAddress in MimeMessage.Cc.Where(t => t is MailboxAddress))
{
Expand All @@ -70,7 +70,7 @@ public Message(DbModel.Message dbMessage)
}
}

Bcc = string.Join(", ", recipients);
Bcc = recipients.ToArray();

Headers = MimeMessage.Headers.Select(h => new Header { Name = h.Field, Value = PunyCodeReplacer.DecodePunycode(h.Value) }).ToList();
Parts.Add(HandleMimeEntity(MimeMessage.Body));
Expand Down Expand Up @@ -216,9 +216,9 @@ private static MimeEntity GetPart(Message message, string id)
public Guid Id { get; set; }

public string From { get; set; }
public string To { get; set; }
public string Cc { get; set; }
public string Bcc { get; set; }
public string[] To { get; set; }
public string[] Cc { get; set; }
public string[] Bcc { get; set; }
public DateTime ReceivedDate { get; set; }

public bool SecureConnection { get; set; }
Expand All @@ -238,6 +238,7 @@ private static MimeEntity GetPart(Message message, string id)

internal byte[] Data { get; set; }

string ICacheByKey.CacheKey => Id.ToString();
[JsonIgnore]
string ICacheByKey.CacheKey => Id.ToString() + "v2";
}
}
9 changes: 6 additions & 3 deletions Rnwood.Smtp4dev/ApiModel/MessageSummary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;

namespace Rnwood.Smtp4dev.ApiModel
{
Expand All @@ -8,7 +9,7 @@ public MessageSummary(DbModel.Message dbMessage)
{
Id = dbMessage.Id;
From = dbMessage.From;
To = dbMessage.To;
To = dbMessage.To.Split(',');
ReceivedDate = dbMessage.ReceivedDate;
Subject = dbMessage.Subject;
AttachmentCount = dbMessage.AttachmentCount;
Expand All @@ -21,7 +22,7 @@ public MessageSummary(DbModel.Message dbMessage)
public Guid Id { get; set; }

public string From { get; set; }
public string To { get; set; }
public string[] To { get; set; }
public DateTime ReceivedDate { get; set; }

public string Subject { get; set; }
Expand All @@ -30,6 +31,8 @@ public MessageSummary(DbModel.Message dbMessage)

public bool IsUnread { get; set; }

string ICacheByKey.CacheKey => Id.ToString() + IsUnread + IsRelayed;

[JsonIgnore]
string ICacheByKey.CacheKey => Id.ToString() + IsUnread + IsRelayed + "v2";
}
}
3 changes: 3 additions & 0 deletions Rnwood.Smtp4dev/ApiModel/SessionSummary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Rnwood.Smtp4dev.ApiModel
Expand Down Expand Up @@ -29,6 +30,8 @@ public SessionSummary(DbModel.Session dbSession)

public int Size { get; private set; }


[JsonIgnore]
string ICacheByKey.CacheKey => Id.ToString();
}
}
12 changes: 6 additions & 6 deletions Rnwood.Smtp4dev/ClientApp/src/ApiClient/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default class Message {
constructor(
id: string,
from: string,
to: string,
cc: string,
bcc: string,
to: string[],
cc: string[],
bcc: string[],
receivedDate: Date,
subject: string,
parts: MessageEntitySummary[],
Expand Down Expand Up @@ -37,9 +37,9 @@ export default class Message {

id: string;
from: string;
to: string;
cc: string;
bcc: string;
to: string[];
cc: string[];
bcc: string[];
receivedDate: Date;
subject: string;
parts: MessageEntitySummary[];
Expand Down
4 changes: 2 additions & 2 deletions Rnwood.Smtp4dev/ClientApp/src/ApiClient/MessageSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
constructor(
id: string,
from: string,
to: string,
to: string[],
receivedDate: Date,
subject: string,
attachmentCount: number,
Expand All @@ -21,7 +21,7 @@

id: string;
from: string;
to: string;
to: string[];
receivedDate: Date;
subject: string;
attachmentCount: number;
Expand Down
8 changes: 7 additions & 1 deletion Rnwood.Smtp4dev/ClientApp/src/components/messagelist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
label="To"
width="180"
sortable="custom"
:formatter="formatTo"
></el-table-column>
<el-table-column
property="isRelayed"
Expand Down Expand Up @@ -228,6 +229,11 @@ export default class MessageList extends Vue {
return (<any>moment)(cellValue).format("YYYY-MM-DD HH:mm:ss");
}
formatTo(row: number, column: number, cellValue: []): string {
return cellValue.join(", ");
}
getRowClass(event: { row: MessageSummary }): string {
return event.row.isUnread ? "unread" : "read";
}
Expand All @@ -245,7 +251,7 @@ export default class MessageList extends Vue {
"Relay Message",
{
confirmButtonText: "OK",
inputValue: this.selectedmessage.to,
inputValue: this.selectedmessage.to.join(","),
cancelButtonText: "Cancel",
inputPattern: /[^, ]+(, *[^, ]+)*/,
inputErrorMessage: "Invalid email addresses",
Expand Down
12 changes: 6 additions & 6 deletions Rnwood.Smtp4dev/ClientApp/src/components/messageview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

<tr>
<td>To:</td>
<td><span v-if="message">{{message.to}}</span></td>
<td><span v-if="message">{{message.to.join(", ")}}</span></td>
</tr>
<tr v-if="message && message.cc">
<tr v-if="message && message.cc.length">
<td>Cc:</td>
<td>{{message.cc}}</td>
<td>{{message.cc.join(", ")}}</td>
</tr>
<tr v-if="message && message.bcc">
<tr v-if="message && message.bcc.length">
<td>Bcc:</td>
<td>{{message.bcc}}</td>
<td>{{message.bcc.join(", ")}}</td>
</tr>
<tr>
<td>Subject:</td>
Expand Down Expand Up @@ -288,7 +288,7 @@ export default class MessageView extends Vue {
let dialogResult = <MessageBoxInputData>await this.$prompt('Email address(es) to relay to (separate multiple with ,)', 'Relay Message', {
confirmButtonText: 'OK',
inputValue: this.messageSummary.to,
inputValue: this.messageSummary.to.join(","),
cancelButtonText: 'Cancel',
inputPattern: /[^, ]+(, *[^, ]+)*/,
inputErrorMessage: 'Invalid email addresses'
Expand Down
8 changes: 1 addition & 7 deletions Rnwood.Smtp4dev/Server/CertificateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

namespace Rnwood.Smtp4dev.Server
{
public static class CertificateHelper
internal static class CertificateHelper
{
/// <summary>
/// Load certificate and private key
/// </summary>
/// <param name="certificatePath"></param>
/// <param name="certificateKeyPath"></param>
/// <returns>Exported x509 Certificate</returns>
public static X509Certificate2 LoadCertificateWithKey(string certificatePath, string certificateKeyPath, string password)
{
using var rsa = RSA.Create();
Expand Down

0 comments on commit 26d5f06

Please sign in to comment.