void AddNewMessage(MessageEntry entry) { _mimeMessageLoader.Get(entry) .ObserveOnDispatcher() .Subscribe( message => { _publishEvent.Publish( new ShowBallonTip( 5000, "New Message Received", string.Format( "From: {0}\r\nSubject: {1}", message.From.ToString().Truncate(50), message.Subject.Truncate(50)), ToolTipIcon.Info)); // Add it to the list box ClearSelected(); entry.IsSelected = true; Messages.Add(new MimeMessageEntry(entry, _mimeMessageLoader)); }, e => { // NOOP }); }
void DoProcessExchange() { try { var exchangeEvent = new AppProcessExchangeEvent(); // attempt to connect to the backend server... using (PapercutClient client = GetClient()) { if (!client.ExchangeEventServer(ref exchangeEvent)) { return; } IsBackendServiceOnline = true; // backend server is online... _logger.Information("Papercut Backend Service Running. Disabling SMTP in App."); _smtpServerCoordinator.SmtpServerEnabled = false; if (!string.IsNullOrWhiteSpace(exchangeEvent.MessageWritePath)) { _logger.Debug( "Background Process Returned {@Event} -- Publishing", exchangeEvent); _publishEvent.Publish(exchangeEvent); } } } catch (Exception ex) { _logger.Warning(ex, BackendServiceFailureMessage); } }
public void Handle([NotNull] AppProcessExchangeEvent @event) { if (@event == null) { throw new ArgumentNullException(nameof(@event)); } if (string.IsNullOrWhiteSpace(@event.MessageWritePath)) { return; } if (!_configurator.LoadPaths.Any( s => s.StartsWith(@event.MessageWritePath, StringComparison.OrdinalIgnoreCase))) { // add it for watching... Settings.Default.MessagePaths = string.Format("{0};{1}", Settings.Default.MessagePaths, @event.MessageWritePath); } // save ip:port bindings as our own to keep in sync... Settings.Default.IP = @event.IP; Settings.Default.Port = @event.Port; Settings.Default.Save(); _publishEvent.Publish(new SettingsUpdatedEvent()); }
public void Handle(PapercutClientReadyEvent message) { if (_notification != null) { return; } // Set up the notification icon _notification = new NotifyIcon { Icon = new Icon(_resourceLocator.GetResource("App.ico").Stream), Text = "Papercut", Visible = true }; _notification.Click += (sender, args) => _publishEvent.Publish(new ShowMainWindowEvent()); _notification.BalloonTipClicked += (sender, args) => _publishEvent.Publish(new ShowMainWindowEvent { SelectMostRecentMessage = true }); var options = new MenuItem( "Options", (sender, args) => _publishEvent.Publish(new ShowOptionWindowEvent())) { DefaultItem = false, }; var menuItems = new[] { new MenuItem( "Show", (sender, args) => _publishEvent.Publish(new ShowMainWindowEvent())) { DefaultItem = true }, options, new MenuItem( "Exit", (sender, args) => _publishEvent.Publish(new AppForceShutdownEvent())) }; _notification.ContextMenu = new ContextMenu(menuItems); }
public void Start() { _publishEvent.Publish( new PapercutServicePreStartEvent { AppMeta = _applicationMetaData }); _papercutServer.BindObservable( PapercutClient.Localhost, PapercutClient.ServerPort, TaskPoolScheduler.Default) .DelaySubscription(TimeSpan.FromSeconds(1)).Retry(5) .Subscribe( (u) => { /* next is not used */ }, (e) => _logger.Warning( e, "Unable to Create Papercut Server Listener on {IP}:{Port}. After 5 Retries. Failing", PapercutClient.Localhost, PapercutClient.ServerPort), // on complete () => { }); _smtpServer.BindObservable(_serviceSettings.IP, _serviceSettings.Port, TaskPoolScheduler.Default) .DelaySubscription(TimeSpan.FromSeconds(1)).Retry(5) .Subscribe( (u) => { /* next is not used */ }, (e) => _logger.Warning( e, "Unable to Create SMTP Server Listener on {IP}:{Port}. After 5 Retries. Failing", _serviceSettings.IP, _serviceSettings.Port), // on complete () => _publishEvent.Publish( new PapercutServiceReadyEvent { AppMeta = _applicationMetaData })); }
public void Handle(PapercutClientReadyEvent @event) { _logger.Information("Attempting to Load Rules from {RuleFileName} on AppReady", RuleFileName); try { // accessing "Rules" forces the collection to be loaded if (Rules.Any()) { _logger.Information( "Loaded {RuleCount} from {RuleFileName}", Rules.Count, RuleFileName); } } catch (Exception ex) { _logger.Error(ex, "Error loading rules from file {RuleFileName}", RuleFileName); } // rules loaded/updated event _publishEvent.Publish(new RulesUpdatedEvent(Rules.ToArray())); Rules.CollectionChanged += RuleCollectionChanged; HookPropertyChangedForRules(Rules); // the backend service handles rules running if it's online if (!_coordinator.IsBackendServiceOnline) { _logger.Debug("Setting up Rule Dispatcher Observable"); // observe message watcher and run rules when a new message arrives Observable.FromEventPattern <NewMessageEventArgs>( e => _messageWatcher.NewMessage += e, e => _messageWatcher.NewMessage -= e, TaskPoolScheduler.Default) .DelaySubscription(TimeSpan.FromSeconds(1)) .Subscribe(e => _rulesRunner.Run(Rules.ToArray(), e.EventArgs.NewMessage)); } }
void ListenSmtpServer() { _smtpServer.Value.BindObservable( Settings.Default.IP, Settings.Default.Port, TaskPoolScheduler.Default) .DelaySubscription(TimeSpan.FromMilliseconds(500)).Retry(5) .Subscribe( b => { }, ex => { _logger.Warning( ex, "Failed to bind SMTP to the {Address} {Port} specified. The port may already be in use by another process.", Settings.Default.IP, Settings.Default.Port); _publishEvent.Publish(new SmtpServerBindFailedEvent()); }, () => _publishEvent.Publish( new SmtpServerBindEvent(Settings.Default.IP, Settings.Default.Port))); }
public void Save() { Settings.Default.IP = IP; Settings.Default.Port = Port; Settings.Default.RunOnStartup = RunOnStartup; Settings.Default.StartMinimized = StartMinimized; Settings.Default.MinimizeOnClose = MinimizeOnClose; Settings.Default.Save(); _publishEvent.Publish(new SettingsUpdatedEvent()); TryClose(true); }
public async Task Handle(TestCommand command, IDictionary <string, object> arguments = null, CancellationToken cancellationToken = default) { var testEvent = new TestEvent(command.Data); var args = new Dictionary <string, object>() { { "test", "test" }, { "int", 1 }, { "RoutingKey", "test.level" } }.EnrichWithCorrelation(command, arguments); var testEvent2 = new TestEvent(command.Data); var args2 = new Dictionary <string, object>() { { "test", "test2" }, { "int", 2 }, { "RoutingKey", "test.level" } }.EnrichWithCorrelation(command, arguments); await _eventPublisher.Publish(testEvent, args, cancellationToken); await _eventPublisher.Publish(testEvent2, args2, cancellationToken); }
public void HandleReceived([CanBeNull] IEnumerable <string> data) { var file = _messageRepository.SaveMessage(data.IfNullEmpty().ToList()); try { if (!string.IsNullOrWhiteSpace(file)) { _publishEvent.Publish(new NewMessageEvent(new MessageEntry(file))); } } catch (Exception ex) { _logger.Fatal(ex, "Unable to publish new message event for message file: {MessageFile}", file); } }
public void HandleReceived(string messageData, [CanBeNull] IList <string> recipients) { using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(messageData))) { var message = MimeMessage.Load(ParserOptions.Default, ms, true); var lookup = recipients.IfNullEmpty() .ToDictionary(s => s, s => s, StringComparer.OrdinalIgnoreCase); // remove TO: lookup.RemoveRange( message.To.Mailboxes.Select(s => s.ToString(FormatOptions.Default, false)) .Where(s => lookup.ContainsKey(s))); // remove CC: lookup.RemoveRange( message.Cc.Mailboxes.Select(s => s.ToString(FormatOptions.Default, false)) .Where(s => lookup.ContainsKey(s))); if (lookup.Any()) { // Bcc is remaining, add to message foreach (var r in lookup) { message.Bcc.Add(MailboxAddress.Parse(r.Key)); } messageData = message.ToString(); } } var file = _messageRepository.SaveMessage(messageData); try { if (!string.IsNullOrWhiteSpace(file)) { _publishEvent.Publish(new NewMessageEvent(new MessageEntry(file))); } } catch (Exception ex) { _logger.Fatal(ex, "Unable to publish new message event for message file: {MessageFile}", file); } }
public void Handle(SettingsUpdatedEvent @event) { try { RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true); // is key currenctly set to this app executable? bool runOnStartup = registryKey.GetValue(App.GlobalName, null).ToType <string>() == App.ExecutablePath; if (Settings.Default.RunOnStartup && !runOnStartup) { // turn on.. _logger.Information( "Setting AppStartup Registry {Key} to Run Papercut at {ExecutablePath}", string.Format("{0}\\{1}", AppStartupKey, App.GlobalName), App.ExecutablePath); registryKey.SetValue(App.GlobalName, App.ExecutablePath); } else if (!Settings.Default.RunOnStartup && runOnStartup) { // turn off... _logger.Information( "Attempting to Delete AppStartup Registry {Key}", string.Format("{0}\\{1}", AppStartupKey, App.GlobalName)); registryKey.DeleteValue(App.GlobalName, false); } } catch (SecurityException ex) { _logger.Error(ex, "Error Opening Registry for App Startup Service"); _publishEvent.Publish( new ShowMessageEvent( "Failed to set Papercut to load at startup due to lack of permission. To fix, exit and run Papercut again with elevated (Admin) permissions.", "Failed")); } }
public void Exit() { _publishEvent.Publish(new AppForceShutdownEvent()); }