rumgebastelt
This commit is contained in:
parent
20bb62ee4e
commit
e0cc259bb2
51
MailServer/IMAP/Server/AuthUser_EventArgs.Properties.cs
Normal file
51
MailServer/IMAP/Server/AuthUser_EventArgs.Properties.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using MailServer.Settings;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class AuthUser_EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt die IMAP Session zurück
|
||||||
|
/// </summary>
|
||||||
|
public IMAP_Session Session
|
||||||
|
{
|
||||||
|
get { return m_pSession; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt den Benutzernamen zurück
|
||||||
|
/// </summary>
|
||||||
|
public string UserName
|
||||||
|
{
|
||||||
|
get { return m_UserName; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt das Passwort zurück
|
||||||
|
/// </summary>
|
||||||
|
public string PasswData
|
||||||
|
{
|
||||||
|
get { return m_PasswData; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt die AuthData zurück
|
||||||
|
/// </summary>
|
||||||
|
public string AuthData
|
||||||
|
{
|
||||||
|
get { return m_Data; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt den Authtyp zurück
|
||||||
|
/// </summary>
|
||||||
|
public AuthType AuthType
|
||||||
|
{
|
||||||
|
get { return m_AuthType; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// ist der Benutzer erlaubt
|
||||||
|
/// </summary>
|
||||||
|
public bool Validated
|
||||||
|
{
|
||||||
|
get { return m_Validated; }
|
||||||
|
set { m_Validated = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
MailServer/IMAP/Server/AuthUser_EventArgs.cs
Normal file
33
MailServer/IMAP/Server/AuthUser_EventArgs.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using MailServer.Settings;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stellt daten für das AuthUser Event zur verfügung
|
||||||
|
/// </summary>
|
||||||
|
public class AuthUser_EventArgs
|
||||||
|
{
|
||||||
|
private IMAP_Session m_pSession = null;
|
||||||
|
private string m_UserName = "";
|
||||||
|
private string m_PasswData = "";
|
||||||
|
private string m_Data = "";
|
||||||
|
private AuthType m_AuthType;
|
||||||
|
private bool m_Validated = false;
|
||||||
|
/// <summary>
|
||||||
|
/// AuthUser_EventArgs Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="userName">Benutzername</param>
|
||||||
|
/// <param name="passwData">Passwort</param>
|
||||||
|
/// <param name="data">Hängt vom Authtyp ab</param>
|
||||||
|
/// <param name="authType">Authtyp</param>
|
||||||
|
public AuthUser_EventArgs(IMAP_Session session, string userName, string passwData, string data, AuthType authType)
|
||||||
|
{
|
||||||
|
m_pSession = session;
|
||||||
|
m_UserName = userName;
|
||||||
|
m_PasswData = passwData;
|
||||||
|
m_Data = data;
|
||||||
|
m_AuthType = authType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3383
MailServer/IMAP/Server/IMAP_Session.cs
Normal file
3383
MailServer/IMAP/Server/IMAP_Session.cs
Normal file
File diff suppressed because it is too large
Load Diff
38
MailServer/IMAP/Server/Server.Designer.cs
generated
Normal file
38
MailServer/IMAP/Server/Server.Designer.cs
generated
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Erforderliche Designervariable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verwendete Ressourcen bereinigen.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Vom Komponenten-Designer generierter Code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Erforderliche Methode für die Designerunterstützung.
|
||||||
|
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
|
this.ServiceName = "IMAP Server";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
16
MailServer/IMAP/Server/Server.EventDelegates.cs
Normal file
16
MailServer/IMAP/Server/Server.EventDelegates.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Representiert die Methode die das AuthUser Event vom SMTP_Server handelt
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">Die Quelle des Events</param>
|
||||||
|
/// <param name="e">Ein AuthUser_EventArgs welches das event beinhaltet</param>
|
||||||
|
public delegate void AuthUserEventHandler(object sender, AuthUser_EventArgs e);
|
||||||
|
public delegate void FolderEventHandler(object sender, Mailbox_EventArgs e);
|
||||||
|
public delegate void FoldersEventHandler(object sender, IMAP_Folders e);
|
||||||
|
public delegate void MessagesEventHandler(object sender, IMAP_Messages e);
|
||||||
|
public delegate void MessageEventHandler(object sender, Message_EventArgs e);
|
||||||
|
}
|
||||||
|
}
|
267
MailServer/IMAP/Server/Server.Events.cs
Normal file
267
MailServer/IMAP/Server/Server.Events.cs
Normal file
@ -0,0 +1,267 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event ValidateIpAdress
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enpoint">Verbundener Host endpoint</param>
|
||||||
|
/// <returns>Gibt true zurück wenn die Verbindung erlaubt ist</returns>
|
||||||
|
internal bool OnValidate_IpAddress(EndPoint enpoint)
|
||||||
|
{
|
||||||
|
ValidateIP_EventArgs oArg = new ValidateIP_EventArgs(enpoint);
|
||||||
|
if (this.ValidateIPAddress != null)
|
||||||
|
{
|
||||||
|
this.ValidateIPAddress(this, oArg);
|
||||||
|
}
|
||||||
|
return oArg.Validated;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event AuthUser
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">referenz zur Aktuellen IMAP Session</param>
|
||||||
|
/// <param name="userName">Benutzername</param>
|
||||||
|
/// <param name="passwordData">Passwort</param>
|
||||||
|
/// <param name="data">Hängt vom AuthTyp ab</param>
|
||||||
|
/// <param name="authType">Authtyp</param>
|
||||||
|
/// <returns>Gibt True zurück, wenn user erlaubt</returns>
|
||||||
|
internal bool OnAuthUser(IMAP_Session session, string userName, string passwordData, string data, AuthType authType)
|
||||||
|
{
|
||||||
|
AuthUser_EventArgs oArgs = new AuthUser_EventArgs(session, userName, passwordData, data, authType);
|
||||||
|
if (this.AuthUser != null)
|
||||||
|
{
|
||||||
|
this.AuthUser(this, oArgs);
|
||||||
|
}
|
||||||
|
return oArgs.Validated;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event SuscribeMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Name der Mailbox welche aboniert werden soll</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnSubscribeMailbox(IMAP_Session session, string mailbox)
|
||||||
|
{
|
||||||
|
if (this.SubscribeFolder != null)
|
||||||
|
{
|
||||||
|
Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox);
|
||||||
|
this.SubscribeFolder(session, eArgs);
|
||||||
|
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event UnSuscribeMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Name der Mailbox welche abbestellt werden soll</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnUnSubscribeMailbox(IMAP_Session session, string mailbox)
|
||||||
|
{
|
||||||
|
if (this.UnSubscribeFolder != null)
|
||||||
|
{
|
||||||
|
Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox);
|
||||||
|
this.UnSubscribeFolder(session, eArgs);
|
||||||
|
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event GetSuscribedMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="referenceName">Mailbox referenz</param>
|
||||||
|
/// <param name="mailBox">Mailbox name oder pattern</param>
|
||||||
|
/// <returns>gibt die Mailbox zurück</returns>
|
||||||
|
internal IMAP_Folders OnGetSubscribedMailboxes(IMAP_Session session, string referenceName, string mailBox)
|
||||||
|
{
|
||||||
|
IMAP_Folders retVal = new IMAP_Folders(referenceName, mailBox);
|
||||||
|
if (this.GetSubscribedFolders != null)
|
||||||
|
{
|
||||||
|
this.GetSubscribedFolders(session, retVal);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event GetMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="referenceName">Mailbox referenz</param>
|
||||||
|
/// <param name="mailBox">Mailbox name oder pattern</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal IMAP_Folders OnGetMailboxes(IMAP_Session session, string referenceName, string mailBox)
|
||||||
|
{
|
||||||
|
IMAP_Folders retVal = new IMAP_Folders(referenceName, mailBox);
|
||||||
|
if (this.GetFolders != null)
|
||||||
|
{
|
||||||
|
this.GetFolders(session, retVal);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event CreateMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Mailbox name</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnCreateMailbox(IMAP_Session session, string mailbox)
|
||||||
|
{
|
||||||
|
if (this.CreateFolder != null)
|
||||||
|
{
|
||||||
|
Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox);
|
||||||
|
this.CreateFolder(session, eArgs);
|
||||||
|
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event DeleteMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referent zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Mailbox name</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnDeleteMailbox(IMAP_Session session, string mailbox)
|
||||||
|
{
|
||||||
|
if (this.DeleteFolder != null)
|
||||||
|
{
|
||||||
|
Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox);
|
||||||
|
this.DeleteFolder(session, eArgs);
|
||||||
|
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt Event RenameMailbox
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Mailbox name</param>
|
||||||
|
/// <param name="newMailboxName">neuer Mailbox name</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnRenameMailbox(IMAP_Session session, string mailbox, string newMailboxName)
|
||||||
|
{
|
||||||
|
if (this.RenameFolder != null)
|
||||||
|
{
|
||||||
|
Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox, newMailboxName);
|
||||||
|
this.RenameFolder(session, eArgs);
|
||||||
|
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event MailboxInfo
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="mailbox">Mailbox name</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal IMAP_Messages OnGetMessagesInfo(IMAP_Session session, string mailbox)
|
||||||
|
{
|
||||||
|
IMAP_Messages messages = new IMAP_Messages(mailbox);
|
||||||
|
if (this.GetMessagesInfo != null)
|
||||||
|
{
|
||||||
|
this.GetMessagesInfo(session, messages);
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeugt event GetMessage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="msg">Nachricht</param>
|
||||||
|
/// <param name="headersOnly">nur Kopfzeilen</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal Message_EventArgs OnGetMessage(IMAP_Session session, IMAP_Message msg, bool headersOnly)
|
||||||
|
{
|
||||||
|
Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg, headersOnly);
|
||||||
|
if (this.GetMessage != null)
|
||||||
|
{
|
||||||
|
this.GetMessage(session, eArgs);
|
||||||
|
}
|
||||||
|
return eArgs;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeuge Event DeleteMessage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="message">Nachricht</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnDeleteMessage(IMAP_Session session, IMAP_Message message)
|
||||||
|
{
|
||||||
|
Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, message);
|
||||||
|
if (this.DeleteMessage != null)
|
||||||
|
{
|
||||||
|
this.DeleteMessage(session, eArgs);
|
||||||
|
}
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeuge Event CopyMesage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="msg">Nachricht</param>
|
||||||
|
/// <param name="location">Neue Position</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnCopyMessage(IMAP_Session session, IMAP_Message msg, string location)
|
||||||
|
{
|
||||||
|
Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg, location);
|
||||||
|
if (this.CopyMessage != null)
|
||||||
|
{
|
||||||
|
this.CopyMessage(session, eArgs);
|
||||||
|
}
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeuge Event StoreMessage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="folder">Ordner</param>
|
||||||
|
/// <param name="msg">Nachricht</param>
|
||||||
|
/// <param name="messageData">Nachrichteninhalt</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnStoreMessage(IMAP_Session session, string folder, IMAP_Message msg, byte[] messageData)
|
||||||
|
{
|
||||||
|
Message_EventArgs eArgs = new Message_EventArgs(folder, msg);
|
||||||
|
eArgs.MessageData = messageData;
|
||||||
|
if (this.StoreMessage != null)
|
||||||
|
{
|
||||||
|
this.StoreMessage(session, eArgs);
|
||||||
|
}
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeuge Event StoreMessageFlags
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="session">Referenz zur IMAP Session</param>
|
||||||
|
/// <param name="msg">Nachricht</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal string OnStoreMessageFlags(IMAP_Session session, IMAP_Message msg)
|
||||||
|
{
|
||||||
|
Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg);
|
||||||
|
if (this.StoreMessageFlags != null)
|
||||||
|
{
|
||||||
|
this.StoreMessageFlags(session, eArgs);
|
||||||
|
}
|
||||||
|
return eArgs.ErrorText;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Erzeuge Event SysError
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Ausnahme</param>
|
||||||
|
/// <param name="stackTrace">Stacktrace</param>
|
||||||
|
internal void OnSysError(Exception x, StackTrace stackTrace)
|
||||||
|
{
|
||||||
|
if (this.SysError != null)
|
||||||
|
{
|
||||||
|
this.SysError(this, new Error_EventArgs(x, stackTrace));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
74
MailServer/IMAP/Server/Server.EventsDeclarations.cs
Normal file
74
MailServer/IMAP/Server/Server.EventsDeclarations.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn ein Computer zum IMAP Server verbindet
|
||||||
|
/// </summary>
|
||||||
|
public event ValidateIPHandler ValidateIPAddress = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn ein User sich zu authentifizieren versucht
|
||||||
|
/// </summary>
|
||||||
|
public event AuthUserEventHandler AuthUser = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht einen Ordner zu beziehen
|
||||||
|
/// </summary>
|
||||||
|
public event FolderEventHandler SubscribeFolder = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht einen Ordner abzubestellen
|
||||||
|
/// </summary>
|
||||||
|
public event FolderEventHandler UnSubscribeFolder = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht alle Ordner zu lesen
|
||||||
|
/// </summary>
|
||||||
|
public event FoldersEventHandler GetFolders = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht die bestellen Ordner zu lesen
|
||||||
|
/// </summary>
|
||||||
|
public event FoldersEventHandler GetSubscribedFolders = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht einen Ordner zu erstellen
|
||||||
|
/// </summary>
|
||||||
|
public event FolderEventHandler CreateFolder = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht einen Ordner zu löschen
|
||||||
|
/// </summary>
|
||||||
|
public event FolderEventHandler DeleteFolder = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht einen Ordner umzubenennen
|
||||||
|
/// </summary>
|
||||||
|
public event FolderEventHandler RenameFolder = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server Nachrichten Infos zu Ordner zu lesen
|
||||||
|
/// </summary>
|
||||||
|
public event MessagesEventHandler GetMessagesInfo = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht eine Nachricht zu löschen
|
||||||
|
/// </summary>
|
||||||
|
public event MessageEventHandler DeleteMessage = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht eine Nachricht zu speichern
|
||||||
|
/// </summary>
|
||||||
|
public event MessageEventHandler StoreMessage = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht Nachrichten Flags zu Setzen
|
||||||
|
/// </summary>
|
||||||
|
public event MessageEventHandler StoreMessageFlags = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht eine Nachricht zu kopieren
|
||||||
|
/// </summary>
|
||||||
|
public event MessageEventHandler CopyMessage = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server versucht eine Nachricht zu lesen
|
||||||
|
/// </summary>
|
||||||
|
public event MessageEventHandler GetMessage = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein wenn der Server einen Fehler hat
|
||||||
|
/// </summary>
|
||||||
|
public event ErrorEventHandler SysError = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Tritt ein Wenn die Sitzung zu ende ist und der Server einen Log hat
|
||||||
|
/// </summary>
|
||||||
|
public event LogEventHandler SessionLog = null;
|
||||||
|
}
|
||||||
|
}
|
97
MailServer/IMAP/Server/Server.Properties.cs
Normal file
97
MailServer/IMAP/Server/Server.Properties.cs
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IP Adresse an der der Server hört
|
||||||
|
/// </summary>
|
||||||
|
[Description("IP Address to Listen IMAP requests"), DefaultValue("ALL")]
|
||||||
|
public string IpAddress
|
||||||
|
{
|
||||||
|
get { return m_IPAddress; }
|
||||||
|
set { m_IPAddress = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Port an dem der Server hört
|
||||||
|
/// </summary>
|
||||||
|
[Description("Port to use for IMAP"),DefaultValue(143)]
|
||||||
|
public int Port
|
||||||
|
{
|
||||||
|
get { return m_port; }
|
||||||
|
set { m_port = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Maximale Sessions
|
||||||
|
/// </summary>
|
||||||
|
[Description("Maximum Allowed threads"),DefaultValue(50)]
|
||||||
|
public int Threads
|
||||||
|
{
|
||||||
|
get { return m_MaxThreads; }
|
||||||
|
set { m_MaxThreads = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Run and Stops the Server
|
||||||
|
/// </summary>
|
||||||
|
[Description("Use this property to run and stop SMTP Server"),DefaultValue(false)]
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get { return m_enabled; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != m_enabled)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
Start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
m_enabled = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Logging
|
||||||
|
/// </summary>
|
||||||
|
public bool LogCommands
|
||||||
|
{
|
||||||
|
get { return m_LogCmds; }
|
||||||
|
set { m_LogCmds = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Session ilde timeout [ms]
|
||||||
|
/// </summary>
|
||||||
|
public int SessionIdleTimeOut
|
||||||
|
{
|
||||||
|
get { return m_SessionIdleTimeOut; }
|
||||||
|
set { m_SessionIdleTimeOut = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Command ilde timeout [ms]
|
||||||
|
/// </summary>
|
||||||
|
public int CommandIdleTimeOut
|
||||||
|
{
|
||||||
|
get { return m_CommandIdleTimeOut; }
|
||||||
|
set { m_CommandIdleTimeOut = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Max message Size [b]
|
||||||
|
/// </summary>
|
||||||
|
public int MaxMessageSize
|
||||||
|
{
|
||||||
|
get { return m_MaxMessageSize; }
|
||||||
|
set { m_MaxMessageSize = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Max bad commands bevore kick
|
||||||
|
/// </summary>
|
||||||
|
public int MaxBadCommands
|
||||||
|
{
|
||||||
|
get { return m_MaxBadCommands; }
|
||||||
|
set { m_MaxBadCommands = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
MailServer/IMAP/Server/Server.Session.cs
Normal file
48
MailServer/IMAP/Server/Server.Session.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Fügt eine Session hinzu
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionID">Session ID</param>
|
||||||
|
/// <param name="session">Session Object</param>
|
||||||
|
/// <param name="logWriter">Logwriter</param>
|
||||||
|
internal void AddSession(string sessionID, IMAP_Session session, _LogWriter logWriter)
|
||||||
|
{
|
||||||
|
lock (m_SessionTable)
|
||||||
|
{
|
||||||
|
m_SessionTable.Add(sessionID, session);
|
||||||
|
|
||||||
|
if (m_LogCmds)
|
||||||
|
{
|
||||||
|
logWriter.AddEntry("//----- Sys: 'Session:'" + sessionID + " added " + DateTime.Now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Löscht eine Session
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionID">Session ID</param>
|
||||||
|
/// <param name="logWriter">Logwriter</param>
|
||||||
|
internal void RemoveSession(string sessionID, _LogWriter logWriter)
|
||||||
|
{
|
||||||
|
lock (m_SessionTable)
|
||||||
|
{
|
||||||
|
if (!m_SessionTable.Contains(sessionID))
|
||||||
|
{
|
||||||
|
OnSysError(new Exception("Session '" + sessionID + "' doesn't exist."), new System.Diagnostics.StackTrace());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_SessionTable.Remove(sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_LogCmds)
|
||||||
|
{
|
||||||
|
logWriter.AddEntry("//----- Sys: 'Session:'" + sessionID + " removed " + DateTime.Now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
MailServer/IMAP/Server/Server.StartStopRun.cs
Normal file
111
MailServer/IMAP/Server/Server.StartStopRun.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Threading;
|
||||||
|
using System;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
partial class Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Startet den IMAP Server
|
||||||
|
/// </summary>
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// if(!m_enabled && !this.DesignMode){
|
||||||
|
m_SessionTable = new Hashtable();
|
||||||
|
|
||||||
|
Thread startServer = new Thread(new ThreadStart(Run));
|
||||||
|
startServer.Start();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
catch (Exception x)
|
||||||
|
{
|
||||||
|
OnSysError(x, new System.Diagnostics.StackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Stoppt den IMAP Server
|
||||||
|
/// </summary>
|
||||||
|
private void Stop()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (IMAP_Listener != null)
|
||||||
|
{
|
||||||
|
IMAP_Listener.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception x)
|
||||||
|
{
|
||||||
|
OnSysError(x, new System.Diagnostics.StackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Server Hauptschleife
|
||||||
|
/// </summary>
|
||||||
|
private void Run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// check which ip's to listen (all or assigned)
|
||||||
|
if (m_IPAddress.ToLower().IndexOf("all") > -1)
|
||||||
|
{
|
||||||
|
IMAP_Listener = new TcpListener(IPAddress.Any, m_port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IMAP_Listener = new TcpListener(IPAddress.Parse(m_IPAddress), m_port);
|
||||||
|
}
|
||||||
|
// Start listening
|
||||||
|
IMAP_Listener.Start();
|
||||||
|
|
||||||
|
|
||||||
|
//-------- Main Server message loop --------------------------------//
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Check if maximum allowed thread count isn't exceeded
|
||||||
|
if (m_SessionTable.Count <= m_MaxThreads)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Thread is sleeping, until a client connects
|
||||||
|
Socket clientSocket = IMAP_Listener.AcceptSocket();
|
||||||
|
|
||||||
|
string sessionID = clientSocket.GetHashCode().ToString();
|
||||||
|
|
||||||
|
//****
|
||||||
|
_LogWriter logWriter = new _LogWriter(this.SessionLog);
|
||||||
|
IMAP_Session session = new IMAP_Session(clientSocket, this, sessionID, logWriter);
|
||||||
|
|
||||||
|
Thread clientThread = new Thread(new ThreadStart(session.StartProcessing));
|
||||||
|
|
||||||
|
// Add session to session list
|
||||||
|
AddSession(sessionID, session, logWriter);
|
||||||
|
|
||||||
|
// Start proccessing
|
||||||
|
clientThread.Start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ThreadInterruptedException e)
|
||||||
|
{
|
||||||
|
string dummy = e.Message; // Neede for to remove compile warning
|
||||||
|
Thread.CurrentThread.Abort();
|
||||||
|
}
|
||||||
|
catch (Exception x)
|
||||||
|
{
|
||||||
|
if (x.Message != "A blocking operation was interrupted by a call to WSACancelBlockingCall")
|
||||||
|
{
|
||||||
|
OnSysError(x, new System.Diagnostics.StackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
MailServer/IMAP/Server/Server.cs
Normal file
62
MailServer/IMAP/Server/Server.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.ServiceProcess;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace MailServer.IMAP.Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IMAP Server Komponente
|
||||||
|
/// </summary>
|
||||||
|
public partial class Server : ServiceBase
|
||||||
|
{
|
||||||
|
private TcpListener IMAP_Listener = null;
|
||||||
|
private Hashtable m_SessionTable = null;
|
||||||
|
|
||||||
|
private string m_IPAddress = "ALL"; // Holds IP Address, which to listen incoming calls.
|
||||||
|
private int m_port = 143; // Holds port number, which to listen incoming calls.
|
||||||
|
private int m_MaxThreads = 20; // Holds maximum allowed Worker Threads.
|
||||||
|
private bool m_enabled = false; // If true listens incoming calls.
|
||||||
|
private bool m_LogCmds = false; // If true, writes commands to log file.
|
||||||
|
private int m_SessionIdleTimeOut = 80000; // Holds session idle timeout.
|
||||||
|
private int m_CommandIdleTimeOut = 6000000; // Holds command ilde timeout.
|
||||||
|
private int m_MaxMessageSize = 1000000; // Hold maximum message size.
|
||||||
|
private int m_MaxBadCommands = 8; // Holds maximum bad commands allowed to session.
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Server laden und anhängen
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container">anhängen an</param>
|
||||||
|
public Server(System.ComponentModel.IContainer container)
|
||||||
|
{
|
||||||
|
container.Add(this);
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Server laden
|
||||||
|
/// </summary>
|
||||||
|
public Server()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Starte Server über Dienst
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
protected override void OnStart(string[] args)
|
||||||
|
{
|
||||||
|
Start();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Stoppe Server über Dienst
|
||||||
|
/// </summary>
|
||||||
|
protected override void OnStop()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,42 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="IMAP\Server\IMAP_Session.cs" />
|
||||||
|
<Compile Include="Settings\Enum.cs" />
|
||||||
|
<Compile Include="IMAP\Server\AuthUser_EventArgs.cs" />
|
||||||
|
<Compile Include="IMAP\Server\AuthUser_EventArgs.Properties.cs">
|
||||||
|
<DependentUpon>AuthUser_EventArgs.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.Designer.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.EventDelegates.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.Events.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.EventsDeclarations.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.Properties.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.Session.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="IMAP\Server\Server.StartStopRun.cs">
|
||||||
|
<DependentUpon>Server.cs</DependentUpon>
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Service1.cs">
|
<Compile Include="Service1.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -8,6 +8,12 @@ namespace MailServer
|
|||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
static void auth_user_arsch(object sender, IMAP.Server.AuthUser_EventArgs e)
|
||||||
|
{
|
||||||
|
e.Validated = false;
|
||||||
|
if(e.UserName == "blubb" && e.PasswData == "asd")
|
||||||
|
e.Validated = true;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Der Haupteinstiegspunkt für die Anwendung.
|
/// Der Haupteinstiegspunkt für die Anwendung.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -19,6 +25,9 @@ namespace MailServer
|
|||||||
new Service1()
|
new Service1()
|
||||||
};
|
};
|
||||||
ServiceBase.Run(ServicesToRun);
|
ServiceBase.Run(ServicesToRun);
|
||||||
|
IMAP.Server.Server asd = new IMAP.Server.Server();
|
||||||
|
asd.AuthUser += new IMAP.Server.Server.AuthUserEventHandler(auth_user_arsch);
|
||||||
|
asd.GetMessage += new IMAP.Server.Server.MessageEventHandler(asd_GetMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
MailServer/Settings/Enum.cs
Normal file
30
MailServer/Settings/Enum.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MailServer.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Autentifizierungstyp
|
||||||
|
/// </summary>
|
||||||
|
public enum AuthType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Plain username/password authentication.
|
||||||
|
/// </summary>
|
||||||
|
Plain = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// APOP
|
||||||
|
/// </summary>
|
||||||
|
APOP = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Not implemented.
|
||||||
|
/// </summary>
|
||||||
|
LOGIN = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Cram-md5 authentication.
|
||||||
|
/// </summary>
|
||||||
|
CRAM_MD5 = 3,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user