early basic email plugin
This commit is contained in:
@@ -12,7 +12,6 @@ namespace NOCQ
|
||||
public Catalog()
|
||||
{
|
||||
Container.ComposeParts(this);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace NOCQ
|
||||
{
|
||||
public class ImapInput
|
||||
{
|
||||
private string loginName { get; set; }
|
||||
private string password { get; set; }
|
||||
private string server { get; set; }
|
||||
private string folderPath { get; set; }
|
||||
|
||||
public ImapInput (dynamic settings)
|
||||
{
|
||||
if (settings.Login == null
|
||||
|| settings.Password == null
|
||||
|| settings.Server == null
|
||||
|| settings.FolderPath == null)
|
||||
throw new ArgumentException ("You are missing a required setting.");
|
||||
|
||||
loginName = settings.Login;
|
||||
password = settings.Password;
|
||||
server = settings.Server;
|
||||
folderPath = settings.FolderPath;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ImapInput.cs" />
|
||||
<Compile Include="Extensability\Catalog.cs" />
|
||||
<Compile Include="Imports\IDataImport.cs" />
|
||||
<Compile Include="Plugins\Email\ImapInput.cs" />
|
||||
<Compile Include="Plugins\Email\EmailSettings.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
@@ -65,5 +66,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Extensability\" />
|
||||
<Folder Include="Imports\" />
|
||||
<Folder Include="Plugins\" />
|
||||
<Folder Include="Plugins\Email\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
16
src/NOCQ/Plugins/Email/EmailSettings.cs
Normal file
16
src/NOCQ/Plugins/Email/EmailSettings.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace NOCQ.Plugins.Email
|
||||
{
|
||||
public class EmailSettings
|
||||
{
|
||||
public string Username {get;set;}
|
||||
public string Password {get;set;}
|
||||
public string Host {get;set;}
|
||||
public int Port {get;set;}
|
||||
public string Folder {get;set;}
|
||||
public bool IsSsl {get;set;}
|
||||
public int Frequency { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
72
src/NOCQ/Plugins/Email/ImapInput.cs
Normal file
72
src/NOCQ/Plugins/Email/ImapInput.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
using AE.Net.Mail;
|
||||
|
||||
namespace NOCQ.Plugins.Email
|
||||
{
|
||||
public class ImapInput
|
||||
{
|
||||
private string loginName { get; set; }
|
||||
private string password { get; set; }
|
||||
private string server { get; set; }
|
||||
private string folderPath { get; set; }
|
||||
private Timer timer { get; set; }
|
||||
private int port { get; set; }
|
||||
private bool ssl { get; set; }
|
||||
private DateTime lastRun { get; set; }
|
||||
|
||||
|
||||
public ImapInput (dynamic settings)
|
||||
{
|
||||
var sets = settings as EmailSettings;
|
||||
|
||||
if (sets.Username == null
|
||||
|| sets.Password == null
|
||||
|| sets.Host == null
|
||||
|| sets.Folder == null
|
||||
|| sets.Frequency == null
|
||||
|| sets.Port == null
|
||||
|| sets.IsSsl == null)
|
||||
throw new ArgumentException ("You are missing a required setting.");
|
||||
|
||||
loginName = settings.Login;
|
||||
password = settings.Password;
|
||||
server = settings.Server;
|
||||
folderPath = settings.FolderPath;
|
||||
|
||||
timer = new Timer (settings.Frequency);
|
||||
|
||||
timer.Elapsed += Execute ();
|
||||
}
|
||||
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
using(var imap = new ImapClient(server, loginName, password, ImapClient.AuthMethods.Login, port, ssl)) {
|
||||
var msgs = imap.SearchMessages(
|
||||
SearchCondition.Undeleted().And(
|
||||
SearchCondition.SentSince(new DateTime(2000, 1, 1))
|
||||
));
|
||||
|
||||
foreach (var msg in msgs)
|
||||
{
|
||||
var realMsg = msg.Value;
|
||||
|
||||
var from = realMsg.From;
|
||||
var body = realMsg.Body;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
timer.Start ();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
timer.Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user