Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Papercut.Core/Domain/Rules/IRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface IRule : INotifyPropertyChanged
{
Guid Id { get; }

string Name { get; set; }

bool IsEnabled { get; set; }

string Type { get; }
Expand Down
18 changes: 17 additions & 1 deletion src/Papercut.Rules/Domain/Rules/NewMessageRuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ public abstract class NewMessageRuleBase : INewMessageRule
{
bool _isEnabled;

string _name;

[Category("Information")]
public Guid Id { get; protected set; } = Guid.NewGuid();

[Category("Information")]
[DisplayName("Name")]
[Description("A friendly name for this rule")]
public string Name
{
get => this._name;
set
{
if (value == this._name) return;
this._name = value;
this.OnPropertyChanged(nameof(this.Name));
}
}

[Category("State")]
[Browsable(true)]
[DisplayName("Is Enabled")]
Expand All @@ -59,7 +75,7 @@ public virtual bool IsEnabled
public virtual string Description
=>
this.GetPropertiesForDescription()
.Where(s => !s.Key.IsAny("Id", "Type", "Description"))
.Where(s => !s.Key.IsAny("Id", "Name", "Type", "Description"))
.OrderBy(s => s.Key)
.ToFormattedPairs()
.Join("\r\n");
Expand Down
18 changes: 17 additions & 1 deletion src/Papercut.Rules/Domain/Rules/PeriodicBackgroundRuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ public abstract class PeriodicBackgroundRuleBase : IPeriodicBackgroundRule
{
bool _isEnabled;

string _name;

[Category("Information")]
public Guid Id { get; protected set; } = Guid.NewGuid();

[Category("Information")]
[DisplayName("Name")]
[Description("A friendly name for this rule")]
public string Name
{
get => this._name;
set
{
if (value == this._name) return;
this._name = value;
this.OnPropertyChanged(nameof(this.Name));
}
}

[Category("State")]
[Browsable(true)]
[DisplayName("Is Enabled")]
Expand All @@ -59,7 +75,7 @@ public virtual bool IsEnabled
public virtual string Description
=>
this.GetPropertiesForDescription()
.Where(s => !s.Key.IsAny("Id", "Type", "Description"))
.Where(s => !s.Key.IsAny("Id", "Name", "Type", "Description"))
.OrderBy(s => s.Key)
.ToFormattedPairs()
.Join("\r\n");
Expand Down
48 changes: 48 additions & 0 deletions src/Papercut.UI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Papercut.UI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
<Setting Name="ForwardTo" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ForwardSmtpUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ForwardSmtpPassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ForwardSmtpPort" Type="System.Int32" Scope="User">
<Value Profile="(Default)">25</Value>
</Setting>
<Setting Name="ForwardSmtpUseSsl" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="MinimizeOnClose" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
Expand Down
154 changes: 147 additions & 7 deletions src/Papercut.UI/ViewModels/ForwardViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
// Papercut
//
// Papercut
//
// Copyright © 2008 - 2012 Ken Robertson
// Copyright © 2013 - 2025 Jaben Cargman
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

using Papercut.AppLayer.Rules;
using Papercut.Core;
using Papercut.Core.Domain.Rules;
using Papercut.Domain.UiCommands;
using Papercut.Rules.Domain.Forwarding;
using Papercut.Rules.Domain.Relaying;

namespace Papercut.ViewModels;

Expand All @@ -32,6 +37,8 @@ public class ForwardViewModel : Screen

readonly IUiCommandHub _uiCommandHub;

readonly RuleService _ruleService;

string _from;

bool _fromSetting;
Expand All @@ -40,11 +47,23 @@ public class ForwardViewModel : Screen

string _to;

string _username;

string _password;

int _port = 25;

bool _useSsl;

string _windowTitle = "Forward Message";

public ForwardViewModel(IUiCommandHub uiCommandHub)
RelayRuleListItem _selectedRule;

public ForwardViewModel(IUiCommandHub uiCommandHub, RuleService ruleService)
{
_uiCommandHub = uiCommandHub;
_ruleService = ruleService;
AvailableRules = new ObservableCollection<RelayRuleListItem>();
}

public bool FromSetting
Expand Down Expand Up @@ -97,12 +116,99 @@ public string From
}
}

public string Username
{
get => this._username;
set
{
this._username = value;
this.NotifyOfPropertyChange(() => this.Username);
}
}

public string Password
{
get => this._password;
set
{
this._password = value;
this.NotifyOfPropertyChange(() => this.Password);
}
}

public int Port
{
get => this._port;
set
{
this._port = value;
this.NotifyOfPropertyChange(() => this.Port);
}
}

public bool UseSsl
{
get => this._useSsl;
set
{
this._useSsl = value;
this.NotifyOfPropertyChange(() => this.UseSsl);
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public ObservableCollection<RelayRuleListItem> AvailableRules { get; }

public RelayRuleListItem SelectedRule
{
get => this._selectedRule;
set
{
this._selectedRule = value;
this.NotifyOfPropertyChange(() => this.SelectedRule);

if (value?.Rule != null)
{
PopulateFromRule(value.Rule);
}
}
}

void PopulateFromRule(RelayRule rule)
{
this.Server = rule.SmtpServer;
this.Port = rule.SmtpPort;
this.UseSsl = rule.SmtpUseSSL;
this.Username = rule.SmtpUsername;
this.Password = rule.SmtpPassword;

if (rule is ForwardRule forwardRule)
{
this.From = forwardRule.FromEmail;
this.To = forwardRule.ToEmail;
}
}

void LoadAvailableRules()
{
AvailableRules.Clear();

var relayRules = _ruleService.Rules.OfType<RelayRule>();
foreach (var rule in relayRules)
{
AvailableRules.Add(new RelayRuleListItem(rule));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

void Load()
{
// Load previous settings
this.Server = Settings.Default.ForwardServer;
this.To = Settings.Default.ForwardTo;
this.From = Settings.Default.ForwardFrom;
this.Username = Settings.Default.ForwardSmtpUsername;
this.Password = Settings.Default.ForwardSmtpPassword;
this.Port = Settings.Default.ForwardSmtpPort;
this.UseSsl = Settings.Default.ForwardSmtpUseSsl;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

public async Task Cancel()
Expand All @@ -114,6 +220,8 @@ protected override void OnViewLoaded(object view)
{
base.OnViewLoaded(view);

LoadAvailableRules();

if (this.FromSetting) this.Load();
}

Expand Down Expand Up @@ -142,9 +250,41 @@ public async Task Send()
Settings.Default.ForwardServer = this.Server.Trim();
Settings.Default.ForwardTo = this.To.Trim();
Settings.Default.ForwardFrom = this.From.Trim();
Settings.Default.ForwardSmtpUsername = this.Username?.Trim() ?? string.Empty;
Settings.Default.ForwardSmtpPassword = this.Password ?? string.Empty;
Settings.Default.ForwardSmtpPort = this.Port;
Settings.Default.ForwardSmtpUseSsl = this.UseSsl;
Settings.Default.Save();
}

await this.TryCloseAsync(true);
}
}
}

public class RelayRuleListItem
{
public RelayRuleListItem(RelayRule rule)
{
Rule = rule;
}

public RelayRule Rule { get; }

public string DisplayName
{
get
{
if (!string.IsNullOrWhiteSpace(Rule.Name))
return Rule.Name;

var type = Rule.Type;
var server = Rule.SmtpServer;
if (Rule is ForwardRule fwd && !string.IsNullOrWhiteSpace(fwd.ToEmail))
return $"{type} - {server} -> {fwd.ToEmail}";

return $"{type} - {server}";
}
}

public override string ToString() => DisplayName;
}
Loading
Loading