Revision: 37
Author: tmyroadctfig
Date: 2006-05-20 08:56:30 -0700 (Sat, 20 May 2006)
ViewCVS: http://svn.sourceforge.net/nmailserver/?rev=37&view=rev
Log Message:
-----------
Further work on local store. Added option to turn of TLS in remoting channel.
Modified Paths:
--------------
NMail/branches/luke-dev/NMail/DataTypes/LocalStore/MailDomain.cs
NMail/branches/luke-dev/NMail/ILocalStore.cs
NMail/branches/luke-dev/NMail/ILocalStoreData.cs
NMail/branches/luke-dev/NMail/ILocalStoreDeliveryAction.cs
NMail/branches/luke-dev/NMail/ILocalStoreRecipientValidator.cs
NMail/branches/luke-dev/NMail/IO/TcpChannel.cs
NMail/branches/luke-dev/NMail/IO/TcpClientChannel.cs
NMail/branches/luke-dev/NMail/IO/TcpClientTransportSink.cs
NMail/branches/luke-dev/NMail/IO/TcpClientTransportSinkProvider.cs
NMail/branches/luke-dev/NMail/IO/TcpServerChannel.cs
NMail/branches/luke-dev/NMail/IO/TcpServerTransportSink.cs
NMail/branches/luke-dev/NMail.Administration.Console/Context/LocalStoreContext.cs
NMail/branches/luke-dev/NMail.Administration.Console/Context/TopLevelContext.cs
NMail/branches/luke-dev/NMail.Administration.Console/NMail.Administration.Console.csproj
NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ClamAvScanner.cs
NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Copy.cs
NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ManageWhiteList.cs
NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Move.cs
NMail/branches/luke-dev/NMail.LocalStore/LocalStore.cs
NMail/branches/luke-dev/NMail.LocalStore/NMail.LocalStore.csproj
NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressDate.cs
NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressKeyword.cs
NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressSender.cs
NMail/branches/luke-dev/NMail.LocalStore/Validators/OnWhiteList.cs
NMail/branches/luke-dev/NMail.LocalStore/Validators/OrdbBlackList.cs
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStore.sql
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs
NMail/branches/luke-dev/NMail.Server/NMail.Server.csproj
NMail/branches/luke-dev/NMail.Server/RemoteAdministration.cs
NMail/branches/luke-dev/NMail.Server.Console/NMail.Server.Console.csproj
NMail/branches/luke-dev/NMail.Server.Console/NMailConsoleServer.cs
Added Paths:
-----------
NMail/branches/luke-dev/NMail.Administration.Console/Command/AddMailDomainCommand.cs
Removed Paths:
-------------
NMail/branches/luke-dev/NMail.LocalStore/Configuration/
Modified: NMail/branches/luke-dev/NMail/DataTypes/LocalStore/MailDomain.cs
===================================================================
--- NMail/branches/luke-dev/NMail/DataTypes/LocalStore/MailDomain.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/DataTypes/LocalStore/MailDomain.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -20,6 +20,7 @@
using System.Text;
using NMail;
+using NMail.Authentication;
using NMail.DataTypes;
namespace NMail.DataTypes.LocalStore {
@@ -27,6 +28,7 @@
/// A mail domain maps users and administrators to a set of hosts that the store
/// accepts mail for.
/// </summary>
+ [Serializable]
public class MailDomain {
public MailDomain(int mailDomainId, Host primaryHost) {
this.mailDomainId = mailDomainId;
@@ -61,76 +63,147 @@
}
}
- WildcardHost[] additionalHosts;
+ private List<WildcardHost> additionalHosts = new List<WildcardHost>();
/// <summary>
/// Other hosts that this domain accepts mail for.
/// </summary>
public WildcardHost[] AdditionalHosts {
get {
- return this.additionalHosts;
+ return this.additionalHosts.ToArray();
}
set {
- this.additionalHosts = value;
+ this.additionalHosts.Clear();
+ this.additionalHosts.AddRange(value);
}
}
- private ILocalStoreUserMap[] mailboxMappings;
+ private List<ILocalStoreUserMap> mailboxMappings = new List<ILocalStoreUserMap>();
/// <summary>
/// Gets the mailbox mappings for this domain.
/// </summary>
public ILocalStoreUserMap[] MailboxMappings {
get {
- return this.mailboxMappings;
+ return this.mailboxMappings.ToArray();
}
set {
- this.mailboxMappings = value;
+ this.mailboxMappings.Clear();
+ this.mailboxMappings.AddRange(value);
}
}
- private ILocalStoreDeliveryAction[] allowedActions;
+ private List<ILocalStoreDeliveryAction> allowedActions = new List<ILocalStoreDeliveryAction>();
/// <summary>
/// The actions that user's of this domain are allowed to use.
/// </summary>
public ILocalStoreDeliveryAction[] AllowedActions {
get {
- return this.allowedActions;
+ return this.allowedActions.ToArray();
}
- set {
- this.allowedActions = value;
- }
+ set {
+ this.allowedActions.Clear();
+ this.allowedActions.AddRange(value);
+ }
}
- private ILocalStoreRecipientValidator[] allowedValidators;
+ private List<ILocalStoreRecipientValidator> allowedValidators = new List<ILocalStoreRecipientValidator>();
/// <summary>
/// The validators that user's of this domain are allowed to use.
/// </summary>
public ILocalStoreRecipientValidator[] AllowedValidators {
get {
- return this.allowedValidators;
+ return this.allowedValidators.ToArray();
}
set {
- this.allowedValidators = value;
+ this.allowedValidators.Clear();
+ this.allowedValidators.AddRange(value);
}
}
- private ILocalStoreDeliveryAction[] defaultActions;
+ private List<ILocalStoreDeliveryAction> defaultActions = new List<ILocalStoreDeliveryAction>();
/// <summary>
/// The default set of actions to apply to incoming messages.
/// </summary>
public ILocalStoreDeliveryAction[] DefaultActions {
get {
- return this.defaultActions;
+ return this.defaultActions.ToArray();
}
set {
- this.defaultActions = value;
+ this.defaultActions.Clear();
+ this.defaultActions.AddRange(value);
}
}
// TODO: add in a recipient validator tree here
+
+
+ /// <summary>
+ /// Maps a given mailbox to a user.
+ /// </summary>
+ /// <param name="mailbox">The mailbox to lookup.</param>
+ /// <returns>The username or null.</returns>
+ public string MapMailboxToUser(string mailbox) {
+ string result = null;
+
+ // Search for a valid mapping for the mailbox
+ for (int i = 0; result == null && i < this.mailboxMappings.Count; i++) {
+ result = this.mailboxMappings[i].MapMailboxToUser(mailbox);
+ }
+
+ return result;
+ }
+
+ public ILocalStoreRecipientValidator GetRecipientValidator(string name) {
+ name = name.Trim().ToLower();
+
+ foreach (ILocalStoreRecipientValidator validator in this.allowedValidators) {
+ if (validator.Name.Trim().ToLower() == name) {
+ return validator;
+ }
+ }
+
+ return null;
+ }
+
+
+ public ILocalStoreDeliveryAction GetDeliveryAction(string name) {
+ name = name.Trim().ToLower();
+
+ foreach (ILocalStoreDeliveryAction action in this.allowedActions) {
+ if (action.Name.Trim().ToLower() == name) {
+ return action;
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Processes the incomming message against the list of delivery actions.
+ /// </summary>
+ /// <param name="delivery">The delivery in progress.</param>
+ /// <param name="username">The associated username.</param>
+ /// <returns>The result of the delivery attempt.</returns>
+ public DeliveryResult ProcessDelivery(LocalStoreDelivery delivery, IAuthenticationToken username) {
+ for (int i = 0; i < this.defaultActions.Count; i++) {
+ string name = this.defaultActions[i].Name;
+ string data = null;
+ if (delivery.Recipient != null) {
+ data = delivery.Recipient.Mailbox.GetDataPairValue(name);
+ }
+
+ DeliveryResult result = this.defaultActions[i].ProcessDelivery(delivery, username, data);
+
+ if (result.Type != DeliveryResultType.Success) {
+ return result;
+ }
+ }
+
+ return new DeliveryResult(DeliveryResultType.Success, null);
+ }
}
}
Modified: NMail/branches/luke-dev/NMail/ILocalStore.cs
===================================================================
--- NMail/branches/luke-dev/NMail/ILocalStore.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/ILocalStore.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -525,13 +525,13 @@
/// <returns>The mail domains.</returns>
MailDomain[] GetMailDomains(IAuthenticationToken authToken);
- /// <summary>
- /// Creates a new mail domain.
- /// </summary>
- /// <param name="authToken">The authentication credentials.</param>
- /// <param name="primaryHost">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to create the mail domain.</returns>
- LocalStoreMailDomainResult CreateMailDomain(IAuthenticationToken authToken, Host primaryHost);
+ /// <summary>
+ /// Adds a new mail domain.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="mailDomain">The mail domain to add.</param>
+ /// <returns>The result of the attempt to add the mail domain.</returns>
+ LocalStoreMailDomainResult AddMailDomain(IAuthenticationToken authToken, MailDomain mailDomain);
/// <summary>
/// Deletes a mail domain from the local store.
@@ -683,21 +683,21 @@
/// <summary>
/// The operation completed successfully.
/// </summary>
- OkSuccessful,
+ OkSuccessful = 0,
/// <summary>
/// A mail domain with the same primary host already exists.
/// </summary>
- AlreadyExists,
+ AlreadyExists = 1,
/// <summary>
/// No matching mail domain exists in the local store.
/// </summary>
- NoSuchMailDomain,
+ NoSuchMailDomain = 2,
/// <summary>
/// The user is not permitted to perform the operation.
/// </summary>
- NotPermitted
+ NotPermitted = 3
}
}
Modified: NMail/branches/luke-dev/NMail/ILocalStoreData.cs
===================================================================
--- NMail/branches/luke-dev/NMail/ILocalStoreData.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/ILocalStoreData.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -71,8 +71,8 @@
/// It is a requirement of the local store that each new folder get an incremented Id number.
/// </remarks>
/// <param name="newFolder">The folder to create.</param>
- /// <returns>The newly created folder details.</returns>
- StoreFolder CreateFolder(string userName, StoreFolder parent, Folder newFolder);
+ /// <returns>The result of the attempt to create the folder.</returns>
+ LocalStoreFolderResult CreateFolder(int userId, StoreFolder parent, Folder newFolder);
/// <summary>
/// Deletes an existing folder.
@@ -441,11 +441,11 @@
MailDomain[] GetMailDomains();
/// <summary>
- /// Creates a new mail domain.
+ /// Adds a new mail domain.
/// </summary>
- /// <param name="primaryHost">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to create the mail domain.</returns>
- LocalStoreMailDomainResult CreateMailDomain(Host primaryHost);
+ /// <param name="mailDomain">The mail domain to add.</param>
+ /// <returns>The result of the attempt to add the mail domain.</returns>
+ LocalStoreMailDomainResult AddMailDomain(MailDomain mailDomain);
/// <summary>
/// Deletes a mail domain from the local store.
Modified: NMail/branches/luke-dev/NMail/ILocalStoreDeliveryAction.cs
===================================================================
--- NMail/branches/luke-dev/NMail/ILocalStoreDeliveryAction.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/ILocalStoreDeliveryAction.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -26,12 +26,11 @@
/// An action that can occur during delivery into the local store.
/// </summary>
public interface ILocalStoreDeliveryAction {
- /// <summary>
- /// Sets up the instance of the action using the configuration in the XML node.
- /// </summary>
- /// <remarks>This will only be called if the validator is part of the default validator.</remarks>
- /// <param name="node">The configuration node.</param>
- void Create(XmlNode node);
+ /// <summary>
+ /// The name of the delivery action. E.g. "move" or "copy".
+ /// </summary>
+ /// <remarks>This is the key used to lookup data in the mailbox part of an address.</remarks>
+ string Name { get; }
/// <summary>
/// Passes the local store delivery data through this action.
Modified: NMail/branches/luke-dev/NMail/ILocalStoreRecipientValidator.cs
===================================================================
--- NMail/branches/luke-dev/NMail/ILocalStoreRecipientValidator.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/ILocalStoreRecipientValidator.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -26,12 +26,11 @@
/// A validation that can be performed on a recipient before accepting delivery.
/// </summary>
public interface ILocalStoreRecipientValidator {
- /// <summary>
- /// Sets up the instance of the validator using the configuration in the XML node.
- /// </summary>
- /// <remarks>This will only be called if the validator is part of the default validator.</remarks>
- /// <param name="node">The configuration node.</param>
- void Create(XmlNode node);
+ /// <summary>
+ /// The name of the validator. E.g. "date" or "sender".
+ /// </summary>
+ /// <remarks>This is the key used to lookup data in the mailbox part of an address.</remarks>
+ string Name { get; }
/// <summary>
/// Checks if the given recipient will be accepted for delivery.
Modified: NMail/branches/luke-dev/NMail/IO/TcpChannel.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpChannel.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpChannel.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -39,6 +39,12 @@
private TcpServerChannel serverChannel;
public TcpChannel(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider) {
+ // Parse common properties
+ bool useTls = true;
+ if (properties.Contains("useTls")) {
+ useTls = (bool) properties["useTls"];
+ }
+
// Create the client sink provider if needed
if (clientSinkProvider == null) {
clientSinkProvider = new BinaryClientFormatterSinkProvider();
@@ -52,7 +58,8 @@
this.clientChannel = new TcpClientChannel(clientSinkProvider,
getAuthDetailsCallback,
certValidationCallback,
- authCompleteCallback);
+ authCompleteCallback,
+ useTls);
if (properties["isServer"] != null && ((string) properties["isServer"]) == "yes") {
// Create the server sink provider if needed
@@ -68,7 +75,8 @@
this.serverChannel = new TcpServerChannel(port,
certificate,
authProvider,
- serverSinkProvider);
+ serverSinkProvider,
+ useTls);
}
}
Modified: NMail/branches/luke-dev/NMail/IO/TcpClientChannel.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpClientChannel.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpClientChannel.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -48,21 +48,11 @@
/// Creates a new client channel with the given provider.
/// </summary>
/// <param name="clientSinkProvider">The provider to use.</param>
- public TcpClientChannel(IClientChannelSinkProvider clientSinkProvider, GetAuthDetailsDelegate getAuthDetailsCallback, ChannelAuthComplete authCompleteCallback) {
- this.clientSinkProvider = clientSinkProvider;
-
- this.transportSinkProvider = new TcpClientTransportSinkProvider(getAuthDetailsCallback, null, authCompleteCallback);
- }
-
- /// <summary>
- /// Creates a new client channel with the given provider.
- /// </summary>
- /// <param name="clientSinkProvider">The provider to use.</param>
/// <param name="certValidationCallback">The certificate to use to validate the remote server's certificate.</param>
- public TcpClientChannel(IClientChannelSinkProvider clientSinkProvider, GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback) {
+ public TcpClientChannel(IClientChannelSinkProvider clientSinkProvider, GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback, bool useTls) {
this.clientSinkProvider = clientSinkProvider;
- this.transportSinkProvider = new TcpClientTransportSinkProvider(getAuthDetailsCallback, certValidationCallback, authCompleteCallback);
+ this.transportSinkProvider = new TcpClientTransportSinkProvider(getAuthDetailsCallback, certValidationCallback, authCompleteCallback, useTls);
if (this.clientSinkProvider == null) {
this.clientSinkProvider = new BinaryClientFormatterSinkProvider();
Modified: NMail/branches/luke-dev/NMail/IO/TcpClientTransportSink.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpClientTransportSink.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpClientTransportSink.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -62,16 +62,19 @@
ChannelAuthComplete authCompleteCallback;
+ private bool useTls;
+
/// <summary>
/// Creates a new sink with the given url.
/// </summary>
/// <param name="url">The URL to connect to.</param>
/// <param name="remoteChannelData">Channel data optionally containing the URL.</param>
/// <param name="certValidationCallback">The callback to use to validate the remote certificate.</param>
- public TcpClientTransportSink(string url, object remoteChannelData, GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback) {
+ public TcpClientTransportSink(string url, object remoteChannelData, GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback, bool useTls) {
this.getAuthDetailsCallback = getAuthDetailsCallback;
this.certValidationCallback = certValidationCallback;
this.authCompleteCallback = authCompleteCallback;
+ this.useTls = useTls;
if (TcpChannel.ValidUrl(url)) {
string objectURI;
@@ -225,33 +228,39 @@
if (response.Trim().ToLower() == "nmail remoting channel") {
this.connection.WriteLine("OK");
- // Go encrypted...
- if (this.certValidationCallback == null) {
- this.connection.StartTlsAsClient(this.host.ToString());
- } else {
- this.connection.StartTlsAsClient(this.host.ToString(), this.certValidationCallback);
- }
+ if (this.useTls)
+ {
+ // Go encrypted...
+ if (this.certValidationCallback == null)
+ {
+ this.connection.StartTlsAsClient(this.host.ToString());
+ }
+ else
+ {
+ this.connection.StartTlsAsClient(this.host.ToString(), this.certValidationCallback);
+ }
- if (this.connection.Encrypted) {
- while (this.connection.Connected && this.authToken == null) {
- // Get the auth details
- TcpUserPasswordPair authDetails = this.getAuthDetailsCallback(this);
-
- // Send them to the server
- this.connection.Write(authDetails);
- this.authToken = (IAuthenticationToken) this.connection.Read();
- }
+ if (!this.connection.Encrypted)
+ {
+ throw new InvalidOperationException("Failed to establish a secure connection to the server.");
+ }
+ }
- if (this.authToken == null) {
- throw new InvalidOperationException("Failed to authenticated to the server.");
- }
+ while (this.connection.Connected && this.authToken == null) {
+ // Get the auth details
+ TcpUserPasswordPair authDetails = this.getAuthDetailsCallback(this);
+
+ // Send them to the server
+ this.connection.Write(authDetails);
+ this.authToken = (IAuthenticationToken) this.connection.Read();
+ }
- // Notify the caller that the auth token has arrived
- this.authCompleteCallback(authToken);
+ if (this.authToken == null) {
+ throw new InvalidOperationException("Failed to authenticated to the server.");
+ }
- } else {
- throw new InvalidOperationException("Failed to establish a secure connection to the server.");
- }
+ // Notify the caller that the auth token has arrived
+ this.authCompleteCallback(authToken);
}
}
}
Modified: NMail/branches/luke-dev/NMail/IO/TcpClientTransportSinkProvider.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpClientTransportSinkProvider.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpClientTransportSinkProvider.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -44,14 +44,17 @@
private ChannelAuthComplete authCompleteCallback;
+ private bool useTls;
+
/// <summary>
/// Creates a new provider with the given certificate validation callback.
/// </summary>
/// <param name="certValidationCallback">The callback to use to validation teh remote server's certificate null for the default.</param>
- public TcpClientTransportSinkProvider(GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback) {
+ public TcpClientTransportSinkProvider(GetAuthDetailsDelegate getAuthDetailsCallback, RemoteCertificateValidationCallback certValidationCallback, ChannelAuthComplete authCompleteCallback, bool useTls) {
this.getAuthDetailsCallback = getAuthDetailsCallback;
this.certValidationCallback = certValidationCallback;
this.authCompleteCallback = authCompleteCallback;
+ this.useTls = useTls;
}
#region IClientChannelSinkProvider Members
@@ -91,7 +94,7 @@
// Create a transport if needed
if (!sinkMap.ContainsKey(key)) {
- this.sinkMap.Add(key, new TcpClientTransportSink(url, remoteChannelData, this.getAuthDetailsCallback, this.certValidationCallback, this.authCompleteCallback));
+ this.sinkMap.Add(key, new TcpClientTransportSink(url, remoteChannelData, this.getAuthDetailsCallback, this.certValidationCallback, this.authCompleteCallback, this.useTls));
}
return this.sinkMap[key];
Modified: NMail/branches/luke-dev/NMail/IO/TcpServerChannel.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpServerChannel.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpServerChannel.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -68,16 +68,19 @@
/// </summary>
private IServerChannelSink nextSink;
+ private bool useTls;
+
/// <summary>
/// Creates a new server channel with the given details.
/// </summary>
/// <param name="port">The port to listen on.</param>
/// <param name="certificate">The certificate to use for SSL.</param>
/// <param name="serverSinkProvider">The provider.</param>
- public TcpServerChannel(int port, X509Certificate2 certificate, IAuthenticationProvider authProvider, IServerChannelSinkProvider serverSinkProvider) {
+ public TcpServerChannel(int port, X509Certificate2 certificate, IAuthenticationProvider authProvider, IServerChannelSinkProvider serverSinkProvider, bool useTls) {
this.port = port;
this.certificate = certificate;
this.authProvider = authProvider;
+ this.useTls = useTls;
// This is needed to report a valid IP to clients asking for channel data
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
@@ -238,7 +241,7 @@
while (true) {
Socket client = socket.AcceptSocket();
- new TcpServerTransportSink(this.nextSink, this.certificate, this.authProvider, client);
+ new TcpServerTransportSink(this.nextSink, this.certificate, this.authProvider, client, this.useTls);
}
} catch (SocketException e) {
// Ignore interrupted exception during shutdown
Modified: NMail/branches/luke-dev/NMail/IO/TcpServerTransportSink.cs
===================================================================
--- NMail/branches/luke-dev/NMail/IO/TcpServerTransportSink.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail/IO/TcpServerTransportSink.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -54,17 +54,20 @@
protected IAuthenticationProvider authProvider;
+ private bool useTls;
+
/// <summary>
/// Creates a new transport sink with the given details.
/// </summary>
/// <param name="nextSink">The next sink in the chain.</param>
/// <param name="certificate">The certificate to use in SSL.</param>
/// <param name="client">The socket to the remote client.</param>
- public TcpServerTransportSink(IServerChannelSink nextSink, X509Certificate2 certificate, IAuthenticationProvider authProvider, Socket client) {
+ public TcpServerTransportSink(IServerChannelSink nextSink, X509Certificate2 certificate, IAuthenticationProvider authProvider, Socket client, bool useTls) {
this.nextSink = nextSink;
this.connection.Create(client);
this.connection.Certificate = certificate;
this.authProvider = authProvider;
+ this.useTls = useTls;
// Create a new thread to read requests with
ThreadHelper th = new ThreadHelper(new WaitCallback(processConnection), null);
@@ -90,8 +93,11 @@
this.connection.Close();
}
- // Go encrypted...
- this.connection.StartTlsAsServer();
+ if (this.useTls)
+ {
+ // Go encrypted...
+ this.connection.StartTlsAsServer();
+ }
int authAttempts = 0;
bool authenticated = false;
Added: NMail/branches/luke-dev/NMail.Administration.Console/Command/AddMailDomainCommand.cs
===================================================================
--- NMail/branches/luke-dev/NMail.Administration.Console/Command/AddMailDomainCommand.cs (rev 0)
+++ NMail/branches/luke-dev/NMail.Administration.Console/Command/AddMailDomainCommand.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2004-2006 Luke Quinane and Daniel Frampton
+ *
+ * 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;
+using System.Collections.Generic;
+using System.Text;
+
+using NMail;
+using NMail.Authentication;
+using NMail.DataTypes;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.Administration.Console.Command {
+ class AddMailDomainCommand : IConsoleCommand {
+
+ private ILocalStore localStore;
+
+ private IAuthenticationToken authToken;
+
+ internal AddMailDomainCommand(ILocalStore localStore, IAuthenticationToken authToken) {
+ this.localStore = localStore;
+ this.authToken = authToken;
+ }
+
+ #region IConsoleCommand Members
+
+ public string Description {
+ get { return "Adds a new mail domain to the local store."; }
+ }
+
+ public string[] Usage {
+ get {
+ List<string> usage = new List<string>();
+
+ usage.Add("addmaildomain PrimaryHost");
+
+ return usage.ToArray();
+ }
+ }
+
+ public string Remarks {
+ get {
+ return null;
+ }
+ }
+
+ public ConsoleExample[] Examples {
+ get {
+ List<ConsoleExample> examples = new List<ConsoleExample>();
+
+ examples.Add(new ConsoleExample("addmaildomain localhost.local", "Add a new mail domain for the domain \"localhost.local\"."));
+
+ return examples.ToArray();
+ }
+ }
+
+ public void Process(string[] commandTokens) {
+ if (commandTokens.Length == 0) {
+ System.Console.WriteLine("A primary host is required.");
+ return;
+ }
+
+ Host host = new Host(commandTokens[0]);
+
+ if (commandTokens.Length > 1) {
+ System.Console.WriteLine("Invalid arguments.");
+ return;
+ }
+
+ MailDomain mailDomain = new MailDomain(-1, host);
+
+ LocalStoreMailDomainResult result = this.localStore.AddMailDomain(this.authToken, mailDomain);
+
+ if (result == LocalStoreMailDomainResult.OkSuccessful) {
+ System.Console.WriteLine("Added new mail domain.");
+ } else {
+ System.Console.WriteLine("Error adding mail domain.");
+ }
+ System.Console.WriteLine();
+ }
+
+ #endregion
+ }
+}
Modified: NMail/branches/luke-dev/NMail.Administration.Console/Context/LocalStoreContext.cs
===================================================================
--- NMail/branches/luke-dev/NMail.Administration.Console/Context/LocalStoreContext.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.Administration.Console/Context/LocalStoreContext.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -34,7 +34,8 @@
this.commands.Add("listmaildomains", new ListMailDomainsCommand(this.localStore, authToken));
this.commands.Add("listaddresses", new ListUsersAddressesCommand(this.localStore));
this.commands.Add("adduser", new AddUserCommand(this.localStore, authToken));
- this.commands.Add("deleteuser", new DeleteUserCommand(this.localStore));
+ this.commands.Add("deleteuser", new DeleteUserCommand(this.localStore));
+ this.commands.Add("addmaildomain", new AddMailDomainCommand(this.localStore, authToken));
}
private ILocalStore localStore;
Modified: NMail/branches/luke-dev/NMail.Administration.Console/Context/TopLevelContext.cs
===================================================================
--- NMail/branches/luke-dev/NMail.Administration.Console/Context/TopLevelContext.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.Administration.Console/Context/TopLevelContext.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -44,8 +44,14 @@
IDictionary props = new Hashtable();
props["port"] = "7877";
props["certificateValidation"] = new RemoteCertificateValidationCallback(remoteCertificateValidation);
- //TcpChannel channel = new TcpChannel(props, null, null);
- TcpClientChannel channel = new TcpClientChannel(null, new GetAuthDetailsDelegate(GetAuthDetails), new RemoteCertificateValidationCallback(remoteCertificateValidation), new ChannelAuthComplete(AuthCompleteCallback));
+
+ bool useTls = true;
+
+#if DEBUG
+ useTls = false;
+#endif
+
+ TcpClientChannel channel = new TcpClientChannel(null, new GetAuthDetailsDelegate(GetAuthDetails), new RemoteCertificateValidationCallback(remoteCertificateValidation), new ChannelAuthComplete(AuthCompleteCallback), useTls);
ChannelServices.RegisterChannel(channel, false);
string url = "nmtcp://127.0.0.1:7877/RemoteAdministration.rem";
Modified: NMail/branches/luke-dev/NMail.Administration.Console/NMail.Administration.Console.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.Administration.Console/NMail.Administration.Console.csproj 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.Administration.Console/NMail.Administration.Console.csproj 2006-05-20 15:56:30 UTC (rev 37)
@@ -23,7 +23,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="Command\AddUserCommand.cs" />
<Compile Include="Command\AddUserToMailDomainCommand.cs" />
+ <Compile Include="Command\AddMailDomainCommand.cs" />
<Compile Include="Command\RemoveUserFromMailDomainCommand.cs" />
<Compile Include="Command\ListFoldersCommand.cs" />
<Compile Include="Command\DeleteUserCommand.cs" />
Modified: NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ClamAvScanner.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ClamAvScanner.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ClamAvScanner.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -29,8 +29,17 @@
/// </summary>
public class ClamAvScanner : ILocalStoreDeliveryAction {
- public void Create(XmlNode node) {}
+ string name = "antivirus";
+ public string Name {
+ get {
+ return this.name;
+ }
+ set {
+ this.name = value;
+ }
+ }
+
public DeliveryResult ProcessDelivery(LocalStoreDelivery delivery, IAuthenticationToken username, string additionalData) {
try {
bool passed = false;
Modified: NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Copy.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Copy.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Copy.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -21,7 +21,6 @@
using NMail;
using NMail.Authentication;
using NMail.DataTypes;
-using NMail.LocalStore.Configuration;
namespace NMail.LocalStore.DeliveryActions {
/// <summary>
@@ -31,10 +30,17 @@
string targetFolder;
- public void Create(XmlNode node) {
- this.targetFolder = node.SelectSingleNode("@folder").Value;
- }
+ string name = "cp";
+ public string Name {
+ get {
+ return this.name;
+ }
+ set {
+ this.name = value;
+ }
+ }
+
public DeliveryResult ProcessDelivery(LocalStoreDelivery delivery, IAuthenticationToken username, string additionalData) {
try {
if (this.targetFolder == null) {
Modified: NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ManageWhiteList.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ManageWhiteList.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/ManageWhiteList.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -25,12 +25,20 @@
using NMail.Authentication;
using NMail.Configuration;
using NMail.DataTypes;
-using NMail.LocalStore.Configuration;
namespace NMail.LocalStore.DeliveryActions {
public class ManageWhiteList : ILocalStoreDeliveryAction {
- public void Create(System.Xml.XmlNode node) { }
+ string name = "wl";
+ public string Name {
+ get {
+ return this.name;
+ }
+ set {
+ this.name = value;
+ }
+ }
+
public DeliveryResult ProcessDelivery(LocalStoreDelivery delivery, IAuthenticationToken username, string additionalData) {
if (delivery.Sender == null) {
// A null sender indicates that the message has been added directly by the user
@@ -103,15 +111,16 @@
}
public bool withinLocalStore(EmailAddress sender) {
- AcceptCaseCollection acceptCases = LocalStoreConfiguration.Current.AcceptCases;
+ //AcceptCaseCollection acceptCases = LocalStoreConfiguration.Current.AcceptCases;
- for (int i = 0; i < acceptCases.Count; i++) {
- if (acceptCases[i].Matches(sender.Host)) {
- return true;
- }
- }
+ //for (int i = 0; i < acceptCases.Count; i++) {
+ // if (acceptCases[i].Matches(sender.Host)) {
+ // return true;
+ // }
+ //}
- return false;
+ //return false;
+ throw new NotImplementedException();
}
}
Modified: NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Move.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Move.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/DeliveryActions/Move.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -21,7 +21,6 @@
using NMail;
using NMail.Authentication;
using NMail.DataTypes;
-using NMail.LocalStore.Configuration;
namespace NMail.LocalStore.DeliveryActions {
/// <summary>
@@ -31,10 +30,17 @@
string targetFolder;
- public void Create(XmlNode node) {
- this.targetFolder = node.SelectSingleNode("@folder").Value;
- }
+ string name = "mv";
+ public string Name {
+ get {
+ return this.name;
+ }
+ set {
+ this.name = value;
+ }
+ }
+
public DeliveryResult ProcessDelivery(LocalStoreDelivery delivery, IAuthenticationToken username, string additionalData) {
try {
if (this.targetFolder == null) {
Modified: NMail/branches/luke-dev/NMail.LocalStore/LocalStore.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/LocalStore.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/LocalStore.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -26,7 +26,6 @@
using NMail.DataTypes.ACLs;
using NMail.DataTypes.LocalStore;
using NMail.Configuration;
-using NMail.LocalStore.Configuration;
using NMail.LocalStore.DeliveryActions;
using NMail.LocalStore.Validators;
@@ -50,13 +49,13 @@
string rawMailbox = recipient.Mailbox.MailboxName;
// Check if this local store will accept devliery for this recipient
- AcceptCase ac = ResolveAccept(recipient.Host);
- if (ac == null) {
+ MailDomain mailDomain = ResolveMailDomain(recipient.Host);
+ if (mailDomain == null) {
return new DeliveryResult(DeliveryResultType.PermanentError, "Local Store does not accept this address.");
}
// Get the username for this mailbox. E.g. "John.Smith" -> "jsmith"
- string username = ac.MapMailboxToUser(rawMailbox);
+ string username = mailDomain.MapMailboxToUser(rawMailbox);
StoreFolder folder = null;
// Ensure the user's folder exists
@@ -72,20 +71,21 @@
// Pass through the default chain
DeliveryResult result;
+
// TODO: sort out the configuration for the validator tree!
- RecipientValidatorElement validationChain = null; //LocalStoreConfiguration.Current.ValidationChain;
- if (validationChain != null) {
- result = validationChain.ValidateRecipient(recipient, authToken);
- } else {
+ //RecipientValidatorElement validationChain = null; //LocalStoreConfiguration.Current.ValidationChain;
+ //if (validationChain != null) {
+ // result = validationChain.ValidateRecipient(recipient, authToken);
+ //} else {
result = new DeliveryResult(DeliveryResultType.Success, null);
- }
+ //}
if (result.Type == DeliveryResultType.Success) {
// Pass through each allowed user validator
IDictionaryEnumerator e = recipient.Mailbox.GetDataPairNames();
while (e.MoveNext() && result.Type == DeliveryResultType.Success) {
- ILocalStoreRecipientValidator validator = ac.GetRecipientValidator((string) e.Key);
+ ILocalStoreRecipientValidator validator = mailDomain.GetRecipientValidator((string) e.Key);
if (validator != null) {
// Pass through the user chain
@@ -103,7 +103,7 @@
/// <param name="host">The host to check.</param>
/// <returns>True if the store accepts delivery.</returns>
public bool WithinLocalStore(Host host) {
- return (ResolveAccept(host) != null);
+ return (ResolveMailDomain(host) != null);
}
#endregion
@@ -118,8 +118,8 @@
string rawMailbox = recipient.Mailbox.MailboxName;
// Check if this local store will accept devliery for this recipient
- AcceptCase ac = ResolveAccept(recipient.Host);
- if (ac == null) {
+ MailDomain mailDomain = ResolveMailDomain(recipient.Host);
+ if (mailDomain == null) {
return new RecipientDeliveryResult(
recipient,
DeliveryResultType.PermanentError,
@@ -127,7 +127,7 @@
}
// Get the username for this mailbox. E.g. "John.Smith" -> "jsmith"
- string username = ac.MapMailboxToUser(rawMailbox);
+ string username = mailDomain.MapMailboxToUser(rawMailbox);
if (username == null) {
return new RecipientDeliveryResult(
recipient,
@@ -158,15 +158,14 @@
LocalStoreDelivery lsd = new LocalStoreDelivery(recipient, inboxFolder);
// Pass through the default chain
- DeliveryActionList deliveryChain = LocalStoreConfiguration.Current.DeliveryChain;
- DeliveryResult result = deliveryChain.ProcessDelivery(lsd, authToken);
+ DeliveryResult result = mailDomain.ProcessDelivery(lsd, authToken);
if (result.Type == DeliveryResultType.Success) {
// Pass through each allowed user action
IDictionaryEnumerator e = recipient.Mailbox.GetDataPairNames();
while (e.MoveNext() && result.Type == DeliveryResultType.Success) {
- ILocalStoreDeliveryAction action = ac.GetDeliveryAction((string)e.Key);
+ ILocalStoreDeliveryAction action = mailDomain.GetDeliveryAction((string)e.Key);
if (action != null) {
// Pass through the user chain
@@ -203,42 +202,56 @@
LocalStoreDelivery lsd = new LocalStoreDelivery((Message) null, folder);
- // Pass through the default chain
- DeliveryActionList deliveryChain = LocalStoreConfiguration.Current.DeliveryChain;
- DeliveryResult result = deliveryChain.ProcessDelivery(lsd, authToken);
-
- // TODO: check the localstoredelivery and ensure the user has the POST
- // privilege on every folder that will be delivered to
+ // Need to get a mail domain for the user here...
+ throw new NotImplementedException();
- if (result.Type == DeliveryResultType.Success) {
- try {
- // Save the message to the store data
- LocalStoreData.DeliverMessage(message, folder);
- } catch (Exception) {
- result.Type = DeliveryResultType.TemporaryError;
- result.Message = "Internal error while delivering message.";
- }
- }
+ //// Pass through the default chain
+ //DeliveryActionList deliveryChain = LocalStoreConfiguration.Current.DeliveryChain;
+ //DeliveryResult result = deliveryChain.ProcessDelivery(lsd, authToken);
+
+ //// TODO: check the localstoredelivery and ensure the user has the POST
+ //// privilege on every folder that will be delivered to
- return result;
+ //if (result.Type == DeliveryResultType.Success) {
+ // try {
+ // // Save the message to the store data
+ // LocalStoreData.DeliverMessage(message, folder);
+ // } catch (Exception) {
+ // result.Type = DeliveryResultType.TemporaryError;
+ // result.Message = "Internal error while delivering message.";
+ // }
+ //}
+
+ //return result;
}
#endregion
- /// <summary>
- /// Determines the accept case that matches the given host, if any.
- /// </summary>
- /// <param name="host">The host to accept delivery for.</param>
- /// <returns>The accept case or null if non exists.</returns>
- private AcceptCase ResolveAccept(Host host) {
- // Matches the given host to an accept case
- foreach(AcceptCase acc in LocalStoreConfiguration.Current.AcceptCases) {
- if (acc.Matches(host)) {
- return acc;
- }
- }
+ private MailDomain ResolveMailDomain(Host host) {
+ MailDomain[] mailDomains = this.LocalStoreData.GetMailDomains();
- return null;
- }
+ // First check primary hosts
+ foreach (MailDomain mailDomain in mailDomains) {
+ if (mailDomain.PrimaryHost == host) {
+ return mailDomain;
+ }
+ }
+
+ // No match, check secondary hosts
+ foreach (MailDomain mailDomain in mailDomains) {
+ if (mailDomain.AdditionalHosts == null) {
+ continue;
+ }
+
+ foreach (WildcardHost wildCardHost in mailDomain.AdditionalHosts) {
+ if (wildCardHost.MatchesHost(host)) {
+ return mailDomain;
+ }
+ }
+ }
+
+ // Nothing matches
+ return null;
+ }
#endregion
#region Folder Retrieval and Manipulation
@@ -311,8 +324,20 @@
// Ensure the user has rights to get the message flags
if (hasFolderPrivilege(authToken.Username, parent, StoreFolderPrivilege.CreateFolders)) {
+ // Get the user Id
+ int? userId = LocalStoreData.GetUserId(authToken.Username);
+ if (!userId.HasValue) {
+ throw new InvalidOperationException("Can't get a user Id for the current user.");
+ }
+
// Create the mailbox
- StoreFolder createdFolder = LocalStoreData.CreateFolder(authToken.Username, parent, resolvedFolder);
+ LocalStoreFolderResult result = LocalStoreData.CreateFolder(userId.Value, parent, resolvedFolder);
+ if (result != LocalStoreFolderResult.OkSuccessful) {
+ return result;
+ }
+
+ // Get the folder
+ StoreFolder createdFolder = LocalStoreData.GetStoreFolder(resolvedFolder);
// Create an ACL for the folder
StoreFolderAce ace = new StoreFolderAce(authToken.Username, StoreFolderPrivilegeHelper.AllPrivileges, AcePrivilegeType.Allow);
@@ -1120,17 +1145,17 @@
return this.LocalStoreData.GetMailDomains();
}
- /// <summary>
- /// Creates a new mail domain.
- /// </summary>
- /// <param name="authToken">The authentication credentials.</param>
- /// <param name="primaryHost">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to create the mail domain.</returns>
- public LocalStoreMailDomainResult CreateMailDomain(IAuthenticationToken authToken, Host primaryHost) {
+ /// <summary>
+ /// Adds a new mail domain.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="mailDomain">The mail domain to add.</param>
+ /// <returns>The result of the attempt to add the mail domain.</returns>
+ public LocalStoreMailDomainResult AddMailDomain(IAuthenticationToken authToken, MailDomain mailDomain) {
+ // TODO: check ACLs
- // TODO: check acls
- return this.LocalStoreData.CreateMailDomain(primaryHost);
- }
+ return this.LocalStoreData.AddMailDomain(mailDomain);
+ }
/// <summary>
/// Deletes a mail domain from the local store.
Modified: NMail/branches/luke-dev/NMail.LocalStore/NMail.LocalStore.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/NMail.LocalStore.csproj 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/NMail.LocalStore.csproj 2006-05-20 15:56:30 UTC (rev 37)
@@ -94,12 +94,6 @@
<Compile Include="AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Configuration\AcceptCase.cs" />
- <Compile Include="Configuration\DelieryActionList.cs" />
- <Compile Include="Configuration\LocalStoreConfiguration.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Configuration\RecipientValidatorTree.cs" />
<Compile Include="DeliveryActions\ClamAvScanner.cs" />
<Compile Include="DeliveryActions\Copy.cs">
<SubType>Code</SubType>
Modified: NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressDate.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressDate.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressDate.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -32,7 +32,11 @@
/// </summary>
public class AddressDate : ILocalStoreRecipientValidator {
- public void Create(XmlNode node) {}
+ public string Name {
+ get {
+ return "date";
+ }
+ }
public DeliveryResult ValidateRecipient(SmtpMessageRecipient recipient, IAuthenticationToken username, string additionalData) {
try {
Modified: NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressKeyword.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressKeyword.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressKeyword.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -32,7 +32,11 @@
/// </summary>
public class AddressKeyword : ILocalStoreRecipientValidator {
- public void Create(XmlNode node) {}
+ public string Name {
+ get {
+ return "keyword";
+ }
+ }
public DeliveryResult ValidateRecipient(SmtpMessageRecipient recipient, IAuthenticationToken username, string additionalData) {
try {
Modified: NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressSender.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressSender.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/Validators/AddressSender.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -32,7 +32,11 @@
/// </summary>
public class AddressSender : ILocalStoreRecipientValidator {
- public void Create(XmlNode node) {}
+ public string Name {
+ get {
+ return "sender";
+ }
+ }
public DeliveryResult ValidateRecipient(SmtpMessageRecipient recipient, IAuthenticationToken username, string additionalData) {
try {
Modified: NMail/branches/luke-dev/NMail.LocalStore/Validators/OnWhiteList.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/Validators/OnWhiteList.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/Validators/OnWhiteList.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -27,7 +27,11 @@
namespace NMail.LocalStore.Validators {
public class OnWhiteList : ILocalStoreRecipientValidator {
- public void Create(System.Xml.XmlNode node) { }
+ public string Name {
+ get {
+ return "wl";
+ }
+ }
public DeliveryResult ValidateRecipient(SmtpMessageRecipient recipient, IAuthenticationToken username, string additionalData) {
// Get the user's whitelist
Modified: NMail/branches/luke-dev/NMail.LocalStore/Validators/OrdbBlackList.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStore/Validators/OrdbBlackList.cs 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStore/Validators/OrdbBlackList.cs 2006-05-20 15:56:30 UTC (rev 37)
@@ -29,8 +29,13 @@
/// A chain that checks the sender against the ORDB blacklist.
/// </summary>
public class OrdbBlackList : ILocalStoreRecipientValidator {
- public void Create(XmlNode node) {}
+ public string Name {
+ get {
+ return "ordb";
+ }
+ }
+
public DeliveryResult ValidateRecipient(SmtpMessageRecipient recipient, IAuthenticationToken username, string additionalData) {
IPAddress source = recipient.Message.SourceAddress;
byte[] sourceBytes = source.GetAddressBytes();
Modified: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStore.sql
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStore.sql 2006-05-20 07:15:35 UTC (rev 36)
+++ NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStore.sql 2006-05-20 15:56:30 UTC (rev 37)
@@ -214,7 +214,8 @@
START TRANSACTION;
/* Check if the parameters are valid. */
- IF EXISTS (SELECT f.FolderId FROM Folder f WHERE f.FolderId = ParentId) THEN
+ IF ParentId IS NULL OR
+ EXISTS (SELECT f.FolderId FROM Folder f WHERE f.FolderId = ParentId) THEN
/* Check for duplicate folders. */
IF NOT EXISTS (SELECT f.FolderId FROM Folder f WHERE f.Name LIKE Name) THEN
@@ -239,7 +240,40 @@
END
//
+DROP PROCEDURE IF EXISTS DeleteFolder //
+CREATE PROCEDURE DeleteFolder
+(
+ DeleteFolderId INT,
+ OUT Result INT
+)
+BEGIN
+ START TRANSACTION;
+ /* Check if the folder Id is valid. */
+ IF EXISTS (SELECT f.FolderId FROM Folder f WHERE f.FolderId = DeleteFolderId) THEN
+
+ /* Check if the folder still has sub-folders. */
+ IF NOT EXISTS (SELECT * FROM Folder f WHERE f.ParentFolderId = DeleteFolderId) THEN
+
+ DELETE FROM Folder WHERE FolderId = DeleteFolderId;
+
+ /* Ok successful. */
+ SELECT 0 INTO Result;
+
+ ELSE
+ /* User still has sub-folders. */
+ SELECT 2 INTO Result;
+ END IF;
+ ELSE
+ /* No such folder. */
+ SELECT 3 INTO Result;
+ END IF;
+
+ COMMIT;
+END
+//
+
+
-- -----------------------------------------------------------------------
--
-- User related stored procedures
@@ -259,7 +293,7 @@
BEGIN
START TRANSACTION;
- IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.Name LIKE Name) THEN
+ IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.Username LIKE Name) THEN
SELECT
u.UserId, u.QuotaHardLimit, u.QuotaWarnLimit, u.UserFolderId
@@ -268,7 +302,7 @@
FROM
`User` u
WHERE
- u.Name LIKE Name;
+ u.Username LIKE Name;
/* Ok successful. */
SELECT 0 INTO Result;
@@ -298,7 +332,7 @@
IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.UserId = UserId) THEN
SELECT
- u.Name, u.QuotaHardLimit, u.QuotaWarnLimit, u.UserFolderId
+ u.Username, u.QuotaHardLimit, u.QuotaWarnLimit, u.UserFolderId
INTO
Name, QuotaHardLimit, QuotaWarnLimit, UserFolderId
FROM
@@ -349,7 +383,7 @@
START TRANSACTION;
/* Check if the name is valid. */
- IF NOT EXISTS (SELECT u.UserId FROM User u WHERE u.Name LIKE Name) THEN
+ IF NOT EXISTS (SELECT u.UserId FROM `User` u WHERE u.Username LIKE Name) THEN
SET InboxName = CONCAT_WS(".", Name, "INBOX");
@@ -357,7 +391,7 @@
IF NOT EXISTS (SELECT * FROM Folder f WHERE f.Name LIKE Name and f.NamespaceId = NamespaceId) AND
NOT EXISTS (SELECT * FROM Folder f WHERE f.Name LIKE InboxName and f.NamespaceId = NamespaceId) THEN
- INSERT INTO User (Name, QuotaHardLimit, QuotaWarnLimit) VALUES (Name, QuotaHardLimit, QuotaWarnLimit);
+ INSERT INTO User (Username, QuotaHardLimit, QuotaWarnLimit) VALUES (Name, QuotaHardLimit, QuotaWarnLimit);
SELECT LAST_INSERT_ID() INTO UserId;
/* Create the user's base folder. */
@@ -406,19 +440,19 @@
DROP PROCEDURE IF EXISTS DeleteUser //
CREATE PROCEDURE DeleteUser
(
- UserId INT
+ DeleteUserId INT,
OUT Result INT
)
BEGIN
START TRANSACTION;
/* Check if the user Id is valid. */
- IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.UserId = UserId) THEN
+ IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.UserId = DeleteUserId) THEN
/* Check if the user still has folders. */
- IF NOT EXISTS (SELECT * FROM Folder WHERE OwnerUserId = UserId) THEN
+ IF NOT EXISTS (SELECT * FROM Folder WHERE OwnerUserId = DeleteUserId) THEN
- DELETE FROM `User` WHERE UserId = UserId;
+ DELETE FROM `User` WHERE UserId = DeleteUserId;
/* Ok successful. */
SELECT 0 INTO Result;
@@ -452,13 +486,13 @@
IF EXISTS (SELECT u.UserId FROM `User` u WHERE u.UserId = UserId) THEN
/* Check if the new name is valid. */
- IF EXISTS (SELECT u.Name FROM `User` u WHERE u.UserId = UserId AND u.Name LIKE Name) OR
- NOT EXISTS (SELECT U.Name FROM `User` u WHERE u.Name LIKE Name) THEN
+ IF EXISTS (SELECT u.Username FROM `User` u WHERE u.UserId = UserId AND u.Username LIKE Name) OR
+ NOT EXISTS (SELECT U.Username FROM `User` u WHERE u.Username LIKE Name) THEN
UPDATE
`User` u
SET
- u.Name = Name,
+ u.Username = Name,
u.QuotaHardLimit = QuotaHardLimit,
u.QuotaWarnLimit = QuotaWarnLimit
WHERE
@@ -612,16 +646,16 @@
DROP PROCEDURE IF EXISTS DeleteGroup //
CREATE PROCEDURE DeleteGroup
(
- GroupId INT,
+ DeleteGroupId INT,
OUT Result INT
)
BEGIN
START TRANSACTION;
/* Check if the Id is valid. */
- IF EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = GroupId) THEN
+ IF EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = DeleteGroupId) THEN
- DELETE FROM `Group` WHERE GroupId = GroupId;
+ DELETE FROM `Group` WHERE GroupId = DeleteGroupId;
/* Ok successful. */
SELECT 0 INTO Result;
@@ -716,18 +750,18 @@
DROP PROCEDURE IF EXISTS RemoveGroupFromGroup //
CREATE PROCEDURE RemoveGroupFromGroup
(
- ParentId INT,
- GroupId INT,
+ DeleteParentId INT,
+ DeleteGroupId INT,
OUT Result INT
)
BEGIN
START TRANSACTION;
/* Check if the Ids is valid. */
- IF EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = GroupId) AND
- EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = ParentId) THEN
+ IF EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = DeleteGroupId) AND
+ EXISTS (SELECT g.Name FROM `Group` g WHERE g.GroupId = DeleteParentId) THEN
- DELETE FROM GroupGroupMap WHERE GroupId = GroupId AND ParentId = ParentId;
+ DELETE FROM GroupGroupMap WHERE GroupId = DeleteGroupId AND ParentId = DeleteParentId;
/* Ok successful. */
SELECT 0 INTO Result;
@@ -741,6 +775,55 @@
END
//
+
+-- -----------------------------------------------------------------------
+--
+-- Mail domain related stored procedures
+--
+-- -----------------------------------------------------------------------
+
+
+DROP PROCEDURE IF EXISTS GetMailDomainIds //
+CREATE PROCEDURE GetMailDomainIds
+()
+BEGIN
+
+ SELECT MailDomainId FROM MailDomain;
+
+END
+//
+
+DROP PROCEDURE IF EXISTS AddMailDomain //
+CREATE PROCEDURE AddMailDomain
+(
+ PrimaryHost VARCHAR(255),
+ ObjectData LONGBLOB,
+ OUT MailDomainId INT,
+ OUT Result INT
+)
+BEGIN
+ START TRANSACTION;
+
+ /* Check if the name is valid. */
+ IF NOT EXISTS (SELECT m.MailDomainId FROM MailDomain m WHERE m.PrimaryHost LIKE PrimaryHost) THEN
+
+ INSERT INTO MailDomain (PrimaryHost, ObjectData) VALUES (PrimaryHost, ObjectData);
+
+ SELECT LAST_INSERT_ID() INTO MailDomainId;
+
+ /* Ok successful. */
+ SELECT 0 INTO Result;
+
+ ELSE
+ /* Already exists. */
+ SELECT 1 INTO Result;
+ END IF;
+
+ COMMIT;
+END
+//
+
+
delimiter ;
Modified: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs
=================================================================...
[truncated message content] |