[Nmailserver-commits] SF.net SVN: nmailserver: [159] NMail/trunk
Brought to you by:
dframpton-oss,
tmyroadctfig
|
From: <tmy...@us...> - 2007-03-04 05:17:46
|
Revision: 159
http://svn.sourceforge.net/nmailserver/?rev=159&view=rev
Author: tmyroadctfig
Date: 2007-03-03 21:17:47 -0800 (Sat, 03 Mar 2007)
Log Message:
-----------
Added NHibernate data projects.
Added Paths:
-----------
NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateAuthProvider.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateUserMap.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.Auth.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.UserMap.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Properties/AssemblyInfo.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/hibernate-configuration.xml
NMail/trunk/NMail.SpoolData.NHibernate/NHibernateSpoolData.cs
NMail/trunk/NMail.SpoolData.NHibernate/NMail.SpoolData.NHibernate.csproj
NMail/trunk/NMail.SpoolData.NHibernate/NMail.SpoolData.NHibernate.hbm.xml
NMail/trunk/NMail.SpoolData.NHibernate/Properties/
NMail/trunk/NMail.SpoolData.NHibernate/Properties/AssemblyInfo.cs
NMail/trunk/NMail.SpoolData.NHibernate/hibernate-configuration.xml
Property Changed:
----------------
NMail/trunk/NMail.LocalStoreData.NHibernate/
NMail/trunk/NMail.SpoolData.NHibernate/
Property changes on: NMail/trunk/NMail.LocalStoreData.NHibernate
___________________________________________________________________
Name: svn:ignore
+ bin
obj
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateAuthProvider.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateAuthProvider.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateAuthProvider.cs 2007-03-04 05:17:47 UTC (rev 159)
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2004-2006 Luke Quinane
+ *
+ * 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.Security.Cryptography;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using NHibernate;
+
+using NMail.Authentication;
+using NMail.Configuration;
+
+// TODO: account lockout if too many bad attempts
+
+namespace NMail.LocalStoreData.NHibernate {
+ public class NHibernateAuthProvider : MarshalByRefObject, IHashAuthProvider {
+
+ /// <summary>
+ /// A map of username to tokens.
+ /// </summary>
+ Dictionary<string, Dictionary<Guid, BasicAuthToken>> currentTokens = new Dictionary<string, Dictionary<Guid, BasicAuthToken>>();
+
+ private void purgeExpiredTokens() {
+ // TODO: implement!!!
+ }
+
+ private void addToCurrentTokens(BasicAuthToken authToken) {
+ // Ensure the user has a token dictionary
+ if (!this.currentTokens.ContainsKey(authToken.Username)) {
+ this.currentTokens.Add(authToken.Username, new Dictionary<Guid, BasicAuthToken>());
+ }
+
+ this.currentTokens[authToken.Username].Add(authToken.TokenId, authToken);
+
+ purgeExpiredTokens();
+ }
+
+ private IAuthenticationToken createValidatedToken(string username, bool disabled, DateTime passwordExpiry) {
+ // TODO: lockout check
+
+ // Check if the password is correct and the account is not disabled, etc
+ if (!disabled) {
+ DateTime expiry = (DateTime.Now + DefaultTokenExpiry > passwordExpiry)
+ ? DateTime.Now + DefaultTokenExpiry
+ : passwordExpiry;
+
+ BasicAuthToken token = new BasicAuthToken(username, passwordExpiry, expiry);
+ addToCurrentTokens(token);
+ return token;
+ }
+
+ return null;
+ }
+
+ #region IAuthenticationProvider
+
+ public DateTime GetTokenExpiry(IAuthenticationToken user) {
+ //// Only basic tokens are valid
+ //BasicAuthToken authToken = user as BasicAuthToken;
+
+ //if (authToken != null && this.currentTokens.ContainsKey(authToken.Username)) {
+ // Dictionary<Guid, BasicAuthToken> userTokens = this.currentTokens[authToken.Username];
+
+ // if (userTokens.ContainsKey(authToken.TokenId)) {
+ // // Don't trust the passed in expiry - we don't know where it has been!
+ // return userTokens[authToken.TokenId].CredentialsExpiry;
+ // }
+ //}
+
+ throw new NotImplementedException();
+
+ // Invalid token
+ return DateTime.MinValue;
+ }
+
+ public bool TokenExpired(IAuthenticationToken user) {
+
+ throw new NotImplementedException();
+ return (GetTokenExpiry(user) > DateTime.Now);
+ }
+
+ public bool ValidToken(IAuthenticationToken user) {
+
+ throw new NotImplementedException();
+ // This also checks if the token is valid as well as not expired
+ return !TokenExpired(user);
+ }
+
+ public bool IsLockedOut(IAuthenticationToken user) {
+
+ throw new NotImplementedException();
+ // TODO: fix this!
+ return false;
+ }
+
+ public bool IsEnabled(IAuthenticationToken user) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Disabled FROM `User` WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", user.Username);
+ // object o = cmd.ExecuteNonQuery();
+
+ // bool disabled = true;
+
+ // if (o is sbyte) {
+ // disabled = ((sbyte) o == 1) ? true : false;
+ // }
+
+ // return (!disabled);
+ // }
+ //}
+
+ throw new NotImplementedException();
+ }
+
+ public bool ChangePassword(IAuthenticationToken user, string newPassword) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "UPDATE `User` SET Password = ?Password WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", user.Username);
+ // cmd.Parameters.Add("?Password", newPassword);
+ // int count = cmd.ExecuteNonQuery();
+
+ // return (count == 1);
+ // }
+ //}
+
+ throw new NotImplementedException();
+ }
+
+ public void ResetLockOut(string username) {
+ throw new NotImplementedException("The method or operation is not implemented.");
+ }
+
+ public void SetEnabled(string username, bool enabled) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "UPDATE `User` SET Disabled = ?Disabled WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", username);
+ // cmd.Parameters.Add("?Disabled", !enabled);
+ // int count = cmd.ExecuteNonQuery();
+ // }
+ //}
+
+ throw new NotImplementedException();
+ }
+
+ public IAuthenticationToken Authenticate(string username, string password) {
+ //// Get the hash stored in the database.
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Disabled, LockedOutData, PasswordExpiry, Password FROM User WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", username);
+ // MySqlDataReader reader = cmd.ExecuteReader();
+
+ // if (reader.Read()) {
+ // string dbHash = reader["Password"] as string;
+ // bool disabled = ((sbyte) reader["Disabled"] == 1) ? true : false;
+ // DateTime passwordExpiry = (DateTime) reader["PasswordExpiry"];
+
+ // return createValidatedToken(username, disabled, passwordExpiry);
+ // }
+ // }
+ //}
+
+ throw new NotImplementedException();
+
+ // Hashes do not match or no such user
+ return null;
+ }
+
+ public IAuthenticationToken CreateAuthToken(string username) {
+ //// Get the hash stored in the database.
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT COUNT(*) FROM User WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", username);
+ // long count = (long) cmd.ExecuteScalar();
+
+ // if (count == 1) {
+ // return createValidatedToken(username, false, DateTime.MaxValue);
+ // }
+ // }
+ //}
+
+ throw new NotImplementedException();
+
+ // No such user
+ return null;
+ }
+ #endregion
+
+ #region IHashAuthProvider Members
+
+ public IAuthenticationToken Authenticate(string username, string hash, HashAuthType authType) {
+ //if ((authType & HashAuthType.Ntlm) == HashAuthType.Ntlm) {
+ // // Get the hash stored in the database.
+ // using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Disabled, LockedOutData, PasswordExpiry, Password FROM User WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", username);
+ // MySqlDataReader reader = cmd.ExecuteReader();
+
+ // if (reader.Read()) {
+ // string dbPassword = reader["Password"] as string;
+ // bool disabled = ((sbyte) reader["Disabled"] == 1) ? true : false;
+ // DateTime passwordExpiry = (DateTime) reader["PasswordExpiry"];
+
+ // // Generate a NTLM hash
+ // Type3Message type3Msg = new Type3Message();
+ // type3Msg.Password = dbPassword;
+ // string dbHash = Convert.ToBase64String(type3Msg.NT);
+
+ // if (dbHash == hash) {
+ // // Hashes match, return a valid token
+ // return createValidatedToken(username, disabled, passwordExpiry);
+ // }
+ // }
+ // }
+ // }
+ //}
+
+ throw new NotImplementedException();
+
+ return null;
+ }
+
+ public HashAuthType HashAuthType {
+ get { return HashAuthType.Ntlm; }
+ }
+
+ #endregion
+
+ public static readonly TimeSpan DefaultTokenExpiry = TimeSpan.FromMinutes(30);
+ }
+}
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-03-04 05:17:47 UTC (rev 159)
@@ -0,0 +1,1819 @@
+/*
+ * 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;
+using System.Collections.Generic;
+using System.Data;
+using System.Security.Cryptography;
+using System.Text;
+
+using NHibernate;
+using NHibernate.Expression;
+
+using NMail.Configuration;
+using NMail.DataTypes;
+using NMail.DataTypes.ACLs;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+using NMail.Helper;
+
+// TODO: implement quotas
+
+namespace NMail.LocalStoreData.NHibernate {
+ /// <summary>
+ /// A MySql based local store data provider.
+ /// </summary>
+ [Serializable]
+ public class NHibernateLocalStoreData : MarshalByRefObject, ILocalStoreData {
+
+ global::NHibernate.Cfg.Configuration hibernateCfg;
+
+ ISessionFactory hibernateFactory;
+
+ public NHibernateLocalStoreData() {
+ this.hibernateCfg = new global::NHibernate.Cfg.Configuration();
+ this.hibernateCfg.Configure(System.Reflection.Assembly.GetExecutingAssembly(), "NMail.LocalStoreData.MySql.Resources.hibernate-configuration.xml");
+ this.hibernateCfg.AddAssembly("NMail.LocalStoreData.NHibernate");
+
+ this.hibernateFactory = this.hibernateCfg.BuildSessionFactory();
+ }
+
+ #region ILocalStoreData Members
+
+ #region Message Delivery
+
+ // TODO: update quotas?
+ public void DeliverMessage(LocalStoreDelivery message) {
+ DeliverMessage(message.Message, GetStoreFolder(message.TargetFolder));
+
+ foreach (StoreFolder folder in message.AdditionalFolders) {
+ DeliverMessage(message.Message, GetStoreFolder(folder));
+ }
+ }
+
+ public void DeliverMessage(Message message, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // MySqlTransaction transaction = null;
+
+ // try {
+ // transaction = cnn.BeginTransaction();
+
+ // MySqlCommand cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+
+ // // Get the next folder message id
+ // cmd.CommandText = "SELECT NextMessageId FROM Folder WHERE FolderId=?FolderId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // int folderMessageId = (int)cmd.ExecuteScalar();
+
+ // // Update the next message id
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+ // cmd.CommandText = "UPDATE Folder SET NextMessageId=?NextMessageId WHERE FolderId=?FolderId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?NextMessageId", folderMessageId + 1);
+ // int count = cmd.ExecuteNonQuery();
+ // if (count == 1) {
+ // // Insert the message body
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+ // cmd.CommandText = "INSERT INTO Message (FolderId, FolderMessageId, MimeMessage, Headers, Preamble, Postamble, MessageFlags, Size, InternalDate) " +
+ // "VALUES (?FolderId, ?FolderMessageId, ?MimeMessage, ?Headers, ?Preamble, ?Postamble, ?MessageFlags, ?Size, ?InternalDate)";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", folderMessageId);
+ // cmd.Parameters.Add("?MimeMessage", message.MultipartBody);
+ // cmd.Parameters.Add("?Headers", message.Headers.Data.Bytes);
+ // cmd.Parameters.Add("?Preamble", (message.Preamble != null) ? message.Preamble.Data.Bytes : null);
+ // cmd.Parameters.Add("?Postamble", (message.Postamble != null) ? message.Postamble.Data.Bytes : null);
+ // cmd.Parameters.Add("?MessageFlags", StoreMessageFlags.Recent);
+ // cmd.Parameters.Add("?Size", message.Size);
+ // cmd.Parameters.Add("?InternalDate", DateTime.Now);
+ // count = cmd.ExecuteNonQuery();
+
+ // if (count == 1) {
+ // // Get the message Id
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+ // cmd.CommandText = "SELECT LAST_INSERT_ID()";
+ // long messageId = (long)cmd.ExecuteScalar(); ;
+
+ // if (message.MultipartBody) {
+ // // Insert each part of the message
+ // for (int i = 0; i < message.MimeParts.Count; i++) {
+ // // Insert the current part
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+ // cmd.CommandText = "INSERT INTO MessageData (MessageId, Part, Data) " +
+ // "VALUES (?MessageId, ?Part, ?Data)";
+ // cmd.Parameters.Add("?MessageId", messageId);
+ // cmd.Parameters.Add("?Part", i + 1); // Count from 1
+ // cmd.Parameters.Add("?Data", message.MimeParts[i].Data.Bytes);
+ // count = cmd.ExecuteNonQuery();
+
+ // if (count != 1) {
+ // // Insert failed, rollback
+ // throw new System.Data.DataException("Error inserting message part.");
+ // }
+ // }
+ // } else {
+ // // Insert the body data
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.Connection = cnn;
+
+ // cmd.CommandText = "INSERT INTO MessageData (MessageId, Part, Data) " +
+ // "VALUES (?MessageId, 1, ?Data)";
+ // cmd.Parameters.Add("?MessageId", messageId);
+ // cmd.Parameters.Add("?Data", message.BodyData.Bytes);
+ // count = cmd.ExecuteNonQuery();
+
+ // if (count != 1) {
+ // // Insert failed, rollback
+ // throw new System.Data.DataException("Error inserting message body.");
+ // }
+ // }
+ // } else {
+ // throw new System.Data.DataException("Error inserting message details.");
+ // }
+ // } else {
+ // throw new System.Data.DataException("Error updating next message id.");
+ // }
+
+ // transaction.Commit();
+
+ // } catch (Exception e) {
+ // if (transaction != null) {
+ // transaction.Rollback();
+ // }
+
+ // throw e;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Folder Retrieval and Manipulation
+
+ #region GetStoreFolder
+
+ //private StoreFolder getStoreFolder(Folder folder, MySqlConnection cnn, MySqlTransaction transaction) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.Transaction = transaction;
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetFolderId";
+ // cmd.Parameters.Add("?FolderId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Name", folder.FullFolderName);
+ // cmd.Parameters.Add("?NameSpace", folder.NameSpace);
+ // cmd.Parameters["FolderId"].Direction = ParameterDirection.Output;
+
+ // int count = cmd.ExecuteNonQuery();
+
+ // object o = cmd.Parameters["FolderId"].Value;
+ // int? folderId = (o == DBNull.Value) ? null : (int?) o;
+
+ // if (folderId.HasValue) {
+ // return GetStoreFolder(folderId.Value);
+ // } else {
+ // return null;
+ // }
+ // }
+ //}
+
+ public StoreFolder GetStoreFolder(Folder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // return getStoreFolder(folder, cnn, null);
+ //}
+ throw new NotImplementedException();
+ }
+
+ public StoreFolder GetStoreFolder(int folderId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetFolder";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?ParentId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Name", MySqlDbType.VarChar);
+ // cmd.Parameters.Add("?NameSpace", MySqlDbType.VarChar);
+ // cmd.Parameters.Add("?Children", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["ParentId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Name"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["NameSpace"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Children"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int resultValue = (int) cmd.Parameters["Result"].Value;
+ // LocalStoreFolderResult result = (LocalStoreFolderResult) resultValue;
+
+ // // Check if the lookup succeeded
+ // if (result != LocalStoreFolderResult.OkSuccessful) {
+ // return null;
+ // }
+
+ // // Parse out all the returned values
+ // string name = (string) cmd.Parameters["Name"].Value;
+ // string nameSpace = (string) cmd.Parameters["NameSpace"].Value;
+ // int children = (int) cmd.Parameters["Children"].Value;
+ // int? parentId = (cmd.Parameters["ParentId"].Value == DBNull.Value)
+ // ? null
+ // : (int?) cmd.Parameters["ParentId"].Value;
+
+ // // Return the folder object
+ // return new StoreFolder(nameSpace,
+ // name,
+ // folderId,
+ // parentId,
+ // (children != 0));
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region CreateFolder
+ /// <summary>
+ /// Creates a new folder.
+ /// </summary>
+ /// <remarks>
+ /// 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 result of the attempt to create the folder.</returns>
+ public LocalStoreFolderResult CreateFolder(int userId, StoreFolder parent, Folder newFolder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // int? parentFolderId = (parent == null) ? null : (int?) parent.FolderId;
+
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "CreateFolder";
+ // cmd.Parameters.Add("?ParentId", parentFolderId);
+ // cmd.Parameters.Add("?NamespaceId", 1);
+ // cmd.Parameters.Add("?Name", newFolder.FullFolderName);
+ // cmd.Parameters.Add("?UserId", userId);
+ // cmd.Parameters.Add("?FolderId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["FolderId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int result = (int) cmd.Parameters["Result"].Value;
+
+ // return (LocalStoreFolderResult) result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region DeleteFolder
+ /// <summary>
+ /// Deletes an existing folder.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="folderId">The Id of the folder to delete.</param>
+ /// <returns>The result of the delete attempt.</returns>
+ public LocalStoreFolderResult DeleteFolder(int folderId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "DeleteFolder";
+ // cmd.Parameters.Add("?DeleteFolderId", folderId);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int result = (int) cmd.Parameters["Result"].Value;
+
+ // return (LocalStoreFolderResult) result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region RenameFolder
+ public LocalStoreFolderResult RenameFolder(StoreFolder folder, string newFolderName) {
+ ///* Several cases:
+ // * a1.b1 -> a1.b2 => simply rename "a1.b1" to "a1.b2"
+ // * a1.b1 -> a2.b1 => rename "a1" to "a2" and "a1.b1" to "a2.b1"
+ // * a1.b1.c1 -> a1.b2.c1 => rename "a1.b1" to "a1.b2" and "a1.b1.c1" to "a1.b2.c1"
+ // * So simply rename the folder and any children.
+ // *
+ // * Also renaming "a1.b1" to "a2.b2" causes problems so renaming will be limited
+ // * to only allow changing the end folder in the hierarchy. For example:
+ // * a1.b1 -> a1.b2 is ok
+ // * a1 -> a2 is ok
+ // * a1.b1 to a2.b1 is not ok
+ // */
+
+ //// Check only the top level folder is being renamed
+ //char[] delim = { NMailConfiguration.Current.LocalStore.FolderDelimiter };
+ //string[] folderParts = folder.FullFolderName.Split(delim);
+ //string[] newParts = newFolderName.Split(delim);
+
+ //if (folderParts.Length != newParts.Length) {
+ // return LocalStoreFolderResult.NotPermitted;
+ //}
+
+ //for (int i = 0; i < folderParts.Length - 1; i++) {
+ // if (!folderParts[i].ToLower().Equals(newParts[i].ToLower())) {
+ // return LocalStoreFolderResult.NotPermitted;
+ // }
+ //}
+
+ //// Only the last part of the folder name has changed, proceed with the rename
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // MySqlTransaction transaction = cnn.BeginTransaction();
+
+ // // Check for a folder with the same name
+ // Folder newFolder = new Folder(folder.NameSpace, newFolderName);
+ // if (getStoreFolder(newFolder, cnn, transaction) != null) {
+ // transaction.Commit();
+ // return LocalStoreFolderResult.AlreadyExists;
+ // }
+
+ // throw new NotImplementedException();
+ // // TODO: rename the folder
+ // // TODO: recursively rename all children
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetChildren
+ public StoreFolder[] GetChildren(StoreFolder parent) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetFolderChildIds";
+ // cmd.Parameters.Add("?FolderId", parent.FolderId);
+
+ // using (MySqlDataReader reader = cmd.ExecuteReader()) {
+ // List<int> childIds = new List<int>();
+
+ // while (reader.Read()) {
+ // int childFolderId = (int)reader["FolderId"];
+ // childIds.Add(childFolderId);
+ // }
+
+ // reader.Close();
+
+ // List<StoreFolder> children = new List<StoreFolder>();
+
+ // foreach (int childFolderId in childIds) {
+ // StoreFolder folder = GetStoreFolder(childFolderId);
+
+ // if (folder != null) {
+ // children.Add(folder);
+ // }
+ // }
+
+ // return children.ToArray();
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ /// <summary>
+ /// Gets a list of all folders
+ /// </summary>
+ /// <returns>The list of folders.</returns>
+ public StoreFolder[] GetFolders() {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetFolders";
+
+ // List<StoreFolder> folders = new List<StoreFolder>();
+ // MySqlDataReader reader = cmd.ExecuteReader();
+
+ // while (reader.Read()) {
+ // int folderId = (int) reader["FolderId"];
+ // string nameSpace = (string) reader["NameSpace"];
+ // string name = (string) reader["Name"];
+ // int? parentId = (reader["ParentFolderId"] == DBNull.Value)
+ // ? null
+ // : (int?) reader["ParentFolderId"];
+
+ // // TODO: Get HasChildren from the reader
+ // folders.Add(new StoreFolder(nameSpace, name, folderId, parentId, false));
+ // }
+
+ // return folders.ToArray();
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Folder Subscription
+
+ #region GetSubscribedFolders
+ public StoreFolder[] GetSubscribedFolders(string userName) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT s.FolderId AS FolderId FROM User u, Subscription s WHERE s.UserId = u.UserId AND u.UserName = ?UserName";
+ // cmd.Parameters.Add("?UserName", userName);
+
+ // using (MySqlDataReader reader = cmd.ExecuteReader()) {
+ // List<int> subscribedIds = new List<int>();
+
+ // while (reader.Read()) {
+ // int currentId = (int) reader["FolderId"];
+
+ // subscribedIds.Add(currentId);
+ // }
+ // reader.Close();
+
+ // List<StoreFolder> subscribedFolders = new List<StoreFolder>();
+ // foreach (int currentId in subscribedIds) {
+ // subscribedFolders.Add(GetStoreFolder(currentId));
+ // }
+ // return subscribedFolders.ToArray();
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Subscribe
+ //private bool folderSubscribed(int userId, int folderId) {
+ // using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT COUNT(*) FROM Subscription WHERE UserId = ?UserId AND FolderId = ?FolderId";
+ // cmd.Parameters.Add("?UserId", userId);
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // long count = (long) cmd.ExecuteScalar();
+
+ // return (count > 0);
+ // }
+ // }
+ //}
+
+ public void Subscribe(string userName, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT UserId FROM User WHERE UserName = ?UserName";
+ // cmd.Parameters.Add("?UserName", userName);
+ // int userId = (int) cmd.ExecuteScalar();
+
+ // if (!folderSubscribed(userId, folder.FolderId)) {
+ // cmd.CommandText = "INSERT INTO Subscription (UserId, FolderId) VALUES(?UserId, ?FolderId)";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?UserId", userId);
+
+ // if (cmd.ExecuteNonQuery() != 1) {
+ // throw new System.Data.DataException("Error updating subscription.");
+ // }
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region UnSubscribe
+ public void UnSubscribe(string userName, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT UserId FROM User WHERE Username = ?Username";
+ // cmd.Parameters.Add("?Username", userName);
+ // int userId = (int)cmd.ExecuteScalar();
+
+ // cmd.CommandText = "DELETE FROM Subscription WHERE UserId = ?UserId AND FolderId = ?FolderId";
+ // cmd.Parameters.Add("?UserId", userId);
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+
+ // if (cmd.ExecuteNonQuery() != 1) {
+ // throw new System.Data.DataException("Error updating subscription.");
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #endregion
+
+ #region Message Id and Offset
+
+ #region GetNextMessageId
+ public int GetNextMessageId(int messageId, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT FolderMessageId FROM Message WHERE FolderId = ?FolderId AND FolderMessageId > ?MessageId ORDER BY FolderMessageId LIMIT 1";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?MessageId", messageId);
+ // object o = cmd.ExecuteScalar();
+
+ // return (o == null) ? 0 : (int)o;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+
+ public int GetNextMessageId(StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT NextMessageId FROM Folder WHERE FolderId = ?FolderId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // object o = cmd.ExecuteScalar();
+
+ // return (o == null) ? 0 : (int)o;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageId
+ public int GetMessageId(int messageOffset, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT FolderMessageId FROM Message WHERE FolderId = ?FolderId ORDER BY FolderMessageId LIMIT 1 OFFSET ?Offset";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?Offset", messageOffset - 1);
+ // return (int)cmd.ExecuteScalar();
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageOffset
+ public int GetMessageOffset(int messageId, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT COUNT(*) FROM Message WHERE FolderId = ?FolderId AND FolderMessageId <= ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // return Convert.ToInt32((long)cmd.ExecuteScalar());
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageIds
+ public IList<int> GetMessageIds(int folderId) {
+ //List<int> result = new List<int>();
+
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT FolderMessageId FROM Message WHERE FolderId = ?FolderId";
+ // cmd.Parameters.Add("?FolderId", folderId);
+
+ // MySqlDataReader reader = cmd.ExecuteReader();
+
+ // while (reader.Read()) {
+ // int id = (int) reader["FolderMessageId"];
+ // result.Add(id);
+ // }
+ // }
+ //}
+
+ //return result;
+ throw new NotImplementedException();
+ }
+ #endregion
+ #endregion
+
+ #region Message Flags
+
+ #region GetMessageFlags
+ public StoreMessageFlags GetMessageFlags(int messageId, StoreFolder folder) {
+ //StoreMessageFlags flags = StoreMessageFlags.None;
+
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT MessageFlags FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // object o = cmd.ExecuteScalar();
+
+ // if (!Convert.IsDBNull(o)) {
+ // flags = (StoreMessageFlags) o;
+ // }
+ // }
+ //}
+
+ //return flags;
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region SetMessageFlags
+ public void SetMessageFlags(int messageId, StoreFolder folder, StoreMessageFlags flags) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "UPDATE Message SET MessageFlags = ?MessageFlags WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // cmd.Parameters.Add("?MessageFlags", (int) flags);
+
+ // if (cmd.ExecuteNonQuery() != 1) {
+ // throw new Exception("Error updating message flags.");
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #endregion
+
+ #region Message Retrieval
+
+ #region GetInternalDate
+ public DateTime GetInternalDate(int messageId, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT InternalDate FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // return (DateTime)cmd.ExecuteScalar();
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageSize
+ public int GetMessageSize(int messageId, StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Size FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // return (int)cmd.ExecuteScalar();
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageHeaders
+ public MessageHeaders GetMessageHeaders(int messageId, int folderId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Headers FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // byte[] headerBytes = (byte[]) cmd.ExecuteScalar();
+
+ // if (headerBytes == null) {
+ // return null;
+ // } else {
+ // return new MessageHeaders(new ByteString(headerBytes, Encoding.ASCII));
+ // }
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageMimePart
+ public IMessageBodyPart GetMessageMimePart(int messageId, int folderId, int messagePart) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT md.Data FROM Message m, MessageData md WHERE m.MessageId = md.MessageId AND m.FolderId = ?FolderId AND m.FolderMessageId = ?FolderMessageId AND md.Part = ?Part";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // cmd.Parameters.Add("?Part", messagePart);
+ // byte[] bodyDataBytes = (byte[]) cmd.ExecuteScalar();
+ // return new SimpleBodyPart(new ByteString(bodyDataBytes, Encoding.ASCII));
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessage
+ public Message GetMessage(int messageId, int folderId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT MimeMessage FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+
+ // SByte sb = (SByte) cmd.ExecuteScalar();
+ // bool mimeMessage = (sb == 1) ? true : false;
+ // Message result = null;
+ // MessageHeaders headers = this.GetMessageHeaders(messageId, folderId);
+
+ // if (mimeMessage) {
+ // cmd.CommandText = "SELECT Preamble, Postamble FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // MySqlDataReader reader = cmd.ExecuteReader();
+
+ // if (reader.Read()) {
+ // MessageDataPart preamble = null;
+ // MessageDataPart postamble = null;
+
+ // if (reader["Preamble"] != DBNull.Value) {
+ // preamble = new MessageDataPart(new ByteString((byte[]) reader["Preamble"], Encoding.ASCII)); // TODO: check if encoding is ok?
+ // }
+ // if (reader["Postamble"] != DBNull.Value) {
+ // postamble = new MessageDataPart(new ByteString((byte[]) reader["Postamble"], Encoding.ASCII)); // TODO: check if encoding is ok?
+ // }
+ // reader.Close();
+
+ // cmd.CommandText = "SELECT md.Data FROM Message m, MessageData md WHERE m.MessageId = md.MessageId AND m.FolderId = ?FolderId AND m.FolderMessageId = ?FolderMessageId ORDER BY md.Part";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // reader = cmd.ExecuteReader();
+ // ArrayList mimePartList = new ArrayList();
+
+ // while (reader.Read()) {
+ // IMessageBodyPart currentPart = MessageHelper.ParseMessage(new ByteString((byte[]) reader["Data"], Encoding.ASCII)); // TODO: check if encoding is ok?
+ // mimePartList.Add(currentPart);
+ // }
+
+ // IMessageBodyPart[] mimeParts = (IMessageBodyPart[]) mimePartList.ToArray(typeof(IMessageBodyPart));
+ // result = new Message(new MultipartBodyPart(headers, preamble, mimeParts, postamble));
+ // }
+
+ // } else {
+ // cmd.CommandText = "SELECT md.Data FROM Message m, MessageData md WHERE m.MessageId = md.MessageId AND m.FolderId = ?FolderId AND m.FolderMessageId = ?FolderMessageId AND md.Part = 1";
+ // cmd.Parameters.Add("?FolderId", folderId);
+ // cmd.Parameters.Add("?FolderMessageId", messageId);
+ // byte[] data = (byte[]) cmd.ExecuteScalar();
+
+ // result = new Message(new SimpleBodyPart(headers, new ByteString(data, Encoding.ASCII))); // TODO: check if encoding is ok?
+ // }
+
+ // return result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #endregion
+
+ #region Message Counts
+
+ #region GetMessageCount
+ public int GetMessageCount(StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT COUNT(*) as MessageCount FROM Message WHERE FolderId = ?FolderId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // return Convert.ToInt32((Int64)cmd.ExecuteScalar());
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region GetMessageCountWithFlags
+ public int GetMessageCountWithFlags(StoreFolder folder, StoreMessageFlags flags) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT COUNT(*) FROM Message WHERE FolderId = ?FolderId AND MessageFlags & ?MessageFlags = ?MessageFlags";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?MessageFlags", flags);
+ // return Convert.ToInt32((long) cmd.ExecuteScalar());
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #endregion
+
+ #region PurgeDeletedMessages
+ public int[] PurgeDeletedMessages(StoreFolder folder) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // ArrayList folderMsgIds = new ArrayList();
+ // MySqlTransaction transaction = cnn.BeginTransaction();
+
+ // MySqlCommand cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.CommandText = "SELECT FolderMessageId FROM Message WHERE FolderId = ?FolderId AND ((MessageFlags & ?DeletedFlag) != 0)";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?DeletedFlag", (int) StoreMessageFlags.Deleted);
+
+ // // Get a list of deleted messages
+ // MySqlDataReader reader = cmd.ExecuteReader();
+ // while (reader.Read()) {
+ // folderMsgIds.Add((int) reader["FolderMessageId"]);
+ // }
+ // reader.Close();
+
+ // int[] result = new int[folderMsgIds.Count];
+ // for (int i = 0; i < folderMsgIds.Count; i++) {
+ // result[i] = GetMessageOffset((int) folderMsgIds[i], folder);
+
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.CommandText = "SELECT MessageId FROM Message WHERE FolderId = ?FolderId AND FolderMessageId = ?FolderMessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?FolderMessageId", (int) folderMsgIds[i]);
+ // long messageId = (long) cmd.ExecuteScalar();
+
+ // cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+ // cmd.CommandText = "DELETE FROM Message WHERE MessageId = ?MessageId";
+ // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ // cmd.Parameters.Add("?MessageId", messageId);
+
+ // if (cmd.ExecuteNonQuery() != 1) {
+ // transaction.Rollback();
+ // throw new Exception("Error deleting message.");
+ // }
+ // }
+
+ // transaction.Commit();
+ // return result;
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Load and Save Object
+ /// <summary>
+ /// Gets a serialized object that can be used by either an validation or a delivery action.
+ /// </summary>
+ /// <param name="key">A key to identify which object to get.</param>
+ /// <returns>The object.</returns>
+ public object LoadObject(string key) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandText = "SELECT Data FROM AuxData WHERE `Key` = ?Key";
+ // cmd.Parameters.Add("?Key", key);
+ // byte[] data = (byte[]) cmd.ExecuteScalar();
+
+ // return SerializationHelper.Deserialize(data);
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Serializes an object that can be used later by either an validation or a delivery action.
+ /// </summary>
+ /// <param name="key">A key to identify the object at load time.</param>
+ public void SaveObject(object o, string key) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // MySqlTransaction trans = cnn.BeginTransaction();
+
+ // MySqlCommand cmd = cnn.CreateCommand();
+ // cmd.CommandText = "DELETE FROM AuxData WHERE `Key` = ?Key";
+ // cmd.Parameters.Add("?Key", key);
+ // cmd.Transaction = trans;
+
+ // cmd.ExecuteNonQuery();
+
+ // cmd = cnn.CreateCommand();
+ // cmd.CommandText = "INSERT INTO AuxData (`Key`, Data) VALUES (?Key, ?Data)";
+ // cmd.Parameters.Add("?Key", key);
+ // cmd.Parameters.Add("?Data", SerializationHelper.Serialize(o));
+ // cmd.Transaction = trans;
+
+ // if (cmd.ExecuteNonQuery() == 1) {
+ // trans.Commit();
+ // } else {
+ // trans.Rollback();
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region User Management
+ #region Get User
+ /// <summary>
+ /// Gets the user for the given username.
+ /// </summary>
+ /// <param name="username">The username to look up.</param>
+ /// <returns>The matching user or null if non is found.</returns>
+ public LocalStoreUser GetUser(string name) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // return getUser(name, cnn, null);
+ //}
+ throw new NotImplementedException();
+ }
+
+ //private LocalStoreUser getUser(string name, MySqlConnection cnn, MySqlTransaction transaction) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.Transaction = transaction;
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetUserFromName";
+ // cmd.Parameters.Add("?Name", name);
+ // cmd.Parameters.Add("?UserId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?QuotaHardLimit", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?QuotaWarnLimit", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?UserFolderId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["UserId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["QuotaHardLimit"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["QuotaWarnLimit"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["UserFolderId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int resultValue = (int) cmd.Parameters["Result"].Value;
+ // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
+
+ // // Check if the lookup succeeded
+ // if (result != LocalStoreUserResult.OkSuccessful) {
+ // return null;
+ // }
+
+ // // Parse out all the returned values
+ // int userId = (int) cmd.Parameters["UserId"].Value;
+ // object quotaHardLimit = cmd.Parameters["QuotaHardLimit"].Value;
+ // object quotaWarnLimit = cmd.Parameters["QuotaWarnLimit"].Value;
+ // int userFolderId = (int) cmd.Parameters["UserFolderId"].Value;
+
+ // int? quotaHardLimitVal = (quotaHardLimit == DBNull.Value) ? null : (int?) quotaHardLimit;
+ // int? quotaWarnLimitVal = (quotaWarnLimit == DBNull.Value) ? null : (int?) quotaWarnLimit;
+
+ // // Return the user object
+ // return new LocalStoreUser(name,
+ // userId,
+ // userFolderId,
+ // quotaWarnLimitVal,
+ // quotaHardLimitVal);
+ // }
+ //}
+
+ /// <summary>
+ /// Gets the user for the given user Id.
+ /// </summary>
+ /// <param name="userId">The Id of the user to look up.</param>
+ /// <returns>The matching user or null if non is found.</returns>
+ public LocalStoreUser GetUser(int userId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // return getUser(userId, cnn, null);
+ //}
+ throw new NotImplementedException();
+ }
+
+ //public LocalStoreUser getUser(int userId, MySqlConnection cnn, MySqlTransaction transaction) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.Transaction = transaction;
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetUserFromId";
+ // cmd.Parameters.Add("?UserId", userId);
+ // cmd.Parameters.Add("?Name", MySqlDbType.VarChar);
+ // cmd.Parameters.Add("?QuotaHardLimit", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?QuotaWarnLimit", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?UserFolderId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["Name"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["QuotaHardLimit"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["QuotaWarnLimit"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["UserFolderId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int resultValue = (int) cmd.Parameters["Result"].Value;
+ // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
+
+ // // Check if the lookup succeeded
+ // if (result != LocalStoreUserResult.OkSuccessful) {
+ // return null;
+ // }
+
+ // // Parse out all the returned values
+ // string name = (string) cmd.Parameters["Name"].Value;
+ // object quotaHardLimit = cmd.Parameters["QuotaHardLimit"].Value;
+ // object quotaWarnLimit = cmd.Parameters["QuotaWarnLimit"].Value;
+ // int userFolderId = (int) cmd.Parameters["UserFolderId"].Value;
+
+ // int? quotaHardLimitVal = (quotaHardLimit == DBNull.Value) ? null : (int?) quotaHardLimit;
+ // int? quotaWarnLimitVal = (quotaWarnLimit == DBNull.Value) ? null : (int?) quotaWarnLimit;
+
+ // // Return the user object
+ // return new LocalStoreUser(name,
+ // userId,
+ // userFolderId,
+ // quotaWarnLimitVal,
+ // quotaHardLimitVal);
+ // }
+ //}
+ #endregion
+
+ #region Get Users
+ /// <summary>
+ /// Gets the list of users that currently exist in the local store.
+ /// </summary>
+ /// <returns>The list of users.</returns>
+ public LocalStoreUser[] GetUsers() {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // MySqlTransaction transaction = cnn.BeginTransaction();
+
+ // try {
+ // MySqlCommand cmd = cnn.CreateCommand();
+ // cmd.Transaction = transaction;
+
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetUserIds";
+ // MySqlDataReader reader = cmd.ExecuteReader();
+ // List<int> userIds = new List<int>();
+
+ // while (reader.Read()) {
+ // int userId = (int) reader["UserId"];
+ // userIds.Add(userId);
+ // }
+ // reader.Close();
+
+ // List<LocalStoreUser> users = new List<LocalStoreUser>();
+ // foreach (int userId in userIds) {
+ // users.Add(getUser(userId, cnn, transaction));
+ // }
+
+ // transaction.Commit();
+ // return users.ToArray();
+
+ // } catch (Exception ex) {
+ // if (transaction != null) {
+ // transaction.Rollback();
+ // }
+
+ // throw ex;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Create User
+ /// <summary>
+ /// Creates a new user in the local store and creates an initial folder.
+ /// </summary>
+ /// <param name="userName">The name of the new user.</param>
+ /// <param name="warnQuota">The warning quota level.</param>
+ /// <param name="hardQuota">The hard quota.</param>
+ /// <returns>The result of the attemp to create a new user.</returns>
+ public LocalStoreUserResult CreateUser(string username, int? warnQuota, int? hardQuota) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "CreateUser";
+ // cmd.Parameters.Add("?Name", username);
+ // cmd.Parameters.Add("?QuotaHardLimit", hardQuota);
+ // cmd.Parameters.Add("?QuotaWarnLimit", warnQuota);
+ // cmd.Parameters.Add("?UserId", MySqlDbType.Int32);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["UserId"].Direction = ParameterDirection.Output;
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int result = (int) cmd.Parameters["Result"].Value;
+
+ // return (LocalStoreUserResult) result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Delete User
+ /// <summary>
+ /// Removes a user from the local store.
+ /// </summary>
+ /// <param name="userId">The Id of the user to delete.</param>
+ /// <returns>The result of the attempt to delete a user.</returns>
+ public LocalStoreUserResult DeleteUser(int userId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "DeleteUser";
+ // cmd.Parameters.Add("?DeleteUserId", userId);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int result = (int) cmd.Parameters["Result"].Value;
+
+ // return (LocalStoreUserResult) result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Update User
+ /// <summary>
+ /// Updates the any changes to the user into the local store.
+ /// </summary>
+ /// <param name="user">The user details to update.</param>
+ /// <returns>The result of the attempt to update the user.</returns>
+ public LocalStoreUserResult UpdateUser(LocalStoreUser user) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "UpdateUser";
+ // cmd.Parameters.Add("?UserId", user.UserId);
+ // cmd.Parameters.Add("?Name", user.Username);
+ // cmd.Parameters.Add("?QuotaHardLimit", user.QuotaHardLimit);
+ // cmd.Parameters.Add("?QuotaWarnLimit", user.QuotaWarnLimit);
+ // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
+ // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+
+ // cmd.ExecuteNonQuery();
+
+ // int result = (int) cmd.Parameters["Result"].Value;
+
+ // return (LocalStoreUserResult) result;
+ // }
+ //}
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ /// <summary>
+ /// Gets a list of folders that belong to the user with the given user Id.
+ /// </summary>
+ /// <param name="userId">The Id of the user to get the folder for.</param>
+ /// <returns>The list of folders or null if the user Id is invalid.</returns>
+ public StoreFolder[] GetUserFolders(int userId) {
+ //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ // using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // cmd.CommandType = CommandType.StoredProcedure;
+ // cmd.CommandText = "GetUserFolders";
+ // cmd.Parameters.Add("?UserId", userId);
+
+ // ...
[truncated message content] |