Revision: 120
http://svn.sourceforge.net/nmailserver/?rev=120&view=rev
Author: tmyroadctfig
Date: 2007-01-19 05:01:52 -0800 (Fri, 19 Jan 2007)
Log Message:
-----------
Further work on RemoteAccessService.
Modified Paths:
--------------
NMail/trunk/NMail.RemoteAccessService/App_Code/RemoteAccessService.cs
Modified: NMail/trunk/NMail.RemoteAccessService/App_Code/RemoteAccessService.cs
===================================================================
--- NMail/trunk/NMail.RemoteAccessService/App_Code/RemoteAccessService.cs 2007-01-19 13:01:16 UTC (rev 119)
+++ NMail/trunk/NMail.RemoteAccessService/App_Code/RemoteAccessService.cs 2007-01-19 13:01:52 UTC (rev 120)
@@ -9,10 +9,14 @@
using NMail.Server;
using NMail.RemoteAccessService.Serializers.DataTypes.LocalStore;
+/// <summary>
+/// A web service that provides access to NMail.
+/// </summary>
[WebService(Namespace = "http://nmailserver.sf.net/RemoteAccessService/1.0")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class RemoteAccessService : System.Web.Services.WebService
{
+ #region Authenticate
/// <summary>
/// Authenticates the current user.
/// </summary>
@@ -24,7 +28,7 @@
[WebMethod]
public string Authenticate(string user, string password)
{
- // TODO: ensure secure
+ // TODO: ensure connection is secure
IAuthenticationToken token = ServiceState.remoteAdmin.NMailServer.AuthenticationProvider.Authenticate(user, password);
@@ -43,7 +47,9 @@
return string.Empty;
}
+ #endregion
+ #region GetNominalFolder
/// <summary>
/// Gets the user's nominal folder.
/// </summary>
@@ -61,13 +67,60 @@
throw new InvalidOperationException("Authentication token is not valid.");
}
+ #endregion
+ #region GetStoreFolder
+ /// <summary>
+ /// Gets a store folder.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="folderId">The folder Id to lookup.</param>
+ /// <returns>The store folder.</returns>
[WebMethod]
- public List<StoreFolderSerializer> GetSubscribedFolders(string authToken)
+ public StoreFolderSerializer GetStoreFolderByFolderId(string authToken, int folderId)
{
IAuthenticationToken token = ValidateAuthenticationToken(authToken);
if (token != null)
{
+ StoreFolder storeFolder = ServiceState.remoteAdmin.NMailServer.LocalStore.GetStoreFolder(token, folderId);
+ return new StoreFolderSerializer(storeFolder);
+ }
+
+ throw new InvalidOperationException("Authentication token is not valid.");
+ }
+
+ /// <summary>
+ /// Gets a store folder.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="folderName">The name of the folder to lookup.</param>
+ /// <returns>The store folder.</returns>
+ [WebMethod]
+ public StoreFolderSerializer GetStoreFolderByName(string authToken, string folderName)
+ {
+ IAuthenticationToken token = ValidateAuthenticationToken(authToken);
+ if (token != null)
+ {
+ StoreFolder storeFolder = ServiceState.remoteAdmin.NMailServer.LocalStore.GetStoreFolder(token, folderName);
+ return new StoreFolderSerializer(storeFolder);
+ }
+
+ throw new InvalidOperationException("Authentication token is not valid.");
+ }
+ #endregion
+
+ #region GetSubscribedFolders
+ /// <summary>
+ /// Gets a list of subscribed folders for the user.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <returns>The list of folders.</returns>
+ [WebMethod]
+ public List<StoreFolderSerializer> GetAllSubscribedFolders(string authToken)
+ {
+ IAuthenticationToken token = ValidateAuthenticationToken(authToken);
+ if (token != null)
+ {
List<StoreFolder> subscribed = new List<StoreFolder>(ServiceState.remoteAdmin.NMailServer.LocalStore.GetSubscribed(token, "*"));
List<StoreFolderSerializer> result = new List<StoreFolderSerializer>();
@@ -81,7 +134,86 @@
throw new InvalidOperationException("Authentication token is not valid.");
}
+ #endregion
+ #region GetFolderMessageCounts
+ /// <summary>
+ /// Gets the number of messages in each requested folder and then the number
+ /// of messages with each matching flag per folder.
+ /// </summary>
+ /// <param name="authToken">The authentication credentials.</param>
+ /// <param name="folderIds">The list of folder Ids to get message counts for.</param>
+ /// <param name="flags">The flags to look up message counts for.</param>
+ /// <returns>The list of counts for each folder Id.</returns>
+ [WebMethod]
+ public List<List<int>> GetFolderMessageCounts(string authToken, List<int> folderIds, int flags)
+ {
+ IAuthenticationToken token = ValidateAuthenticationToken(authToken);
+ if (token != null)
+ {
+ List<List<int>> result = new List<List<int>>();
+ StoreMessageFlags messageFlags = (StoreMessageFlags)flags;
+
+ // Process each folder
+ foreach (int folderId in folderIds)
+ {
+ List<int> currentList = new List<int>();
+ result.Add(currentList);
+
+ StoreFolder storeFolder = ServiceState.remoteAdmin.NMailServer.LocalStore.GetStoreFolder(token, folderId);
+
+ if (storeFolder != null)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCount(token, storeFolder));
+
+ if ((messageFlags & StoreMessageFlags.Answered) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Answered));
+ }
+
+ if ((messageFlags & StoreMessageFlags.Deleted) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Deleted));
+ }
+
+ if ((messageFlags & StoreMessageFlags.Draft) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Draft));
+ }
+
+ if ((messageFlags & StoreMessageFlags.Flagged) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Flagged));
+ }
+
+ if ((messageFlags & StoreMessageFlags.Recent) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Recent));
+ }
+
+ if ((messageFlags & StoreMessageFlags.Seen) != 0)
+ {
+ addMessageCount(currentList, ServiceState.remoteAdmin.NMailServer.LocalStore.GetMessageCountWithFlags(token, storeFolder, StoreMessageFlags.Seen));
+ }
+ }
+ else
+ {
+ // List will remain empty
+ }
+ }
+
+ return result;
+ }
+
+ throw new InvalidOperationException("Authentication token is not valid.");
+ }
+
+ private void addMessageCount(List<int> list, int? item)
+ {
+ list.Add(item.HasValue ? item.Value : -1);
+ }
+ #endregion
+
protected IAuthenticationToken ValidateAuthenticationToken(string authToken)
{
Guid key = new Guid(Convert.FromBase64String(authToken));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|