Skip to content

Commit 57bfae0

Browse files
committed
Fix formatting
Line endings were not changed within this formatting to avoid making the change log huge for reviewing purposes.
1 parent bbffe07 commit 57bfae0

File tree

9 files changed

+49
-47
lines changed

9 files changed

+49
-47
lines changed

src/MiddleMail.Client.RabbitMQ/MiddleMailClient.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using EasyNetQ;
44
using Microsoft.Extensions.Options;
@@ -31,12 +31,12 @@ public async Task<bool> SendEmailAsync(EmailMessage emailMessage) {
3131
try {
3232
await bus.PublishAsync(emailMessage);
3333
return true;
34-
} catch(Exception e) {
34+
} catch (Exception e) {
3535
logger.LogError("Failed to publish to rabbitmq queue.", e);
3636
return false;
3737
}
3838
}
39-
39+
4040
public void Dispose() {
4141
bus?.Dispose();
4242
}

src/MiddleMail.Delivery.Smtp/MimeMessageBuilder.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.Extensions.Options;
77

88
namespace MiddleMail.Delivery.Smtp {
9-
9+
1010
/// <summary>
1111
/// Builds MIME messages from an <see cref="EMailMessage" />.
1212
/// </summary>
@@ -22,22 +22,22 @@ public MimeMessageBuilder(IOptions<MimeMessageOptions> options) {
2222
/// Note that <paramref name="emailMessage" /> must specify at least a plaintext version.
2323
/// </summary>
2424
public MimeMessage Create(EmailMessage emailMessage) {
25-
if(emailMessage.PlainText == null) {
25+
if (emailMessage.PlainText == null) {
2626
throw new ArgumentException($"EmailMessage should always contains a Plaintext, but it is null.", nameof(emailMessage));
2727
}
28-
28+
2929
var mimeMessage = new MimeMessage();
3030
mimeMessage.From.Add(new MailboxAddress(emailMessage.From.name, emailMessage.From.address));
3131
mimeMessage.To.Add(new MailboxAddress(emailMessage.To.name, emailMessage.To.address));
3232

3333
emailMessage.Cc?.ForEach(cc => mimeMessage.Cc.Add(new MailboxAddress(cc.name, cc.address)));
3434

35-
if(emailMessage.ReplyTo.HasValue) {
35+
if (emailMessage.ReplyTo.HasValue) {
3636
mimeMessage.ReplyTo.Add(new MailboxAddress(emailMessage.ReplyTo.Value.name, emailMessage.ReplyTo.Value.address));
3737
}
3838
mimeMessage.Subject = emailMessage.Subject;
3939

40-
if(emailMessage.HtmlText == null) {
40+
if (emailMessage.HtmlText == null) {
4141
createBodyPlainText(emailMessage, mimeMessage);
4242
} else {
4343
createBodyMultipart(emailMessage, mimeMessage);
@@ -58,15 +58,15 @@ private void createBodyPlainText(EmailMessage emailMessage, MimeMessage message)
5858
private void createBodyMultipart(EmailMessage emailMessage, MimeMessage message) {
5959
var bodyBuilder = new BodyBuilder();
6060
bodyBuilder.HtmlBody = emailMessage.HtmlText;
61-
bodyBuilder.TextBody = emailMessage.PlainText;
61+
bodyBuilder.TextBody = emailMessage.PlainText;
6262

6363
message.Body = bodyBuilder.ToMessageBody();
6464
}
6565

6666
private void setHeaders(EmailMessage emailMessage, MimeMessage message) {
6767
foreach (var item in emailMessage.Headers) {
6868
// do not override any headers
69-
var header = message.Headers.FirstOrDefault(h => h.Field == item.Key);
69+
var header = message.Headers.FirstOrDefault(h => h.Field == item.Key);
7070
if (header == null) {
7171
message.Headers.Add(item.Key, item.Value);
7272
}

src/MiddleMail.Delivery.Smtp/SmtpDeliverer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task DeliverAsync(EmailMessage emailMessage) {
2323
MimeMessage mimeMessage;
2424
try {
2525
mimeMessage = builder.Create(emailMessage);
26-
} catch(Exception e) {
26+
} catch (Exception e) {
2727
throw new MimeMessageBuilderException(emailMessage, e);
2828
}
2929
try {

src/MiddleMail.Storage.ElasticSearch/ElasticSearchStorage.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace MiddleMail.Storage.ElasticSearch {
1414
/// Use <see cref="ElasticSearchStorageOptions" /> to configure the connection and index.
1515
/// </summary>
1616
public class ElasticSearchStorage : IMailStorage {
17-
17+
1818
private readonly ElasticClient client;
1919
private readonly ElasticSearchStorageOptions options;
2020
public ElasticSearchStorage(IOptions<ElasticSearchStorageOptions> options) {
@@ -28,21 +28,21 @@ public ElasticSearchStorage(IOptions<ElasticSearchStorageOptions> options) {
2828
}
2929

3030
public async Task SetProcessedAsync(EmailMessage emailMessage) {
31-
await updateOrCreateAsync(emailMessage,
31+
await updateOrCreateAsync(emailMessage,
3232
update: (EmailDocument emailDocument) => { },
3333
create: () => new EmailDocument(emailMessage));
3434
}
3535

3636
public async Task SetSentAsync(EmailMessage emailMessage) {
37-
await updateOrCreateAsync(emailMessage,
37+
await updateOrCreateAsync(emailMessage,
3838
update: (EmailDocument emailDocument) => {
3939
emailDocument.Sent = DateTime.UtcNow;
4040
},
4141
create: () => new EmailDocument(emailMessage, sent: DateTime.UtcNow));
4242
}
4343

4444
public async Task SetErrorAsync(EmailMessage emailMessage, string errorMessage) {
45-
await updateOrCreateAsync(emailMessage,
45+
await updateOrCreateAsync(emailMessage,
4646
update: (EmailDocument emailDocument) => {
4747
emailDocument.Error = errorMessage;
4848
},
@@ -51,7 +51,7 @@ await updateOrCreateAsync(emailMessage,
5151

5252
private async Task updateOrCreateAsync(EmailMessage emailMessage, Action<EmailDocument> update, Func<EmailDocument> create) {
5353
var emailDocument = await searchDocument(emailMessage.Id);
54-
if(emailDocument != null) {
54+
if (emailDocument != null) {
5555
if (emailDocument.Sent != null) {
5656
throw new EMailMessageAlreadySentStorageException(emailMessage);
5757
}
@@ -71,22 +71,22 @@ private async Task updateOrCreateAsync(EmailMessage emailMessage, Action<EmailDo
7171
var existingDocument = await searchDocument(emailMessage.Id);
7272
return existingDocument?.Sent != null;
7373
}
74-
74+
7575
public async Task<string> GetErrorAsync(EmailMessage emailMessage) {
7676
var existingDocument = await searchDocument(emailMessage.Id);
77-
return existingDocument?.Error;
77+
return existingDocument?.Error;
7878
}
7979

8080
private string index => options.Index;
81-
81+
8282
private async Task<EmailDocument> searchDocument(Guid id) {
8383
var response = await client.SearchAsync<EmailDocument>(s => s
8484
.Index(index)
8585
.Query(q => q
8686
.Term(c => c
8787
.Field(p => p.Id)
8888
.Value(id))));
89-
89+
9090
return response.Documents.SingleOrDefault();
9191
}
9292
}

src/MiddleMail.Storage.Memory/MemoryStorage.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ namespace MiddleMail.Storage.Memory {
1111
/// A reference implementation for <see cref="IMailStorage" /> backed by a dictionary in memory.
1212
/// </summary>
1313
public class MemoryStorage : IMailStorage {
14-
14+
1515
private readonly ConcurrentDictionary<EmailMessage, (bool sent, string error)> storage;
1616

1717
public MemoryStorage() {
1818
this.storage = new ConcurrentDictionary<EmailMessage, (bool sent, string error)>();
1919
}
2020

2121
public Task SetProcessedAsync(EmailMessage emailMessage) {
22-
storage.AddOrUpdate(emailMessage,
23-
addValue: (false, null),
22+
storage.AddOrUpdate(emailMessage,
23+
addValue: (false, null),
2424
updateValueFactory: (EmailMessage key, (bool sent, string error) value) => {
2525
if (value.sent) {
2626
throw new EMailMessageAlreadySentStorageException(emailMessage);
@@ -32,8 +32,8 @@ public Task SetProcessedAsync(EmailMessage emailMessage) {
3232
}
3333

3434
public Task SetSentAsync(EmailMessage emailMessage) {
35-
storage.AddOrUpdate(emailMessage,
36-
addValue: (true, null),
35+
storage.AddOrUpdate(emailMessage,
36+
addValue: (true, null),
3737
updateValueFactory: (EmailMessage key, (bool sent, string error) value) => {
3838
if (value.sent) {
3939
throw new EMailMessageAlreadySentStorageException(emailMessage);
@@ -45,7 +45,7 @@ public Task SetSentAsync(EmailMessage emailMessage) {
4545
}
4646

4747
public Task SetErrorAsync(EmailMessage emailMessage, string errorMessage) {
48-
storage.AddOrUpdate(emailMessage,
48+
storage.AddOrUpdate(emailMessage,
4949
addValue: (false, errorMessage),
5050
updateValueFactory: (EmailMessage key, (bool sent, string error) value) => {
5151
if (value.sent) {
@@ -56,7 +56,7 @@ public Task SetErrorAsync(EmailMessage emailMessage, string errorMessage) {
5656
);
5757
return Task.CompletedTask;
5858
}
59-
59+
6060
public Task<bool?> GetSentAsync(EmailMessage emailMessage) {
6161
var found = storage.TryGetValue(emailMessage, out var value);
6262
if (found) {

src/MiddleMail/IMailStorage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using MiddleMail.Model;
33

44
namespace MiddleMail {
5-
5+
66
/// <summary>
77
/// A storage to persist email activity. When calling any of the methods that set data, the order must be kept.
88
/// Writing data does not need to be instantly and might not be reflected when reading it directly back.
@@ -14,7 +14,7 @@ public interface IMailStorage {
1414
/// This can happen multiple times.
1515
/// </summary>
1616
Task SetProcessedAsync(EmailMessage emailMessage);
17-
17+
1818
/// <summary>
1919
/// Store that an <see cref="EmailMessage" /> was successfully sent.
2020
/// </summary>

src/MiddleMail/MessageProcessor.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,38 @@ public async Task ProcessAsync(EmailMessage emailMessage) {
3535
string cached = null;
3636
try {
3737
cached = await cache.GetStringAsync(emailMessage.Id.ToString());
38-
} catch(Exception e) {
38+
} catch (Exception e) {
3939
throw new GeneralProcessingException(emailMessage, e);
4040
}
4141

42-
if(cached != null) {
42+
if (cached != null) {
4343
logger.LogInformation($"Caught duplicate email {emailMessage.Id}");
4444
return;
4545
}
4646

47-
if(emailMessage.Store) {
47+
if (emailMessage.Store) {
4848
await tryStoreOrLogAsync(() => storage.SetProcessedAsync(emailMessage));
4949
}
5050
try {
5151
await deliverer.DeliverAsync(emailMessage);
52-
} catch (Exception e){
53-
if(emailMessage.Store) {
52+
} catch (Exception e) {
53+
if (emailMessage.Store) {
5454
await tryStoreOrLogAsync(() => storage.SetErrorAsync(emailMessage, e.ToString()));
5555
}
5656
throw;
5757
}
58-
58+
5959
// if the cache throws an exception we do not rethrow a GeneralProcessingException here because the message has already been delivered
6060
await cache.SetStringAsync(emailMessage.Id.ToString(), "t");
61-
if(emailMessage.Store) {
61+
if (emailMessage.Store) {
6262
await tryStoreOrLogAsync(() => storage.SetSentAsync(emailMessage));
6363
}
6464
}
6565

6666
private async Task tryStoreOrLogAsync(Func<Task> storeFunc) {
6767
try {
6868
await storeFunc();
69-
} catch(Exception e) {
69+
} catch (Exception e) {
7070
logger.LogError(e, "Exception while storing EmailMessage.");
7171
}
7272
}

src/MiddleMail/MiddleMailService.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace MiddleMail {
1414
/// Implements a graceful shutdown by waiting for all processing tasks to finish work if cancellation is requested.
1515
/// </summary>
1616
public class MiddleMailService : BackgroundService {
17-
17+
1818
private IMessageProcessor processor;
1919
private readonly ILogger<MiddleMailService> logger;
2020
private readonly IMessageSource messageSource;
@@ -36,26 +36,26 @@ protected async override Task ExecuteAsync(CancellationToken cancellationToken)
3636

3737
// wait for all consumer tasks to finish
3838
// this is important: a consumer task is only idempotent if does not get canceled
39-
while(consumerTasksPending != 0) {
39+
while (consumerTasksPending != 0) {
4040
logger.LogInformation($"Waiting for {consumerTasksPending} Tasks to finish.");
4141
await Task.Delay(25);
4242
}
4343
}
4444
}
4545

46-
private async Task processAsync(EmailMessage emailMessage ) {
46+
private async Task processAsync(EmailMessage emailMessage) {
4747
logger.LogDebug($"Start processing email message {emailMessage.Id}");
4848
Interlocked.Increment(ref consumerTasksPending);
4949
try {
5050
await processor.ProcessAsync(emailMessage);
5151
logger.LogDebug($"Successfully processed email message {emailMessage.Id}");
52-
} catch(SingleProcessingException e) {
52+
} catch (SingleProcessingException e) {
5353
logger.LogError(e, $"Delivery error for message {emailMessage.Id}");
5454
throw;
55-
} catch(GeneralProcessingException e) {
55+
} catch (GeneralProcessingException e) {
5656
logger.LogError(e, $"General delivery problem for message {emailMessage.Id}");
5757
await messageSource.RetryAsync(emailMessage);
58-
} catch(Exception e) {
58+
} catch (Exception e) {
5959
logger.LogError(e, $"Unexpected Exception while processing message {emailMessage.Id}");
6060
throw;
6161
} finally {

tests/FakerFactory.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public static class FakerFactory {
2121
plainText: f.Lorem.Sentences(),
2222
htmlText: f.Lorem.Sentences(),
2323
headers: null,
24-
tags: f.Lorem.Words().ToList()));
24+
tags: f.Lorem.Words().ToList()
25+
));
2526

2627
private static List<(string name, string address)> GenerateRandomCcList(Faker f) {
2728
var count = f.Random.Int(0, 4);
@@ -32,9 +33,10 @@ public static class FakerFactory {
3233

3334
public static Faker<MimeMessage> MimeMessageFaker = new Faker<MimeMessage>()
3435
.CustomInstantiator(f => new MimeMessage(
35-
from: new MailboxAddress[] { new MailboxAddress(f.Name.FullName(), f.Internet.Email())},
36-
to: new MailboxAddress[] { new MailboxAddress(f.Name.FullName(), f.Internet.Email())},
36+
from: new MailboxAddress[] { new MailboxAddress(f.Name.FullName(), f.Internet.Email()) },
37+
to: new MailboxAddress[] { new MailboxAddress(f.Name.FullName(), f.Internet.Email()) },
3738
subject: f.Lorem.Sentence(),
38-
body: new TextPart("plain") { Text = f.Lorem.Sentences(10)}));
39+
body: new TextPart("plain") { Text = f.Lorem.Sentences(10) }
40+
));
3941
}
4042
}

0 commit comments

Comments
 (0)