Initial project's source code check-in.
This commit is contained in:
commit
b03b0b373f
4573 changed files with 981205 additions and 0 deletions
|
@ -0,0 +1,399 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Security.AccessControl;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using WebsitePanel.Server.Utils;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class AMSHelper
|
||||
{
|
||||
|
||||
public static string MailListsConfigFile
|
||||
{
|
||||
get { return @"mailinglists.ini"; }
|
||||
}
|
||||
|
||||
public static string DomainsConfigFile
|
||||
{
|
||||
get { return @"domains.ini"; }
|
||||
|
||||
}
|
||||
|
||||
public static string UsersConfigFile
|
||||
{
|
||||
get { return @"users.ini"; }
|
||||
}
|
||||
|
||||
public static string AccountConfigFile
|
||||
{
|
||||
get { return @"{0}\{1}\config.ini"; }
|
||||
}
|
||||
|
||||
public static string AccountDeliveryFile
|
||||
{
|
||||
get { return @"{0}\{1}\delivery.ini"; }
|
||||
}
|
||||
|
||||
public static string MailListConfigFile
|
||||
{
|
||||
get { return @"{0}\{1}.ini"; }
|
||||
}
|
||||
|
||||
public static string AccountFolder
|
||||
{
|
||||
get { return @"{0}\{1}\"; }
|
||||
}
|
||||
|
||||
public static string DomainFolder
|
||||
{
|
||||
get {return @"{0}\"; }
|
||||
}
|
||||
|
||||
public static string GroupsConfigFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"config\accounts\groups.ini";
|
||||
}
|
||||
}
|
||||
|
||||
public static string AMSLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
string serverLocation = null;
|
||||
|
||||
RegistryKey HKLM = Registry.LocalMachine;
|
||||
|
||||
RegistryKey key = HKLM.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Ability Mail Server 2_is1");
|
||||
|
||||
if (key != null)
|
||||
serverLocation = (string)key.GetValue("InstallLocation");
|
||||
|
||||
string amsMailConfig = serverLocation + @"config\mailserver.ini";
|
||||
string[] lines = File.ReadAllLines(amsMailConfig);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (string s in lines)
|
||||
{
|
||||
if (s.StartsWith("accountpath"))
|
||||
{
|
||||
string[] split = s.Split(new char[] { '=' });
|
||||
if (Path.IsPathRooted(split[1]))
|
||||
{
|
||||
if (String.Equals(split[1], "\\config\\accounts\\"))
|
||||
{
|
||||
if (serverLocation != null)
|
||||
return Path.Combine(serverLocation, "config\\accounts\\");
|
||||
}
|
||||
serverLocation = split[1];
|
||||
DirectoryInfo Location = new DirectoryInfo(split[1]);
|
||||
if (!Location.Exists)
|
||||
Location.Create();
|
||||
string groupConfPath = Path.Combine(split[1], @"\groups.ini");
|
||||
if (!File.Exists(groupConfPath))
|
||||
if (key != null)
|
||||
File.Copy(
|
||||
Path.Combine((string) key.GetValue("InstallLocation"), GroupsConfigFile),
|
||||
groupConfPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(ex);
|
||||
}
|
||||
return serverLocation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Tree GetDomainsConfig()
|
||||
{
|
||||
return ReadAmsConfigurationFile(DomainsConfigFile);
|
||||
}
|
||||
|
||||
public static bool SetDomainsConfig(Tree config)
|
||||
{
|
||||
return SaveAmsConfigurationFile(config, DomainsConfigFile);
|
||||
}
|
||||
|
||||
public static Tree GetUsersConfig()
|
||||
{
|
||||
return ReadAmsConfigurationFile(UsersConfigFile);
|
||||
}
|
||||
|
||||
public static bool SetUsersConfig(Tree config)
|
||||
{
|
||||
return SaveAmsConfigurationFile(config, UsersConfigFile);
|
||||
}
|
||||
|
||||
public static Tree GetAccountConfig(string mailboxName)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(mailboxName);
|
||||
string domain = AmsMailbox.GetDomainName(mailboxName);
|
||||
string accountConfig = string.Format(AccountConfigFile, domain, account);
|
||||
|
||||
return ReadAmsConfigurationFile(accountConfig);
|
||||
}
|
||||
|
||||
public static bool SetAccountConfig(Tree config, string mailboxName)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(mailboxName);
|
||||
string domain = AmsMailbox.GetDomainName(mailboxName);
|
||||
string accountConfig = string.Format(AccountConfigFile, domain, account);
|
||||
|
||||
return SaveAmsConfigurationFile(config, accountConfig);
|
||||
}
|
||||
|
||||
public static Tree GetMailListsConfig()
|
||||
{
|
||||
return ReadAmsConfigurationFile(MailListsConfigFile);
|
||||
}
|
||||
|
||||
public static bool SetMailListsConfig(Tree config)
|
||||
{
|
||||
return SaveAmsConfigurationFile(config, MailListsConfigFile);
|
||||
}
|
||||
|
||||
public static Tree GetMailingListConfig(string maillistName)
|
||||
{
|
||||
string domain = AmsMailbox.GetDomainName(maillistName);
|
||||
string account = AmsMailbox.GetAccountName(maillistName);
|
||||
string listConfig = Path.Combine(AMSLocation, string.Format(MailListConfigFile, domain, account));
|
||||
|
||||
return ReadAmsConfigurationFile(listConfig);
|
||||
}
|
||||
|
||||
public static bool SetMailingListConfig(Tree config, string maillistName)
|
||||
{
|
||||
string domain = AmsMailbox.GetDomainName(maillistName);
|
||||
string account = AmsMailbox.GetAccountName(maillistName);
|
||||
string listConfig = Path.Combine(AMSLocation, string.Format(MailListConfigFile, domain, account));
|
||||
|
||||
return SaveAmsConfigurationFile(config, listConfig);
|
||||
}
|
||||
|
||||
public static Tree GetAccountDelivery(string mailboxName)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(mailboxName);
|
||||
string domain = AmsMailbox.GetDomainName(mailboxName);
|
||||
string deliveryConfig = string.Format(AccountDeliveryFile, domain, account);
|
||||
|
||||
return ReadAmsConfigurationFile(deliveryConfig);
|
||||
}
|
||||
|
||||
public static bool SetAccountDelivery(Tree config, string mailboxName)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(mailboxName);
|
||||
string domain = AmsMailbox.GetDomainName(mailboxName);
|
||||
string deliveryConfig = string.Format(AccountDeliveryFile, domain, account);
|
||||
|
||||
return SaveAmsConfigurationFile(config, deliveryConfig);
|
||||
}
|
||||
|
||||
public static bool RemoveAccount(string mailboxName)
|
||||
{
|
||||
bool succeed = false;
|
||||
string account = AmsMailbox.GetAccountName(mailboxName);
|
||||
string domain = AmsMailbox.GetDomainName(mailboxName);
|
||||
string accountDir = Path.Combine(AMSLocation, string.Format(AccountFolder, domain, account));
|
||||
|
||||
try
|
||||
{
|
||||
Directory.Delete(accountDir, true);
|
||||
succeed = true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.WriteError(ex);
|
||||
}
|
||||
|
||||
return succeed;
|
||||
}
|
||||
|
||||
public static bool RemoveDomain(string domainName)
|
||||
{
|
||||
bool succeed = false;
|
||||
string domainFolder = Path.Combine(AMSLocation, string.Format(DomainFolder, domainName));
|
||||
|
||||
try
|
||||
{
|
||||
Directory.Delete(domainFolder, true);
|
||||
succeed = true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.WriteError(ex.Message, ex);
|
||||
}
|
||||
|
||||
return succeed;
|
||||
}
|
||||
|
||||
public static bool RemoveMailList(string maillistName)
|
||||
{
|
||||
bool succeed = false;
|
||||
string account = AmsMailbox.GetAccountName(maillistName);
|
||||
string domain = AmsMailbox.GetDomainName(maillistName);
|
||||
string maillistConfig = Path.Combine(AMSLocation, string.Format(MailListConfigFile, domain, account));
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(maillistConfig);
|
||||
succeed = true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.WriteError(ex.Message, ex);
|
||||
}
|
||||
|
||||
return succeed;
|
||||
}
|
||||
|
||||
protected static Tree ReadAmsConfigurationFile(string configFile)
|
||||
{
|
||||
Tree configTree = new Tree();
|
||||
|
||||
try
|
||||
{
|
||||
string amsConfig = Path.Combine(AMSLocation, configFile);
|
||||
|
||||
if (!File.Exists(amsConfig))
|
||||
{
|
||||
FileStream stream = File.Create(amsConfig);
|
||||
stream.Close();
|
||||
stream.Dispose();
|
||||
return configTree;
|
||||
}
|
||||
|
||||
string[] lines = File.ReadAllLines(amsConfig);
|
||||
|
||||
TreeNode parent = null;
|
||||
|
||||
foreach(string lineStr in lines)
|
||||
{
|
||||
bool isLeaf = false;
|
||||
string line = lineStr.Trim();
|
||||
TreeNode node = new TreeNode(parent);
|
||||
|
||||
if (line.StartsWith("}"))
|
||||
{
|
||||
if (parent != null) parent = parent.Parent;
|
||||
continue;
|
||||
}
|
||||
|
||||
// fill node
|
||||
if (line.StartsWith("{"))
|
||||
{
|
||||
line = line.Replace("{", string.Empty).Trim();
|
||||
node.NodeName = line;
|
||||
isLeaf = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int splitIndex = line.IndexOf("=");
|
||||
node.NodeName = line.Substring(0, splitIndex);
|
||||
node.NodeValue = line.Substring(splitIndex + 1);
|
||||
}
|
||||
|
||||
// add node
|
||||
if (parent != null)
|
||||
parent.ChildNodes.Add(node);
|
||||
else
|
||||
configTree.ChildNodes.Add(node);
|
||||
|
||||
parent = isLeaf ? node : parent;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return configTree;
|
||||
}
|
||||
|
||||
public static bool SaveAmsConfigurationFile(Tree config, string configFile)
|
||||
{
|
||||
string amsConfig = null;
|
||||
string amsBackup = null;
|
||||
bool succeed = false;
|
||||
|
||||
try
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
config.Serialize(builder);
|
||||
|
||||
amsConfig = Path.Combine(AMSLocation, configFile);
|
||||
amsBackup = string.Concat(amsConfig, ".bak");
|
||||
|
||||
string configFolder = Path.GetDirectoryName(amsConfig);
|
||||
|
||||
if (!Directory.Exists(configFolder))
|
||||
Directory.CreateDirectory(configFolder);
|
||||
|
||||
// create backup
|
||||
if (File.Exists(amsConfig))
|
||||
File.Move(amsConfig, amsBackup);
|
||||
|
||||
File.WriteAllText(amsConfig, builder.ToString());
|
||||
succeed = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(ex);
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!succeed) // restore backup
|
||||
{
|
||||
if (File.Exists(amsBackup))
|
||||
File.Move(amsBackup, amsConfig);
|
||||
}
|
||||
else // remove backup
|
||||
{
|
||||
File.Delete(amsBackup);
|
||||
}
|
||||
}
|
||||
|
||||
return succeed;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,548 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using WebsitePanel.Server.Utils;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class AbilityMailServer : HostingServiceProviderBase, IMailServer
|
||||
{
|
||||
#region IMailServer Members
|
||||
|
||||
public bool AccountExists(string mailboxName)
|
||||
{
|
||||
Tree users = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox accnt = new AmsMailbox(mailboxName);
|
||||
|
||||
return accnt.Load(users);
|
||||
}
|
||||
|
||||
public void AddDomainAlias(string domainName, string aliasName)
|
||||
{
|
||||
Tree domains = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain alias = new AmsDomain(aliasName);
|
||||
|
||||
if (!alias.Load(domains))
|
||||
{
|
||||
alias.DomainConfig["enabled"] = "1";
|
||||
alias.DomainConfig["domain"] = aliasName;
|
||||
alias.DomainConfig["mode"] = "1"; // alias mode
|
||||
alias.DomainConfig["useconvertdomain"] = "1";
|
||||
alias.DomainConfig["convertdomain"] = domainName;
|
||||
|
||||
if (!alias.Save(domains))
|
||||
{
|
||||
Log.WriteInfo("Couldn't save domains configuration.");
|
||||
throw new Exception("Couldn't add domain alias.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WriteInfo("Alias already exists.");
|
||||
throw new Exception("Alias already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateAccount(MailAccount mailbox)
|
||||
{
|
||||
Tree users = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox accnt = new AmsMailbox(mailbox.Name);
|
||||
|
||||
if (accnt.Load(users))
|
||||
throw new Exception("Mailbox is already registered.");
|
||||
|
||||
accnt.Read(mailbox);
|
||||
|
||||
if (!accnt.Save(users))
|
||||
throw new Exception("Couldn't create a mailbox.");
|
||||
}
|
||||
|
||||
public void CreateDomain(MailDomain domain)
|
||||
{
|
||||
Tree domains = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsDomain = new AmsDomain(domain.Name);
|
||||
|
||||
if (amsDomain.Load(domains))
|
||||
throw new Exception("Domain is already registered.");
|
||||
|
||||
amsDomain.Read(domain);
|
||||
|
||||
if (!amsDomain.Save(domains))
|
||||
throw new Exception("Couldn't create a domain.");
|
||||
}
|
||||
|
||||
public void CreateGroup(MailGroup group)
|
||||
{
|
||||
Tree users = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsGroup = new AmsMailbox(group.Name);
|
||||
|
||||
if (amsGroup.Load(users))
|
||||
throw new Exception("Mail group is already exists.");
|
||||
|
||||
amsGroup.Read(group);
|
||||
|
||||
if (!amsGroup.Save(users))
|
||||
throw new Exception("Couldn't create a mail group.");
|
||||
}
|
||||
|
||||
public void CreateList(MailList maillist)
|
||||
{
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
AmsMailList amsList = new AmsMailList(maillist.Name);
|
||||
|
||||
if (amsList.Load(config))
|
||||
throw new Exception("Mail list is already exists.");
|
||||
|
||||
amsList.Read(maillist);
|
||||
|
||||
if (!amsList.Save(config))
|
||||
throw new Exception("Couldn't create a mail list.");
|
||||
}
|
||||
|
||||
public void DeleteAccount(string mailboxName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsMailbox = new AmsMailbox(mailboxName);
|
||||
|
||||
if (amsMailbox.Load(config))
|
||||
{
|
||||
if (!amsMailbox.Delete(config))
|
||||
throw new Exception("Couldn't delete a specified account.");
|
||||
}
|
||||
else
|
||||
throw new Exception("Couldn't load account settings.");
|
||||
}
|
||||
|
||||
public bool MailAliasExists(string mailAliasName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public MailAlias[] GetMailAliases(string domainName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public MailAlias GetMailAlias(string mailAliasName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void CreateMailAlias(MailAlias mailAlias)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpdateMailAlias(MailAlias mailAlias)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteMailAlias(string mailAliasName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteDomain(string domainName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsDomain = new AmsDomain(domainName);
|
||||
|
||||
if (amsDomain.Load(config))
|
||||
{
|
||||
if (!amsDomain.Delete(config))
|
||||
throw new Exception("Couldn't delete specified domain.");
|
||||
}
|
||||
else
|
||||
throw new Exception("Couldn't find specified domain.");
|
||||
}
|
||||
|
||||
public void DeleteDomainAlias(string domainName, string aliasName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsAlias = new AmsDomain(aliasName);
|
||||
|
||||
if (amsAlias.Load(config))
|
||||
{
|
||||
string amsDomain = amsAlias.DomainConfig["convertdomain"];
|
||||
if (string.Compare(amsDomain, domainName, true) == 0)
|
||||
{
|
||||
if (!amsAlias.DeleteAlias(config))
|
||||
throw new Exception("Couldn't delete alias.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified alias.");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteGroup(string groupName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsGroup = new AmsMailbox(groupName);
|
||||
|
||||
if (amsGroup.Load(config))
|
||||
{
|
||||
if (!amsGroup.Delete(config))
|
||||
throw new Exception("Couldn't delete specified mail group.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified mail group.");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteList(string maillistName)
|
||||
{
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
AmsMailList amsList = new AmsMailList(maillistName);
|
||||
|
||||
if (amsList.Load(config))
|
||||
{
|
||||
if (!amsList.Delete(config))
|
||||
throw new Exception("Couldn't delete a mail list.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified mail list.");
|
||||
}
|
||||
}
|
||||
|
||||
public bool DomainAliasExists(string domainName, string aliasName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsAlias = new AmsDomain(aliasName);
|
||||
|
||||
if (amsAlias.Load(config))
|
||||
if (string.Compare(amsAlias.DomainConfig["convertdomain"], domainName, true) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool DomainExists(string domainName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsDomain = new AmsDomain(domainName);
|
||||
|
||||
return amsDomain.Load(config);
|
||||
}
|
||||
|
||||
public MailAccount GetAccount(string mailboxName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsMailbox = new AmsMailbox(mailboxName);
|
||||
|
||||
if (amsMailbox.Load(config))
|
||||
{
|
||||
amsMailbox.LoadAccountConfig();
|
||||
return amsMailbox.ToMailAccount();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public MailAccount[] GetAccounts(string domainName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
List<MailAccount> accounts = new List<MailAccount>();
|
||||
|
||||
AmsMailbox[] mbList = AmsMailbox.GetMailboxes(config, domainName);
|
||||
foreach (AmsMailbox mb in mbList)
|
||||
accounts.Add(mb.ToMailAccount());
|
||||
|
||||
return accounts.ToArray();
|
||||
}
|
||||
|
||||
public MailDomain GetDomain(string domainName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsDomain = new AmsDomain(domainName);
|
||||
|
||||
if (amsDomain.Load(config))
|
||||
return amsDomain.ToMailDomain();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual string[] GetDomains()
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
|
||||
return AmsDomain.GetDomains(config);
|
||||
}
|
||||
|
||||
public string[] GetDomainAliases(string domainName)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
|
||||
return AmsDomain.GetDomainAliases(config, domainName);
|
||||
}
|
||||
|
||||
public MailGroup GetGroup(string groupName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsGroup = new AmsMailbox(groupName);
|
||||
|
||||
if (amsGroup.Load(config))
|
||||
{
|
||||
amsGroup.LoadAccountConfig();
|
||||
return amsGroup.ToMailGroup();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public MailGroup[] GetGroups(string domainName)
|
||||
{
|
||||
List<MailGroup> groups = new List<MailGroup>();
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
|
||||
AmsMailbox[] amsGroups = AmsMailbox.GetMailGroups(config, domainName);
|
||||
|
||||
foreach (AmsMailbox amsGroup in amsGroups)
|
||||
groups.Add(amsGroup.ToMailGroup());
|
||||
|
||||
return groups.ToArray();
|
||||
}
|
||||
|
||||
public MailList GetList(string maillistName)
|
||||
{
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
AmsMailList amsList = new AmsMailList(maillistName);
|
||||
|
||||
if (amsList.Load(config))
|
||||
{
|
||||
amsList.LoadListConfig();
|
||||
return amsList.ToMailList();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public MailList[] GetLists(string domainName)
|
||||
{
|
||||
List<MailList> lists = new List<MailList>();
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
|
||||
AmsMailList[] amsLists = AmsMailList.GetMailLists(config, domainName);
|
||||
|
||||
foreach (AmsMailList amsList in amsLists)
|
||||
lists.Add(amsList.ToMailList());
|
||||
|
||||
return lists.ToArray();
|
||||
}
|
||||
|
||||
public bool GroupExists(string groupName)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsGroup = new AmsMailbox(groupName);
|
||||
|
||||
if (amsGroup.Load(config))
|
||||
{
|
||||
amsGroup.LoadAccountConfig();
|
||||
|
||||
return amsGroup.IsMailGroup();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ListExists(string maillistName)
|
||||
{
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
AmsMailList amsList = new AmsMailList(maillistName);
|
||||
|
||||
return amsList.Load(config);
|
||||
}
|
||||
|
||||
public void UpdateAccount(MailAccount mailbox)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsMailbox = new AmsMailbox(mailbox.Name);
|
||||
|
||||
if (amsMailbox.Load(config))
|
||||
{
|
||||
amsMailbox.LoadAccountConfig();
|
||||
amsMailbox.Read(mailbox);
|
||||
|
||||
if (!amsMailbox.Save(config))
|
||||
throw new Exception("Couldn't update specified mailbox.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified mailbox.");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDomain(MailDomain domain)
|
||||
{
|
||||
Tree config = AMSHelper.GetDomainsConfig();
|
||||
AmsDomain amsDomain = new AmsDomain(domain.Name);
|
||||
|
||||
if (amsDomain.Load(config))
|
||||
{
|
||||
amsDomain.Read(domain);
|
||||
|
||||
if (!amsDomain.Save(config))
|
||||
throw new Exception("Couldn't update specified domain.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified domain.");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateGroup(MailGroup group)
|
||||
{
|
||||
Tree config = AMSHelper.GetUsersConfig();
|
||||
AmsMailbox amsGroup = new AmsMailbox(group.Name);
|
||||
|
||||
if (amsGroup.Load(config))
|
||||
{
|
||||
amsGroup.LoadAccountConfig();
|
||||
amsGroup.Read(group);
|
||||
|
||||
if (!amsGroup.Save(config))
|
||||
throw new Exception("Couldn't update specified mail group.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified mail group.");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateList(MailList maillist)
|
||||
{
|
||||
Tree config = AMSHelper.GetMailListsConfig();
|
||||
AmsMailList amsList = new AmsMailList(maillist.Name);
|
||||
|
||||
if (amsList.Load(config))
|
||||
{
|
||||
amsList.LoadListConfig();
|
||||
amsList.Read(maillist);
|
||||
|
||||
if (!amsList.Save(config))
|
||||
throw new Exception("Couldn't update specified mail list.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Couldn't find specified mail list.");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HostingServiceProviderBase members
|
||||
|
||||
public override void DeleteServiceItems(ServiceProviderItem[] items)
|
||||
{
|
||||
foreach (ServiceProviderItem item in items)
|
||||
{
|
||||
if (item is MailDomain)
|
||||
{
|
||||
try
|
||||
{
|
||||
// delete mail domain
|
||||
DeleteDomain(item.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("Error deleting '{0}' mail domain", item.Name), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ChangeServiceItemsState(ServiceProviderItem[] items, bool enabled)
|
||||
{
|
||||
foreach (ServiceProviderItem item in items)
|
||||
{
|
||||
if (item is MailDomain)
|
||||
{
|
||||
try
|
||||
{
|
||||
MailDomain domain = GetDomain(item.Name);
|
||||
domain.Enabled = enabled;
|
||||
// update mail domain
|
||||
UpdateDomain(domain);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.WriteError(String.Format("Error switching '{0}' mail domain", item.Name), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public override bool IsInstalled()
|
||||
{
|
||||
string name = null;
|
||||
string versionNumber = null;
|
||||
|
||||
RegistryKey HKLM = Registry.LocalMachine;
|
||||
|
||||
RegistryKey key = HKLM.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Ability Mail Server 2_is1");
|
||||
|
||||
if (key != null)
|
||||
{
|
||||
name = (string) key.GetValue("DisplayName");
|
||||
string[] parts = name.Split(new char[] {' '});
|
||||
versionNumber = parts[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
key = HKLM.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Ability Mail Server 2_is1");
|
||||
if (key != null)
|
||||
{
|
||||
name = (string)key.GetValue("DisplayName");
|
||||
string[] parts = name.Split(new char[] { ' ' });
|
||||
versionNumber = parts[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string[] split = versionNumber.Split(new char[] {'.'});
|
||||
|
||||
return split[0].Equals("2");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class AmsDomain
|
||||
{
|
||||
private string domainName;
|
||||
private TreeNode domainConfig;
|
||||
|
||||
public WebsitePanel.Providers.Mail.TreeNode DomainConfig
|
||||
{
|
||||
get { return this.domainConfig; }
|
||||
}
|
||||
|
||||
public AmsDomain(string domainName)
|
||||
{
|
||||
this.domainName = domainName;
|
||||
this.domainConfig = new TreeNode();
|
||||
}
|
||||
|
||||
public bool Load(Tree config)
|
||||
{
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string amsDomain = node["domain"];
|
||||
if (String.Compare(amsDomain, domainName, true) == 0)
|
||||
{
|
||||
this.domainConfig = node;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Save(Tree config)
|
||||
{
|
||||
if (!config.ChildNodes.Contains(domainConfig))
|
||||
{
|
||||
domainConfig["dir"] = Path.Combine(AMSHelper.AMSLocation, domainName);
|
||||
config.ChildNodes.Add(domainConfig);
|
||||
}
|
||||
|
||||
return AMSHelper.SetDomainsConfig(config);
|
||||
}
|
||||
|
||||
public bool Delete(Tree config)
|
||||
{
|
||||
if (config.ChildNodes.Contains(domainConfig))
|
||||
config.ChildNodes.Remove(domainConfig);
|
||||
|
||||
Tree usersConfig = AMSHelper.GetUsersConfig();
|
||||
List<TreeNode> nodesToDelete = new List<TreeNode>();
|
||||
foreach (TreeNode node in usersConfig.ChildNodes)
|
||||
{
|
||||
if (string.Compare(node["domain"], domainName, true) == 0)
|
||||
nodesToDelete.Add(node);
|
||||
}
|
||||
|
||||
while (nodesToDelete.Count > 0)
|
||||
{
|
||||
usersConfig.ChildNodes.Remove(nodesToDelete[0]);
|
||||
nodesToDelete.RemoveAt(0);
|
||||
}
|
||||
|
||||
Tree listsConfig = AMSHelper.GetMailListsConfig();
|
||||
foreach (TreeNode node in listsConfig.ChildNodes)
|
||||
{
|
||||
if (string.Compare(node["domain"], domainName, true) == 0)
|
||||
nodesToDelete.Add(node);
|
||||
}
|
||||
|
||||
while (nodesToDelete.Count > 0)
|
||||
{
|
||||
listsConfig.ChildNodes.Remove(nodesToDelete[0]);
|
||||
nodesToDelete.RemoveAt(0);
|
||||
}
|
||||
|
||||
return AMSHelper.RemoveDomain(domainName) &&
|
||||
AMSHelper.SetUsersConfig(usersConfig) &&
|
||||
AMSHelper.SetMailListsConfig(listsConfig) &&
|
||||
AMSHelper.SetDomainsConfig(config);
|
||||
}
|
||||
|
||||
public bool DeleteAlias(Tree config)
|
||||
{
|
||||
if (config.ChildNodes.Contains(domainConfig))
|
||||
config.ChildNodes.Remove(domainConfig);
|
||||
|
||||
Tree usersConfig = AMSHelper.GetUsersConfig();
|
||||
List<TreeNode> nodesToDelete = new List<TreeNode>();
|
||||
foreach (TreeNode node in usersConfig.ChildNodes)
|
||||
{
|
||||
if (string.Compare(node["domain"], domainName, true) == 0)
|
||||
nodesToDelete.Add(node);
|
||||
}
|
||||
|
||||
while (nodesToDelete.Count > 0)
|
||||
{
|
||||
usersConfig.ChildNodes.Remove(nodesToDelete[0]);
|
||||
nodesToDelete.RemoveAt(0);
|
||||
}
|
||||
|
||||
Tree listsConfig = AMSHelper.GetMailListsConfig();
|
||||
foreach (TreeNode node in listsConfig.ChildNodes)
|
||||
{
|
||||
if (string.Compare(node["domain"], domainName, true) == 0)
|
||||
nodesToDelete.Add(node);
|
||||
}
|
||||
|
||||
while (nodesToDelete.Count > 0)
|
||||
{
|
||||
listsConfig.ChildNodes.Remove(nodesToDelete[0]);
|
||||
nodesToDelete.RemoveAt(0);
|
||||
}
|
||||
|
||||
return AMSHelper.SetUsersConfig(usersConfig) &&
|
||||
AMSHelper.SetMailListsConfig(listsConfig) &&
|
||||
AMSHelper.SetDomainsConfig(config);
|
||||
}
|
||||
|
||||
public void Read(MailDomain domain)
|
||||
{
|
||||
domainConfig["enabled"] = domain.Enabled ? "1" : "0";
|
||||
domainConfig["domain"] = domain.Name;
|
||||
domainConfig["mode"] = "0";
|
||||
|
||||
domainConfig["usemaxusers"] = (domain.MaxDomainUsers == 0) ? "0" : "1";
|
||||
domainConfig["maxusers"] = (domain.MaxDomainUsers == 0) ? "0" : domain.MaxDomainUsers.ToString();
|
||||
|
||||
domainConfig["usemaxmailinglists"] = (domain.MaxLists == 0) ? "0" : "1";
|
||||
domainConfig["maxmailinglists"] = (domain.MaxLists == 0) ? "0" : domain.MaxLists.ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(domain.CatchAllAccount))
|
||||
{
|
||||
domainConfig["usecatchcalluser"] = "1";
|
||||
domainConfig["catchalluser"] = domain.CatchAllAccount;
|
||||
}
|
||||
else
|
||||
{
|
||||
domainConfig["usecatchcalluser"] = "0";
|
||||
domainConfig["catchalluser"] = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public MailDomain ToMailDomain()
|
||||
{
|
||||
if (domainConfig["mode"] == "0")
|
||||
{
|
||||
MailDomain domain = new MailDomain();
|
||||
|
||||
domain.Enabled = domainConfig["enabled"] == "1" ? true : false;
|
||||
domain.Name = domainConfig["domain"];
|
||||
|
||||
if (domainConfig["usemaxusers"] == "1")
|
||||
domain.MaxDomainUsers = Convert.ToInt32(domainConfig["maxusers"]);
|
||||
|
||||
if (domainConfig["usemaxmailinglists"] == "1")
|
||||
domain.MaxLists = Convert.ToInt32(domainConfig["maxmailinglists"]);
|
||||
|
||||
if (domainConfig["usecatchcalluser"] == "1")
|
||||
domain.CatchAllAccount = domainConfig["catchalluser"];
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string[] GetDomainAliases(Tree config, string domainName)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string mode = node["mode"];
|
||||
string convert = node["convertdomain"];
|
||||
|
||||
if (String.Compare(convert, domainName, true) == 0 && mode == "1")
|
||||
list.Add(node["domain"]);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static string[] GetDomains(Tree config)
|
||||
{
|
||||
List<string> domains = new List<string>();
|
||||
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
domains.Add(node["domain"]);
|
||||
|
||||
return domains.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class AmsMailList
|
||||
{
|
||||
private TreeNode nodeConfig;
|
||||
private Tree listConfig;
|
||||
private string maillistName;
|
||||
|
||||
public TreeNode Config
|
||||
{
|
||||
get { return nodeConfig; }
|
||||
}
|
||||
|
||||
public Tree ListConfig
|
||||
{
|
||||
get { return listConfig; }
|
||||
}
|
||||
|
||||
public AmsMailList(string maillistName)
|
||||
{
|
||||
this.maillistName = maillistName;
|
||||
nodeConfig = new TreeNode();
|
||||
listConfig = new Tree();
|
||||
}
|
||||
|
||||
public bool Load(Tree config)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(maillistName);
|
||||
string domain = AmsMailbox.GetDomainName(maillistName);
|
||||
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string amsUser = node["user"];
|
||||
string amsDomain = node["domain"];
|
||||
|
||||
if (string.Compare(amsUser, account, true) == 0 &&
|
||||
string.Compare(amsDomain, domain, true) == 0)
|
||||
{
|
||||
nodeConfig = node;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Load(TreeNode configNode)
|
||||
{
|
||||
string account = AmsMailbox.GetAccountName(maillistName);
|
||||
string domain = AmsMailbox.GetDomainName(maillistName);
|
||||
|
||||
string amsUser = configNode["user"];
|
||||
string amsDomain = configNode["domain"];
|
||||
|
||||
if (string.Compare(amsUser, account, true) == 0 &&
|
||||
string.Compare(amsDomain, domain, true) == 0)
|
||||
{
|
||||
nodeConfig = configNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public MailList ToMailList()
|
||||
{
|
||||
MailList list = new MailList();
|
||||
|
||||
list.Name = maillistName;
|
||||
|
||||
if (nodeConfig["enabled"] == "1")
|
||||
list.Enabled = true;
|
||||
|
||||
// copy mail list members
|
||||
TreeNode addresses = listConfig.ChildNodes["addresses"];
|
||||
|
||||
if (addresses != null)
|
||||
{
|
||||
List<string> members = new List<string>();
|
||||
|
||||
foreach (TreeNode node in addresses.ChildNodes)
|
||||
members.Add(node.NodeValue);
|
||||
|
||||
list.Members = members.ToArray();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Save(Tree config)
|
||||
{
|
||||
if (!config.ChildNodes.Contains(nodeConfig))
|
||||
{
|
||||
nodeConfig["file"] = string.Format(AMSHelper.MailListConfigFile, AmsMailbox.GetDomainName(maillistName), AmsMailbox.GetAccountName(maillistName));
|
||||
config.ChildNodes.Add(nodeConfig);
|
||||
}
|
||||
|
||||
return AMSHelper.SetMailListsConfig(config) &&
|
||||
AMSHelper.SetMailingListConfig(listConfig, maillistName);
|
||||
}
|
||||
|
||||
public void LoadListConfig()
|
||||
{
|
||||
this.listConfig = AMSHelper.GetMailingListConfig(maillistName);
|
||||
}
|
||||
|
||||
public void Read(MailList maillist)
|
||||
{
|
||||
nodeConfig["domain"] = AmsMailbox.GetDomainName(maillist.Name);
|
||||
nodeConfig["enabled"] = maillist.Enabled ? "1" : "0";
|
||||
nodeConfig["user"] = AmsMailbox.GetAccountName(maillist.Name);
|
||||
nodeConfig["triggertext"] = "TRIGGER";
|
||||
nodeConfig["usetriggeredreplyto"] = "0";
|
||||
nodeConfig["triggeredreplyto"] = string.Empty;
|
||||
nodeConfig["usetriggeredfrom"] = string.Empty;
|
||||
nodeConfig["triggeredfrom"] = string.Empty;
|
||||
nodeConfig["maxtriggersperday"] = "100";
|
||||
nodeConfig["useonlymemberscantrigger"] = "0";
|
||||
nodeConfig["maxaddresses"] = "5000";
|
||||
|
||||
// copy mail list members
|
||||
TreeNode addresses = listConfig.ChildNodes["addresses"];
|
||||
|
||||
if (addresses == null)
|
||||
{
|
||||
addresses = new TreeNode();
|
||||
addresses.NodeName = "addresses";
|
||||
listConfig.ChildNodes.Add(addresses);
|
||||
}
|
||||
addresses.ChildNodes.Clear();
|
||||
|
||||
foreach (string member in maillist.Members)
|
||||
{
|
||||
TreeNode node = new TreeNode(addresses);
|
||||
node.NodeValue = member;
|
||||
addresses.ChildNodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Delete(Tree config)
|
||||
{
|
||||
if (config.ChildNodes.Contains(nodeConfig))
|
||||
config.ChildNodes.Remove(nodeConfig);
|
||||
|
||||
return AMSHelper.RemoveMailList(maillistName) &&
|
||||
AMSHelper.SetMailListsConfig(config);
|
||||
}
|
||||
|
||||
public static AmsMailList[] GetMailLists(Tree config, string domainName)
|
||||
{
|
||||
List<AmsMailList> list = new List<AmsMailList>();
|
||||
|
||||
foreach(TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string user = node["user"];
|
||||
string domain = node["domain"];
|
||||
if (string.Compare(domain, domainName, true) == 0)
|
||||
{
|
||||
AmsMailList ml = new AmsMailList(string.Concat(user, "@", domain));
|
||||
ml.Load(node);
|
||||
ml.LoadListConfig();
|
||||
|
||||
list.Add(ml);
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class AmsMailbox
|
||||
{
|
||||
private TreeNode userConfig;
|
||||
private Tree accountConfig;
|
||||
private Tree deliveryConfig;
|
||||
private string mailboxName;
|
||||
|
||||
public TreeNode UserConfig
|
||||
{
|
||||
get { return userConfig; }
|
||||
}
|
||||
|
||||
public Tree AccountConfig
|
||||
{
|
||||
get { return accountConfig; }
|
||||
/*set { accountConfig = value; }*/
|
||||
}
|
||||
|
||||
public Tree DeliveryConfig
|
||||
{
|
||||
get { return deliveryConfig; }
|
||||
/*set { deliveryConfig = value; }*/
|
||||
}
|
||||
|
||||
public AmsMailbox(string mailboxName)
|
||||
{
|
||||
this.mailboxName = mailboxName;
|
||||
|
||||
this.accountConfig = new Tree();
|
||||
this.deliveryConfig = new Tree();
|
||||
|
||||
this.userConfig = new TreeNode();
|
||||
}
|
||||
|
||||
public bool Load(Tree userConfig)
|
||||
{
|
||||
string account = GetAccountName(mailboxName);
|
||||
string domain = GetDomainName(mailboxName);
|
||||
|
||||
foreach (TreeNode node in userConfig.ChildNodes)
|
||||
{
|
||||
string amsUser = node["user"];
|
||||
string amsDomain = node["domain"];
|
||||
|
||||
if (string.Compare(amsUser, account, true) == 0 &&
|
||||
string.Compare(amsDomain, domain, true) == 0)
|
||||
{
|
||||
this.userConfig = node;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Load(TreeNode configNode)
|
||||
{
|
||||
string account = GetAccountName(mailboxName);
|
||||
string domain = GetDomainName(mailboxName);
|
||||
|
||||
string amsUser = configNode["user"];
|
||||
string amsDomain = configNode["domain"];
|
||||
|
||||
if (string.Compare(amsUser, account, true) == 0 &&
|
||||
string.Compare(amsDomain, domain, true) == 0)
|
||||
{
|
||||
this.userConfig = configNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LoadAccountConfig()
|
||||
{
|
||||
this.accountConfig = AMSHelper.GetAccountConfig(mailboxName);
|
||||
this.deliveryConfig = AMSHelper.GetAccountDelivery(mailboxName);
|
||||
}
|
||||
|
||||
public bool Save(Tree config)
|
||||
{
|
||||
if (!config.ChildNodes.Contains(userConfig))
|
||||
{
|
||||
userConfig["dir"] = Path.Combine(AMSHelper.AMSLocation, string.Format(@"{0}\{1}\", GetDomainName(mailboxName), GetAccountName(mailboxName)));
|
||||
config.ChildNodes.Add(userConfig);
|
||||
}
|
||||
|
||||
return AMSHelper.SetUsersConfig(config) &&
|
||||
AMSHelper.SetAccountConfig(accountConfig, mailboxName) &&
|
||||
AMSHelper.SetAccountDelivery(deliveryConfig, mailboxName);
|
||||
}
|
||||
|
||||
public bool Delete(Tree config)
|
||||
{
|
||||
if (config.ChildNodes.Contains(userConfig))
|
||||
config.ChildNodes.Remove(userConfig);
|
||||
|
||||
return AMSHelper.RemoveAccount(mailboxName) &&
|
||||
AMSHelper.SetUsersConfig(config);
|
||||
}
|
||||
|
||||
public MailAccount ToMailAccount()
|
||||
{
|
||||
MailAccount account = new MailAccount();
|
||||
|
||||
account.Name = string.Concat(userConfig["user"], "@", userConfig["domain"]);
|
||||
account.Enabled = userConfig["enabled"] == "1" ? true : false;
|
||||
account.Password = userConfig["pass"];
|
||||
|
||||
// read forwardings
|
||||
TreeNode redirection = deliveryConfig.ChildNodes["redirection"];
|
||||
if (redirection != null)
|
||||
{
|
||||
TreeNode redirections = redirection.ChildNodes["redirections"];
|
||||
|
||||
if (redirections != null)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
foreach (TreeNode node in redirections.ChildNodes)
|
||||
list.Add(node.NodeValue);
|
||||
|
||||
account.ForwardingAddresses = list.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
// read autoresponder
|
||||
TreeNode autoresponses = deliveryConfig.ChildNodes["autoresponses"];
|
||||
if (autoresponses != null)
|
||||
{
|
||||
account.ResponderEnabled = autoresponses["enabled"] == "1" ? true : false;
|
||||
account.ResponderSubject = autoresponses["subject"];
|
||||
account.ResponderMessage = autoresponses["body"];
|
||||
|
||||
if (autoresponses["usereplyto"] == "1")
|
||||
account.ReplyTo = autoresponses["replyto"];
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
public MailGroup ToMailGroup()
|
||||
{
|
||||
MailGroup group = new MailGroup();
|
||||
|
||||
group.Name = mailboxName;
|
||||
group.Enabled = userConfig["enabled"] == "1" ? true : false;
|
||||
|
||||
TreeNode redirection = deliveryConfig.ChildNodes["redirection"];
|
||||
|
||||
if (redirection != null)
|
||||
{
|
||||
TreeNode redirections = redirection.ChildNodes["redirections"];
|
||||
|
||||
if (redirections != null)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
|
||||
foreach (TreeNode node in redirections.ChildNodes)
|
||||
list.Add(node.NodeValue);
|
||||
|
||||
group.Members = list.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
public void Read(MailAccount mailbox)
|
||||
{
|
||||
userConfig["domain"] = GetDomainName(mailbox.Name);
|
||||
userConfig["enabled"] = mailbox.Enabled ? "1" : "0";
|
||||
userConfig["user"] = GetAccountName(mailbox.Name);
|
||||
userConfig["pass"] = mailbox.Password;
|
||||
// forwardings
|
||||
if (mailbox.ForwardingAddresses != null)
|
||||
AddForwardingInfo(mailbox.ForwardingAddresses, mailbox.DeleteOnForward);
|
||||
|
||||
AddAutoResponderInfo(mailbox);
|
||||
}
|
||||
|
||||
private void AddAutoResponderInfo(MailAccount mailbox)
|
||||
{
|
||||
TreeNode autoresponses = deliveryConfig.ChildNodes["autoresponses"];
|
||||
|
||||
if (autoresponses == null)
|
||||
{
|
||||
autoresponses = new TreeNode();
|
||||
autoresponses.NodeName = "autoresponses";
|
||||
deliveryConfig.ChildNodes.Add(autoresponses);
|
||||
}
|
||||
|
||||
autoresponses["enabled"] = mailbox.ResponderEnabled ? "1" : "0";
|
||||
|
||||
if (mailbox.ResponderEnabled)
|
||||
{
|
||||
autoresponses["subject"] = mailbox.ResponderSubject;
|
||||
autoresponses["body"] = mailbox.ResponderMessage;
|
||||
|
||||
if (!string.IsNullOrEmpty(mailbox.ReplyTo))
|
||||
{
|
||||
autoresponses["usereplyto"] = "1";
|
||||
autoresponses["replyto"] = mailbox.ReplyTo;
|
||||
}
|
||||
else
|
||||
{
|
||||
autoresponses["usereplyto"] = "0";
|
||||
autoresponses["replyto"] = string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
autoresponses["subject"] = string.Empty;
|
||||
autoresponses["body"] = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddForwardingInfo(string[] forwardings, bool removeCopies)
|
||||
{
|
||||
TreeNode redirection = deliveryConfig.ChildNodes["redirection"];
|
||||
|
||||
if (redirection == null)
|
||||
{
|
||||
redirection = new TreeNode();
|
||||
redirection.NodeName = "redirection";
|
||||
deliveryConfig.ChildNodes.Add(redirection);
|
||||
}
|
||||
|
||||
if (forwardings.Length > 0)
|
||||
{
|
||||
redirection["enabled"] = "1";
|
||||
redirection["stilldeliver"] = removeCopies ? "0" : "1";
|
||||
|
||||
TreeNode redirections = redirection.ChildNodes["redirections"];
|
||||
|
||||
if (redirections == null)
|
||||
{
|
||||
redirections = new TreeNode(redirection);
|
||||
redirections.NodeName = "redirections";
|
||||
redirection.ChildNodes.Add(redirections);
|
||||
}
|
||||
redirections.ChildNodes.Clear();
|
||||
|
||||
foreach (string forwarding in forwardings)
|
||||
{
|
||||
TreeNode node = new TreeNode(redirections);
|
||||
node.NodeValue = forwarding;
|
||||
redirections.ChildNodes.Add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Read(MailGroup group)
|
||||
{
|
||||
userConfig["domain"] = GetDomainName(group.Name);
|
||||
userConfig["enabled"] = group.Enabled ? "1" : "0";
|
||||
userConfig["user"] = GetAccountName(group.Name);
|
||||
|
||||
AddForwardingInfo(group.Members, true);
|
||||
}
|
||||
|
||||
public bool IsMailGroup()
|
||||
{
|
||||
TreeNode redirection = deliveryConfig.ChildNodes["redirection"];
|
||||
|
||||
if (redirection != null)
|
||||
if (redirection["stilldeliver"] == "0")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static AmsMailbox[] GetMailboxes(Tree config, string domainName)
|
||||
{
|
||||
List<AmsMailbox> list = new List<AmsMailbox>();
|
||||
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string account = node["user"];
|
||||
string amsDomain = node["domain"];
|
||||
if (string.Compare(amsDomain, domainName, true) == 0)
|
||||
{
|
||||
AmsMailbox mb = new AmsMailbox(string.Concat(account, "@", amsDomain));
|
||||
mb.Load(node);
|
||||
mb.LoadAccountConfig();
|
||||
list.Add(mb);
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static AmsMailbox[] GetMailGroups(Tree config, string domainName)
|
||||
{
|
||||
List<AmsMailbox> groups = new List<AmsMailbox>();
|
||||
|
||||
foreach (TreeNode node in config.ChildNodes)
|
||||
{
|
||||
string account = node["user"];
|
||||
string amsDomain = node["domain"];
|
||||
|
||||
if (string.Compare(amsDomain, domainName, true) == 0)
|
||||
{
|
||||
AmsMailbox mb = new AmsMailbox(string.Concat(account, "@", amsDomain));
|
||||
mb.Load(node);
|
||||
mb.LoadAccountConfig();
|
||||
|
||||
if (mb.IsMailGroup())
|
||||
groups.Add(mb);
|
||||
}
|
||||
}
|
||||
|
||||
return groups.ToArray();
|
||||
}
|
||||
|
||||
public static string GetAccountName(string email)
|
||||
{
|
||||
if (email.IndexOf("@") == -1)
|
||||
return email;
|
||||
|
||||
return email.Substring(0, email.IndexOf("@"));
|
||||
}
|
||||
|
||||
public static string GetDomainName(string email)
|
||||
{
|
||||
return email.Substring(email.IndexOf("@") + 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("WebsitePanel.Providers.Mail.AbilityMailServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyProduct("WebsitePanel.Providers.Mail.AbilityMailServer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("46384882-0684-45c2-933b-bf680e2f3cf5")]
|
|
@ -0,0 +1,258 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Providers.Mail
|
||||
{
|
||||
public class Tree
|
||||
{
|
||||
private TreeNodeCollection childNodes;
|
||||
|
||||
public TreeNodeCollection ChildNodes
|
||||
{
|
||||
get { return childNodes; }
|
||||
}
|
||||
|
||||
public Tree()
|
||||
{
|
||||
childNodes = new TreeNodeCollection();
|
||||
}
|
||||
|
||||
public void Serialize(StringBuilder builder)
|
||||
{
|
||||
foreach(TreeNode node in childNodes.ToArray())
|
||||
node.Serialize(builder);
|
||||
}
|
||||
}
|
||||
|
||||
public class TreeNodeCollection : ICollection<TreeNode>
|
||||
{
|
||||
private List<TreeNode> _collection;
|
||||
private Dictionary<string, TreeNode> _searchIndex;
|
||||
|
||||
public TreeNode this[string keyName]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_searchIndex.ContainsKey(keyName))
|
||||
return _searchIndex[keyName];
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNodeCollection()
|
||||
{
|
||||
_collection = new List<TreeNode>();
|
||||
_searchIndex = new Dictionary<string, TreeNode>();
|
||||
}
|
||||
|
||||
public void Add(TreeNode node)
|
||||
{
|
||||
string keyName = node.NodeName;
|
||||
|
||||
_collection.Add(node);
|
||||
|
||||
if (keyName != TreeNode.Unnamed)
|
||||
_searchIndex.Add(keyName, node);
|
||||
}
|
||||
|
||||
public TreeNode[] ToArray()
|
||||
{
|
||||
return _collection.ToArray();
|
||||
}
|
||||
|
||||
#region ICollection<TreeNode> Members
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_collection.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(TreeNode item)
|
||||
{
|
||||
return _collection.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo(TreeNode[] array, int arrayIndex)
|
||||
{
|
||||
_collection.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return _collection.Count; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool Remove(TreeNode item)
|
||||
{
|
||||
return _collection.Remove(item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<TreeNode> Members
|
||||
|
||||
public IEnumerator<TreeNode> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class TreeNode
|
||||
{
|
||||
private Tree root;
|
||||
private TreeNode parent;
|
||||
private TreeNodeCollection childNodes;
|
||||
|
||||
private string nodeName;
|
||||
private string nodeValue;
|
||||
|
||||
public const string Unnamed = "-";
|
||||
|
||||
public TreeNodeCollection ChildNodes
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureChildControlsCreated();
|
||||
|
||||
return childNodes;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsUnnamed
|
||||
{
|
||||
get { return nodeName == Unnamed; }
|
||||
}
|
||||
|
||||
public Tree Root
|
||||
{
|
||||
get { return root; }
|
||||
set { root = value; }
|
||||
}
|
||||
|
||||
public TreeNode Parent
|
||||
{
|
||||
get { return parent; }
|
||||
set { parent = value; }
|
||||
}
|
||||
|
||||
public string NodeName
|
||||
{
|
||||
get { return nodeName; }
|
||||
set { nodeName = value; }
|
||||
}
|
||||
|
||||
public string NodeValue
|
||||
{
|
||||
get { return nodeValue; }
|
||||
set { nodeValue = value; }
|
||||
}
|
||||
|
||||
public string this[string keyName]
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureChildControlsCreated();
|
||||
|
||||
TreeNode keyNode = childNodes[keyName];
|
||||
if (keyNode != null)
|
||||
return keyNode.NodeValue;
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
EnsureChildControlsCreated();
|
||||
|
||||
TreeNode keyNode = childNodes[keyName];
|
||||
if (keyNode == null)
|
||||
{
|
||||
keyNode = new TreeNode(this);
|
||||
keyNode.NodeName = keyName;
|
||||
childNodes.Add(keyNode);
|
||||
}
|
||||
|
||||
keyNode.NodeValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNode(TreeNode parent) : this()
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public TreeNode()
|
||||
{
|
||||
this.nodeName = Unnamed;
|
||||
}
|
||||
|
||||
private void EnsureChildControlsCreated()
|
||||
{
|
||||
if (childNodes == null)
|
||||
childNodes = new TreeNodeCollection();
|
||||
}
|
||||
|
||||
public virtual void Serialize(StringBuilder builder)
|
||||
{
|
||||
if (childNodes != null)
|
||||
{
|
||||
builder.AppendLine(string.Concat("{ ", nodeName));
|
||||
|
||||
foreach (TreeNode node in childNodes)
|
||||
node.Serialize(builder);
|
||||
|
||||
builder.AppendLine("}");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AppendLine(string.Concat(nodeName, "=", nodeValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{54EE4293-6CCB-4859-8B76-90205F7B35A1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WebsitePanel.Providers.Mail</RootNamespace>
|
||||
<AssemblyName>WebsitePanel.Providers.Mail.AbilityMailServer</AssemblyName>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\WebsitePanel.Server\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<WarningsAsErrors>618</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\WebsitePanel.Server\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<WarningsAsErrors>618</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\VersionInfo.cs">
|
||||
<Link>VersionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AbilityMailServer.cs" />
|
||||
<Compile Include="AmsDomain.cs" />
|
||||
<Compile Include="AMSHelper.cs" />
|
||||
<Compile Include="AmsMailbox.cs" />
|
||||
<Compile Include="AmsMailList.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tree.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WebsitePanel.Providers.Base\WebsitePanel.Providers.Base.csproj">
|
||||
<Project>{684C932A-6C75-46AC-A327-F3689D89EB42}</Project>
|
||||
<Name>WebsitePanel.Providers.Base</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\WebsitePanel.Server.Utils\WebsitePanel.Server.Utils.csproj">
|
||||
<Project>{E91E52F3-9555-4D00-B577-2B1DBDD87CA7}</Project>
|
||||
<Name>WebsitePanel.Server.Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue