PO Nummern Erfassung Erster Wurf

This commit is contained in:
Daniel Schick 2020-02-29 06:14:20 +00:00
parent fe63082330
commit 17091a8544
7 changed files with 137 additions and 11 deletions

Binary file not shown.

View File

@ -0,0 +1,56 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace bsmd.POService.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ConnectionString {
get {
return ((string)(this["ConnectionString"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("30")]
public int SleepSeconds {
get {
return ((int)(this["SleepSeconds"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3." +
"org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <s" +
"tring>guettner@bsmd.de</string>\r\n <string>hsok@gmx.de</string>\r\n</ArrayOfString" +
">")]
public global::System.Collections.Specialized.StringCollection ValidSender {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["ValidSender"]));
}
}
}
}

View File

@ -0,0 +1,19 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="bsmd.POService.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SleepSeconds" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">30</Value>
</Setting>
<Setting Name="ValidSender" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;guettner@bsmd.de&lt;/string&gt;
&lt;string&gt;hsok@gmx.de&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,15 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) 2015-present schick Informatik
// Description:
extensions: .aspx .ascx
<%--
Copyright (c) 2015-present schick Informatik
--%>
extensions: .vb
'Sample license text.
extensions: .xml .config .xsd
<!--
Sample license text.
-->

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.8" targetFramework="net472" />
</packages>

View File

@ -1,11 +1,11 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) 2015-2017 schick Informatik
// Copyright (c) 2020-present schick Informatik
// Description:
extensions: .aspx .ascx
<%--
Copyright (c) 2015-present schick Informatik
Copyright (c) 2020-present schick Informatik
--%>
extensions: .vb
'Sample license text.

View File

@ -19,9 +19,8 @@ namespace bsmd.email
{
public class BSMDPopClient : IDisposable
{
private Pop3Client pop3Client;
private bool _connected = false;
private ILog _log = LogManager.GetLogger(typeof(BSMDPopClient));
private readonly Pop3Client pop3Client;
private readonly ILog _log = LogManager.GetLogger(typeof(BSMDPopClient));
private int currentMail = 1;
public BSMDPopClient()
@ -34,7 +33,7 @@ namespace bsmd.email
60000, 60000, new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate));
this.pop3Client.Authenticate(Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
this._connected = true;
this.IsConnected = true;
}
catch (Exception ex)
{
@ -51,7 +50,40 @@ namespace bsmd.email
return true;
}
public bool IsConnected { get { return this._connected; } }
public bool IsConnected { get; } = false;
public bool ReceiveSingleMailText(out string messageId, out string sender, out string subject, out string body)
{
messageId = null;
sender = null;
subject = null;
body = null;
if (!IsConnected) return false;
int messageCount = this.pop3Client.GetMessageCount();
if (messageCount > (this.currentMail - 1))
{
Message mailMessage = this.pop3Client.GetMessage(this.currentMail);
if (mailMessage.Headers.Sender?.HasValidMailAddress == true)
sender = mailMessage.Headers.Sender.MailAddress.Address;
if ((sender == null) && (mailMessage.Headers.From?.HasValidMailAddress == true))
sender = mailMessage.Headers.From.MailAddress.Address;
MessagePart aPart = mailMessage.FindFirstPlainTextVersion();
body = aPart?.GetBodyAsText();
messageId = mailMessage.Headers.MessageId;
subject = mailMessage.Headers.Subject;
this.currentMail++; // advance message pointer
return true;
}
else
{
return false;
}
}
public bool ReceiveSingleMail(out string attachmentLocalFile, out string messageId, out string sender, out string subject)
{
@ -60,16 +92,16 @@ namespace bsmd.email
sender = null;
subject = null;
if (!_connected) return false;
if (!IsConnected) return false;
int messageCount = this.pop3Client.GetMessageCount();
if (messageCount > (this.currentMail - 1))
{
Message mailMessage = this.pop3Client.GetMessage(this.currentMail);
if ((mailMessage.Headers.Sender != null) && mailMessage.Headers.Sender.HasValidMailAddress)
if (mailMessage.Headers.Sender?.HasValidMailAddress == true)
sender = mailMessage.Headers.Sender.MailAddress.Address;
if ((sender == null) && (mailMessage.Headers.From != null) && mailMessage.Headers.From.HasValidMailAddress)
if ((sender == null) && (mailMessage.Headers.From?.HasValidMailAddress == true))
sender = mailMessage.Headers.From.MailAddress.Address;
messageId = mailMessage.Headers.MessageId;
@ -107,7 +139,7 @@ namespace bsmd.email
/// <returns>true if successful</returns>
public bool DeleteMessageByMessageId(string messageId)
{
if (!_connected) return false;
if (!IsConnected) return false;
// Get the number of messages on the POP3 server
int messageCount = this.pop3Client.GetMessageCount();