Skip to content

Commit fc829d2

Browse files
Add configurable email age threshold bypass for regex testing (#16)
* Initial plan * Add DisableEmailAgeThreshold configuration option with warning Co-authored-by: andreaslampe <[email protected]> * Remove comment from appsettings.json and extend documentation Co-authored-by: andreaslampe <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: andreaslampe <[email protected]>
1 parent df2c2c2 commit fc829d2

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

MailAgent/Options/MailAgentOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public class MailAgentOptions
2626
public string HeartbeatUrl { get; set; } = string.Empty;
2727

2828
public string O365ClientId { get; set; } = string.Empty;
29+
30+
public bool DisableEmailAgeThreshold { get; set; } = false;
2931
}
3032
}

MailAgent/Services/ConfigurationValidator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public List<ConfigurationIssue> ValidateConfiguration()
2121
{
2222
var issues = new List<ConfigurationIssue>();
2323

24+
// Check if email age threshold is disabled
25+
if (_options.DisableEmailAgeThreshold)
26+
{
27+
issues.Add(new ConfigurationIssue
28+
{
29+
Severity = IssueSeverity.Warning,
30+
Category = "EmailAgeThreshold",
31+
Message = "Email age threshold is DISABLED. All unread emails will be processed regardless of age.",
32+
Hint = "This setting is intended for testing purposes only. DO NOT use in production! Set 'DisableEmailAgeThreshold' to false for production use."
33+
});
34+
}
35+
2436
if (!_options.EmailSettings.Any())
2537
{
2638
issues.Add(new ConfigurationIssue

MailAgent/Services/MailService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ await client.Connect(
113113
&& !sender.Contains(siteEmailSetting.EMailSenderFilter, StringComparison.InvariantCultureIgnoreCase);
114114

115115
// Message is too old
116-
if ((DateTimeOffset.Now - eMail.message.Date).Duration() > TimeSpan.FromMinutes(15))
116+
if (!_options.DisableEmailAgeThreshold && (DateTimeOffset.Now - eMail.message.Date).Duration() > TimeSpan.FromMinutes(15))
117117
{
118118
_log.LogInformation($"Mail with subject '{eMail.message.Subject}' received delayed. EMail was sent at {eMail.message.Date.ToLocalTime()}. Ignore and mark as read.");
119119

MailAgent/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"EMailMode": "Imap",
7171
"IgnoreCertificateErrors": false,
7272
"HeartbeatInterval": "00:00:10",
73-
"HeartbeatUrl": ""
73+
"HeartbeatUrl": "",
74+
"DisableEmailAgeThreshold": false
7475
}
7576
}

MailAgent/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Für das entwickeln der regulären Ausdrücke sind folgende Seiten/Tools hilfrei
9191
https://regex101.com/ (testen und entwickeln)
9292
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet (allgemeine Informationen)
9393

94+
**Tipp zum Testen von regulären Ausdrücken:** Um reguläre Ausdrücke mit älteren E-Mails zu testen, kann die Einstellung `DisableEmailAgeThreshold` auf `true` gesetzt werden. Dadurch werden auch E-Mails verarbeitet, die älter als 15 Minuten sind. Siehe Abschnitt `MailAgentOptions` für weitere Details.
95+
9496
## Konfiguration
9597

9698
### Abschnitt `Serilog`
@@ -133,6 +135,7 @@ Weitere Einstellungen:
133135
* `HeartbeatInterval` -> Intervall für das Senden von Heartbeats. (z.B. an UptimeRobot)
134136
* `HeartbeatUrl` -> HTTP-GET Endpunkt, der für Heartbeats aufgerufen werden soll
135137
* `O365ClientId` -> Die Client-ID für die O365 OAuth2-Authentifizierung (nur erforderlich bei Verwendung von `O365` Authentifizierung). Der Standardwert ist eine öffentliche Client-ID.
138+
* `DisableEmailAgeThreshold` -> Deaktiviert die 15-Minuten-Altersschwelle für E-Mails. **Nur für Testzwecke!** Standardmäßig werden E-Mails, die älter als 15 Minuten sind, ignoriert und als gelesen markiert. Wenn diese Einstellung auf `true` gesetzt wird, werden alle ungelesenen E-Mails unabhängig vom Alter verarbeitet. Dies ist nützlich zum Testen von regulären Ausdrücken mit älteren E-Mails. **Warnung:** Diese Einstellung sollte in Produktivumgebungen NICHT aktiviert werden! Bei Aktivierung wird beim Start eine deutliche Warnung angezeigt.
136139

137140
## Copyright
138141
Copyright Feuer Software GmbH, Karlsbader Str. 16, Eschborn

0 commit comments

Comments
 (0)