/// <summary>
/// Creates new IMAP folder.
/// </summary>
/// <param name="accessingUser">User who accesses this method.
/// User needs r permission to call this method or Exception is thrown.
/// There is special user 'system' for which permission check is skipped.</param>
/// <param name="folderOwnerUser">User who's folder it is.</param>
/// <param name="folder">Folder what contains message to copy. For example: Inbox,Public Folders/Documnets .</param>
public void CreateFolder(string accessingUser,string folderOwnerUser,string folder)
{
/* Implementation notes:
*) Validate values. Throw ArgumnetExcetion if invalid values.
*) Ensure that user exists.
*) Normalize folder. Remove '/' from folder start and end, ... .
*) Do Shared Folders mapping.
*) Ensure that folder doesn't exists. Throw Exception if don't.
*) See if user has sufficient permissions. User requires 'c' permission.
There is builtin user system, skip ACL for it.
*) Create folder.
*/
//--- Validate values -------------------//
ArgsValidator.ValidateUserName(folderOwnerUser);
ArgsValidator.ValidateFolder(folder);
//---------------------------------------//
// Ensure that user exists.
if(!UserExists(folderOwnerUser)){
throw new Exception("User '" + folderOwnerUser + "' doesn't exist !");
}
// Normalize folder. Remove '/' from folder start and end.
folder = API_Utlis.NormalizeFolder(folder);
// Do Shared Folders mapping.
string originalFolder = folder;
SharedFolderMapInfo mappedFolder = MapSharedFolder(originalFolder);
if(mappedFolder.IsSharedFolder){
folderOwnerUser = mappedFolder.FolderOnwer;
folder = mappedFolder.Folder;
if(folderOwnerUser == "" || folder == ""){
throw new ArgumentException("Specified root folder '" + originalFolder + "' isn't accessible !");
}
}
// Ensure that folder doesn't exists. Throw Exception if don't.
if(FolderExists(folderOwnerUser + "/" + folder)){
throw new Exception("Folder '" + folder + "' already exist !");
}
// See if user has sufficient permissions. User requires 'c' permission.
// There is builtin user system, skip ACL for it.
if(accessingUser.ToLower() != "system"){
IMAP_ACL_Flags acl = GetUserACL(folderOwnerUser,folder,accessingUser);
if((acl & IMAP_ACL_Flags.c) == 0){
throw new InsufficientPermissionsException("Insufficient permissions for folder '" + accessingUser + "/" + folder + "' !");
}
}
//--- Create folder
using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_CreateFolder")){
sqlCmd.AddParameter("_folderID",NpgsqlDbType.Varchar,Guid.NewGuid().ToString());
sqlCmd.AddParameter("_userName",NpgsqlDbType.Varchar,folderOwnerUser);
sqlCmd.AddParameter("_folder" ,NpgsqlDbType.Varchar,folder);
DataSet ds = sqlCmd.Execute();
}
}
/// <summary>
/// AAdds new remote pop3 server to user.
/// </summary>
/// <param name="serverID">Server ID. Suggested value is Guid.NewGuid() .</param>
/// <param name="userName">User name. Use <see cref="IMailServerApi.GetUsers">GetUsers()</see> to get valid values.</param>
/// <param name="description">Remote server description.</param>
/// <param name="remoteServer">Remote server name.</param>
/// <param name="remotePort">Remote server port.</param>
/// <param name="remoteUser">Remote server user name.</param>
/// <param name="remotePassword">Remote server password.</param>
/// <param name="useSSL">Specifies if SSL must be used to connect to remote server.</param>
/// <param name="enabled">Specifies if remote server is enabled.</param>
/// <remarks>Throws exception if specified user remote server already exists.</remarks>
public void AddUserRemoteServer(string serverID,string userName,string description,string remoteServer,int remotePort,string remoteUser,string remotePassword,bool useSSL,bool enabled)
{
if(serverID.Length == 0){
throw new Exception("You must specify serverID");
}
if(userName.Length == 0){
throw new Exception("You must specify userName");
}
using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUserRemoteServer")){
sqlCmd.AddParameter("_serverID" ,NpgsqlDbType.Varchar,serverID);
sqlCmd.AddParameter("_userName" ,NpgsqlDbType.Varchar,userName);
sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description);
sqlCmd.AddParameter("_remoteServer" ,NpgsqlDbType.Varchar,remoteServer);
sqlCmd.AddParameter("_remotePort" ,NpgsqlDbType.Integer,remotePort);
sqlCmd.AddParameter("_remoteUserName" ,NpgsqlDbType.Varchar,remoteUser);
sqlCmd.AddParameter("_remotePassword" ,NpgsqlDbType.Varchar,remotePassword);
sqlCmd.AddParameter("_useSSL" ,NpgsqlDbType.Boolean,useSSL);
sqlCmd.AddParameter("_enabled" ,NpgsqlDbType.Boolean,enabled);
DataSet ds = sqlCmd.Execute();
}
}
/// <summary>
/// Updates recycle bin settings.
/// </summary>
/// <param name="deleteToRecycleBin">Specifies if deleted messages are store to recycle bin.</param>
/// <param name="deleteMessagesAfter">Specifies how old messages will be deleted.</param>
public void UpdateRecycleBinSettings(bool deleteToRecycleBin,int deleteMessagesAfter)
{
using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_UpdateRecycleBinSettings")){
sqlCmd.AddParameter("_deleteToRecycleBin" ,NpgsqlDbType.Boolean,deleteToRecycleBin);
sqlCmd.AddParameter("_deleteMessagesAfter",NpgsqlDbType.Integer,deleteMessagesAfter);
DataSet ds = sqlCmd.Execute();
}
}
/// <summary>
/// Updates user group info.
/// </summary>
/// <param name="groupID">Group ID.</param>
/// <param name="groupName">Group name.</param>
/// <param name="description">Group description.</param>
/// <param name="enabled">Specifies if group is enabled.</param>
public void UpdateGroup(string groupID,string groupName,string description,bool enabled)
{
/* Implementation notes:
*) Validate values. Throw ArgumnetExcetion if invalid values.
*) Ensure that group with specified ID does exist. Throw Exception if doesn't.
*) If group name is changed, ensure that new group name won't conflict
any other group or user name. Throw Exception if does.
*) Udpate group.
*/
//--- Validate values --------------------//
if(groupID == null || groupID == ""){
throw new Exception("Invalid groupID value, groupID can't be '' or null !");
}
ArgsValidator.ValidateUserName(groupName);
ArgsValidator.ValidateNotNull(description);
//----------------------------------------//
/* We handle these is SQL, sql throws Excption
*) Ensure that group with specified ID does exist. Throw Exception if doesn't.
*) If group name is changed, ensure that new group name won't conflict
any other group or user name. Throw Exception if does.
*/
// Update group
using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_UpdateGroup")){
sqlCmd.AddParameter("_groupID" ,NpgsqlDbType.Varchar,groupID);
sqlCmd.AddParameter("_groupName" ,NpgsqlDbType.Varchar,groupName);
sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description);
sqlCmd.AddParameter("_enabled" ,NpgsqlDbType.Boolean,enabled);
DataSet ds = sqlCmd.Execute();
ds.Tables[0].TableName = "Groups";
}
}
/// <summary>
/// Add new email address to specified mailing list.
/// </summary>
/// <param name="addressID">Address ID. Suggested value is Guid.NewGuid() .</param>
/// <param name="mailingListName">Mailing list name name. Use <see cref="IMailServerApi.GetMailingLists">GetMailingLists()</see> to get valid values.</param>
/// <param name="address">Mailing list member address.</param>
/// <remarks>Throws exception if specified mailing list member already exists.</remarks>
public void AddMailingListAddress(string addressID,string mailingListName,string address)
{
if(addressID.Length == 0){
throw new Exception("You must specify addressID");
}
if(mailingListName.Length == 0){
throw new Exception("You must specify mailingListName");
}
if(address.Length == 0){
throw new Exception("You must specify address");
}
using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddMailingListAddress")){
sqlCmd.AddParameter("_addressID" ,NpgsqlDbType.Varchar,addressID);
sqlCmd.AddParameter("_mailingListName" ,NpgsqlDbType.Varchar,mailingListName);
sqlCmd.AddParameter("_address" ,NpgsqlDbType.Varchar,address);
DataSet ds = sqlCmd.Execute();
}
}
请发表评论